Fixed SchemaPath resolution for base YANG types. 60/260/2
authorMartin Vitez <mvitez@cisco.com>
Fri, 26 Apr 2013 09:42:59 +0000 (11:42 +0200)
committerMartin Vitez <mvitez@cisco.com>
Mon, 29 Apr 2013 07:38:53 +0000 (09:38 +0200)
Refactored refine statement parsing.

Change-Id: Ic00b86c611f1f56b69d9e09bf197d9ddb79da145
Signed-off-by: Martin Vitez <mvitez@cisco.com>
34 files changed:
opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/java/org/opendaylight/controller/sal/binding/generator/impl/GeneratedTypesTest.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/UsesNodeBuilder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/IdentityrefTypeBuilder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/ModuleBuilder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/TypedefBuilder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/UnionTypeBuilder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/UsesNodeBuilderImpl.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/impl/YangModelParserImpl.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/impl/YangModelParserListenerImpl.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/util/ParserUtils.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/util/RefineHolder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/util/YangModelBuilderUtil.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/model/parser/impl/TypesResolutionTest.java
opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/AbstractSignedInteger.java
opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/AbstractUnsignedInteger.java
opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/BinaryType.java
opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/BitsType.java
opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/BooleanType.java
opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Decimal64.java
opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/EmptyType.java
opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/ExtendedType.java
opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/IdentityrefType.java
opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/InstanceIdentifier.java
opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Int16.java
opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Int32.java
opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Int64.java
opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Int8.java
opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/StringType.java
opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Uint16.java
opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Uint32.java
opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Uint64.java
opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Uint8.java
opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/UnionType.java
opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/YangTypesConverter.java

index 99add7c33470c5d0acc5c7474686ae82ee73c8be..69346b0f72a239554ce115e36a78a1695ac2a896 100644 (file)
@@ -22,7 +22,7 @@ public interface UsesNodeBuilder extends Builder {
     void addAugment(AugmentationSchemaBuilder builder);
     void setAugmenting(boolean augmenting);
     List<RefineHolder> getRefines();
-    void setRefines(List<RefineHolder> refines);
+    void addRefine(RefineHolder refine);
     void addRefineNode(SchemaNodeBuilder refineNode);
     UsesNode build();
 
index 9cf91c73158ed2c8c43659cc7904b4fec222c58f..33b6416234b83750a19e249109f706ef09671281 100644 (file)
@@ -31,10 +31,13 @@ import org.opendaylight.controller.yang.model.util.IdentityrefType;
 public class IdentityrefTypeBuilder extends AbstractTypeAwareBuilder implements
         TypeDefinitionBuilder, Builder {
     private final String baseString;
+    private final SchemaPath schemaPath;
     private QName baseQName;
 
-    public IdentityrefTypeBuilder(String baseString) {
+
+    public IdentityrefTypeBuilder(final String baseString, SchemaPath schemaPath) {
         this.baseString = baseString;
+        this.schemaPath = schemaPath;
     }
 
     public String getBaseString() {
@@ -69,7 +72,7 @@ public class IdentityrefTypeBuilder extends AbstractTypeAwareBuilder implements
 
     @Override
     public IdentityrefType build() {
-        return new IdentityrefType(baseQName);
+        return new IdentityrefType(baseQName, schemaPath);
     }
 
     @Override
index e309172f4ca35177f82aac613da99ec6687037d3..51ab3639bbf4d084e15dde3dddd389d473f53e24 100644 (file)
@@ -29,6 +29,7 @@ import org.opendaylight.controller.yang.model.api.Module;
 import org.opendaylight.controller.yang.model.api.ModuleImport;
 import org.opendaylight.controller.yang.model.api.NotificationDefinition;
 import org.opendaylight.controller.yang.model.api.RpcDefinition;
+import org.opendaylight.controller.yang.model.api.SchemaPath;
 import org.opendaylight.controller.yang.model.api.TypeDefinition;
 import org.opendaylight.controller.yang.model.api.UsesNode;
 import org.opendaylight.controller.yang.model.parser.builder.api.AugmentationSchemaBuilder;
@@ -41,6 +42,7 @@ import org.opendaylight.controller.yang.model.parser.builder.api.TypeAwareBuilde
 import org.opendaylight.controller.yang.model.parser.builder.api.TypeDefinitionAwareBuilder;
 import org.opendaylight.controller.yang.model.parser.builder.api.TypeDefinitionBuilder;
 import org.opendaylight.controller.yang.model.parser.builder.api.UsesNodeBuilder;
+import org.opendaylight.controller.yang.model.parser.util.RefineHolder;
 import org.opendaylight.controller.yang.model.parser.util.YangParseException;
 
 /**
@@ -419,10 +421,9 @@ public class ModuleBuilder implements Builder {
     public UsesNodeBuilder addUsesNode(final String groupingPathStr,
             final List<String> parentPath) {
         final List<String> pathToUses = new ArrayList<String>(parentPath);
-
-        UsesNodeBuilder usesBuilder = new UsesNodeBuilderImpl(groupingPathStr);
-
-        ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes
+        final UsesNodeBuilder usesBuilder = new UsesNodeBuilderImpl(
+                groupingPathStr);
+        final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes
                 .get(pathToUses);
         if (parent != null) {
             parent.addUsesNode(usesBuilder);
@@ -430,33 +431,46 @@ public class ModuleBuilder implements Builder {
 
         pathToUses.add(groupingPathStr);
         addedUsesNodes.put(pathToUses, usesBuilder);
-
+        moduleNodes.put(pathToUses, usesBuilder);
         return usesBuilder;
     }
 
-    public RpcDefinitionBuilder addRpc(final QName qname,
+    public void addRefine(final RefineHolder refine,
             final List<String> parentPath) {
-        List<String> pathToRpc = new ArrayList<String>(parentPath);
+        final List<String> path = new ArrayList<String>(parentPath);
+        final Builder parent = moduleNodes.get(path);
+        if (!(parent instanceof UsesNodeBuilder)) {
+            throw new YangParseException("Failed to parse refine "
+                    + refine.getName());
+        }
+        UsesNodeBuilder usesBuilder = (UsesNodeBuilder) parent;
+        usesBuilder.addRefine(refine);
+        path.add(refine.getName());
+        moduleNodes.put(path, refine);
+    }
 
-        RpcDefinitionBuilder rpcBuilder = new RpcDefinitionBuilder(qname);
+    public RpcDefinitionBuilder addRpc(final QName qname,
+            final List<String> parentPath) {
+        final List<String> pathToRpc = new ArrayList<String>(parentPath);
+        final RpcDefinitionBuilder rpcBuilder = new RpcDefinitionBuilder(qname);
 
         pathToRpc.add(qname.getLocalName());
         addedRpcs.put(pathToRpc, rpcBuilder);
 
-        QName inputQName = new QName(qname.getNamespace(), qname.getRevision(),
-                qname.getPrefix(), "input");
-        ContainerSchemaNodeBuilder inputBuilder = new ContainerSchemaNodeBuilder(
+        final QName inputQName = new QName(qname.getNamespace(),
+                qname.getRevision(), qname.getPrefix(), "input");
+        final ContainerSchemaNodeBuilder inputBuilder = new ContainerSchemaNodeBuilder(
                 inputQName);
-        List<String> pathToInput = new ArrayList<String>(pathToRpc);
+        final List<String> pathToInput = new ArrayList<String>(pathToRpc);
         pathToInput.add("input");
         moduleNodes.put(pathToInput, inputBuilder);
         rpcBuilder.setInput(inputBuilder);
 
-        QName outputQName = new QName(qname.getNamespace(),
+        final QName outputQName = new QName(qname.getNamespace(),
                 qname.getRevision(), qname.getPrefix(), "output");
-        ContainerSchemaNodeBuilder outputBuilder = new ContainerSchemaNodeBuilder(
+        final ContainerSchemaNodeBuilder outputBuilder = new ContainerSchemaNodeBuilder(
                 outputQName);
-        List<String> pathToOutput = new ArrayList<String>(pathToRpc);
+        final List<String> pathToOutput = new ArrayList<String>(pathToRpc);
         pathToOutput.add("output");
         moduleNodes.put(pathToOutput, outputBuilder);
         rpcBuilder.setOutput(outputBuilder);
@@ -577,23 +591,28 @@ public class ModuleBuilder implements Builder {
         parent.setType(type);
     }
 
-    public void addUnionType(List<String> parentPath) {
+    public void addUnionType(final List<String> actualPath,
+            final URI namespace, final Date revision) {
+        List<String> pathToUnion = new ArrayList<String>(actualPath);
         TypeAwareBuilder parent = (TypeAwareBuilder) moduleNodes
-                .get(parentPath);
-        UnionTypeBuilder union = new UnionTypeBuilder();
+                .get(pathToUnion);
+        UnionTypeBuilder union = new UnionTypeBuilder(pathToUnion, namespace,
+                revision);
         parent.setType(union);
 
-        List<String> path = new ArrayList<String>(parentPath);
+        List<String> path = new ArrayList<String>(pathToUnion);
         path.add("union");
 
         moduleNodes.put(path, union);
     }
 
-    public void addIdentityrefType(String baseString, List<String> parentPath) {
+    public void addIdentityrefType(String baseString, List<String> parentPath,
+            SchemaPath schemaPath) {
         List<String> pathToIdentityref = new ArrayList<String>(parentPath);
         TypeAwareBuilder parent = (TypeAwareBuilder) moduleNodes
                 .get(pathToIdentityref);
-        IdentityrefTypeBuilder identityref = new IdentityrefTypeBuilder(baseString);
+        IdentityrefTypeBuilder identityref = new IdentityrefTypeBuilder(
+                baseString, schemaPath);
         parent.setType(identityref);
         dirtyNodes.put(pathToIdentityref, parent);
     }
@@ -608,7 +627,8 @@ public class ModuleBuilder implements Builder {
         return builder;
     }
 
-    public IdentitySchemaNodeBuilder addIdentity(QName qname, List<String> parentPath) {
+    public IdentitySchemaNodeBuilder addIdentity(QName qname,
+            List<String> parentPath) {
         List<String> pathToIdentity = new ArrayList<String>(parentPath);
         IdentitySchemaNodeBuilder builder = new IdentitySchemaNodeBuilder(qname);
         pathToIdentity.add(qname.getLocalName());
@@ -632,14 +652,13 @@ public class ModuleBuilder implements Builder {
         final List<String> pathToUnknown = new ArrayList<String>(parentPath);
         final UnknownSchemaNodeBuilder builder = new UnknownSchemaNodeBuilder(
                 qname);
-
-        final SchemaNodeBuilder parent = (SchemaNodeBuilder) moduleNodes
-                .get(pathToUnknown);
-        if (parent != null) {
-            parent.addUnknownSchemaNode(builder);
+        final Builder parent = moduleNodes.get(pathToUnknown);
+        if (parent instanceof RefineHolder) {
+            ((RefineHolder) parent).addUnknownSchemaNode(builder);
+        } else if (parent instanceof SchemaNodeBuilder) {
+            ((SchemaNodeBuilder) parent).addUnknownSchemaNode(builder);
         }
-
-        return new UnknownSchemaNodeBuilder(qname);
+        return builder;
     }
 
     private class ModuleImpl implements Module {
index e4b1be5d75fd5629253b553559f02f037442bb1a..0e768c1107f4c9a48cbc3eba653476b427509b7f 100644 (file)
@@ -59,7 +59,7 @@ public class TypedefBuilder extends AbstractTypeAwareBuilder implements
         }
 
         typeBuilder = new ExtendedType.Builder(qname, type, description,
-                reference);
+                reference, schemaPath);
 
         typeBuilder.status(status);
         typeBuilder.units(units);
index 50a7a3a1f01a2bf51d1745b04562f62c3a8a57a8..9ab103d71e890696e5ae60367bb48fd5f160906d 100644 (file)
@@ -7,8 +7,10 @@
  */
 package org.opendaylight.controller.yang.model.parser.builder.impl;
 
+import java.net.URI;
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.Date;
 import java.util.List;
 
 import org.opendaylight.controller.yang.common.QName;
@@ -35,10 +37,19 @@ public class UnionTypeBuilder extends AbstractTypeAwareBuilder implements
     private final List<TypeDefinitionBuilder> typedefs;
     private final UnionType instance;
 
-    public UnionTypeBuilder() {
+    private final List<String> actualPath;
+    private final URI namespace;
+    private final Date revision;
+
+    public UnionTypeBuilder(final List<String> actualPath, final URI namespace,
+            final Date revision) {
         types = new ArrayList<TypeDefinition<?>>();
         typedefs = new ArrayList<TypeDefinitionBuilder>();
-        instance = new UnionType(types);
+        instance = new UnionType(actualPath, namespace, revision, types);
+
+        this.actualPath = actualPath;
+        this.namespace = namespace;
+        this.revision = revision;
     }
 
     public List<TypeDefinition<?>> getTypes() {
@@ -203,6 +214,18 @@ public class UnionTypeBuilder extends AbstractTypeAwareBuilder implements
                 + UnionTypeBuilder.class.getSimpleName());
     }
 
+    public List<String> getActualPath() {
+        return actualPath;
+    }
+
+    public URI getNamespace() {
+        return namespace;
+    }
+
+    public Date getRevision() {
+        return revision;
+    }
+
     @Override
     public String toString() {
         final StringBuilder result = new StringBuilder(
index 5fb4c99ff6cd8798c7023b2183e92b36014b4231..7d3e9293571f25c155f0271f3ca7fe2ae48181d5 100644 (file)
@@ -32,7 +32,7 @@ public class UsesNodeBuilderImpl implements UsesNodeBuilder, Builder {
     private final SchemaPath groupingPath;\r
     private final Set<AugmentationSchemaBuilder> addedAugments = new HashSet<AugmentationSchemaBuilder>();\r
     private List<SchemaNodeBuilder> refineBuilders = new ArrayList<SchemaNodeBuilder>();\r
-    private List<RefineHolder> refines = Collections.emptyList();\r
+    private List<RefineHolder> refines = new ArrayList<RefineHolder>();\r
 \r
     UsesNodeBuilderImpl(final String groupingPathStr) {\r
         this.groupingPath = parseUsesPath(groupingPathStr);\r
@@ -79,15 +79,14 @@ public class UsesNodeBuilderImpl implements UsesNodeBuilder, Builder {
         refineBuilders.add(refineNode);\r
     }\r
 \r
+    @Override\r
     public List<RefineHolder> getRefines() {\r
         return refines;\r
     }\r
 \r
     @Override\r
-    public void setRefines(List<RefineHolder> refines) {\r
-        if(refines != null) {\r
-            this.refines = refines;\r
-        }\r
+    public void addRefine(RefineHolder refine) {\r
+        refines.add(refine);\r
     }\r
 \r
     private SchemaPath parseUsesPath(final String augmentPath) {\r
index b10798b980ba5e45ab3eae1012012ebb56ad623b..8a724191765c6436c0e52b593452ad1f06fcb27c 100644 (file)
@@ -70,9 +70,9 @@ import org.opendaylight.controller.yang.model.parser.builder.impl.ListSchemaNode
 import org.opendaylight.controller.yang.model.parser.builder.impl.ModuleBuilder;
 import org.opendaylight.controller.yang.model.parser.builder.impl.TypedefBuilder;
 import org.opendaylight.controller.yang.model.parser.builder.impl.UnionTypeBuilder;
+import org.opendaylight.controller.yang.model.parser.builder.impl.UnknownSchemaNodeBuilder;
 import org.opendaylight.controller.yang.model.parser.util.ParserUtils;
 import org.opendaylight.controller.yang.model.parser.util.RefineHolder;
-import org.opendaylight.controller.yang.model.parser.util.RefineHolder.Refine;
 import org.opendaylight.controller.yang.model.parser.util.TypeConstraints;
 import org.opendaylight.controller.yang.model.parser.util.YangParseException;
 import org.opendaylight.controller.yang.model.util.ExtendedType;
@@ -282,9 +282,11 @@ public class YangModelParserImpl implements YangModelParser {
                         }
                     }
                     unionTypes.removeAll(toRemove);
-                } else if(nodeToResolve.getTypedef() instanceof IdentityrefTypeBuilder) {
-                    IdentityrefTypeBuilder idref = (IdentityrefTypeBuilder)nodeToResolve.getTypedef();
-                    nodeToResolve.setType(new IdentityrefType(findFullQName(modules, module, idref)));
+                } else if (nodeToResolve.getTypedef() instanceof IdentityrefTypeBuilder) {
+                    IdentityrefTypeBuilder idref = (IdentityrefTypeBuilder) nodeToResolve
+                            .getTypedef();
+                    nodeToResolve.setType(new IdentityrefType(findFullQName(
+                            modules, module, idref), idref.getPath()));
                 } else {
                     final TypeDefinitionBuilder resolvedType = resolveType(
                             nodeToResolve, modules, module);
@@ -388,7 +390,9 @@ public class YangModelParserImpl implements YangModelParser {
             final TypeDefinitionBuilder old, final boolean seekByTypedefBuilder) {
         if (old instanceof UnionTypeBuilder) {
             final UnionTypeBuilder oldUnion = (UnionTypeBuilder) old;
-            final UnionTypeBuilder newUnion = new UnionTypeBuilder();
+            final UnionTypeBuilder newUnion = new UnionTypeBuilder(
+                    oldUnion.getActualPath(), oldUnion.getNamespace(),
+                    oldUnion.getRevision());
             for (TypeDefinition<?> td : oldUnion.getTypes()) {
                 newUnion.setType(td);
             }
@@ -472,8 +476,8 @@ public class YangModelParserImpl implements YangModelParser {
             copy.setType(baseTdbCopyResolved);
             return copy;
         } else {
-            throw new IllegalStateException(
-                    "TypeDefinitionBuilder in unexpected state");
+            throw new IllegalStateException("Failed to resolve type "
+                    + copy.getQName().getLocalName());
         }
     }
 
@@ -481,14 +485,11 @@ public class YangModelParserImpl implements YangModelParser {
             final QName unknownTypeQName,
             final Map<String, TreeMap<Date, ModuleBuilder>> modules,
             final ModuleBuilder builder) {
-
         // search for module which contains referenced typedef
         final ModuleBuilder dependentModule = findDependentModule(modules,
                 builder, unknownTypeQName.getPrefix());
-
         final TypeDefinitionBuilder lookedUpBuilder = findTypedefBuilderByName(
                 dependentModule, unknownTypeQName.getLocalName());
-
         return copyTypedefBuilder(lookedUpBuilder, true);
     }
 
@@ -497,7 +498,6 @@ public class YangModelParserImpl implements YangModelParser {
             final TypeConstraints constraints,
             final Map<String, TreeMap<Date, ModuleBuilder>> modules,
             final ModuleBuilder builder) {
-
         // union type cannot be restricted
         if (nodeToResolve instanceof UnionTypeBuilder) {
             return constraints;
@@ -560,7 +560,6 @@ public class YangModelParserImpl implements YangModelParser {
             mergeConstraints(referencedType, constraints);
             return constraints;
         }
-
     }
 
     /**
@@ -666,6 +665,13 @@ public class YangModelParserImpl implements YangModelParser {
         }
     }
 
+    /**
+     *
+     * @param modules
+     *            all available modules
+     * @param module
+     *            current module
+     */
     private void resolveAugment(
             final Map<String, TreeMap<Date, ModuleBuilder>> modules,
             final ModuleBuilder module) {
@@ -679,7 +685,7 @@ public class YangModelParserImpl implements YangModelParser {
                 int i = 0;
                 final QName qname = path.get(i);
                 String prefix = qname.getPrefix();
-                if(prefix == null) {
+                if (prefix == null) {
                     prefix = module.getPrefix();
                 }
 
@@ -719,7 +725,7 @@ public class YangModelParserImpl implements YangModelParser {
                 final QName lastAugmentPathElement = path.get(path.size() - 1);
                 if (currentQName.getLocalName().equals(
                         lastAugmentPathElement.getLocalName())) {
-                    fillAugmentTarget(augmentBuilder,
+                    ParserUtils.fillAugmentTarget(augmentBuilder,
                             (ChildNodeBuilder) currentParent);
                     ((AugmentationTargetBuilder) currentParent)
                             .addAugmentation(augmentBuilder);
@@ -729,20 +735,6 @@ public class YangModelParserImpl implements YangModelParser {
         }
     }
 
-    /**
-     * Add all augment's child nodes to given target.
-     *
-     * @param augment
-     * @param target
-     */
-    private void fillAugmentTarget(final AugmentationSchemaBuilder augment,
-            final ChildNodeBuilder target) {
-        for (DataSchemaNodeBuilder builder : augment.getChildNodes()) {
-            builder.setAugmenting(true);
-            target.addChildNode(builder);
-        }
-    }
-
     /**
      * Go through identity statements defined in current module and resolve
      * their 'base' statement if present.
@@ -806,9 +798,7 @@ public class YangModelParserImpl implements YangModelParser {
 
             final String groupingName = key.get(key.size() - 1);
 
-            final List<RefineHolder> refines = usesNode.getRefines();
-            for (RefineHolder refine : refines) {
-                final Refine refineType = refine.getType();
+            for (RefineHolder refine : usesNode.getRefines()) {
                 // refine statements
                 final String defaultStr = refine.getDefaultStr();
                 final Boolean mandatory = refine.isMandatory();
@@ -816,11 +806,13 @@ public class YangModelParserImpl implements YangModelParser {
                 final Boolean presence = refine.isPresence();
                 final Integer min = refine.getMinElements();
                 final Integer max = refine.getMaxElements();
+                final List<UnknownSchemaNodeBuilder> unknownNodes = refine
+                        .getUnknownNodes();
 
-                switch (refineType) {
-                case LEAF:
-                    final LeafSchemaNodeBuilder leaf = (LeafSchemaNodeBuilder) getRefineTargetBuilder(
-                            groupingName, refine, modules, module);
+                Builder refineTarget = getRefineTargetBuilder(groupingName,
+                        refine, modules, module);
+                if (refineTarget instanceof LeafSchemaNodeBuilder) {
+                    final LeafSchemaNodeBuilder leaf = (LeafSchemaNodeBuilder) refineTarget;
                     if (defaultStr != null && !("".equals(defaultStr))) {
                         leaf.setDefaultStr(defaultStr);
                     }
@@ -830,22 +822,28 @@ public class YangModelParserImpl implements YangModelParser {
                     if (must != null) {
                         leaf.getConstraints().addMustDefinition(must);
                     }
+                    if (unknownNodes != null) {
+                        for (UnknownSchemaNodeBuilder unknown : unknownNodes) {
+                            leaf.addUnknownSchemaNode(unknown);
+                        }
+                    }
                     usesNode.addRefineNode(leaf);
-                    break;
-                case CONTAINER:
-                    final ContainerSchemaNodeBuilder container = (ContainerSchemaNodeBuilder) getRefineTargetBuilder(
-                            groupingName, refine, modules, module);
+                } else if (refineTarget instanceof ContainerSchemaNodeBuilder) {
+                    final ContainerSchemaNodeBuilder container = (ContainerSchemaNodeBuilder) refineTarget;
                     if (presence != null) {
                         container.setPresence(presence);
                     }
                     if (must != null) {
                         container.getConstraints().addMustDefinition(must);
                     }
+                    if (unknownNodes != null) {
+                        for (UnknownSchemaNodeBuilder unknown : unknownNodes) {
+                            container.addUnknownSchemaNode(unknown);
+                        }
+                    }
                     usesNode.addRefineNode(container);
-                    break;
-                case LIST:
-                    final ListSchemaNodeBuilder list = (ListSchemaNodeBuilder) getRefineTargetBuilder(
-                            groupingName, refine, modules, module);
+                } else if (refineTarget instanceof ListSchemaNodeBuilder) {
+                    final ListSchemaNodeBuilder list = (ListSchemaNodeBuilder) refineTarget;
                     if (must != null) {
                         list.getConstraints().addMustDefinition(must);
                     }
@@ -855,8 +853,12 @@ public class YangModelParserImpl implements YangModelParser {
                     if (max != null) {
                         list.getConstraints().setMaxElements(max);
                     }
-                    break;
-                case LEAF_LIST:
+                    if (unknownNodes != null) {
+                        for (UnknownSchemaNodeBuilder unknown : unknownNodes) {
+                            list.addUnknownSchemaNode(unknown);
+                        }
+                    }
+                } else if (refineTarget instanceof LeafListSchemaNodeBuilder) {
                     final LeafListSchemaNodeBuilder leafList = (LeafListSchemaNodeBuilder) getRefineTargetBuilder(
                             groupingName, refine, modules, module);
                     if (must != null) {
@@ -868,26 +870,37 @@ public class YangModelParserImpl implements YangModelParser {
                     if (max != null) {
                         leafList.getConstraints().setMaxElements(max);
                     }
-                    break;
-                case CHOICE:
-                    final ChoiceBuilder choice = (ChoiceBuilder) getRefineTargetBuilder(
-                            groupingName, refine, modules, module);
+                    if (unknownNodes != null) {
+                        for (UnknownSchemaNodeBuilder unknown : unknownNodes) {
+                            leafList.addUnknownSchemaNode(unknown);
+                        }
+                    }
+                } else if (refineTarget instanceof ChoiceBuilder) {
+                    final ChoiceBuilder choice = (ChoiceBuilder) refineTarget;
                     if (defaultStr != null) {
                         choice.setDefaultCase(defaultStr);
                     }
                     if (mandatory != null) {
                         choice.getConstraints().setMandatory(mandatory);
                     }
-                    break;
-                case ANYXML:
-                    final AnyXmlBuilder anyXml = (AnyXmlBuilder) getRefineTargetBuilder(
-                            groupingName, refine, modules, module);
+                    if (unknownNodes != null) {
+                        for (UnknownSchemaNodeBuilder unknown : unknownNodes) {
+                            choice.addUnknownSchemaNode(unknown);
+                        }
+                    }
+                } else if (refineTarget instanceof AnyXmlBuilder) {
+                    final AnyXmlBuilder anyXml = (AnyXmlBuilder) refineTarget;
                     if (mandatory != null) {
                         anyXml.getConstraints().setMandatory(mandatory);
                     }
                     if (must != null) {
                         anyXml.getConstraints().addMustDefinition(must);
                     }
+                    if (unknownNodes != null) {
+                        for (UnknownSchemaNodeBuilder unknown : unknownNodes) {
+                            anyXml.addUnknownSchemaNode(unknown);
+                        }
+                    }
                 }
             }
         }
@@ -978,21 +991,26 @@ public class YangModelParserImpl implements YangModelParser {
         return builder.getChildNode(refineNodeName);
     }
 
-    private QName findFullQName(final Map<String, TreeMap<Date, ModuleBuilder>> modules,
+    private QName findFullQName(
+            final Map<String, TreeMap<Date, ModuleBuilder>> modules,
             final ModuleBuilder module, final IdentityrefTypeBuilder idref) {
         QName result = null;
         String baseString = idref.getBaseString();
-        if(baseString.contains(":")) {
+        if (baseString.contains(":")) {
             String[] splittedBase = baseString.split(":");
-            if(splittedBase.length > 2) {
-                throw new YangParseException("Failed to parse identityref base: "+ baseString);
+            if (splittedBase.length > 2) {
+                throw new YangParseException(
+                        "Failed to parse identityref base: " + baseString);
             }
             String prefix = splittedBase[0];
             String name = splittedBase[1];
-            ModuleBuilder dependentModule = findDependentModule(modules, module, prefix);
-            result = new QName(dependentModule.getNamespace(), dependentModule.getRevision(), prefix, name);
+            ModuleBuilder dependentModule = findDependentModule(modules,
+                    module, prefix);
+            result = new QName(dependentModule.getNamespace(),
+                    dependentModule.getRevision(), prefix, name);
         } else {
-            result = new QName(module.getNamespace(), module.getRevision(), module.getPrefix(), baseString);
+            result = new QName(module.getNamespace(), module.getRevision(),
+                    module.getPrefix(), baseString);
         }
         return result;
     }
@@ -1017,8 +1035,8 @@ public class YangModelParserImpl implements YangModelParser {
         if (prefix.equals(module.getPrefix())) {
             dependentModule = module;
         } else {
-            final ModuleImport dependentModuleImport = ParserUtils.getModuleImport(module,
-                    prefix);
+            final ModuleImport dependentModuleImport = ParserUtils
+                    .getModuleImport(module, prefix);
             if (dependentModuleImport == null) {
                 throw new YangParseException("No import found with prefix '"
                         + prefix + "' in module " + module.getName() + "'.");
@@ -1053,7 +1071,6 @@ public class YangModelParserImpl implements YangModelParser {
         return dependentModule;
     }
 
-
     private static class SchemaContextImpl implements SchemaContext {
         private final Set<Module> modules;
 
index bc5f77be838eb6b329feec9e1e756c6522d14d20..11b655b4a140503103117d22bf5bc63e8ca92b4a 100644 (file)
@@ -52,11 +52,11 @@ import org.opendaylight.controller.antlrv4.code.gen.YangParser.When_stmtContext;
 import org.opendaylight.controller.antlrv4.code.gen.YangParser.Yang_version_stmtContext;
 import org.opendaylight.controller.antlrv4.code.gen.YangParserBaseListener;
 import org.opendaylight.controller.yang.common.QName;
+import org.opendaylight.controller.yang.model.api.SchemaPath;
 import org.opendaylight.controller.yang.model.api.Status;
 import org.opendaylight.controller.yang.model.api.TypeDefinition;
 import org.opendaylight.controller.yang.model.parser.builder.api.AugmentationSchemaBuilder;
 import org.opendaylight.controller.yang.model.parser.builder.api.GroupingBuilder;
-import org.opendaylight.controller.yang.model.parser.builder.api.UsesNodeBuilder;
 import org.opendaylight.controller.yang.model.parser.builder.impl.AnyXmlBuilder;
 import org.opendaylight.controller.yang.model.parser.builder.impl.ChoiceBuilder;
 import org.opendaylight.controller.yang.model.parser.builder.impl.ChoiceCaseBuilder;
@@ -329,9 +329,10 @@ public final class YangModelParserListenerImpl extends YangParserBaseListener {
                 moduleBuilder.setType(type, actualPath);
             } else {
                 if ("union".equals(typeName)) {
-                    moduleBuilder.addUnionType(actualPath);
+                    moduleBuilder.addUnionType(actualPath, namespace, revision);
                 } else if("identityref".equals(typeName)) {
-                    moduleBuilder.addIdentityrefType(getIdentityrefBase(typeBody), actualPath);
+                    SchemaPath path = createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix);
+                    moduleBuilder.addIdentityrefType(getIdentityrefBase(typeBody), actualPath, path);
                 } else {
                     List<String> typePath = new ArrayList<String>(actualPath);
                     typePath.remove(0);
@@ -459,12 +460,9 @@ public final class YangModelParserListenerImpl extends YangParserBaseListener {
     @Override
     public void enterUses_stmt(YangParser.Uses_stmtContext ctx) {
         final String groupingPathStr = stringFromNode(ctx);
-        UsesNodeBuilder builder = moduleBuilder.addUsesNode(groupingPathStr,
+        moduleBuilder.addUsesNode(groupingPathStr,
                 actualPath);
         updatePath(groupingPathStr);
-
-        final List<RefineHolder> refines = parseRefines(ctx);
-        builder.setRefines(refines);
     }
 
     @Override
@@ -473,6 +471,20 @@ public final class YangModelParserListenerImpl extends YangParserBaseListener {
         logger.debug("exiting " + actContainer);
     }
 
+    @Override
+    public void enterRefine_stmt(YangParser.Refine_stmtContext ctx) {
+        String refineString = stringFromNode(ctx);
+        RefineHolder refine = parseRefine(ctx);
+        moduleBuilder.addRefine(refine, actualPath);
+        updatePath(refineString);
+    }
+
+    @Override
+    public void exitRefine_stmt(YangParser.Refine_stmtContext ctx) {
+        final String actContainer = actualPath.pop();
+        logger.debug("exiting " + actContainer);
+    }
+
     @Override
     public void enterLeaf_list_stmt(Leaf_list_stmtContext ctx) {
         final String leafListName = stringFromNode(ctx);
index e7775ce73470b0435d62520be78d8e412504b190..fa88a29981335c1f34c834decbc0f2bb366e53f7 100644 (file)
@@ -16,6 +16,7 @@ import org.opendaylight.controller.yang.model.api.MustDefinition;
 import org.opendaylight.controller.yang.model.api.SchemaPath;
 import org.opendaylight.controller.yang.model.api.TypeDefinition;
 import org.opendaylight.controller.yang.model.parser.builder.api.AugmentationSchemaBuilder;
+import org.opendaylight.controller.yang.model.parser.builder.api.ChildNodeBuilder;
 import org.opendaylight.controller.yang.model.parser.builder.api.DataSchemaNodeBuilder;
 import org.opendaylight.controller.yang.model.parser.builder.api.GroupingBuilder;
 import org.opendaylight.controller.yang.model.parser.builder.api.TypeDefinitionBuilder;
@@ -59,7 +60,9 @@ public final class ParserUtils {
 
     /**
      * Parse uses path.
-     * @param usesPath as String
+     *
+     * @param usesPath
+     *            as String
      * @return SchemaPath from given String
      */
     public static SchemaPath parseUsesPath(final String usesPath) {
@@ -82,6 +85,21 @@ public final class ParserUtils {
         return new SchemaPath(path, absolute);
     }
 
+    /**
+     * Add all augment's child nodes to given target.
+     *
+     * @param augment
+     * @param target
+     */
+    public static void fillAugmentTarget(
+            final AugmentationSchemaBuilder augment,
+            final ChildNodeBuilder target) {
+        for (DataSchemaNodeBuilder builder : augment.getChildNodes()) {
+            builder.setAugmenting(true);
+            target.addChildNode(builder);
+        }
+    }
+
     public static LeafSchemaNodeBuilder copyLeafBuilder(
             final LeafSchemaNodeBuilder old) {
         final LeafSchemaNodeBuilder copy = new LeafSchemaNodeBuilder(
index 19b6764e0a3f18777128d5812a52bd4a62ba5c3e..0c31655610410e50ab929546e4d69464462df115 100644 (file)
@@ -7,11 +7,15 @@
  */
 package org.opendaylight.controller.yang.model.parser.util;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import org.opendaylight.controller.yang.model.api.MustDefinition;
+import org.opendaylight.controller.yang.model.parser.builder.api.Builder;
+import org.opendaylight.controller.yang.model.parser.builder.impl.UnknownSchemaNodeBuilder;
 
-public final class RefineHolder {
+public final class RefineHolder implements Builder {
     private final String name;
-    private Refine type;
     private String defaultStr;
     private String description;
     private String reference;
@@ -21,19 +25,12 @@ public final class RefineHolder {
     private MustDefinition must;
     private Integer minElements;
     private Integer maxElements;
+    private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
 
     public RefineHolder(final String name) {
         this.name = name;
     }
 
-    public Refine getType() {
-        return type;
-    }
-
-    public void setType(final Refine type) {
-        this.type = type;
-    }
-
     public String getDefaultStr() {
         return defaultStr;
     }
@@ -110,8 +107,17 @@ public final class RefineHolder {
         return name;
     }
 
-    public enum Refine {
-        CONTAINER, LEAF, LIST, LEAF_LIST, CHOICE, ANYXML
+    public List<UnknownSchemaNodeBuilder> getUnknownNodes() {
+        return addedUnknownNodes;
+    }
+
+    public void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownNode) {
+        addedUnknownNodes.add(unknownNode);
+    }
+
+    @Override
+    public Object build() {
+        return null;
     }
 
 }
index 94b790f78ff46962fd9528e8bfe23b57e3d13b51..fff33b63bd513baa2b4e435b6266e497ce5ea874 100644 (file)
@@ -63,7 +63,6 @@ import org.opendaylight.controller.antlrv4.code.gen.YangParser.StringContext;
 import org.opendaylight.controller.antlrv4.code.gen.YangParser.String_restrictionsContext;
 import org.opendaylight.controller.antlrv4.code.gen.YangParser.Type_body_stmtsContext;
 import org.opendaylight.controller.antlrv4.code.gen.YangParser.Units_stmtContext;
-import org.opendaylight.controller.antlrv4.code.gen.YangParser.Uses_stmtContext;
 import org.opendaylight.controller.antlrv4.code.gen.YangParser.Value_stmtContext;
 import org.opendaylight.controller.antlrv4.code.gen.YangParser.When_stmtContext;
 import org.opendaylight.controller.antlrv4.code.gen.YangParser.Yin_element_argContext;
@@ -84,7 +83,6 @@ import org.opendaylight.controller.yang.model.api.type.PatternConstraint;
 import org.opendaylight.controller.yang.model.api.type.RangeConstraint;
 import org.opendaylight.controller.yang.model.parser.builder.api.SchemaNodeBuilder;
 import org.opendaylight.controller.yang.model.parser.builder.impl.ConstraintsBuilder;
-import org.opendaylight.controller.yang.model.parser.util.RefineHolder.Refine;
 import org.opendaylight.controller.yang.model.util.BaseConstraints;
 import org.opendaylight.controller.yang.model.util.BinaryType;
 import org.opendaylight.controller.yang.model.util.BitsType;
@@ -1017,7 +1015,7 @@ public final class YangModelBuilderUtil {
         } else if ("string".equals(typeName)) {
             type = new StringType(actualPath, namespace, revision, lengthStatements, patternStatements);
         } else if ("bits".equals(typeName)) {
-            type = new BitsType(getBits(typeBody, actualPath, namespace,
+            type = new BitsType(actualPath, namespace, revision, getBits(typeBody, actualPath, namespace,
                     revision, prefix));
         } else if ("leafref".equals(typeName)) {
             final String path = parseLeafrefPath(typeBody);
@@ -1027,10 +1025,10 @@ public final class YangModelBuilderUtil {
             type = new Leafref(actualPath, namespace, revision, xpath);
         } else if ("binary".equals(typeName)) {
             List<Byte> bytes = Collections.emptyList();
-            type = new BinaryType(bytes, lengthStatements, null);
+            type = new BinaryType(actualPath, namespace, revision, bytes, lengthStatements, null);
         } else if ("instance-identifier".equals(typeName)) {
             boolean requireInstance = isRequireInstance(typeBody);
-            type = new InstanceIdentifier(null, requireInstance);
+            type = new InstanceIdentifier(actualPath, namespace, revision, null, requireInstance);
         }
         return type;
     }
@@ -1196,52 +1194,86 @@ public final class YangModelBuilderUtil {
         return yinValue;
     }
 
-    public static List<RefineHolder> parseRefines(Uses_stmtContext ctx) {
-        List<RefineHolder> refines = new ArrayList<RefineHolder>();
-
-        for (int i = 0; i < ctx.getChildCount(); i++) {
-            ParseTree child = ctx.getChild(i);
-            if (child instanceof Refine_stmtContext) {
-                final String refineTarget = stringFromNode(child);
-                final RefineHolder refine = new RefineHolder(refineTarget);
-                for (int j = 0; j < child.getChildCount(); j++) {
-                    ParseTree refinePom = child.getChild(j);
-                    if (refinePom instanceof Refine_pomContext) {
-                        for (int k = 0; k < refinePom.getChildCount(); k++) {
-                            ParseTree refineStmt = refinePom.getChild(k);
-                            if (refineStmt instanceof Refine_leaf_stmtsContext) {
-                                parseRefine(refine,
-                                        (Refine_leaf_stmtsContext) refineStmt);
-                            } else if (refineStmt instanceof Refine_container_stmtsContext) {
-                                parseRefine(
-                                        refine,
-                                        (Refine_container_stmtsContext) refineStmt);
-                            } else if (refineStmt instanceof Refine_list_stmtsContext) {
-                                parseRefine(refine,
-                                        (Refine_list_stmtsContext) refineStmt);
-                            } else if (refineStmt instanceof Refine_leaf_list_stmtsContext) {
-                                parseRefine(
-                                        refine,
-                                        (Refine_leaf_list_stmtsContext) refineStmt);
-                            } else if (refineStmt instanceof Refine_choice_stmtsContext) {
-                                parseRefine(refine,
-                                        (Refine_choice_stmtsContext) refineStmt);
-                            } else if (refineStmt instanceof Refine_anyxml_stmtsContext) {
-                                parseRefine(refine,
-                                        (Refine_anyxml_stmtsContext) refineStmt);
-                            }
-                        }
+//    public static List<RefineHolder> parseRefines(Uses_stmtContext ctx) {
+//        List<RefineHolder> refines = new ArrayList<RefineHolder>();
+//
+//        for (int i = 0; i < ctx.getChildCount(); i++) {
+//            ParseTree child = ctx.getChild(i);
+//            if (child instanceof Refine_stmtContext) {
+//                final String refineTarget = stringFromNode(child);
+//                final RefineHolder refine = new RefineHolder(refineTarget);
+//                for (int j = 0; j < child.getChildCount(); j++) {
+//                    ParseTree refinePom = child.getChild(j);
+//                    if (refinePom instanceof Refine_pomContext) {
+//                        for (int k = 0; k < refinePom.getChildCount(); k++) {
+//                            ParseTree refineStmt = refinePom.getChild(k);
+//                            if (refineStmt instanceof Refine_leaf_stmtsContext) {
+//                                parseRefine(refine,
+//                                        (Refine_leaf_stmtsContext) refineStmt);
+//                            } else if (refineStmt instanceof Refine_container_stmtsContext) {
+//                                parseRefine(
+//                                        refine,
+//                                        (Refine_container_stmtsContext) refineStmt);
+//                            } else if (refineStmt instanceof Refine_list_stmtsContext) {
+//                                parseRefine(refine,
+//                                        (Refine_list_stmtsContext) refineStmt);
+//                            } else if (refineStmt instanceof Refine_leaf_list_stmtsContext) {
+//                                parseRefine(
+//                                        refine,
+//                                        (Refine_leaf_list_stmtsContext) refineStmt);
+//                            } else if (refineStmt instanceof Refine_choice_stmtsContext) {
+//                                parseRefine(refine,
+//                                        (Refine_choice_stmtsContext) refineStmt);
+//                            } else if (refineStmt instanceof Refine_anyxml_stmtsContext) {
+//                                parseRefine(refine,
+//                                        (Refine_anyxml_stmtsContext) refineStmt);
+//                            }
+//                        }
+//                    }
+//                }
+//                refines.add(refine);
+//            }
+//        }
+//        return refines;
+//    }
+
+    public static RefineHolder parseRefine(Refine_stmtContext child) {
+        final String refineTarget = stringFromNode(child);
+        final RefineHolder refine = new RefineHolder(refineTarget);
+        for (int j = 0; j < child.getChildCount(); j++) {
+            ParseTree refinePom = child.getChild(j);
+            if (refinePom instanceof Refine_pomContext) {
+                for (int k = 0; k < refinePom.getChildCount(); k++) {
+                    ParseTree refineStmt = refinePom.getChild(k);
+                    if (refineStmt instanceof Refine_leaf_stmtsContext) {
+                        parseRefine(refine,
+                                (Refine_leaf_stmtsContext) refineStmt);
+                    } else if (refineStmt instanceof Refine_container_stmtsContext) {
+                        parseRefine(
+                                refine,
+                                (Refine_container_stmtsContext) refineStmt);
+                    } else if (refineStmt instanceof Refine_list_stmtsContext) {
+                        parseRefine(refine,
+                                (Refine_list_stmtsContext) refineStmt);
+                    } else if (refineStmt instanceof Refine_leaf_list_stmtsContext) {
+                        parseRefine(
+                                refine,
+                                (Refine_leaf_list_stmtsContext) refineStmt);
+                    } else if (refineStmt instanceof Refine_choice_stmtsContext) {
+                        parseRefine(refine,
+                                (Refine_choice_stmtsContext) refineStmt);
+                    } else if (refineStmt instanceof Refine_anyxml_stmtsContext) {
+                        parseRefine(refine,
+                                (Refine_anyxml_stmtsContext) refineStmt);
                     }
                 }
-                refines.add(refine);
             }
         }
-        return refines;
+        return refine;
     }
 
     private static RefineHolder parseRefine(RefineHolder refine,
             Refine_leaf_stmtsContext refineStmt) {
-        refine.setType(Refine.LEAF);
         for (int i = 0; i < refineStmt.getChildCount(); i++) {
             ParseTree refineArg = refineStmt.getChild(i);
             if (refineArg instanceof Default_stmtContext) {
@@ -1267,7 +1299,6 @@ public final class YangModelBuilderUtil {
 
     private static RefineHolder parseRefine(RefineHolder refine,
             Refine_container_stmtsContext refineStmt) {
-        refine.setType(Refine.CONTAINER);
         for (int m = 0; m < refineStmt.getChildCount(); m++) {
             ParseTree refineArg = refineStmt.getChild(m);
             if (refineArg instanceof Must_stmtContext) {
@@ -1282,7 +1313,6 @@ public final class YangModelBuilderUtil {
 
     private static RefineHolder parseRefine(RefineHolder refine,
             Refine_list_stmtsContext refineStmt) {
-        refine.setType(Refine.LIST);
         for (int m = 0; m < refineStmt.getChildCount(); m++) {
             ParseTree refineArg = refineStmt.getChild(m);
             if (refineArg instanceof Must_stmtContext) {
@@ -1301,7 +1331,6 @@ public final class YangModelBuilderUtil {
 
     private static RefineHolder parseRefine(RefineHolder refine,
             Refine_leaf_list_stmtsContext refineStmt) {
-        refine.setType(Refine.LEAF_LIST);
         for (int m = 0; m < refineStmt.getChildCount(); m++) {
             ParseTree refineArg = refineStmt.getChild(m);
             if (refineArg instanceof Must_stmtContext) {
@@ -1320,7 +1349,6 @@ public final class YangModelBuilderUtil {
 
     private static RefineHolder parseRefine(RefineHolder refine,
             Refine_choice_stmtsContext refineStmt) {
-        refine.setType(Refine.CHOICE);
         for (int i = 0; i < refineStmt.getChildCount(); i++) {
             ParseTree refineArg = refineStmt.getChild(i);
             if (refineArg instanceof Default_stmtContext) {
@@ -1342,7 +1370,6 @@ public final class YangModelBuilderUtil {
 
     private static RefineHolder parseRefine(RefineHolder refine,
             Refine_anyxml_stmtsContext refineStmt) {
-        refine.setType(Refine.ANYXML);
         for (int i = 0; i < refineStmt.getChildCount(); i++) {
             ParseTree refineArg = refineStmt.getChild(i);
             if (refineArg instanceof Must_stmtContext) {
index 3907cc13e5d4bc314619885644935a9a74875ced..c2ae7d304a8c1ca9bae54b109e94f3b46d023ef4 100644 (file)
@@ -46,6 +46,20 @@ public abstract class AbstractSignedInteger implements IntegerTypeDefinition {
     private final String units;
     private final List<RangeConstraint> rangeStatements;
 
+    protected AbstractSignedInteger(final QName name, final String description,
+            final Number minRange, final Number maxRange, final String units) {
+        this.name = name;
+        this.description = description;
+        this.path = BaseTypes.schemaPath(name);
+        this.units = units;
+        this.rangeStatements = new ArrayList<RangeConstraint>();
+        final String rangeDescription = "Integer values between " + minRange
+                + " and " + maxRange + ", inclusively.";
+        this.rangeStatements.add(BaseConstraints.rangeConstraint(minRange,
+                maxRange, rangeDescription,
+                "https://tools.ietf.org/html/rfc6020#section-9.2.4"));
+    }
+
     /**
      * @param name
      * @param description
index 76048519e7f226653f220aa73aff85dae7ed5681..31a62ececda6f4e2a652adac5b7c90449be0c837 100644 (file)
@@ -42,7 +42,26 @@ public abstract class AbstractUnsignedInteger implements
     private final String units;
     private final List<RangeConstraint> rangeStatements;
 
+    protected AbstractUnsignedInteger(final QName name,
+            final String description, final Number minRange,
+            final Number maxRange, final String units) {
+        this.name = name;
+        this.description = description;
+        this.path = BaseTypes.schemaPath(name);
+        this.units = units;
+        this.rangeStatements = new ArrayList<RangeConstraint>();
+        final String rangeDescription = "Integer values between " + minRange
+                + " and " + maxRange + ", inclusively.";
+        this.rangeStatements.add(BaseConstraints.rangeConstraint(minRange,
+                maxRange, rangeDescription,
+                "https://tools.ietf.org/html/rfc6020#section-9.2.4"));
+    }
+
     /**
+     *
+     * @param actualPath
+     * @param namespace
+     * @param revision
      * @param name
      * @param description
      * @param minRange
index 70298a7e07bf3e9bd94d3b743e3c1b649f022396..253fe484f0459a7f410014814a549166c5477dbd 100644 (file)
@@ -7,8 +7,10 @@
   */
 package org.opendaylight.controller.yang.model.util;
 
+import java.net.URI;
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.Date;
 import java.util.List;
 
 import org.opendaylight.controller.yang.common.QName;
@@ -20,43 +22,55 @@ import org.opendaylight.controller.yang.model.api.type.LengthConstraint;
 
 /**
  * The <code>default</code> implementation of Binary Type Definition interface.
- * 
+ *
  * @see BinaryTypeDefinition
  */
 public class BinaryType implements BinaryTypeDefinition {
 
     private final QName name = BaseTypes.constructQName("binary");
-    private final SchemaPath path = BaseTypes.schemaPath(name);
+    private final SchemaPath path;
     private final String description = "The binary built-in type represents any binary data, i.e., a sequence of octets.";
     private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.8";
-
+    private final BinaryTypeDefinition baseType;
     private List<Byte> bytes;
     private final List<LengthConstraint> lengthConstraints;
     private String units = "";
 
-    /**
-     * 
-     */
-    public BinaryType() {
+    private BinaryType() {
+        super();
+
+        final List<LengthConstraint> constraints = new ArrayList<LengthConstraint>();
+        constraints.add(BaseConstraints.lengthConstraint(0, Long.MAX_VALUE, "", ""));
+        this.lengthConstraints = Collections.unmodifiableList(constraints);
+        this.bytes = Collections.emptyList();
+        this.path = BaseTypes.schemaPath(name);
+        this.baseType = this;
+    }
+
+    public BinaryType(final List<String> actualPath, final URI namespace,
+            final Date revision) {
         super();
-        
+
         final List<LengthConstraint> constraints = new ArrayList<LengthConstraint>();
         constraints.add(BaseConstraints.lengthConstraint(0, Long.MAX_VALUE, "", ""));
-        lengthConstraints = Collections.unmodifiableList(constraints);
-        bytes = Collections.emptyList();
+        this.lengthConstraints = Collections.unmodifiableList(constraints);
+        this.bytes = Collections.emptyList();
+        this.path = BaseTypes.schemaPath(actualPath, namespace, revision);
+        this.baseType = new BinaryType();
     }
 
     /**
-     * 
-     * 
+     *
+     *
      * @param bytes
      * @param lengthConstraints
      * @param units
      */
-    public BinaryType(final List<Byte> bytes,
+    public BinaryType(final List<String> actualPath, final URI namespace,
+            final Date revision, final List<Byte> bytes,
             final List<LengthConstraint> lengthConstraints, final String units) {
         super();
-        
+
         if ((lengthConstraints == null) || (lengthConstraints.isEmpty())) {
             final List<LengthConstraint> constraints = new ArrayList<LengthConstraint>();
             constraints.add(BaseConstraints.lengthConstraint(0, Long.MAX_VALUE, "", ""));
@@ -64,9 +78,11 @@ public class BinaryType implements BinaryTypeDefinition {
         } else {
             this.lengthConstraints = Collections.unmodifiableList(lengthConstraints);
         }
-        
+
+        this.path = BaseTypes.schemaPath(actualPath, namespace, revision);
         this.bytes = Collections.unmodifiableList(bytes);
         this.units = units;
+        this.baseType = new BinaryType();
     }
 
     /*
@@ -76,7 +92,7 @@ public class BinaryType implements BinaryTypeDefinition {
      */
     @Override
     public BinaryTypeDefinition getBaseType() {
-        return this;
+        return baseType;
     }
 
     /*
index e6c118934e72ef78f9e958b21765f36a56fe5720..717c24ed5083c2b89cc47fd0fa9a6b473aaa4d6d 100644 (file)
@@ -1,13 +1,15 @@
 /*
 * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
 package org.opendaylight.controller.yang.model.util;
 
+import java.net.URI;
 import java.util.Collections;
+import java.util.Date;
 import java.util.List;
 
 import org.opendaylight.controller.yang.common.QName;
@@ -16,22 +18,21 @@ import org.opendaylight.controller.yang.model.api.Status;
 import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
 import org.opendaylight.controller.yang.model.api.type.BitsTypeDefinition;
 
-
 /**
  * The <code>default</code> implementation of Bits Type Definition interface.
- * 
+ *
  * @see BitsTypeDefinition
  */
 public class BitsType implements BitsTypeDefinition {
 
     private final QName name = BaseTypes.constructQName("bits");
-    private final SchemaPath path = BaseTypes.schemaPath(name);
-    private final String description = "The bits built-in type represents a bit set.  " +
-               "That is, a bits value is a set of flags identified by small integer position " +
-               "numbers starting at 0.  Each bit number has an assigned name.";
-    
-    private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.7";
+    private final SchemaPath path;
+    private final String description = "The bits built-in type represents a bit set.  "
+            + "That is, a bits value is a set of flags identified by small integer position "
+            + "numbers starting at 0.  Each bit number has an assigned name.";
 
+    private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.7";
+    private final BitsTypeDefinition baseType;
     private final List<Bit> bits;
     private String units = "";
 
@@ -39,52 +40,72 @@ public class BitsType implements BitsTypeDefinition {
      * Default constructor. <br>
      * Instantiates Bits type as empty bits list.
      */
-    public BitsType() {
+    private BitsType() {
         super();
-        bits = Collections.emptyList();
+        this.bits = Collections.emptyList();
+        this.path = BaseTypes.schemaPath(name);
+        this.baseType = this;
+    }
+
+    public BitsType(final List<String> actualPath, final URI namespace,
+            final Date revision) {
+        super();
+        this.bits = Collections.emptyList();
+        this.path = BaseTypes.schemaPath(actualPath, namespace, revision);
+        this.baseType = new BitsType();
     }
 
     /**
-     * Constructor with explicit definition of bits assigned to
-     * BitsType.
-     * 
+     * Constructor with explicit definition of bits assigned to BitsType.
+     *
+     * @param actualPath
+     * @param namespace
+     * @param revision
      * @param bits
      *            The bits assigned for Bits Type
      */
-    public BitsType(final List<Bit> bits) {
+    public BitsType(final List<String> actualPath, final URI namespace,
+            final Date revision, final List<Bit> bits) {
         super();
         this.bits = Collections.unmodifiableList(bits);
         this.units = "";
+        this.path = BaseTypes.schemaPath(actualPath, namespace, revision);
+        this.baseType = new BitsType();
     }
 
     /**
-     * Constructor with explicit definition of bits assigned to
-     * BitsType and Units.
-     * <br>
+     * Constructor with explicit definition of bits assigned to BitsType and
+     * Units. <br>
      * The default value of Bits Type is List of bits.
-     * 
-     * @param bits The bits assigned for Bits Type
-     * @param units units for bits type
+     *
+     * @param bits
+     *            The bits assigned for Bits Type
+     * @param units
+     *            units for bits type
      */
-    public BitsType(List<Bit> bits, String units) {
+    public BitsType(final List<String> actualPath, final URI namespace,
+            final Date revision, List<Bit> bits, String units) {
         super();
         this.bits = Collections.unmodifiableList(bits);
         this.units = units;
+        this.path = BaseTypes.schemaPath(actualPath, namespace, revision);
+        this.baseType = new BitsType();
     }
 
     /*
      * (non-Javadoc)
-     * 
-     * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getBaseType()
+     *
+     * @see
+     * org.opendaylight.controller.yang.model.api.TypeDefinition#getBaseType()
      */
     @Override
     public BitsTypeDefinition getBaseType() {
-        return this;
+        return baseType;
     }
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getUnits()
      */
     @Override
@@ -94,8 +115,10 @@ public class BitsType implements BitsTypeDefinition {
 
     /*
      * (non-Javadoc)
-     * 
-     * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getDefaultValue()
+     *
+     * @see
+     * org.opendaylight.controller.yang.model.api.TypeDefinition#getDefaultValue
+     * ()
      */
     @Override
     public Object getDefaultValue() {
@@ -104,7 +127,7 @@ public class BitsType implements BitsTypeDefinition {
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getQName()
      */
     @Override
@@ -114,7 +137,7 @@ public class BitsType implements BitsTypeDefinition {
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getPath()
      */
     @Override
@@ -124,8 +147,9 @@ public class BitsType implements BitsTypeDefinition {
 
     /*
      * (non-Javadoc)
-     * 
-     * @see org.opendaylight.controller.yang.model.api.SchemaNode#getDescription()
+     *
+     * @see
+     * org.opendaylight.controller.yang.model.api.SchemaNode#getDescription()
      */
     @Override
     public String getDescription() {
@@ -134,7 +158,7 @@ public class BitsType implements BitsTypeDefinition {
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getReference()
      */
     @Override
@@ -144,7 +168,7 @@ public class BitsType implements BitsTypeDefinition {
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getStatus()
      */
     @Override
index 9717ff66a6a1791f5c1c90408028986b4e3ea2f5..f588bf425c9ae4ed2f6deabd91cf723bc6b9d2fd 100644 (file)
@@ -1,13 +1,15 @@
 /*
 * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
 package org.opendaylight.controller.yang.model.util;
 
+import java.net.URI;
 import java.util.Collections;
+import java.util.Date;
 import java.util.List;
 
 import org.opendaylight.controller.yang.common.QName;
@@ -18,62 +20,82 @@ import org.opendaylight.controller.yang.model.api.type.BooleanTypeDefinition;
 
 /**
  * The <code>default</code> implementation of Boolean Type Definition interface.
- * 
+ *
  * @see BooleanTypeDefinition
  */
 public class BooleanType implements BooleanTypeDefinition {
 
     private final QName name = BaseTypes.constructQName("boolean");
-    private final SchemaPath path = BaseTypes.schemaPath(name);
+    private final SchemaPath path;
     private final String description = "The boolean built-in type represents a boolean value.";
     private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.5";
-
+    private final BooleanTypeDefinition baseType;
     private final Boolean defaultValue;
     private String units = "";
 
     /**
      * Default constructor with default value set to "false".
      */
-    public BooleanType() {
+    private BooleanType() {
+        super();
+        this.defaultValue = false;
+        this.path = BaseTypes.schemaPath(name);
+        this.baseType = this;
+    }
+
+    public BooleanType(final List<String> actualPath, final URI namespace,
+            final Date revision) {
         super();
-        defaultValue = false;
+        this.defaultValue = false;
+        this.path = BaseTypes.schemaPath(actualPath, namespace, revision);
+        this.baseType = new BooleanType();
     }
 
     /**
      * Boolean Type constructor.
-     * 
-     * @param defaultValue Default Value
+     *
+     * @param defaultValue
+     *            Default Value
      */
-    public BooleanType(final Boolean defaultValue) {
+    public BooleanType(final List<String> actualPath, final URI namespace,
+            final Date revision, final Boolean defaultValue) {
         super();
         this.defaultValue = defaultValue;
+        this.path = BaseTypes.schemaPath(actualPath, namespace, revision);
+        this.baseType = new BooleanType();
     }
 
     /**
      * Boolean Type constructor.
-     * 
-     * @param defaultValue Default Value
-     * @param units Units
+     *
+     * @param defaultValue
+     *            Default Value
+     * @param units
+     *            Units
      */
-    public BooleanType(final Boolean defaultValue, final String units) {
+    public BooleanType(final List<String> actualPath, final URI namespace,
+            final Date revision, final Boolean defaultValue, final String units) {
         super();
         this.defaultValue = defaultValue;
         this.units = units;
+        this.path = BaseTypes.schemaPath(actualPath, namespace, revision);
+        this.baseType = new BooleanType();
     }
 
     /*
      * (non-Javadoc)
-     * 
-     * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getBaseType()
+     *
+     * @see
+     * org.opendaylight.controller.yang.model.api.TypeDefinition#getBaseType()
      */
     @Override
     public BooleanTypeDefinition getBaseType() {
-        return this;
+        return baseType;
     }
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getUnits()
      */
     @Override
@@ -83,8 +105,10 @@ public class BooleanType implements BooleanTypeDefinition {
 
     /*
      * (non-Javadoc)
-     * 
-     * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getDefaultValue()
+     *
+     * @see
+     * org.opendaylight.controller.yang.model.api.TypeDefinition#getDefaultValue
+     * ()
      */
     @Override
     public Object getDefaultValue() {
@@ -93,7 +117,7 @@ public class BooleanType implements BooleanTypeDefinition {
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getQName()
      */
     @Override
@@ -103,7 +127,7 @@ public class BooleanType implements BooleanTypeDefinition {
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getPath()
      */
     @Override
@@ -113,8 +137,9 @@ public class BooleanType implements BooleanTypeDefinition {
 
     /*
      * (non-Javadoc)
-     * 
-     * @see org.opendaylight.controller.yang.model.api.SchemaNode#getDescription()
+     *
+     * @see
+     * org.opendaylight.controller.yang.model.api.SchemaNode#getDescription()
      */
     @Override
     public String getDescription() {
@@ -123,7 +148,7 @@ public class BooleanType implements BooleanTypeDefinition {
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getReference()
      */
     @Override
@@ -133,7 +158,7 @@ public class BooleanType implements BooleanTypeDefinition {
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getStatus()
      */
     @Override
index 158865aec9dff12a3d21f50b8e06f08e2beec151..adb4c1a3cb00a21f6993c4de9e8140cc86d29674 100644 (file)
@@ -43,6 +43,7 @@ public class Decimal64 implements DecimalTypeDefinition {
 
     private final List<RangeConstraint> rangeStatements;
     private final Integer fractionDigits;
+    private final DecimalTypeDefinition baseType;
 
     /**
      * Default Decimal64 Type Constructor. <br>
@@ -61,6 +62,17 @@ public class Decimal64 implements DecimalTypeDefinition {
      * @see DecimalTypeDefinition
      * @exception IllegalArgumentException
      */
+    private Decimal64(final Integer fractionDigits) {
+        if (!((fractionDigits.intValue() > 1) && (fractionDigits.intValue() <= 18))) {
+            throw new IllegalArgumentException(
+                    "The fraction digits outside of boundaries. Fraction digits MUST be integer between 1 and 18 inclusively");
+        }
+        this.fractionDigits = fractionDigits;
+        this.rangeStatements = defaultRangeStatements();
+        this.path = BaseTypes.schemaPath(name);
+        this.baseType = this;
+    }
+
     public Decimal64(final List<String> actualPath, final URI namespace,
             final Date revision, final Integer fractionDigits) {
         super();
@@ -71,6 +83,7 @@ public class Decimal64 implements DecimalTypeDefinition {
         this.fractionDigits = fractionDigits;
         rangeStatements = defaultRangeStatements();
         this.path = BaseTypes.schemaPath(actualPath, namespace, revision);
+        this.baseType = new Decimal64(fractionDigits);
     }
 
     /**
@@ -87,6 +100,9 @@ public class Decimal64 implements DecimalTypeDefinition {
      * If the fraction digits are not defined inner the definition boundaries
      * the constructor will throw {@link IllegalArgumentException}
      *
+     * @param actualPath
+     * @param namespace
+     * @param revision
      * @param rangeStatements
      *            Range Constraint Statements
      * @param fractionDigits
@@ -104,10 +120,12 @@ public class Decimal64 implements DecimalTypeDefinition {
         if (rangeStatements == null || rangeStatements.isEmpty()) {
             this.rangeStatements = defaultRangeStatements();
         } else {
-            this.rangeStatements = Collections.unmodifiableList(rangeStatements);
+            this.rangeStatements = Collections
+                    .unmodifiableList(rangeStatements);
         }
         this.fractionDigits = fractionDigits;
         this.path = BaseTypes.schemaPath(actualPath, namespace, revision);
+        this.baseType = new Decimal64(fractionDigits);
     }
 
     /**
@@ -123,6 +141,9 @@ public class Decimal64 implements DecimalTypeDefinition {
      * If the fraction digits are not defined inner the definition boundaries
      * the constructor will throw {@link IllegalArgumentException}
      *
+     * @param actualPath
+     * @param namespace
+     * @param revision
      * @param units
      *            units associated with the type
      * @param defaultValue
@@ -131,11 +152,10 @@ public class Decimal64 implements DecimalTypeDefinition {
      *            Range Constraint Statements
      * @param fractionDigits
      *            integer between 1 and 18 inclusively
-     *
-     * @exception IllegalArgumentException
      */
     public Decimal64(final List<String> actualPath, final URI namespace,
-            final Date revision, final String units, final BigDecimal defaultValue,
+            final Date revision, final String units,
+            final BigDecimal defaultValue,
             final List<RangeConstraint> rangeStatements,
             final Integer fractionDigits) {
         super();
@@ -148,12 +168,14 @@ public class Decimal64 implements DecimalTypeDefinition {
             this.rangeStatements = defaultRangeStatements();
 
         } else {
-            this.rangeStatements = Collections.unmodifiableList(rangeStatements);
+            this.rangeStatements = Collections
+                    .unmodifiableList(rangeStatements);
         }
         this.units = units;
         this.defaultValue = defaultValue;
         this.fractionDigits = fractionDigits;
         this.path = BaseTypes.schemaPath(name);
+        this.baseType = new Decimal64(fractionDigits);
     }
 
     /**
@@ -175,7 +197,7 @@ public class Decimal64 implements DecimalTypeDefinition {
 
     @Override
     public DecimalTypeDefinition getBaseType() {
-        return this;
+        return baseType;
     }
 
     @Override
index 9a7b13ddb3e0e9f34c611111348169a7b558dc9b..1b5abb22093080657f00037ecd2e017324214c03 100644 (file)
@@ -7,7 +7,9 @@
  */
 package org.opendaylight.controller.yang.model.util;
 
+import java.net.URI;
 import java.util.Collections;
+import java.util.Date;
 import java.util.List;
 
 import org.opendaylight.controller.yang.common.QName;
@@ -19,13 +21,25 @@ import org.opendaylight.controller.yang.model.api.type.EmptyTypeDefinition;
 public class EmptyType implements EmptyTypeDefinition {
 
     private final QName name = BaseTypes.constructQName("empty");
-    private final SchemaPath path = BaseTypes.schemaPath(name);
+    private final SchemaPath path;
     private final String description = "The empty built-in type represents a leaf that does not have any value, it conveys information by its presence or absence.";
     private final String reference = "https://tools.ietf.org/html/rfc6020#page-131";
+    private final EmptyTypeDefinition baseType;
+
+    private EmptyType() {
+        path = BaseTypes.schemaPath(name);
+        this.baseType = this;
+    }
+
+    public EmptyType(final List<String> actualPath,
+            final URI namespace, final Date revision) {
+        path = BaseTypes.schemaPath(actualPath, namespace, revision);
+        this.baseType = new EmptyType();
+    }
 
     @Override
     public EmptyTypeDefinition getBaseType() {
-        return this;
+        return baseType;
     }
 
     @Override
index 2057a42eb6490bf659d11149ff85bb138326634b..86bde24d62d8131314f0f1d37b7e8ed61552f72e 100644 (file)
@@ -1,13 +1,15 @@
 /*
 * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
 package org.opendaylight.controller.yang.model.util;
 
+import java.net.URI;
 import java.util.Collections;
+import java.util.Date;
 import java.util.List;
 
 import org.opendaylight.controller.yang.common.QName;
@@ -33,7 +35,6 @@ public class ExtendedType implements TypeDefinition<TypeDefinition<?>> {
     private List<PatternConstraint> patterns = Collections.emptyList();
     private Integer fractionDigits = null;
 
-
     private Status status;
     private String units;
     private Object defaultValue;
@@ -46,7 +47,8 @@ public class ExtendedType implements TypeDefinition<TypeDefinition<?>> {
         private final String description;
         private final String reference;
 
-        private List<UnknownSchemaNode> unknownSchemaNodes = Collections.emptyList();;
+        private List<UnknownSchemaNode> unknownSchemaNodes = Collections
+                .emptyList();
         private Status status = Status.CURRENT;
         private String units = "";
         private Object defaultValue = null;
@@ -56,11 +58,23 @@ public class ExtendedType implements TypeDefinition<TypeDefinition<?>> {
         private List<PatternConstraint> patterns = Collections.emptyList();
         private Integer fractionDigits = null;
 
+        public Builder(final List<String> actualPath, final URI namespace,
+                final Date revision, final QName typeName,
+                TypeDefinition<?> baseType, final String description,
+                final String reference) {
+            this.typeName = typeName;
+            this.baseType = baseType;
+            this.path = BaseTypes.schemaPath(actualPath, namespace, revision);
+            this.description = description;
+            this.reference = reference;
+        }
+
         public Builder(final QName typeName, TypeDefinition<?> baseType,
-                final String description, final String reference) {
+                final String description, final String reference,
+                SchemaPath path) {
             this.typeName = typeName;
             this.baseType = baseType;
-            this.path = BaseTypes.schemaPath(typeName);
+            this.path = path;
             this.description = description;
             this.reference = reference;
         }
@@ -80,27 +94,28 @@ public class ExtendedType implements TypeDefinition<TypeDefinition<?>> {
             return this;
         }
 
-        public Builder unknownSchemaNodes(final List<UnknownSchemaNode> unknownSchemaNodes) {
+        public Builder unknownSchemaNodes(
+                final List<UnknownSchemaNode> unknownSchemaNodes) {
             this.unknownSchemaNodes = unknownSchemaNodes;
             return this;
         }
 
         public Builder ranges(final List<RangeConstraint> ranges) {
-            if(ranges != null) {
+            if (ranges != null) {
                 this.ranges = ranges;
             }
             return this;
         }
 
         public Builder lengths(final List<LengthConstraint> lengths) {
-            if(lengths != null) {
+            if (lengths != null) {
                 this.lengths = lengths;
             }
             return this;
         }
 
         public Builder patterns(final List<PatternConstraint> patterns) {
-            if(patterns != null) {
+            if (patterns != null) {
                 this.patterns = patterns;
             }
             return this;
@@ -188,8 +203,10 @@ public class ExtendedType implements TypeDefinition<TypeDefinition<?>> {
                 + ((defaultValue == null) ? 0 : defaultValue.hashCode());
         result = prime * result
                 + ((description == null) ? 0 : description.hashCode());
-        result = prime * result
-                + ((unknownSchemaNodes == null) ? 0 : unknownSchemaNodes.hashCode());
+        result = prime
+                * result
+                + ((unknownSchemaNodes == null) ? 0 : unknownSchemaNodes
+                        .hashCode());
         result = prime * result + ((path == null) ? 0 : path.hashCode());
         result = prime * result
                 + ((reference == null) ? 0 : reference.hashCode());
index 3837f72a8ae6d937e6d96f2e4c79da2865330a41..533318e39e3c15e8ac5fc1fcde2ac5d36fb669f0 100644 (file)
@@ -7,7 +7,9 @@
   */\r
 package org.opendaylight.controller.yang.model.util;\r
 \r
+import java.net.URI;\r
 import java.util.Collections;\r
+import java.util.Date;\r
 import java.util.List;\r
 \r
 import org.opendaylight.controller.yang.common.QName;\r
@@ -24,16 +26,32 @@ import org.opendaylight.controller.yang.model.api.type.IdentityrefTypeDefinition
 public class IdentityrefType implements IdentityrefTypeDefinition {\r
 \r
     private final QName name = BaseTypes.constructQName("identityref");\r
-    private final SchemaPath path = BaseTypes.schemaPath(name);\r
+    private final SchemaPath path;\r
     private final String description = "The identityref type is used to reference an existing identity.";\r
     private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.10";\r
+    private final IdentityrefTypeDefinition baseType;\r
 \r
     private final QName identity;\r
 \r
     private String units = "";\r
 \r
-    public IdentityrefType(QName identity) {\r
+    private IdentityrefType(QName identity) {\r
         this.identity = identity;\r
+        this.path = BaseTypes.schemaPath(name);\r
+        this.baseType = this;\r
+    }\r
+\r
+    public IdentityrefType(QName identity, SchemaPath schemaPath) {\r
+        this.identity = identity;\r
+        this.path = schemaPath;\r
+        this.baseType = new IdentityrefType(identity);\r
+    }\r
+\r
+    public IdentityrefType(final List<String> actualPath,\r
+            final URI namespace, final Date revision, final QName identity) {\r
+        this.identity = identity;\r
+        this.path = BaseTypes.schemaPath(actualPath, namespace, revision);\r
+        this.baseType = new IdentityrefType(identity);\r
     }\r
 \r
     @Override\r
@@ -83,7 +101,7 @@ public class IdentityrefType implements IdentityrefTypeDefinition {
 \r
     @Override\r
     public IdentityrefTypeDefinition getBaseType() {\r
-        return this;\r
+        return baseType;\r
     }\r
 \r
 }\r
index e4f62546f68abfebdfbc295869b223c3c4d170f3..e39b1fa02646feec0263417e1e39e54ac4d5585c 100644 (file)
@@ -7,7 +7,9 @@
   */
 package org.opendaylight.controller.yang.model.util;
 
+import java.net.URI;
 import java.util.Collections;
+import java.util.Date;
 import java.util.List;
 
 import org.opendaylight.controller.yang.common.QName;
@@ -30,31 +32,42 @@ public class InstanceIdentifier implements InstanceIdentifierTypeDefinition {
                "uniquely identify a particular instance node in the data tree.";
     private static final String reference = "https://tools.ietf.org/html/rfc6020#section-9.13";
 
-    private final transient SchemaPath path = BaseTypes.schemaPath(name);
+    private final transient SchemaPath path;
     private final RevisionAwareXPath xpath;
     private final String units = "";
-
+    private final InstanceIdentifierTypeDefinition baseType;
     private final boolean requireInstance;
 
-    public InstanceIdentifier(RevisionAwareXPath xpath, boolean requireInstance) {
+    private InstanceIdentifier(RevisionAwareXPath xpath, boolean requireInstance) {
+        super();
+        path = BaseTypes.schemaPath(name);
+        this.xpath = xpath;
+        this.requireInstance = requireInstance;
+        this.baseType = this;
+    }
+
+    public InstanceIdentifier(final List<String> actualPath, final URI namespace,
+            final Date revision, RevisionAwareXPath xpath, boolean requireInstance) {
         super();
+        path = BaseTypes.schemaPath(actualPath, namespace, revision);
         this.xpath = xpath;
         this.requireInstance = requireInstance;
+        this.baseType = new InstanceIdentifier(xpath, requireInstance);
     }
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getBaseType()
      */
     @Override
     public InstanceIdentifierTypeDefinition getBaseType() {
-        return this;
+        return baseType;
     }
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getUnits()
      */
     @Override
@@ -64,7 +77,7 @@ public class InstanceIdentifier implements InstanceIdentifierTypeDefinition {
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getDefaultValue()
      */
     @Override
@@ -74,7 +87,7 @@ public class InstanceIdentifier implements InstanceIdentifierTypeDefinition {
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getQName()
      */
     @Override
@@ -84,7 +97,7 @@ public class InstanceIdentifier implements InstanceIdentifierTypeDefinition {
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getPath()
      */
     @Override
@@ -94,7 +107,7 @@ public class InstanceIdentifier implements InstanceIdentifierTypeDefinition {
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getDescription()
      */
     @Override
@@ -104,7 +117,7 @@ public class InstanceIdentifier implements InstanceIdentifierTypeDefinition {
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getReference()
      */
     @Override
@@ -114,7 +127,7 @@ public class InstanceIdentifier implements InstanceIdentifierTypeDefinition {
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getStatus()
      */
     @Override
@@ -124,7 +137,7 @@ public class InstanceIdentifier implements InstanceIdentifierTypeDefinition {
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getExtensionSchemaNodes()
      */
     @Override
@@ -134,7 +147,7 @@ public class InstanceIdentifier implements InstanceIdentifierTypeDefinition {
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.opendaylight.controller.yang.model.api.type.InstanceIdentifierTypeDefinition#
      * getPathStatement()
      */
@@ -145,7 +158,7 @@ public class InstanceIdentifier implements InstanceIdentifierTypeDefinition {
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.opendaylight.controller.yang.model.api.type.InstanceIdentifierTypeDefinition#
      * requireInstance()
      */
index 750dff5c7a5e9d88094c728f097a7e1c0ca81809..0e100dc79077d846d2f0ae83ce3dd4768cefdcec 100644 (file)
@@ -28,10 +28,18 @@ public class Int16 extends AbstractSignedInteger {
     private Short defaultValue = null;
     private static final String description =
             "int16  represents integer values between -32768 and 32767, inclusively.";
+    private final IntegerTypeDefinition baseType;
+
+    private Int16() {
+        super(name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
+        this.baseType = this;
+    }
 
     public Int16(final List<String> actualPath, final URI namespace,
             final Date revision) {
         super(actualPath, namespace, revision, name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
+        this.baseType = new Int16();
+
     }
 
     public Int16(final List<String> actualPath, final URI namespace,
@@ -39,11 +47,12 @@ public class Int16 extends AbstractSignedInteger {
             final String units, final Short defaultValue) {
         super(actualPath, namespace, revision, name, description, rangeStatements, units);
         this.defaultValue = defaultValue;
+        this.baseType = new Int16();
     }
 
     @Override
     public IntegerTypeDefinition getBaseType() {
-        return this;
+        return baseType;
     }
 
     @Override
index da356309a504735f5644eced96fbebedd81addf2..fb777c5992399aed543986684f2e94acd0531cd6 100644 (file)
@@ -30,15 +30,23 @@ public class Int32 extends AbstractSignedInteger {
     private Integer defaultValue = null;
     private static final String description =
             "int32  represents integer values between -2147483648 and 2147483647, inclusively.";
+    private final IntegerTypeDefinition baseType;
+
+    private Int32() {
+        super(name, description, Integer.MIN_VALUE, Integer.MAX_VALUE, "");
+        this.baseType = this;
+    }
 
     public Int32(final List<String> actualPath, final URI namespace,
             final Date revision) {
         super(actualPath, namespace, revision, name, description, Integer.MIN_VALUE, Integer.MAX_VALUE, "");
+        this.baseType = new Int32();
     }
 
     public Int32(final List<String> actualPath, final URI namespace,
             final Date revision, final Integer defaultValue) {
         super(actualPath, namespace, revision, name, description, Integer.MIN_VALUE, Integer.MAX_VALUE, "");
+        this.baseType = new Int32();
         this.defaultValue = defaultValue;
     }
 
@@ -46,6 +54,7 @@ public class Int32 extends AbstractSignedInteger {
             final Date revision, final List<RangeConstraint> rangeStatements,
             final String units, final Integer defaultValue) {
         super(actualPath, namespace, revision, name, description, rangeStatements, units);
+        this.baseType = new Int32();
         this.defaultValue = defaultValue;
     }
 
@@ -57,7 +66,7 @@ public class Int32 extends AbstractSignedInteger {
      */
     @Override
     public IntegerTypeDefinition getBaseType() {
-        return this;
+        return baseType;
     }
 
     /*
index 4b05bc59e72a9f011f36809e864a9b767217451d..b22412012b0e8d54c8bbe3819dd09ba1678f255d 100644 (file)
@@ -28,15 +28,23 @@ public class Int64 extends AbstractSignedInteger {
     private Long defaultValue = null;
     private static final String description =
             "int64  represents integer values between -9223372036854775808 and 9223372036854775807, inclusively.";
+    private final IntegerTypeDefinition baseType;
+
+    private Int64() {
+        super(name, description, Integer.MIN_VALUE, Integer.MAX_VALUE, "");
+        this.baseType = this;
+    }
 
     public Int64(final List<String> actualPath, final URI namespace,
             final Date revision) {
         super(actualPath, namespace, revision, name, description, Integer.MIN_VALUE, Integer.MAX_VALUE, "");
+        this.baseType = new Int64();
     }
 
     public Int64(final List<String> actualPath, final URI namespace,
             final Date revision, final Long defaultValue) {
         super(actualPath, namespace, revision, name, description, Integer.MIN_VALUE, Integer.MAX_VALUE, "");
+        this.baseType = new Int64();
         this.defaultValue = defaultValue;
     }
 
@@ -44,6 +52,7 @@ public class Int64 extends AbstractSignedInteger {
             final Date revision, final List<RangeConstraint> rangeStatements,
             final String units, final Long defaultValue) {
         super(actualPath, namespace, revision, name, description, rangeStatements, units);
+        this.baseType = new Int64();
         this.defaultValue = defaultValue;
     }
 
@@ -54,7 +63,7 @@ public class Int64 extends AbstractSignedInteger {
      */
     @Override
     public IntegerTypeDefinition getBaseType() {
-        return this;
+        return baseType;
     }
 
     /*
index 6a917b252f4bd916bca5359add44bc4dd3c1262b..8b0fbe1fa7148197807db9ebbfc2e6b1b997091f 100644 (file)
@@ -29,15 +29,23 @@ public class Int8 extends AbstractSignedInteger {
     private Byte defaultValue = null;
     private static final String description =
             "represents integer values between -128 and 127, inclusively.";
+    private final IntegerTypeDefinition baseType;
+
+    private Int8() {
+        super(name, description, Byte.MIN_VALUE, Byte.MAX_VALUE, "");
+        this.baseType = this;
+    }
 
     public Int8(final List<String> actualPath, final URI namespace,
             final Date revision) {
         super(actualPath, namespace, revision, name, description, Byte.MIN_VALUE, Byte.MAX_VALUE, "");
+        this.baseType = new Int8();
     }
 
     public Int8(final List<String> actualPath, final URI namespace,
             final Date revision, final Byte defaultValue) {
         super(actualPath, namespace, revision, name, description, Byte.MIN_VALUE, Byte.MAX_VALUE, "");
+        this.baseType = new Int8();
         this.defaultValue = defaultValue;
     }
 
@@ -45,6 +53,7 @@ public class Int8 extends AbstractSignedInteger {
             final Date revision, final List<RangeConstraint> rangeStatements,
             final String units, final Byte defaultValue) {
         super(actualPath, namespace, revision, name, description, rangeStatements, units);
+        this.baseType = new Int8();
         this.defaultValue = defaultValue;
     }
 
@@ -55,7 +64,7 @@ public class Int8 extends AbstractSignedInteger {
      */
     @Override
     public IntegerTypeDefinition getBaseType() {
-        return this;
+        return baseType;
     }
 
     /*
index f58075bf307d9d6d2bd4f2012620dc4970426c7a..b4e2d6b9ad867dd3e4c3fac226be78c0fdd7a774 100644 (file)
@@ -36,6 +36,17 @@ public class StringType implements StringTypeDefinition {
     private final List<LengthConstraint> lengthStatements;
     private final List<PatternConstraint> patterns;
     private String units = "";
+    private final StringTypeDefinition baseType;
+
+    private StringType() {
+        super();
+        path = BaseTypes.schemaPath(name);
+        final List<LengthConstraint> constraints = new ArrayList<LengthConstraint>();
+        constraints.add(BaseConstraints.lengthConstraint(0, Long.MAX_VALUE, "", ""));
+        lengthStatements = Collections.unmodifiableList(constraints);
+        patterns = Collections.emptyList();
+        baseType = this;
+    }
 
     /**
      * Default Constructor.
@@ -47,13 +58,15 @@ public class StringType implements StringTypeDefinition {
         final List<LengthConstraint> constraints = new ArrayList<LengthConstraint>();
         constraints.add(BaseConstraints.lengthConstraint(0, Long.MAX_VALUE, "", ""));
         lengthStatements = Collections.unmodifiableList(constraints);
-
-        this.patterns = Collections.emptyList();
+        patterns = Collections.emptyList();
+        baseType = new StringType();
     }
 
     /**
      *
-     *
+     * @param actualPath
+     * @param namespace
+     * @param revision
      * @param lengthStatements
      * @param patterns
      */
@@ -70,6 +83,7 @@ public class StringType implements StringTypeDefinition {
             this.lengthStatements = Collections.unmodifiableList(lengthStatements);
         }
         this.patterns = Collections.unmodifiableList(patterns);
+        baseType = new StringType();
     }
 
     /**
@@ -85,7 +99,7 @@ public class StringType implements StringTypeDefinition {
             final List<LengthConstraint> lengthStatements,
             final List<PatternConstraint> patterns, final String units) {
         super();
-        path = BaseTypes.schemaPath(actualPath, namespace, revision);
+        this.path = BaseTypes.schemaPath(actualPath, namespace, revision);
         this.defaultValue = defaultValue;
         if(lengthStatements == null || lengthStatements.size() == 0) {
             final List<LengthConstraint> constraints = new ArrayList<LengthConstraint>();
@@ -94,8 +108,9 @@ public class StringType implements StringTypeDefinition {
         } else {
             this.lengthStatements = Collections.unmodifiableList(lengthStatements);
         }
-        this.patterns = patterns;
+        this.patterns = Collections.unmodifiableList(patterns);
         this.units = units;
+        this.baseType = new StringType();
     }
 
     /*
@@ -105,7 +120,7 @@ public class StringType implements StringTypeDefinition {
      */
     @Override
     public StringTypeDefinition getBaseType() {
-        return this;
+        return baseType;
     }
 
     /*
index 9db4ea9df878cdbc72da18ef30ebd431a99d0fdb..5764cb26c7bd0d616ac0ce9575d3fa9f752189c0 100644 (file)
@@ -26,15 +26,23 @@ public class Uint16 extends AbstractUnsignedInteger {
     private static final QName name = BaseTypes.constructQName("uint16");
     private Integer defaultValue = null;
     private static final String description = "uint16 represents integer values between 0 and 65535, inclusively.";
+    private final UnsignedIntegerTypeDefinition baseType;
+
+    private Uint16() {
+        super(name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
+        this.baseType = this;
+    }
 
     public Uint16(final List<String> actualPath,
             final URI namespace, final Date revision) {
         super(actualPath, namespace, revision, name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
+        this.baseType = new Uint16();
     }
 
     public Uint16(final List<String> actualPath,
             final URI namespace, final Date revision, final Integer defaultValue) {
         super(actualPath, namespace, revision, name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
+        this.baseType = new Uint16();
         this.defaultValue = defaultValue;
     }
 
@@ -42,6 +50,7 @@ public class Uint16 extends AbstractUnsignedInteger {
             final URI namespace, final Date revision, final List<RangeConstraint> rangeStatements,
             final String units, final Integer defaultValue) {
         super(actualPath, namespace, revision, name, description, rangeStatements, units);
+        this.baseType = new Uint16();
         this.defaultValue = defaultValue;
     }
 
@@ -53,7 +62,7 @@ public class Uint16 extends AbstractUnsignedInteger {
      */
     @Override
     public UnsignedIntegerTypeDefinition getBaseType() {
-        return this;
+        return baseType;
     }
 
     /*
index 75f9b49693e41ad01015156b31836334c02e330f..47af1e1c986d4ad10680833690be31b645c9e06c 100644 (file)
@@ -26,15 +26,23 @@ public class Uint32 extends AbstractUnsignedInteger {
     private static final QName name = BaseTypes.constructQName("uint32");
     private Long defaultValue = null;
     private static final String description = "uint32 represents integer values between 0 and 4294967295, inclusively.";
+    private final UnsignedIntegerTypeDefinition baseType;
+
+    private Uint32() {
+        super(name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
+        this.baseType = this;
+    }
 
     public Uint32(final List<String> actualPath,
             final URI namespace, final Date revision) {
         super(actualPath, namespace, revision, name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
+        this.baseType = new Uint32();
     }
 
     public Uint32(final List<String> actualPath,
             final URI namespace, final Date revision, final Long defaultValue) {
         super(actualPath, namespace, revision, name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
+        this.baseType = new Uint32();
         this.defaultValue = defaultValue;
     }
 
@@ -42,6 +50,7 @@ public class Uint32 extends AbstractUnsignedInteger {
             final URI namespace, final Date revision, final List<RangeConstraint> rangeStatements,
             final String units, final Long defaultValue) {
         super(actualPath, namespace, revision, name, description, rangeStatements, units);
+        this.baseType = new Uint32();
         this.defaultValue = defaultValue;
     }
 
@@ -53,7 +62,7 @@ public class Uint32 extends AbstractUnsignedInteger {
      */
     @Override
     public UnsignedIntegerTypeDefinition getBaseType() {
-        return this;
+        return baseType;
     }
 
     /*
index 05ea8c9e0983f98687a950fc8c2cffbc841c1328..f9c2aa3c90a15f41acb9700bae152aa953a237a9 100644 (file)
@@ -30,15 +30,23 @@ public class Uint64 extends AbstractUnsignedInteger {
     private BigInteger defaultValue = null;
     private static final String description =
             "uint64 represents integer values between 0 and 18446744073709551615, inclusively.";
+    private final UnsignedIntegerTypeDefinition baseType;
+
+    private Uint64() {
+        super(name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
+        this.baseType = this;
+    }
 
     public Uint64(final List<String> actualPath,
             final URI namespace, final Date revision) {
         super(actualPath, namespace, revision, name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
+        this.baseType = new Uint64();
     }
 
     public Uint64(final List<String> actualPath,
             final URI namespace, final Date revision, final BigInteger defaultValue) {
         super(actualPath, namespace, revision, name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
+        this.baseType = new Uint64();
         this.defaultValue = defaultValue;
     }
 
@@ -46,6 +54,7 @@ public class Uint64 extends AbstractUnsignedInteger {
             final URI namespace, final Date revision, final List<RangeConstraint> rangeStatements,
             final String units, final BigInteger defaultValue) {
         super(actualPath, namespace, revision, name, description, rangeStatements, units);
+        this.baseType = new Uint64();
         this.defaultValue = defaultValue;
     }
 
@@ -57,7 +66,7 @@ public class Uint64 extends AbstractUnsignedInteger {
      */
     @Override
     public UnsignedIntegerTypeDefinition getBaseType() {
-        return this;
+        return baseType;
     }
 
     /*
index aa1e6cacfbf3e315b0604d35114df1360f6e325b..ece0eb5c3f37dba7d132160e47ecd9130e253c62 100644 (file)
@@ -29,15 +29,23 @@ public class Uint8 extends AbstractUnsignedInteger {
     private Short defaultValue = null;
     private static final String description =
             "uint8  represents integer values between 0 and 255, inclusively.";
+    private final UnsignedIntegerTypeDefinition baseType;
+
+    private Uint8() {
+        super(name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
+        this.baseType = this;
+    }
 
     public Uint8(final List<String> actualPath,
             final URI namespace, final Date revision) {
         super(actualPath, namespace, revision, name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
+        this.baseType = new Uint8();
     }
 
     public Uint8(final List<String> actualPath,
             final URI namespace, final Date revision, final Short defaultValue) {
         super(actualPath, namespace, revision, name, description, Short.MIN_VALUE, Short.MAX_VALUE, "");
+        this.baseType = new Uint8();
         this.defaultValue = defaultValue;
     }
 
@@ -45,6 +53,7 @@ public class Uint8 extends AbstractUnsignedInteger {
             final URI namespace, final Date revision, final List<RangeConstraint> rangeStatements,
             final String units, final Short defaultValue) {
         super(actualPath, namespace, revision, name, description, rangeStatements, units);
+        this.baseType = new Uint8();
         this.defaultValue = defaultValue;
     }
 
@@ -55,7 +64,7 @@ public class Uint8 extends AbstractUnsignedInteger {
      */
     @Override
     public UnsignedIntegerTypeDefinition getBaseType() {
-        return this;
+        return baseType;
     }
 
     /*
index ad40393291d748a0a428fed9674789589e0e0d0e..1063f3b22b6bfe4720af2539803f6296875c9c72 100644 (file)
@@ -7,7 +7,9 @@
   */
 package org.opendaylight.controller.yang.model.util;
 
+import java.net.URI;
 import java.util.Collections;
+import java.util.Date;
 import java.util.List;
 
 import org.opendaylight.controller.yang.common.QName;
@@ -20,23 +22,34 @@ import org.opendaylight.controller.yang.model.api.type.UnionTypeDefinition;
 public class UnionType implements UnionTypeDefinition {
 
     private final QName name = BaseTypes.constructQName("union");
-    private final SchemaPath path = BaseTypes.schemaPath(name);
+    private final SchemaPath path;
     private final String description = "The union built-in type represents a value that corresponds to one of its member types.";
     private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.12";
-
+    private final UnionTypeDefinition baseType;
     private final List<TypeDefinition<?>> types;
 
+    private UnionType(List<TypeDefinition<?>> types) {
+        if(types == null) {
+            throw new NullPointerException("When the type is 'union', the 'type' statement MUST be present.");
+        }
+        path = BaseTypes.schemaPath(name);
+        this.types = types;
+        this.baseType = this;
+    }
 
-    public UnionType(List<TypeDefinition<?>> types) {
+    public UnionType(final List<String> actualPath, final URI namespace,
+            final Date revision, List<TypeDefinition<?>> types) {
         if(types == null) {
             throw new NullPointerException("When the type is 'union', the 'type' statement MUST be present.");
         }
+        path = BaseTypes.schemaPath(actualPath, namespace, revision);
         this.types = types;
+        this.baseType = new UnionType(types);
     }
 
     @Override
     public UnionTypeDefinition getBaseType() {
-        return this;
+        return baseType;
     }
 
     @Override
@@ -86,8 +99,12 @@ public class UnionType implements UnionTypeDefinition {
 
     @Override
     public int hashCode() {
-        // TODO: implement hashcode
-        return 4;
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((name == null) ? 0 : name.hashCode());
+        result = prime * result + ((path == null) ? 0 : path.hashCode());
+        result = prime * result + ((types == null) ? 0 : types.hashCode());
+        return result;
     }
 
     @Override
index f3db85cf9a0242ab0f90d2753e0d1408368e4b36..6d41321bfd0cb5042c150f3f77779e9f68cc344a 100644 (file)
@@ -9,39 +9,16 @@ package org.opendaylight.controller.yang.model.util;
 \r
 import java.net.URI;\r
 import java.util.Date;\r
-import java.util.HashMap;\r
 import java.util.HashSet;\r
 import java.util.List;\r
-import java.util.Map;\r
 import java.util.Set;\r
 \r
-import org.opendaylight.controller.yang.common.QName;\r
 import org.opendaylight.controller.yang.model.api.TypeDefinition;\r
-import org.opendaylight.controller.yang.model.api.type.BinaryTypeDefinition;\r
-import org.opendaylight.controller.yang.model.api.type.BitsTypeDefinition;\r
-import org.opendaylight.controller.yang.model.api.type.BooleanTypeDefinition;\r
-import org.opendaylight.controller.yang.model.api.type.EmptyTypeDefinition;\r
-import org.opendaylight.controller.yang.model.api.type.InstanceIdentifierTypeDefinition;\r
 \r
 public class YangTypesConverter {\r
-\r
-    private static final Map<String, TypeDefinition<? extends TypeDefinition<?>>> baseYangTypeMap = new HashMap<String, TypeDefinition<? extends TypeDefinition<?>>>();\r
     private static final Set<String> baseYangTypes = new HashSet<String>();\r
 \r
-    private static final TypeDefinition<BinaryTypeDefinition> BINARY = new BinaryType();\r
-    private static final TypeDefinition<BitsTypeDefinition> BITS = new BitsType();\r
-    private static final TypeDefinition<BooleanTypeDefinition> BOOLEAN_TYPE = new BooleanType();\r
-    private static final TypeDefinition<EmptyTypeDefinition> EMPTY_TYPE = new EmptyType();\r
-    private static final TypeDefinition<InstanceIdentifierTypeDefinition> INST_ID_TYPE = new InstanceIdentifier(\r
-            null, true);\r
-\r
     static {\r
-        baseYangTypeMap.put("binary", BINARY);\r
-        baseYangTypeMap.put("bits", BITS);\r
-        baseYangTypeMap.put("boolean", BOOLEAN_TYPE);\r
-        baseYangTypeMap.put("empty", EMPTY_TYPE);\r
-        baseYangTypeMap.put("instance-identifier", INST_ID_TYPE);\r
-\r
         baseYangTypes.add("binary");\r
         baseYangTypes.add("bits");\r
         baseYangTypes.add("boolean");\r
@@ -67,40 +44,45 @@ public class YangTypesConverter {
         return baseYangTypes.contains(type);\r
     }\r
 \r
-    public static TypeDefinition<?> javaTypeForBaseYangType(QName typeQName) {\r
-        TypeDefinition<?> type = baseYangTypeMap.get(typeQName.getLocalName());\r
-        return type;\r
-    }\r
-\r
     public static TypeDefinition<?> javaTypeForBaseYangType(\r
             List<String> actualPath, URI namespace, Date revision,\r
             String typeName) {\r
+        TypeDefinition<?> type = null;\r
 \r
         if (typeName.startsWith("int")) {\r
             if (typeName.equals("int8")) {\r
-                return new Int8(actualPath, namespace, revision);\r
+                type = new Int8(actualPath, namespace, revision);\r
             } else if (typeName.equals("int16")) {\r
-                return new Int16(actualPath, namespace, revision);\r
+                type = new Int16(actualPath, namespace, revision);\r
             } else if (typeName.equals("int32")) {\r
-                return new Int32(actualPath, namespace, revision);\r
+                type = new Int32(actualPath, namespace, revision);\r
             } else if (typeName.equals("int64")) {\r
-                return new Int64(actualPath, namespace, revision);\r
+                type = new Int64(actualPath, namespace, revision);\r
             }\r
         } else if (typeName.startsWith("uint")) {\r
             if (typeName.equals("uint8")) {\r
-                return new Uint8(actualPath, namespace, revision);\r
+                type = new Uint8(actualPath, namespace, revision);\r
             } else if (typeName.equals("uint16")) {\r
-                return new Uint16(actualPath, namespace, revision);\r
+                type = new Uint16(actualPath, namespace, revision);\r
             } else if (typeName.equals("uint32")) {\r
-                return new Uint32(actualPath, namespace, revision);\r
+                type = new Uint32(actualPath, namespace, revision);\r
             } else if (typeName.equals("uint64")) {\r
-                return new Uint64(actualPath, namespace, revision);\r
+                type = new Uint64(actualPath, namespace, revision);\r
             }\r
-        } else if (typeName.equals("string")) {\r
-            return new StringType(actualPath, namespace, revision);\r
+        } else if ("string".equals(typeName)) {\r
+            type = new StringType(actualPath, namespace, revision);\r
+        } else if("binary".equals(typeName)) {\r
+            type = new BinaryType(actualPath, namespace, revision);\r
+        } else if("bits".equals(typeName)) {\r
+            type = new BitsType(actualPath, namespace, revision);\r
+        } else if("boolean".equals(typeName)) {\r
+            type = new BooleanType(actualPath, namespace, revision);\r
+        } else if("empty".equals(typeName)) {\r
+            type = new EmptyType(actualPath, namespace, revision);\r
+        } else if("instance-identifier".equals(typeName)) {\r
+            type = new InstanceIdentifier(actualPath, namespace, revision, null, true);\r
         }\r
 \r
-        TypeDefinition<?> type = baseYangTypeMap.get(typeName);\r
         return type;\r
     }\r
 \r