2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
10 import java.util.Collection;
11 import javax.annotation.Nonnull;
12 import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
13 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
14 import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement;
15 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
16 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
17 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
18 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
19 import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
20 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.ExtendedTypeEffectiveStatementImpl;
21 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.BinaryEffectiveStatementImpl;
22 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.BooleanEffectiveStatementImpl;
23 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.EmptyEffectiveStatementImpl;
24 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.Int16EffectiveStatementImpl;
25 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.Int32EffectiveStatementImpl;
26 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.Int64EffectiveStatementImpl;
27 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.Int8EffectiveStatementImpl;
28 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.StringEffectiveStatementImpl;
29 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.UInt16EffectiveStatementImpl;
30 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.UInt32EffectiveStatementImpl;
31 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.UInt64EffectiveStatementImpl;
32 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.UInt8EffectiveStatementImpl;
34 public class TypeStatementImpl extends AbstractDeclaredStatement<String>
35 implements TypeStatement {
37 protected TypeStatementImpl(final StmtContext<String, TypeStatement, ?> context) {
41 public static class Definition
43 AbstractStatementSupport<String, TypeStatement, EffectiveStatement<String, TypeStatement>> {
46 super(Rfc6020Mapping.TYPE);
50 public String parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value)
51 throws SourceException {
56 public TypeStatement createDeclared(
57 final StmtContext<String, TypeStatement, ?> ctx) {
58 return new TypeStatementImpl(ctx);
62 public EffectiveStatement<String, TypeStatement> createEffective(
63 final StmtContext<String, TypeStatement, EffectiveStatement<String, TypeStatement>> ctx) {
65 // :FIXME improve the test of isExtended - e.g. unknown statements,
67 Collection<StatementContextBase<?, ?, ?>> declaredSubstatements = ctx
68 .declaredSubstatements();
69 boolean isExtended = !declaredSubstatements.isEmpty();
71 return new ExtendedTypeEffectiveStatementImpl(ctx, true);
74 switch (ctx.getStatementArgument()) {
76 return new Int8EffectiveStatementImpl(ctx);
78 return new Int16EffectiveStatementImpl(ctx);
80 return new Int32EffectiveStatementImpl(ctx);
82 return new Int64EffectiveStatementImpl(ctx);
84 return new UInt8EffectiveStatementImpl(ctx);
85 case TypeUtils.UINT16:
86 return new UInt16EffectiveStatementImpl(ctx);
87 case TypeUtils.UINT32:
88 return new UInt32EffectiveStatementImpl(ctx);
89 case TypeUtils.UINT64:
90 return new UInt64EffectiveStatementImpl(ctx);
91 case TypeUtils.STRING:
92 return new StringEffectiveStatementImpl(ctx);
93 case TypeUtils.BOOLEAN:
94 return new BooleanEffectiveStatementImpl(ctx);
96 return new EmptyEffectiveStatementImpl(ctx);
97 case TypeUtils.BINARY:
98 return new BinaryEffectiveStatementImpl(ctx);
100 // :FIXME try to resolve original typedef context here and
101 // return buildEffective of original typedef context
102 return new ExtendedTypeEffectiveStatementImpl(ctx, false);
109 public String getName() {