Refactored parsing of YANG uses statement. 28/528/3
authorMartin Vitez <mvitez@cisco.com>
Thu, 27 Jun 2013 14:26:12 +0000 (16:26 +0200)
committerGerrit Code Review <gerrit@opendaylight.org>
Fri, 28 Jun 2013 07:39:52 +0000 (07:39 +0000)
Uses statement now add nodes from referenced grouping to context where uses is defined. Added GroupingMember interface as marker interface for nodes defined in grouping.
Fixed parsing of config statement: when config is not specified, the default is same as parent schema node. If top node does not specify config, default is true.
Added ConfigNode as marker interface for nodes which can contains 'config' statement.
Added AbstractSchemaNodeBuilder as base class for builders of SchemaNode nodes.
Updated tests.

Change-Id: Ibabcf590608bdf482258826fa250692507a71c01
Signed-off-by: Martin Vitez <mvitez@cisco.com>
53 files changed:
opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/java/org/opendaylight/controller/sal/binding/generator/impl/GenEnumResolvingTest.java
opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/java/org/opendaylight/controller/sal/binding/generator/impl/GeneratedTypesBitsTest.java
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/parser/builder/api/AbstractDataNodeContainerBuilder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/api/AbstractSchemaNodeBuilder.java [new file with mode: 0644]
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/api/AugmentationSchemaBuilder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/api/Builder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/api/ConfigNode.java [new file with mode: 0644]
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/api/DataNodeContainerBuilder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/api/DataSchemaNodeBuilder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/api/GroupingBuilder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/api/GroupingMember.java [new file with mode: 0644]
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/api/TypeDefinitionBuilder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/api/UsesNodeBuilder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/impl/AnyXmlBuilder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/impl/AugmentationSchemaBuilderImpl.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/impl/ChoiceBuilder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/impl/ChoiceCaseBuilder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/impl/ConstraintsBuilder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/impl/ContainerSchemaNodeBuilder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/impl/DeviationBuilder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/impl/ExtensionBuilder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/impl/FeatureBuilder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/impl/GroupingBuilderImpl.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/impl/IdentitySchemaNodeBuilder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/impl/IdentityrefTypeBuilder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/impl/LeafListSchemaNodeBuilder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/impl/LeafSchemaNodeBuilder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/impl/ListSchemaNodeBuilder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/impl/ModuleBuilder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/impl/NotificationBuilder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/impl/RpcDefinitionBuilder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/impl/TypeDefinitionBuilderImpl.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/impl/UnionTypeBuilder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/impl/UnknownSchemaNodeBuilder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/impl/UsesNodeBuilderImpl.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/impl/YangParserImpl.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/impl/YangParserListenerImpl.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/util/ParserUtils.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/util/RefineHolder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/util/RefineUtils.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/util/YangModelBuilderUtil.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/parser/impl/GroupingTest.java [new file with mode: 0644]
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/parser/impl/YangParserTest.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/parser/impl/YangParserWithContextTest.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/model/testfile1.yang
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/model/testfile2.yang
opendaylight/sal/yang-prototype/yang/yang-model-api/src/main/java/org/opendaylight/controller/yang/model/api/DataSchemaNode.java
opendaylight/sal/yang-prototype/yang/yang-model-api/src/main/java/org/opendaylight/controller/yang/model/api/GroupingDefinition.java
opendaylight/sal/yang-prototype/yang/yang-model-api/src/main/java/org/opendaylight/controller/yang/model/api/UnknownSchemaNode.java
opendaylight/sal/yang-prototype/yang/yang-model-api/src/main/java/org/opendaylight/controller/yang/model/api/UsesNode.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/InstanceIdentifier.java

index 10ea9fa..f8cf951 100644 (file)
@@ -7,6 +7,13 @@
  */
 package org.opendaylight.controller.sal.binding.generator.impl;
 
+import static org.junit.Assert.*;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
 import org.junit.Test;
 import org.opendaylight.controller.binding.generator.util.ReferencedTypeImpl;
 import org.opendaylight.controller.sal.binding.generator.api.BindingGenerator;
@@ -19,15 +26,6 @@ import org.opendaylight.controller.yang.model.api.SchemaContext;
 import org.opendaylight.controller.yang.model.parser.api.YangModelParser;
 import org.opendaylight.controller.yang.parser.impl.YangParserImpl;
 
-import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
 public class GenEnumResolvingTest {
 
     private SchemaContext resolveSchemaContextFromFiles(
@@ -108,8 +106,8 @@ public class GenEnumResolvingTest {
         assertNotNull("Generated Interface cannot contain NULL reference for " +
                 "Method Signature Definitions!", methods);
 
-        assertEquals("Expected count of method signature definitions is 26",
-                26, methods.size());
+        assertEquals("Expected count of method signature definitions is 21",
+                21, methods.size());
         Enumeration ianaIfType = null;
         for (final MethodSignature method : methods) {
             if (method.getName().equals("getType")) {
@@ -186,8 +184,8 @@ public class GenEnumResolvingTest {
         final List<MethodSignature> methods = genInterface.getMethodDefinitions();
         assertNotNull("Generated Type Interface cannot contain NULL reference" +
                 " to Enumeration types!", methods);
-        assertEquals("Generated Type Interface MUST contain 7 Methods ",
-                7, methods.size());
+        assertEquals("Generated Type Interface MUST contain 4 Methods ",
+                4, methods.size());
         for (final MethodSignature method : methods) {
             if (method.getName().equals("getLinkUpDownTrapEnable")) {
                 linkUpDownTrapEnable = method.getReturnType();
index af08ac2..c98f8bf 100644 (file)
@@ -1,8 +1,6 @@
 package org.opendaylight.controller.sal.binding.generator.impl;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.*;
 
 import java.io.File;
 import java.util.ArrayList;
@@ -134,10 +132,8 @@ public class GeneratedTypesBitsTest {
         assertTrue(getByteLeafMethodFound);
         assertEquals(nameReturnParamType,"ByteType");
 
-        assertTrue(setByteLeafMethodFound);
-        assertEquals(setByteLeafMethodParamNum,1);
-        assertEquals(nameMethodeParamType,"ByteType");
-
+        assertFalse(setByteLeafMethodFound);
+        assertEquals(0, setByteLeafMethodParamNum);
     }
 
 }
\ No newline at end of file
index 6d50975..ce9f131 100644 (file)
@@ -253,8 +253,8 @@ public class GeneratedTypesTest {
 
         assertEquals("SimpleContainer", simpleContainer.getName());
         assertEquals("NestedContainer", nestedContainer.getName());
-        assertEquals(5, simpleContainer.getMethodDefinitions().size());
-        assertEquals(4, nestedContainer.getMethodDefinitions().size());
+        assertEquals(3, simpleContainer.getMethodDefinitions().size());
+        assertEquals(2, nestedContainer.getMethodDefinitions().size());
 
         int setFooMethodCounter = 0;
         int getFooMethodCounter = 0;
@@ -293,9 +293,10 @@ public class GeneratedTypesTest {
         assertEquals(getFooMethodCounter, 1);
         assertEquals(getFooMethodReturnTypeName, "Integer");
 
-        assertEquals(setFooMethodCounter, 1);
-        assertEquals(setFooMethodInputParamName, "foo");
-        assertEquals(setFooMethodInputParamTypeName, "Integer");
+        // TODO no setter methods, because 'config' is default true
+        // assertEquals(setFooMethodCounter, 1);
+        // assertEquals(setFooMethodInputParamName, "foo");
+        // assertEquals(setFooMethodInputParamTypeName, "Integer");
 
         assertEquals(getBarMethodCounter, 1);
         assertEquals(getBarMethodReturnTypeName, "String");
@@ -345,16 +346,18 @@ public class GeneratedTypesTest {
         assertEquals(1, getFooMethodCounter);
         assertEquals(getFooMethodReturnTypeName, "Short");
 
-        assertEquals(1, setFooMethodCounter);
-        assertEquals(setFooMethodInputParamName, "foo");
-        assertEquals(setFooMethodInputParamTypeName, "Short");
+        // TODO no setter methods, because 'config' is default true
+        // assertEquals(1, setFooMethodCounter);
+        // assertEquals(setFooMethodInputParamName, "foo");
+        // assertEquals(setFooMethodInputParamTypeName, "Short");
 
         assertEquals(1, getBarMethodCounter);
         assertEquals(getBarMethodReturnTypeName, "String");
 
-        assertEquals(1, setBarMethodCounter);
-        assertEquals(setBarMethodInputParamName, "bar");
-        assertEquals(setBarMethodInputParamTypeName, "String");
+        // TODO no setter methods, because 'config' is default true
+        // assertEquals(1, setBarMethodCounter);
+        // assertEquals(setBarMethodInputParamName, "bar");
+        // assertEquals(setBarMethodInputParamTypeName, "String");
     }
 
     @Test
@@ -374,8 +377,8 @@ public class GeneratedTypesTest {
 
         assertEquals("SimpleContainer", simpleContainer.getName());
         assertEquals("NestedContainer", nestedContainer.getName());
-        assertEquals(5, simpleContainer.getMethodDefinitions().size());
-        assertEquals(3, nestedContainer.getMethodDefinitions().size());
+        assertEquals(3, simpleContainer.getMethodDefinitions().size());
+        assertEquals(2, nestedContainer.getMethodDefinitions().size());
 
         int setFooMethodCounter = 0;
         int getFooMethodCounter = 0;
@@ -414,9 +417,10 @@ public class GeneratedTypesTest {
         assertEquals(1, getFooMethodCounter);
         assertEquals(getFooMethodReturnTypeName, "List");
 
-        assertEquals(1, setFooMethodCounter);
-        assertEquals(setFooMethodInputParamName, "foo");
-        assertEquals(setFooMethodInputParamTypeName, "List");
+        // TODO no setter methods, because 'config' is default true
+        // assertEquals(1, setFooMethodCounter);
+        // assertEquals(setFooMethodInputParamName, "foo");
+        // assertEquals(setFooMethodInputParamTypeName, "List");
 
         assertEquals(1, getBarMethodCounter);
         assertEquals(getBarMethodReturnTypeName, "String");
@@ -455,9 +459,10 @@ public class GeneratedTypesTest {
         assertEquals(1, getFooMethodCounter);
         assertEquals(getFooMethodReturnTypeName, "Short");
 
-        assertEquals(1, setFooMethodCounter);
-        assertEquals(setFooMethodInputParamName, "foo");
-        assertEquals(setFooMethodInputParamTypeName, "Short");
+        // TODO no setter methods, because 'config' is default true
+        // assertEquals(1, setFooMethodCounter);
+        // assertEquals(setFooMethodInputParamName, "foo");
+        // assertEquals(setFooMethodInputParamTypeName, "Short");
 
         assertEquals(1, getBarMethodCounter);
         assertEquals(getBarMethodReturnTypeName, "List");
@@ -564,8 +569,8 @@ public class GeneratedTypesTest {
             }
         }
 
-        assertEquals(2, listParentContainerMethodsCount);
-        assertEquals(2, listChildContainerMethodsCount);
+        assertEquals(1, listParentContainerMethodsCount);
+        assertEquals(1, listChildContainerMethodsCount);
         assertEquals(1, getSimpleListKeyMethodCount);
         assertEquals(1, listKeyClassCount);
 
@@ -585,12 +590,12 @@ public class GeneratedTypesTest {
         assertEquals(1, getListChildContainerMethodCount);
         assertEquals("ListChildContainer", getListChildContainerMethodReturnTypeName);
         assertEquals(1, getFooMethodCount);
-        assertEquals(1, setFooMethodCount);
+        assertEquals(0, setFooMethodCount);
         assertEquals(1, getSimpleLeafListMethodCount);
-        assertEquals(1, setSimpleLeafListMethodCount);
+        assertEquals(0, setSimpleLeafListMethodCount);
         assertEquals(1, getBarMethodCount);
 
-        assertEquals(8, simpleListMethodsCount);
+        assertEquals(5, simpleListMethodsCount);
     }
 
     @Test
index 8ca88d8..d6722be 100644 (file)
@@ -15,7 +15,6 @@ import org.opendaylight.controller.yang.model.api.DataSchemaNode;
 import org.opendaylight.controller.yang.model.api.GroupingDefinition;
 
 public abstract class AbstractDataNodeContainerBuilder implements DataNodeContainerBuilder {
-
     private final QName qname;
 
     protected Set<DataSchemaNode> childNodes;
@@ -34,7 +33,12 @@ public abstract class AbstractDataNodeContainerBuilder implements DataNodeContai
     }
 
     @Override
-    public Set<DataSchemaNodeBuilder> getChildNodes() {
+    public Set<DataSchemaNode> getChildNodes() {
+        return childNodes;
+    }
+
+    @Override
+    public Set<DataSchemaNodeBuilder> getChildNodeBuilders() {
         return addedChildNodes;
     }
 
@@ -47,7 +51,12 @@ public abstract class AbstractDataNodeContainerBuilder implements DataNodeContai
         this.childNodes = childNodes;
     }
 
-    public Set<GroupingBuilder> getGroupings() {
+    @Override
+    public Set<GroupingDefinition> getGroupings() {
+        return groupings;
+    }
+
+    public Set<GroupingBuilder> getGroupingBuilders() {
         return addedGroupings;
     }
 
diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/api/AbstractSchemaNodeBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/api/AbstractSchemaNodeBuilder.java
new file mode 100644 (file)
index 0000000..c8e6968
--- /dev/null
@@ -0,0 +1,83 @@
+/*\r
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.controller.yang.parser.builder.api;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import org.opendaylight.controller.yang.common.QName;\r
+import org.opendaylight.controller.yang.model.api.SchemaPath;\r
+import org.opendaylight.controller.yang.model.api.Status;\r
+import org.opendaylight.controller.yang.parser.builder.impl.UnknownSchemaNodeBuilder;\r
+\r
+/**\r
+ * Basic implementation of SchemaNodeBuilder.\r
+ */\r
+public abstract class AbstractSchemaNodeBuilder implements SchemaNodeBuilder {\r
+    protected final int line;\r
+    protected final QName qname;\r
+    protected SchemaPath path;\r
+    protected String description;\r
+    protected String reference;\r
+    protected Status status = Status.CURRENT;\r
+    protected final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();\r
+\r
+    protected AbstractSchemaNodeBuilder(final QName qname, final int line) {\r
+        this.qname = qname;\r
+        this.line = line;\r
+    }\r
+\r
+    @Override\r
+    public int getLine() {\r
+        return line;\r
+    }\r
+\r
+    public QName getQName() {\r
+        return qname;\r
+    }\r
+\r
+    public SchemaPath getPath() {\r
+        return path;\r
+    }\r
+\r
+    public void setPath(SchemaPath schemaPath) {\r
+        this.path = schemaPath;\r
+    }\r
+\r
+    public String getDescription() {\r
+        return description;\r
+    }\r
+\r
+    public void setDescription(String description) {\r
+        this.description = description;\r
+    }\r
+\r
+    public String getReference() {\r
+        return reference;\r
+    }\r
+\r
+    public void setReference(String reference) {\r
+        this.reference = reference;\r
+    }\r
+\r
+    public Status getStatus() {\r
+        return status;\r
+    }\r
+\r
+    public void setStatus(Status status) {\r
+        if (status != null) {\r
+            this.status = status;\r
+        }\r
+    }\r
+\r
+    @Override\r
+    public void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownNode) {\r
+        addedUnknownNodes.add(unknownNode);\r
+    }\r
+\r
+}\r
index f991798..76fe19f 100644 (file)
@@ -7,8 +7,6 @@
  */
 package org.opendaylight.controller.yang.parser.builder.api;
 
-import java.util.Set;
-
 import org.opendaylight.controller.yang.model.api.AugmentationSchema;
 import org.opendaylight.controller.yang.model.api.SchemaPath;
 import org.opendaylight.controller.yang.model.api.Status;
@@ -18,6 +16,8 @@ import org.opendaylight.controller.yang.model.api.Status;
  */
 public interface AugmentationSchemaBuilder extends DataNodeContainerBuilder {
 
+    Builder getParent();
+
     String getWhenCondition();
 
     void addWhenCondition(String whenCondition);
@@ -34,8 +34,6 @@ public interface AugmentationSchemaBuilder extends DataNodeContainerBuilder {
 
     void setTargetPath(SchemaPath path);
 
-    Set<DataSchemaNodeBuilder> getChildNodes();
-
     AugmentationSchema build();
 
     boolean isResolved();
index ee50d2a..1d199c2 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.controller.yang.parser.builder.api;
 
+import org.opendaylight.controller.yang.parser.builder.impl.UnknownSchemaNodeBuilder;
+
 /**
  * Parent interface for all builder interfaces.
  */
@@ -25,4 +27,6 @@ public interface Builder {
 
     int getLine();
 
+    void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownNode);
+
 }
diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/api/ConfigNode.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/api/ConfigNode.java
new file mode 100644 (file)
index 0000000..85f6b07
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+ * 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.parser.builder.api;
+
+/**
+ * Interface for all nodes which can have 'config' statement.
+ * [container, leaf, leaf-list, list, choice, anyxml, deviate]
+ *
+ */
+public interface ConfigNode {
+
+    Boolean isConfiguration();
+
+    void setConfiguration(Boolean config);
+
+}
index e64bb02..13b7e48 100644 (file)
@@ -10,6 +10,8 @@ package org.opendaylight.controller.yang.parser.builder.api;
 import java.util.Set;
 
 import org.opendaylight.controller.yang.common.QName;
+import org.opendaylight.controller.yang.model.api.DataSchemaNode;
+import org.opendaylight.controller.yang.model.api.GroupingDefinition;
 import org.opendaylight.controller.yang.model.api.SchemaPath;
 
 /**
@@ -20,20 +22,24 @@ public interface DataNodeContainerBuilder extends Builder {
 
     QName getQName();
 
-    Set<DataSchemaNodeBuilder> getChildNodes();
+    SchemaPath getPath();
+
+    Set<DataSchemaNode> getChildNodes();
+
+    Set<DataSchemaNodeBuilder> getChildNodeBuilders();
 
     void addChildNode(DataSchemaNodeBuilder childNode);
 
-    Set<GroupingBuilder> getGroupings();
+    Set<GroupingDefinition> getGroupings();
+
+    Set<GroupingBuilder> getGroupingBuilders();
 
     void addGrouping(GroupingBuilder groupingBuilder);
 
     void addUsesNode(UsesNodeBuilder usesBuilder);
 
-    Set<TypeDefinitionBuilder> getTypeDefinitions();
+    Set<TypeDefinitionBuilder> getTypeDefinitionBuilders();
 
     void addTypedef(TypeDefinitionBuilder typedefBuilder);
 
-    SchemaPath getPath();
-
 }
index e4088a8..20d9417 100644 (file)
@@ -11,20 +11,12 @@ import java.util.List;
 import java.util.Set;
 
 import org.opendaylight.controller.yang.model.api.GroupingDefinition;
-import org.opendaylight.controller.yang.model.api.Status;
 import org.opendaylight.controller.yang.parser.builder.impl.UnknownSchemaNodeBuilder;
 
 /**
  * Interface for builders of 'grouping' statement.
  */
-public interface GroupingBuilder extends DataNodeContainerBuilder, SchemaNodeBuilder,
-        TypeDefinitionAwareBuilder {
-
-    String getDescription();
-
-    String getReference();
-
-    Status getStatus();
+public interface GroupingBuilder extends DataNodeContainerBuilder, SchemaNodeBuilder, TypeDefinitionAwareBuilder, GroupingMember {
 
     GroupingDefinition build();
 
@@ -32,8 +24,6 @@ public interface GroupingBuilder extends DataNodeContainerBuilder, SchemaNodeBui
 
     List<UnknownSchemaNodeBuilder> getUnknownNodes();
 
-    Set<GroupingBuilder> getGroupings();
-
     Set<UsesNodeBuilder> getUses();
 
 }
diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/api/GroupingMember.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/api/GroupingMember.java
new file mode 100644 (file)
index 0000000..bcdc077
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+ * 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.parser.builder.api;
+
+/**
+ * Marker interface for nodes which can be defined in grouping statement.
+ * [anyxml, choice, container, grouping, leaf, leaf-list, list, typedef, uses]
+ */
+public interface GroupingMember extends Builder {
+
+    boolean isAddedByUses();
+
+    void setAddedByUses(boolean addedByUses);
+
+}
index db3ac36..289dcfe 100644 (file)
@@ -9,8 +9,8 @@ package org.opendaylight.controller.yang.parser.builder.api;
 \r
 import java.util.List;\r
 \r
-import org.opendaylight.controller.yang.model.api.Status;\r
 import org.opendaylight.controller.yang.model.api.TypeDefinition;\r
+import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;\r
 import org.opendaylight.controller.yang.model.api.type.LengthConstraint;\r
 import org.opendaylight.controller.yang.model.api.type.PatternConstraint;\r
 import org.opendaylight.controller.yang.model.api.type.RangeConstraint;\r
@@ -19,17 +19,10 @@ import org.opendaylight.controller.yang.parser.builder.impl.UnknownSchemaNodeBui
 /**\r
  * Interface for builders of 'typedef' statement.\r
  */\r
-public interface TypeDefinitionBuilder extends TypeAwareBuilder,\r
-        SchemaNodeBuilder {\r
+public interface TypeDefinitionBuilder extends TypeAwareBuilder, SchemaNodeBuilder, GroupingMember {\r
 \r
     TypeDefinition<?> build();\r
 \r
-    String getDescription();\r
-\r
-    String getReference();\r
-\r
-    Status getStatus();\r
-\r
     List<RangeConstraint> getRanges();\r
 \r
     void setRanges(List<RangeConstraint> ranges);\r
@@ -46,7 +39,9 @@ public interface TypeDefinitionBuilder extends TypeAwareBuilder,
 \r
     void setFractionDigits(Integer fractionDigits);\r
 \r
-    List<UnknownSchemaNodeBuilder> getUnknownNodes();\r
+    List<UnknownSchemaNode> getUnknownNodes();\r
+\r
+    List<UnknownSchemaNodeBuilder> getUnknownNodeBuilders();\r
 \r
     Object getDefaultValue();\r
 \r
index c295c0e..626f0f4 100644 (file)
@@ -17,15 +17,15 @@ import org.opendaylight.controller.yang.parser.util.RefineHolder;
 /**
  * Interface for builders of 'uses' statement.
  */
-public interface UsesNodeBuilder extends Builder {
+public interface UsesNodeBuilder extends GroupingMember, Builder {
 
-    String getGroupingName();
+    DataNodeContainerBuilder getParent();
 
-    void setGroupingPath(SchemaPath groupingPath);
+    String getGroupingName();
 
-    SchemaPath getPath();
+    SchemaPath getGroupingPath();
 
-    void setPath(SchemaPath path);
+    void setGroupingPath(SchemaPath groupingPath);
 
     Set<AugmentationSchemaBuilder> getAugmentations();
 
index 78284c1..d5f3c52 100644 (file)
@@ -17,32 +17,47 @@ import org.opendaylight.controller.yang.model.api.ConstraintDefinition;
 import org.opendaylight.controller.yang.model.api.SchemaPath;
 import org.opendaylight.controller.yang.model.api.Status;
 import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.controller.yang.parser.builder.api.AbstractSchemaNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.ConfigNode;
 import org.opendaylight.controller.yang.parser.builder.api.DataSchemaNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.GroupingMember;
 
-public final class AnyXmlBuilder implements DataSchemaNodeBuilder {
+public final class AnyXmlBuilder extends AbstractSchemaNodeBuilder implements DataSchemaNodeBuilder, GroupingMember,
+        ConfigNode {
     private boolean built;
-    private final int line;
-    private final QName qname;
-    private SchemaPath path;
     private final AnyXmlSchemaNodeImpl instance;
     private final ConstraintsBuilder constraints;
 
     private List<UnknownSchemaNode> unknownNodes;
-    private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
 
-    private String description;
-    private String reference;
-    private Status status = Status.CURRENT;
-    private boolean configuration;
+    private Boolean configuration;
     private boolean augmenting;
+    private boolean addedByUses;
 
-    public AnyXmlBuilder(final QName qname, final int line) {
-        this.qname = qname;
-        this.line = line;
+    public AnyXmlBuilder(final QName qname, final SchemaPath schemaPath, final int line) {
+        super(qname, line);
+        this.path = schemaPath;
         instance = new AnyXmlSchemaNodeImpl(qname);
         constraints = new ConstraintsBuilder(line);
     }
 
+    public AnyXmlBuilder(final AnyXmlBuilder builder) {
+        super(builder.qname, builder.line);
+        instance = new AnyXmlSchemaNodeImpl(qname);
+        constraints = builder.constraints;
+        path = builder.path;
+        unknownNodes = builder.unknownNodes;
+        for (UnknownSchemaNodeBuilder un : builder.addedUnknownNodes) {
+            addedUnknownNodes.add(un);
+        }
+        description = builder.description;
+        reference = builder.reference;
+        status = builder.status;
+        configuration = builder.configuration;
+        augmenting = builder.augmenting;
+        addedByUses = builder.addedByUses;
+    }
+
     @Override
     public AnyXmlSchemaNode build() {
         if (!built) {
@@ -53,9 +68,10 @@ public final class AnyXmlBuilder implements DataSchemaNodeBuilder {
             instance.setStatus(status);
             instance.setConfiguration(configuration);
             instance.setAugmenting(augmenting);
+            instance.setAddedByUses(addedByUses);
 
             // UNKNOWN NODES
-            if(unknownNodes == null) {
+            if (unknownNodes == null) {
                 unknownNodes = new ArrayList<UnknownSchemaNode>();
                 for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
                     unknownNodes.add(b.build());
@@ -68,35 +84,11 @@ public final class AnyXmlBuilder implements DataSchemaNodeBuilder {
         return instance;
     }
 
-    @Override
-    public int getLine() {
-        return line;
-    }
-
-    @Override
-    public QName getQName() {
-        return qname;
-    }
-
-    public SchemaPath getPath() {
-        return path;
-    }
-
-    @Override
-    public void setPath(final SchemaPath path) {
-        this.path = path;
-    }
-
     @Override
     public ConstraintsBuilder getConstraints() {
         return constraints;
     }
 
-    @Override
-    public void addUnknownSchemaNode(final UnknownSchemaNodeBuilder unknownNode) {
-        addedUnknownNodes.add(unknownNode);
-    }
-
     public List<UnknownSchemaNodeBuilder> getUnknownNodes() {
         return addedUnknownNodes;
     }
@@ -105,52 +97,34 @@ public final class AnyXmlBuilder implements DataSchemaNodeBuilder {
         this.unknownNodes = unknownNodes;
     }
 
-    public String getDescription() {
-        return description;
-    }
-
     @Override
-    public void setDescription(final String description) {
-        this.description = description;
-    }
-
-    public String getReference() {
-        return reference;
+    public boolean isAugmenting() {
+        return augmenting;
     }
 
     @Override
-    public void setReference(final String reference) {
-        this.reference = reference;
-    }
-
-    public Status getStatus() {
-        return status;
+    public void setAugmenting(final boolean augmenting) {
+        this.augmenting = augmenting;
     }
 
     @Override
-    public void setStatus(final Status status) {
-        if (status != null) {
-            this.status = status;
-        }
+    public boolean isAddedByUses() {
+        return addedByUses;
     }
 
     @Override
-    public boolean isAugmenting() {
-        return augmenting;
+    public void setAddedByUses(final boolean addedByUses) {
+        this.addedByUses = addedByUses;
     }
 
     @Override
-    public void setAugmenting(final boolean augmenting) {
-        this.augmenting = augmenting;
-    }
-
-    public boolean isConfiguration() {
+    public Boolean isConfiguration() {
         return configuration;
     }
 
     @Override
-    public void setConfiguration(final boolean configuration) {
-        instance.setConfiguration(configuration);
+    public void setConfiguration(final Boolean configuration) {
+        this.configuration = configuration;
     }
 
     private final class AnyXmlSchemaNodeImpl implements AnyXmlSchemaNode {
@@ -162,6 +136,7 @@ public final class AnyXmlBuilder implements DataSchemaNodeBuilder {
         private boolean configuration;
         private ConstraintDefinition constraintsDef;
         private boolean augmenting;
+        private boolean addedByUses;
         private List<UnknownSchemaNode> unknownNodes = Collections.emptyList();
 
         private AnyXmlSchemaNodeImpl(final QName qname) {
@@ -220,6 +195,15 @@ public final class AnyXmlBuilder implements DataSchemaNodeBuilder {
             this.augmenting = augmenting;
         }
 
+        @Override
+        public boolean isAddedByUses() {
+            return addedByUses;
+        }
+
+        private void setAddedByUses(boolean addedByUses) {
+            this.addedByUses = addedByUses;
+        }
+
         @Override
         public boolean isConfiguration() {
             return configuration;
@@ -289,8 +273,7 @@ public final class AnyXmlBuilder implements DataSchemaNodeBuilder {
 
         @Override
         public String toString() {
-            StringBuilder sb = new StringBuilder(
-                    AnyXmlSchemaNodeImpl.class.getSimpleName());
+            StringBuilder sb = new StringBuilder(AnyXmlSchemaNodeImpl.class.getSimpleName());
             sb.append("[");
             sb.append("qname=" + qname);
             sb.append(", path=" + path);
index 775751a..b18f255 100644 (file)
@@ -7,9 +7,11 @@
  */
 package org.opendaylight.controller.yang.parser.builder.impl;
 
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
@@ -21,9 +23,11 @@ import org.opendaylight.controller.yang.model.api.RevisionAwareXPath;
 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.api.UnknownSchemaNode;
 import org.opendaylight.controller.yang.model.api.UsesNode;
 import org.opendaylight.controller.yang.model.util.RevisionAwareXPathImpl;
 import org.opendaylight.controller.yang.parser.builder.api.AugmentationSchemaBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.Builder;
 import org.opendaylight.controller.yang.parser.builder.api.DataSchemaNodeBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.GroupingBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionBuilder;
@@ -35,21 +39,30 @@ public final class AugmentationSchemaBuilderImpl implements AugmentationSchemaBu
     private boolean built;
     private final AugmentationSchemaImpl instance;
     private final int line;
+    private final Builder parent;
+
+    private String whenCondition;
+    private String description;
+    private String reference;
+    private Status status = Status.CURRENT;
+
     private final String augmentTargetStr;
-    private SchemaPath augmentTarget;
+    private SchemaPath dirtyAugmentTarget;
     private SchemaPath finalAugmentTarget;
-    private String whenCondition;
+
     private final Set<DataSchemaNodeBuilder> childNodes = new HashSet<DataSchemaNodeBuilder>();
     private final Set<GroupingBuilder> groupings = new HashSet<GroupingBuilder>();
     private final Set<UsesNodeBuilder> usesNodes = new HashSet<UsesNodeBuilder>();
+    private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
     private boolean resolved;
 
-    AugmentationSchemaBuilderImpl(final String augmentTargetStr, final int line) {
+    AugmentationSchemaBuilderImpl(final String augmentTargetStr, final int line, final Builder parent) {
         this.augmentTargetStr = augmentTargetStr;
         this.line = line;
+        this.parent = parent;
         final SchemaPath targetPath = YangModelBuilderUtil
                 .parseAugmentPath(augmentTargetStr);
-        augmentTarget = targetPath;
+        dirtyAugmentTarget = targetPath;
         instance = new AugmentationSchemaImpl(targetPath);
     }
 
@@ -58,18 +71,34 @@ public final class AugmentationSchemaBuilderImpl implements AugmentationSchemaBu
         return line;
     }
 
+    @Override
+    public Builder getParent() {
+        return parent;
+    }
+
+
     @Override
     public void addChildNode(DataSchemaNodeBuilder childNode) {
         childNodes.add(childNode);
     }
 
     @Override
-    public Set<DataSchemaNodeBuilder> getChildNodes() {
+    public Set<DataSchemaNode> getChildNodes() {
+        return Collections.emptySet();
+    }
+
+    @Override
+    public Set<DataSchemaNodeBuilder> getChildNodeBuilders() {
         return childNodes;
     }
 
     @Override
-    public Set<GroupingBuilder> getGroupings() {
+    public Set<GroupingDefinition> getGroupings() {
+        return Collections.emptySet();
+    }
+
+    @Override
+    public Set<GroupingBuilder> getGroupingBuilders() {
         return groupings;
     }
 
@@ -102,6 +131,9 @@ public final class AugmentationSchemaBuilderImpl implements AugmentationSchemaBu
     @Override
     public AugmentationSchema build() {
         if (!built) {
+            instance.setDescription(description);
+            instance.setReference(reference);
+            instance.setStatus(status);
             instance.setTargetPath(finalAugmentTarget);
 
             RevisionAwareXPath whenStmt;
@@ -133,6 +165,13 @@ public final class AugmentationSchemaBuilderImpl implements AugmentationSchemaBu
             }
             instance.setUses(usesNodeDefinitions);
 
+            // UNKNOWN NODES
+            List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();
+            for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
+                unknownNodes.add(b.build());
+            }
+            instance.setUnknownSchemaNodes(unknownNodes);
+
             built = true;
         }
         return instance;
@@ -157,34 +196,36 @@ public final class AugmentationSchemaBuilderImpl implements AugmentationSchemaBu
     }
 
     @Override
-    public Set<TypeDefinitionBuilder> getTypeDefinitions() {
+    public Set<TypeDefinitionBuilder> getTypeDefinitionBuilders() {
         return Collections.emptySet();
     }
 
     @Override
     public void addTypedef(TypeDefinitionBuilder type) {
         throw new YangParseException(line,
-                "Augmentation can not contains type definitions");
+                "Augmentation can not contains typedef statement.");
     }
 
     @Override
     public void setDescription(String description) {
-        instance.setDescription(description);
+        this.description = description;
     }
 
     @Override
     public void setReference(String reference) {
-        instance.setReference(reference);
+        this.reference = reference;
     }
 
     @Override
     public void setStatus(Status status) {
-        instance.setStatus(status);
+        if(status != null) {
+            this.status = status;
+        }
     }
 
     @Override
     public SchemaPath getTargetPath() {
-        return augmentTarget;
+        return dirtyAugmentTarget;
     }
 
     @Override
@@ -197,6 +238,15 @@ public final class AugmentationSchemaBuilderImpl implements AugmentationSchemaBu
         return augmentTargetStr;
     }
 
+    public List<UnknownSchemaNodeBuilder> getUnknownNodes() {
+        return addedUnknownNodes;
+    }
+
+    @Override
+    public void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownNode) {
+        addedUnknownNodes.add(unknownNode);
+    }
+
     @Override
     public int hashCode() {
         final int prime = 17;
@@ -253,10 +303,10 @@ public final class AugmentationSchemaBuilderImpl implements AugmentationSchemaBu
         private Map<QName, DataSchemaNode> childNodes = Collections.emptyMap();
         private Set<GroupingDefinition> groupings = Collections.emptySet();
         private Set<UsesNode> uses = Collections.emptySet();
-
         private String description;
         private String reference;
         private Status status;
+        private List<UnknownSchemaNode> unknownNodes = Collections.emptyList();
 
         private AugmentationSchemaImpl(SchemaPath targetPath) {
             this.targetPath = targetPath;
@@ -349,6 +399,17 @@ public final class AugmentationSchemaBuilderImpl implements AugmentationSchemaBu
             this.status = status;
         }
 
+        public List<UnknownSchemaNode> getUnknownSchemaNodes() {
+            return unknownNodes;
+        }
+
+        private void setUnknownSchemaNodes(
+                List<UnknownSchemaNode> unknownSchemaNodes) {
+            if (unknownSchemaNodes != null) {
+                this.unknownNodes = unknownSchemaNodes;
+            }
+        }
+
         @Override
         public DataSchemaNode getDataChildByName(QName name) {
             return childNodes.get(name);
@@ -421,9 +482,7 @@ public final class AugmentationSchemaBuilderImpl implements AugmentationSchemaBu
                     AugmentationSchemaImpl.class.getSimpleName());
             sb.append("[");
             sb.append("targetPath=" + targetPath);
-            sb.append(", childNodes=" + childNodes.values());
-            sb.append(", groupings=" + groupings);
-            sb.append(", uses=" + uses);
+            sb.append(", when=" + whenCondition);
             sb.append("]");
             return sb.toString();
         }
index 1ba1a2d..0761618 100644 (file)
@@ -21,25 +21,24 @@ import org.opendaylight.controller.yang.model.api.ConstraintDefinition;
 import org.opendaylight.controller.yang.model.api.SchemaPath;
 import org.opendaylight.controller.yang.model.api.Status;
 import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.controller.yang.parser.builder.api.AbstractSchemaNodeBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.AugmentationSchemaBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.AugmentationTargetBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.ConfigNode;
 import org.opendaylight.controller.yang.parser.builder.api.DataSchemaNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.GroupingMember;
+import org.opendaylight.controller.yang.parser.util.ParserUtils;
 
-public final class ChoiceBuilder implements DataSchemaNodeBuilder, AugmentationTargetBuilder {
+public final class ChoiceBuilder extends AbstractSchemaNodeBuilder implements DataSchemaNodeBuilder,
+        AugmentationTargetBuilder, GroupingMember, ConfigNode {
     private boolean isBuilt;
     private final ChoiceNodeImpl instance;
-    private final int line;
     // SchemaNode args
-    private final QName qname;
-    private SchemaPath schemaPath;
-    private String description;
-    private String reference;
-    private Status status = Status.CURRENT;
     private List<UnknownSchemaNode> unknownNodes;
-    private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
     // DataSchemaNode args
     private boolean augmenting;
-    private boolean configuration;
+    private boolean addedByUses;
+    private Boolean configuration;
     private final ConstraintsBuilder constraints;
     // AugmentationTarget args
     private final Set<AugmentationSchemaBuilder> addedAugmentations = new HashSet<AugmentationSchemaBuilder>();
@@ -49,26 +48,45 @@ public final class ChoiceBuilder implements DataSchemaNodeBuilder, AugmentationT
     private String defaultCase;
 
     public ChoiceBuilder(final QName qname, final int line) {
-        this.qname = qname;
-        this.line = line;
+        super(qname, line);
         instance = new ChoiceNodeImpl(qname);
         constraints = new ConstraintsBuilder(line);
     }
 
+    public ChoiceBuilder(ChoiceBuilder b) {
+        super(b.getQName(), b.getLine());
+        instance = new ChoiceNodeImpl(qname);
+        constraints = b.constraints;
+        path = b.getPath();
+        description = b.getDescription();
+        reference = b.getReference();
+        status = b.getStatus();
+        unknownNodes = b.unknownNodes;
+        addedUnknownNodes.addAll(b.getUnknownNodes());
+        augmenting = b.isAugmenting();
+        addedByUses = b.isAddedByUses();
+        configuration = b.isConfiguration();
+        addedAugmentations.addAll(b.getAugmentations());
+        cases = b.cases;
+        addedCases.addAll(b.getCases());
+        defaultCase = b.getDefaultCase();
+    }
+
     @Override
     public ChoiceNode build() {
         if (!isBuilt) {
-            instance.setPath(schemaPath);
+            instance.setPath(path);
             instance.setDescription(description);
             instance.setReference(reference);
             instance.setStatus(status);
             instance.setAugmenting(augmenting);
+            instance.setAddedByUses(addedByUses);
             instance.setConfiguration(configuration);
             instance.setConstraints(constraints.build());
             instance.setDefaultCase(defaultCase);
 
             // CASES
-            if(cases == null) {
+            if (cases == null) {
                 cases = new HashSet<ChoiceCaseNode>();
                 for (ChoiceCaseBuilder caseBuilder : addedCases) {
                     cases.add(caseBuilder.build());
@@ -84,7 +102,7 @@ public final class ChoiceBuilder implements DataSchemaNodeBuilder, AugmentationT
             instance.setAvailableAugmentations(augmentations);
 
             // UNKNOWN NODES
-            if(unknownNodes == null) {
+            if (unknownNodes == null) {
                 unknownNodes = new ArrayList<UnknownSchemaNode>();
                 for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
                     unknownNodes.add(b.build());
@@ -103,18 +121,16 @@ public final class ChoiceBuilder implements DataSchemaNodeBuilder, AugmentationT
         build();
     }
 
-    @Override
-    public int getLine() {
-        return line;
-    }
-
     public Set<ChoiceCaseBuilder> getCases() {
         return addedCases;
     }
 
     public void addChildNode(DataSchemaNodeBuilder childNode) {
         if (!(childNode instanceof ChoiceCaseBuilder)) {
-            ChoiceCaseBuilder caseBuilder = new ChoiceCaseBuilder(childNode.getQName(), childNode.getLine());
+            ChoiceCaseBuilder caseBuilder = new ChoiceCaseBuilder(this, childNode.getQName(), childNode.getLine());
+            caseBuilder.setPath(childNode.getPath());
+            SchemaPath newPath = ParserUtils.createSchemaPath(childNode.getPath(), childNode.getQName().getLocalName());
+            childNode.setPath(newPath);
             caseBuilder.addChildNode(childNode);
             addedCases.add(caseBuilder);
         } else {
@@ -126,64 +142,31 @@ public final class ChoiceBuilder implements DataSchemaNodeBuilder, AugmentationT
         this.cases = cases;
     }
 
-    @Override
-    public QName getQName() {
-        return qname;
-    }
-
-    public SchemaPath getPath() {
-        return schemaPath;
-    }
-
-    @Override
-    public void setPath(final SchemaPath schemaPath) {
-        this.schemaPath = schemaPath;
-    }
-
-    public String getDescription() {
-        return description;
-    }
-
-    @Override
-    public void setDescription(final String description) {
-        this.description = description;
-    }
-
-    public String getReference() {
-        return reference;
+    public boolean isAugmenting() {
+        return augmenting;
     }
 
     @Override
-    public void setReference(String reference) {
-        this.reference = reference;
-    }
-
-    public Status getStatus() {
-        return status;
+    public void setAugmenting(boolean augmenting) {
+        this.augmenting = augmenting;
     }
 
     @Override
-    public void setStatus(Status status) {
-        if (status != null) {
-            this.status = status;
-        }
-    }
-
-    public boolean isAugmenting() {
-        return augmenting;
+    public boolean isAddedByUses() {
+        return addedByUses;
     }
 
     @Override
-    public void setAugmenting(boolean augmenting) {
-        this.augmenting = augmenting;
+    public void setAddedByUses(final boolean addedByUses) {
+        this.addedByUses = addedByUses;
     }
 
-    public boolean isConfiguration() {
+    public Boolean isConfiguration() {
         return configuration;
     }
 
     @Override
-    public void setConfiguration(boolean configuration) {
+    public void setConfiguration(Boolean configuration) {
         this.configuration = configuration;
     }
 
@@ -205,11 +188,6 @@ public final class ChoiceBuilder implements DataSchemaNodeBuilder, AugmentationT
         return addedUnknownNodes;
     }
 
-    @Override
-    public void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownNode) {
-        addedUnknownNodes.add(unknownNode);
-    }
-
     public void setUnknownNodes(List<UnknownSchemaNode> unknownNodes) {
         this.unknownNodes = unknownNodes;
     }
@@ -229,6 +207,7 @@ public final class ChoiceBuilder implements DataSchemaNodeBuilder, AugmentationT
         private String reference;
         private Status status = Status.CURRENT;
         private boolean augmenting;
+        private boolean addedByUses;
         private boolean configuration;
         private ConstraintDefinition constraints;
         private Set<ChoiceCaseNode> cases = Collections.emptySet();
@@ -292,6 +271,15 @@ public final class ChoiceBuilder implements DataSchemaNodeBuilder, AugmentationT
             this.augmenting = augmenting;
         }
 
+        @Override
+        public boolean isAddedByUses() {
+            return addedByUses;
+        }
+
+        private void setAddedByUses(boolean addedByUses) {
+            this.addedByUses = addedByUses;
+        }
+
         @Override
         public boolean isConfiguration() {
             return configuration;
index d54cd22..cfd3866 100644 (file)
@@ -27,23 +27,29 @@ import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionBuilder
 import org.opendaylight.controller.yang.parser.builder.api.UsesNodeBuilder;
 import org.opendaylight.controller.yang.parser.util.YangParseException;
 
-public final class ChoiceCaseBuilder extends AbstractDataNodeContainerBuilder implements
-        DataSchemaNodeBuilder, AugmentationTargetBuilder {
+public final class ChoiceCaseBuilder extends AbstractDataNodeContainerBuilder implements DataSchemaNodeBuilder,
+        AugmentationTargetBuilder {
     private boolean isBuilt;
     private final ChoiceCaseNodeImpl instance;
+    private final ChoiceBuilder parent;
     private final int line;
+    // SchemaNode args
     private SchemaPath schemaPath;
     private String description;
     private String reference;
     private Status status = Status.CURRENT;
     private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
+    // DataSchemaNode args
     private boolean augmenting;
     private final ConstraintsBuilder constraints;
+    // DataNodeContainer args
     private final Set<UsesNodeBuilder> addedUsesNodes = new HashSet<UsesNodeBuilder>();
+    // AugmentationTarget args
     private final Set<AugmentationSchemaBuilder> addedAugmentations = new HashSet<AugmentationSchemaBuilder>();
 
-    ChoiceCaseBuilder(final QName qname, final int line) {
+    ChoiceCaseBuilder(final ChoiceBuilder parent, final QName qname, final int line) {
         super(qname);
+        this.parent = parent;
         this.line = line;
         instance = new ChoiceCaseNodeImpl(qname);
         constraints = new ConstraintsBuilder(line);
@@ -51,7 +57,7 @@ public final class ChoiceCaseBuilder extends AbstractDataNodeContainerBuilder im
 
     @Override
     public ChoiceCaseNode build() {
-        if(!isBuilt) {
+        if (!isBuilt) {
             instance.setConstraints(constraints.build());
             instance.setPath(schemaPath);
             instance.setDescription(description);
@@ -104,6 +110,10 @@ public final class ChoiceCaseBuilder extends AbstractDataNodeContainerBuilder im
         return line;
     }
 
+    public ChoiceBuilder getParent() {
+        return parent;
+    }
+
     public SchemaPath getPath() {
         return schemaPath;
     }
@@ -170,25 +180,13 @@ public final class ChoiceCaseBuilder extends AbstractDataNodeContainerBuilder im
     }
 
     @Override
-    public Set<TypeDefinitionBuilder> getTypeDefinitions() {
+    public Set<TypeDefinitionBuilder> getTypeDefinitionBuilders() {
         return Collections.emptySet();
     }
 
     @Override
     public void addTypedef(TypeDefinitionBuilder typedefBuilder) {
-        throw new YangParseException(line,
-                "Can not add type definition to choice case.");
-    }
-
-    @Override
-    public boolean isConfiguration() {
-        return false;
-    }
-
-    @Override
-    public void setConfiguration(boolean configuration) {
-        throw new YangParseException(line,
-                "Can not add config definition to choice case.");
+        throw new YangParseException(line, "Can not add type definition to choice case.");
     }
 
     @Override
@@ -284,6 +282,11 @@ public final class ChoiceCaseBuilder extends AbstractDataNodeContainerBuilder im
             this.augmenting = augmenting;
         }
 
+        @Override
+        public boolean isAddedByUses() {
+            return false;
+        }
+
         @Override
         public List<UnknownSchemaNode> getUnknownSchemaNodes() {
             return unknownNodes;
@@ -353,8 +356,7 @@ public final class ChoiceCaseBuilder extends AbstractDataNodeContainerBuilder im
             return augmentations;
         }
 
-        private void setAvailableAugmentations(
-                Set<AugmentationSchema> augmentations) {
+        private void setAvailableAugmentations(Set<AugmentationSchema> augmentations) {
             if (augmentations != null) {
                 this.augmentations = augmentations;
             }
@@ -404,8 +406,7 @@ public final class ChoiceCaseBuilder extends AbstractDataNodeContainerBuilder im
 
         @Override
         public String toString() {
-            StringBuilder sb = new StringBuilder(
-                    ChoiceCaseNodeImpl.class.getSimpleName());
+            StringBuilder sb = new StringBuilder(ChoiceCaseNodeImpl.class.getSimpleName());
             sb.append("[");
             sb.append("qname=" + qname);
             sb.append("]");
index b1aa7de..ebfe520 100644 (file)
@@ -16,6 +16,7 @@ import org.opendaylight.controller.yang.model.api.MustDefinition;
 import org.opendaylight.controller.yang.model.api.RevisionAwareXPath;
 import org.opendaylight.controller.yang.model.util.RevisionAwareXPathImpl;
 import org.opendaylight.controller.yang.parser.builder.api.Builder;
+import org.opendaylight.controller.yang.parser.util.YangParseException;
 
 public final class ConstraintsBuilder implements Builder {
     private final ConstraintDefinitionImpl instance;
@@ -53,6 +54,11 @@ public final class ConstraintsBuilder implements Builder {
         return line;
     }
 
+    @Override
+    public void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownNode) {
+        throw new YangParseException(line, "Can not add unknown node to constraints.");
+    }
+
     public Integer getMinElements() {
         return min;
     }
@@ -93,8 +99,7 @@ public final class ConstraintsBuilder implements Builder {
         this.mandatory = mandatory;
     }
 
-    private final class ConstraintDefinitionImpl implements
-            ConstraintDefinition {
+    private final class ConstraintDefinitionImpl implements ConstraintDefinition {
         private RevisionAwareXPath whenCondition;
         private Set<MustDefinition> mustConstraints;
         private boolean mandatory;
@@ -156,16 +161,10 @@ public final class ConstraintsBuilder implements Builder {
         public int hashCode() {
             final int prime = 31;
             int result = 1;
-            result = prime * result
-                    + ((whenCondition == null) ? 0 : whenCondition.hashCode());
-            result = prime
-                    * result
-                    + ((mustConstraints == null) ? 0 : mustConstraints
-                            .hashCode());
-            result = prime * result
-                    + ((minElements == null) ? 0 : minElements.hashCode());
-            result = prime * result
-                    + ((maxElements == null) ? 0 : maxElements.hashCode());
+            result = prime * result + ((whenCondition == null) ? 0 : whenCondition.hashCode());
+            result = prime * result + ((mustConstraints == null) ? 0 : mustConstraints.hashCode());
+            result = prime * result + ((minElements == null) ? 0 : minElements.hashCode());
+            result = prime * result + ((maxElements == null) ? 0 : maxElements.hashCode());
             result = prime * result + (mandatory ? 1231 : 1237);
             return result;
         }
@@ -218,8 +217,7 @@ public final class ConstraintsBuilder implements Builder {
 
         @Override
         public String toString() {
-            StringBuilder sb = new StringBuilder(
-                    ConstraintDefinitionImpl.class.getSimpleName());
+            StringBuilder sb = new StringBuilder(ConstraintDefinitionImpl.class.getSimpleName());
             sb.append("[");
             sb.append("whenCondition=" + whenCondition);
             sb.append(", mustConstraints=" + mustConstraints);
index e677d3c..a194dea 100644 (file)
@@ -29,42 +29,78 @@ import org.opendaylight.controller.yang.model.api.UsesNode;
 import org.opendaylight.controller.yang.parser.builder.api.AbstractDataNodeContainerBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.AugmentationSchemaBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.AugmentationTargetBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.ConfigNode;
 import org.opendaylight.controller.yang.parser.builder.api.DataSchemaNodeBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.GroupingBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.GroupingMember;
 import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionAwareBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.UsesNodeBuilder;
 
-public final class ContainerSchemaNodeBuilder extends AbstractDataNodeContainerBuilder
-        implements TypeDefinitionAwareBuilder, AugmentationTargetBuilder,
-        DataSchemaNodeBuilder {
+public final class ContainerSchemaNodeBuilder extends AbstractDataNodeContainerBuilder implements
+        TypeDefinitionAwareBuilder, AugmentationTargetBuilder, DataSchemaNodeBuilder, GroupingMember, ConfigNode {
     private boolean isBuilt;
     private final ContainerSchemaNodeImpl instance;
     private final int line;
-    private final ConstraintsBuilder constraints;
+
+    // SchemaNode args
     private SchemaPath schemaPath;
     private String description;
     private String reference;
     private Status status = Status.CURRENT;
-    private boolean presence;
+    private List<UnknownSchemaNode> unknownNodes;
+    private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
+    // DataSchemaNode args
     private boolean augmenting;
-    private boolean configuration;
+    private boolean addedByUses;
+    private Boolean configuration;
+    private final ConstraintsBuilder constraints;
+    // DataNodeContainer args
     private Set<TypeDefinition<?>> typedefs;
     private final Set<TypeDefinitionBuilder> addedTypedefs = new HashSet<TypeDefinitionBuilder>();
     private Set<UsesNode> usesNodes;
     private final Set<UsesNodeBuilder> addedUsesNodes = new HashSet<UsesNodeBuilder>();
+    // AugmentationTarget args
     private Set<AugmentationSchema> augmentations;
     private final Set<AugmentationSchemaBuilder> addedAugmentations = new HashSet<AugmentationSchemaBuilder>();
-    private List<UnknownSchemaNode> unknownNodes;
-    private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
+    // ContainerSchemaNode args
+    private boolean presence;
 
-    public ContainerSchemaNodeBuilder(final QName qname, final int line) {
+    public ContainerSchemaNodeBuilder(final QName qname, final SchemaPath schemaPath, final int line) {
         super(qname);
+        this.schemaPath = schemaPath;
         this.line = line;
         instance = new ContainerSchemaNodeImpl(qname);
         constraints = new ConstraintsBuilder(line);
     }
 
+    public ContainerSchemaNodeBuilder(final ContainerSchemaNodeBuilder b) {
+        super(b.getQName());
+        line = b.getLine();
+        instance = new ContainerSchemaNodeImpl(b.getQName());
+        constraints = b.getConstraints();
+        schemaPath = b.getPath();
+        description = b.getDescription();
+        reference = b.getReference();
+        status = b.getStatus();
+        presence = b.isPresence();
+        augmenting = b.isAugmenting();
+        addedByUses = b.isAddedByUses();
+        configuration = b.isConfiguration();
+        childNodes = b.getChildNodes();
+        addedChildNodes.addAll(b.getChildNodeBuilders());
+        groupings = b.getGroupings();
+        addedGroupings.addAll(b.getGroupingBuilders());
+        typedefs = b.typedefs;
+        addedTypedefs.addAll(b.getTypeDefinitionBuilders());
+        usesNodes = b.usesNodes;
+        addedUsesNodes.addAll(b.getUsesNodes());
+        augmentations = b.augmentations;
+        addedAugmentations.addAll(b.getAugmentations());
+        unknownNodes = b.unknownNodes;
+        addedUnknownNodes.addAll(b.getUnknownNodes());
+    }
+
     @Override
     public ContainerSchemaNode build() {
         if (!isBuilt) {
@@ -74,23 +110,29 @@ public final class ContainerSchemaNodeBuilder extends AbstractDataNodeContainerB
             instance.setStatus(status);
             instance.setPresenceContainer(presence);
             instance.setAugmenting(augmenting);
+            instance.setAddedByUses(addedByUses);
+
+            // if this builder represents rpc input or output, it can has configuration value set to null
+            if(configuration == null) {
+                configuration = false;
+            }
             instance.setConfiguration(configuration);
 
             // CHILD NODES
             final Map<QName, DataSchemaNode> childs = new HashMap<QName, DataSchemaNode>();
-            if(childNodes == null) {
+            if (childNodes == null) {
                 for (DataSchemaNodeBuilder node : addedChildNodes) {
                     childs.put(node.getQName(), node.build());
                 }
             } else {
-                for(DataSchemaNode node : childNodes) {
+                for (DataSchemaNode node : childNodes) {
                     childs.put(node.getQName(), node);
                 }
             }
             instance.setChildNodes(childs);
 
             // GROUPINGS
-            if(groupings == null) {
+            if (groupings == null) {
                 groupings = new HashSet<GroupingDefinition>();
                 for (GroupingBuilder builder : addedGroupings) {
                     groupings.add(builder.build());
@@ -99,7 +141,7 @@ public final class ContainerSchemaNodeBuilder extends AbstractDataNodeContainerB
             instance.setGroupings(groupings);
 
             // TYPEDEFS
-            if(typedefs == null) {
+            if (typedefs == null) {
                 typedefs = new HashSet<TypeDefinition<?>>();
                 for (TypeDefinitionBuilder entry : addedTypedefs) {
                     typedefs.add(entry.build());
@@ -108,7 +150,7 @@ public final class ContainerSchemaNodeBuilder extends AbstractDataNodeContainerB
             instance.setTypeDefinitions(typedefs);
 
             // USES
-            if(usesNodes == null) {
+            if (usesNodes == null) {
                 usesNodes = new HashSet<UsesNode>();
                 for (UsesNodeBuilder builder : addedUsesNodes) {
                     usesNodes.add(builder.build());
@@ -117,7 +159,7 @@ public final class ContainerSchemaNodeBuilder extends AbstractDataNodeContainerB
             instance.setUses(usesNodes);
 
             // AUGMENTATIONS
-            if(augmentations == null) {
+            if (augmentations == null) {
                 augmentations = new HashSet<AugmentationSchema>();
                 for (AugmentationSchemaBuilder builder : addedAugmentations) {
                     augmentations.add(builder.build());
@@ -126,7 +168,7 @@ public final class ContainerSchemaNodeBuilder extends AbstractDataNodeContainerB
             instance.setAvailableAugmentations(augmentations);
 
             // UNKNOWN NODES
-            if(unknownNodes == null) {
+            if (unknownNodes == null) {
                 unknownNodes = new ArrayList<UnknownSchemaNode>();
                 for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
                     unknownNodes.add(b.build());
@@ -154,7 +196,7 @@ public final class ContainerSchemaNodeBuilder extends AbstractDataNodeContainerB
     }
 
     @Override
-    public Set<TypeDefinitionBuilder> getTypeDefinitions() {
+    public Set<TypeDefinitionBuilder> getTypeDefinitionBuilders() {
         return addedTypedefs;
     }
 
@@ -232,12 +274,22 @@ public final class ContainerSchemaNodeBuilder extends AbstractDataNodeContainerB
     }
 
     @Override
-    public boolean isConfiguration() {
+    public boolean isAddedByUses() {
+        return addedByUses;
+    }
+
+    @Override
+    public void setAddedByUses(final boolean addedByUses) {
+        this.addedByUses = addedByUses;
+    }
+
+    @Override
+    public Boolean isConfiguration() {
         return configuration;
     }
 
     @Override
-    public void setConfiguration(boolean configuration) {
+    public void setConfiguration(Boolean configuration) {
         this.configuration = configuration;
     }
 
@@ -292,6 +344,7 @@ public final class ContainerSchemaNodeBuilder extends AbstractDataNodeContainerB
         private String reference;
         private Status status = Status.CURRENT;
         private boolean augmenting;
+        private boolean addedByUses;
         private boolean configuration;
         private ConstraintDefinition constraints;
         private Set<AugmentationSchema> augmentations = Collections.emptySet();
@@ -358,6 +411,15 @@ public final class ContainerSchemaNodeBuilder extends AbstractDataNodeContainerB
             this.augmenting = augmenting;
         }
 
+        @Override
+        public boolean isAddedByUses() {
+            return addedByUses;
+        }
+
+        private void setAddedByUses(boolean addedByUses) {
+            this.addedByUses = addedByUses;
+        }
+
         @Override
         public boolean isConfiguration() {
             return configuration;
@@ -381,8 +443,7 @@ public final class ContainerSchemaNodeBuilder extends AbstractDataNodeContainerB
             return augmentations;
         }
 
-        private void setAvailableAugmentations(
-                Set<AugmentationSchema> augmentations) {
+        private void setAvailableAugmentations(Set<AugmentationSchema> augmentations) {
             if (augmentations != null) {
                 this.augmentations = augmentations;
             }
@@ -463,8 +524,7 @@ public final class ContainerSchemaNodeBuilder extends AbstractDataNodeContainerB
             return unknownNodes;
         }
 
-        private void setUnknownSchemaNodes(
-                List<UnknownSchemaNode> unknownSchemaNodes) {
+        private void setUnknownSchemaNodes(List<UnknownSchemaNode> unknownSchemaNodes) {
             if (unknownSchemaNodes != null) {
                 this.unknownNodes = unknownSchemaNodes;
             }
@@ -514,8 +574,7 @@ public final class ContainerSchemaNodeBuilder extends AbstractDataNodeContainerB
 
         @Override
         public String toString() {
-            StringBuilder sb = new StringBuilder(
-                    ContainerSchemaNodeImpl.class.getSimpleName());
+            StringBuilder sb = new StringBuilder(ContainerSchemaNodeImpl.class.getSimpleName());
             sb.append("[");
             sb.append("qname=" + qname);
             sb.append("]");
index 239c0a5..790275c 100644 (file)
@@ -7,9 +7,14 @@
  */
 package org.opendaylight.controller.yang.parser.builder.impl;
 
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
 import org.opendaylight.controller.yang.model.api.Deviation;
 import org.opendaylight.controller.yang.model.api.Deviation.Deviate;
 import org.opendaylight.controller.yang.model.api.SchemaPath;
+import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
 import org.opendaylight.controller.yang.parser.builder.api.Builder;
 import org.opendaylight.controller.yang.parser.util.YangModelBuilderUtil;
 import org.opendaylight.controller.yang.parser.util.YangParseException;
@@ -17,6 +22,7 @@ import org.opendaylight.controller.yang.parser.util.YangParseException;
 public final class DeviationBuilder implements Builder {
     private final DeviationImpl instance;
     private final int line;
+    private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
 
     DeviationBuilder(final String targetPathStr, final int line) {
         this.line = line;
@@ -27,6 +33,13 @@ public final class DeviationBuilder implements Builder {
 
     @Override
     public Deviation build() {
+        // UNKNOWN NODES
+        List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();
+        for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
+            unknownNodes.add(b.build());
+        }
+        instance.setUnknownSchemaNodes(unknownNodes);
+
         return instance;
     }
 
@@ -35,6 +48,11 @@ public final class DeviationBuilder implements Builder {
         return line;
     }
 
+    @Override
+    public void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownNode) {
+        addedUnknownNodes.add(unknownNode);
+    }
+
     public void setDeviate(final String deviate) {
         if ("not-supported".equals(deviate)) {
             instance.setDeviate(Deviate.NOT_SUPPORTED);
@@ -58,6 +76,7 @@ public final class DeviationBuilder implements Builder {
         private final SchemaPath targetPath;
         private Deviate deviate;
         private String reference;
+        private List<UnknownSchemaNode> unknownNodes = Collections.emptyList();
 
         private DeviationImpl(final SchemaPath targetPath) {
             this.targetPath = targetPath;
@@ -86,6 +105,16 @@ public final class DeviationBuilder implements Builder {
             this.reference = reference;
         }
 
+        public List<UnknownSchemaNode> getUnknownSchemaNodes() {
+            return unknownNodes;
+        }
+
+        private void setUnknownSchemaNodes(List<UnknownSchemaNode> unknownSchemaNodes) {
+            if (unknownSchemaNodes != null) {
+                this.unknownNodes = unknownSchemaNodes;
+            }
+        }
+
         @Override
         public int hashCode() {
             final int prime = 31;
index 0558b91..65fd1c4 100644 (file)
@@ -16,30 +16,22 @@ import org.opendaylight.controller.yang.model.api.ExtensionDefinition;
 import org.opendaylight.controller.yang.model.api.SchemaPath;
 import org.opendaylight.controller.yang.model.api.Status;
 import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
-import org.opendaylight.controller.yang.parser.builder.api.SchemaNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.AbstractSchemaNodeBuilder;
 
-public final class ExtensionBuilder implements SchemaNodeBuilder {
+public final class ExtensionBuilder extends AbstractSchemaNodeBuilder {
     private boolean isBuilt;
     private final ExtensionDefinitionImpl instance;
-    private final int line;
-    private final QName qname;
-    private SchemaPath schemaPath;
-    private String description;
-    private String reference;
-    private Status status = Status.CURRENT;
     private final List<UnknownSchemaNodeBuilder> addedExtensions = new ArrayList<UnknownSchemaNodeBuilder>();
-    private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
 
     ExtensionBuilder(final QName qname, final int line) {
-        this.qname = qname;
-        this.line = line;
+        super(qname, line);
         instance = new ExtensionDefinitionImpl(qname);
     }
 
     @Override
     public ExtensionDefinition build() {
         if(!isBuilt) {
-            instance.setPath(schemaPath);
+            instance.setPath(path);
             instance.setDescription(description);
             instance.setReference(reference);
             instance.setStatus(status);
@@ -57,10 +49,6 @@ public final class ExtensionBuilder implements SchemaNodeBuilder {
         return instance;
     }
 
-    @Override
-    public int getLine() {
-        return line;
-    }
 
     public void addExtension(UnknownSchemaNodeBuilder extension) {
         addedExtensions.add(extension);
@@ -74,55 +62,6 @@ public final class ExtensionBuilder implements SchemaNodeBuilder {
         instance.setArgument(argument);
     }
 
-    @Override
-    public QName getQName() {
-        return qname;
-    }
-
-    @Override
-    public SchemaPath getPath() {
-        return schemaPath;
-    }
-
-    @Override
-    public void setPath(SchemaPath schemaPath) {
-        this.schemaPath = schemaPath;
-    }
-
-    @Override
-    public String getDescription() {
-        return description;
-    }
-
-    @Override
-    public void setDescription(final String description) {
-        this.description = description;
-    }
-
-    @Override
-    public String getReference() {
-        return reference;
-    }
-
-    @Override
-    public void setReference(final String reference) {
-        this.reference = reference;
-    }
-
-    @Override
-    public Status getStatus() {
-        return status;
-    }
-
-    @Override
-    public void setStatus(final Status status) {
-        instance.setStatus(status);
-    }
-
-    @Override
-    public void addUnknownSchemaNode(final UnknownSchemaNodeBuilder unknownNode) {
-        addedUnknownNodes.add(unknownNode);
-    }
 
     private final class ExtensionDefinitionImpl implements ExtensionDefinition {
         private final QName qname;
index 0681cf6..758478b 100644 (file)
@@ -16,29 +16,21 @@ import org.opendaylight.controller.yang.model.api.FeatureDefinition;
 import org.opendaylight.controller.yang.model.api.SchemaPath;
 import org.opendaylight.controller.yang.model.api.Status;
 import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
-import org.opendaylight.controller.yang.parser.builder.api.SchemaNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.AbstractSchemaNodeBuilder;
 
-public final class FeatureBuilder implements SchemaNodeBuilder {
+public final class FeatureBuilder extends AbstractSchemaNodeBuilder {
     private boolean isBuilt;
     private final FeatureDefinitionImpl instance;
-    private final int line;
-    private final QName qname;
-    private SchemaPath schemaPath;
-    private String description;
-    private String reference;
-    private Status status = Status.CURRENT;
-    private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
 
     FeatureBuilder(final QName qname, final int line) {
-        this.qname = qname;
-        this.line = line;
+        super(qname, line);
         instance = new FeatureDefinitionImpl(qname);
     }
 
     @Override
     public FeatureDefinitionImpl build() {
-        if(!isBuilt) {
-            instance.setPath(schemaPath);
+        if (!isBuilt) {
+            instance.setPath(path);
             instance.setDescription(description);
             instance.setReference(reference);
             instance.setStatus(status);
@@ -55,61 +47,6 @@ public final class FeatureBuilder implements SchemaNodeBuilder {
         return instance;
     }
 
-    @Override
-    public int getLine() {
-        return line;
-    }
-
-    @Override
-    public QName getQName() {
-        return qname;
-    }
-
-    @Override
-    public SchemaPath getPath() {
-        return schemaPath;
-    }
-
-    @Override
-    public void setPath(SchemaPath schemaPath) {
-        this.schemaPath = schemaPath;
-    }
-
-    @Override
-    public String getDescription() {
-        return description;
-    }
-
-    @Override
-    public void setDescription(final String description) {
-        this.description = description;
-    }
-
-    @Override
-    public String getReference() {
-        return reference;
-    }
-
-    @Override
-    public void setReference(final String reference) {
-        this.reference = reference;
-    }
-
-    @Override
-    public Status getStatus() {
-        return status;
-    }
-
-    @Override
-    public void setStatus(final Status status) {
-        this.status = status;
-    }
-
-    @Override
-    public void addUnknownSchemaNode(final UnknownSchemaNodeBuilder unknownNode) {
-        addedUnknownNodes.add(unknownNode);
-    }
-
     private final class FeatureDefinitionImpl implements FeatureDefinition {
         private final QName qname;
         private SchemaPath path;
@@ -170,8 +107,7 @@ public final class FeatureBuilder implements SchemaNodeBuilder {
             return unknownNodes;
         }
 
-        private void setUnknownSchemaNodes(
-                final List<UnknownSchemaNode> unknownNodes) {
+        private void setUnknownSchemaNodes(final List<UnknownSchemaNode> unknownNodes) {
             if (unknownNodes != null) {
                 this.unknownNodes = unknownNodes;
             }
@@ -217,8 +153,7 @@ public final class FeatureBuilder implements SchemaNodeBuilder {
 
         @Override
         public String toString() {
-            StringBuilder sb = new StringBuilder(
-                    FeatureDefinitionImpl.class.getSimpleName());
+            StringBuilder sb = new StringBuilder(FeatureDefinitionImpl.class.getSimpleName());
             sb.append("[name=" + qname + "]");
             return sb.toString();
         }
index 5428259..1cfba25 100644 (file)
@@ -37,6 +37,7 @@ public final class GroupingBuilderImpl implements GroupingBuilder {
     private String description;
     private String reference;
     private Status status = Status.CURRENT;
+    private boolean addedByUses;
 
     private Set<DataSchemaNode> childNodes;
     private final Set<DataSchemaNodeBuilder> addedChildNodes = new HashSet<DataSchemaNodeBuilder>();
@@ -55,10 +56,27 @@ public final class GroupingBuilderImpl implements GroupingBuilder {
 
     public GroupingBuilderImpl(final QName qname, final int line) {
         this.qname = qname;
-        this.instance = new GroupingDefinitionImpl(qname);
+        instance = new GroupingDefinitionImpl(qname);
         this.line = line;
     }
 
+    public GroupingBuilderImpl(GroupingBuilder builder) {
+        qname = builder.getQName();
+        instance = new GroupingDefinitionImpl(qname);
+        line = builder.getLine();
+        schemaPath = builder.getPath();
+        description = builder.getDescription();
+        reference = builder.getReference();
+        status = builder.getStatus();
+        addedByUses = builder.isAddedByUses();
+        childNodes = builder.getChildNodes();
+        addedChildNodes.addAll(builder.getChildNodeBuilders());
+        groupings = builder.getGroupings();
+        addedGroupings.addAll(builder.getGroupingBuilders());
+        addedUsesNodes.addAll(builder.getUses());
+        addedUnknownNodes.addAll(builder.getUnknownNodes());
+    }
+
     @Override
     public GroupingDefinition build() {
         if (!isBuilt) {
@@ -66,15 +84,16 @@ public final class GroupingBuilderImpl implements GroupingBuilder {
             instance.setDescription(description);
             instance.setReference(reference);
             instance.setStatus(status);
+            instance.setAddedByUses(addedByUses);
 
             // CHILD NODES
             final Map<QName, DataSchemaNode> childs = new HashMap<QName, DataSchemaNode>();
-            if(childNodes == null) {
+            if (childNodes == null) {
                 for (DataSchemaNodeBuilder node : addedChildNodes) {
                     childs.put(node.getQName(), node.build());
                 }
             } else {
-                for(DataSchemaNode node : childNodes) {
+                for (DataSchemaNode node : childNodes) {
                     childs.put(node.getQName(), node);
                 }
             }
@@ -133,7 +152,7 @@ public final class GroupingBuilderImpl implements GroupingBuilder {
     }
 
     @Override
-    public Set<TypeDefinitionBuilder> getTypeDefinitions() {
+    public Set<TypeDefinitionBuilder> getTypeDefinitionBuilders() {
         return addedTypedefs;
     }
 
@@ -186,6 +205,16 @@ public final class GroupingBuilderImpl implements GroupingBuilder {
         this.status = status;
     }
 
+    @Override
+    public boolean isAddedByUses() {
+        return addedByUses;
+    }
+
+    @Override
+    public void setAddedByUses(final boolean addedByUses) {
+        this.addedByUses = addedByUses;
+    }
+
     @Override
     public DataSchemaNodeBuilder getChildNode(String name) {
         DataSchemaNodeBuilder result = null;
@@ -198,13 +227,18 @@ public final class GroupingBuilderImpl implements GroupingBuilder {
         return result;
     }
 
+    @Override
+    public Set<DataSchemaNode> getChildNodes() {
+        return childNodes;
+    }
+
     @Override
     public void addChildNode(final DataSchemaNodeBuilder childNode) {
         addedChildNodes.add(childNode);
     }
 
     @Override
-    public Set<DataSchemaNodeBuilder> getChildNodes() {
+    public Set<DataSchemaNodeBuilder> getChildNodeBuilders() {
         return addedChildNodes;
     }
 
@@ -213,7 +247,12 @@ public final class GroupingBuilderImpl implements GroupingBuilder {
     }
 
     @Override
-    public Set<GroupingBuilder> getGroupings() {
+    public Set<GroupingDefinition> getGroupings() {
+        return Collections.emptySet();
+    }
+
+    @Override
+    public Set<GroupingBuilder> getGroupingBuilders() {
         return addedGroupings;
     }
 
@@ -261,6 +300,7 @@ public final class GroupingBuilderImpl implements GroupingBuilder {
         private String description;
         private String reference;
         private Status status;
+        private boolean addedByUses;
         private Map<QName, DataSchemaNode> childNodes = Collections.emptyMap();
         private Set<GroupingDefinition> groupings = Collections.emptySet();
         private Set<TypeDefinition<?>> typeDefinitions = Collections.emptySet();
@@ -312,6 +352,15 @@ public final class GroupingBuilderImpl implements GroupingBuilder {
             this.status = status;
         }
 
+        @Override
+        public boolean isAddedByUses() {
+            return addedByUses;
+        }
+
+        private void setAddedByUses(final boolean addedByUses) {
+            this.addedByUses = addedByUses;
+        }
+
         @Override
         public Set<DataSchemaNode> getChildNodes() {
             return new HashSet<DataSchemaNode>(childNodes.values());
index 6b76314..9cce264 100644 (file)
@@ -16,32 +16,24 @@ import org.opendaylight.controller.yang.model.api.IdentitySchemaNode;
 import org.opendaylight.controller.yang.model.api.SchemaPath;
 import org.opendaylight.controller.yang.model.api.Status;
 import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
-import org.opendaylight.controller.yang.parser.builder.api.SchemaNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.AbstractSchemaNodeBuilder;
 
-public final class IdentitySchemaNodeBuilder implements SchemaNodeBuilder {
+public final class IdentitySchemaNodeBuilder extends AbstractSchemaNodeBuilder {
     private boolean isBuilt;
     private final IdentitySchemaNodeImpl instance;
-    private final int line;
-    private final QName qname;
-    private SchemaPath schemaPath;
-    private String description;
-    private String reference;
-    private Status status = Status.CURRENT;
     private IdentitySchemaNodeBuilder baseIdentityBuilder;
     private IdentitySchemaNode baseIdentity;
     private String baseIdentityName;
-    private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
 
     IdentitySchemaNodeBuilder(final QName qname, final int line) {
-        this.qname = qname;
-        this.line = line;
+        super(qname, line);
         instance = new IdentitySchemaNodeImpl(qname);
     }
 
     @Override
     public IdentitySchemaNode build() {
-        if(!isBuilt) {
-            instance.setPath(schemaPath);
+        if (!isBuilt) {
+            instance.setPath(path);
             instance.setDescription(description);
             instance.setReference(reference);
             instance.setStatus(status);
@@ -67,63 +59,6 @@ public final class IdentitySchemaNodeBuilder implements SchemaNodeBuilder {
         return instance;
     }
 
-    @Override
-    public int getLine() {
-        return line;
-    }
-
-    @Override
-    public QName getQName() {
-        return qname;
-    }
-
-    @Override
-    public SchemaPath getPath() {
-        return schemaPath;
-    }
-
-    @Override
-    public void setPath(SchemaPath schemaPath) {
-        this.schemaPath = schemaPath;
-    }
-
-    @Override
-    public String getDescription() {
-        return description;
-    }
-
-    @Override
-    public void setDescription(final String description) {
-        this.description = description;
-    }
-
-    @Override
-    public String getReference() {
-        return reference;
-    }
-
-    @Override
-    public void setReference(final String reference) {
-        this.reference = reference;
-    }
-
-    @Override
-    public Status getStatus() {
-        return status;
-    }
-
-    @Override
-    public void setStatus(final Status status) {
-        if (status != null) {
-            this.status = status;
-        }
-    }
-
-    @Override
-    public void addUnknownSchemaNode(final UnknownSchemaNodeBuilder unknownNode) {
-        addedUnknownNodes.add(unknownNode);
-    }
-
     public String getBaseIdentityName() {
         return baseIdentityName;
     }
index 175910d..ea504af 100644 (file)
@@ -14,6 +14,7 @@ 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.api.UnknownSchemaNode;
 import org.opendaylight.controller.yang.model.api.type.LengthConstraint;
 import org.opendaylight.controller.yang.model.api.type.PatternConstraint;
 import org.opendaylight.controller.yang.model.api.type.RangeConstraint;
@@ -28,8 +29,7 @@ import org.opendaylight.controller.yang.parser.util.YangParseException;
  * When build is called, types in builder form will be built and add to resolved
  * types.
  */
-public final class IdentityrefTypeBuilder extends AbstractTypeAwareBuilder
-        implements TypeDefinitionBuilder {
+public final class IdentityrefTypeBuilder extends AbstractTypeAwareBuilder implements TypeDefinitionBuilder {
     private static final String NAME = "identityref";
 
     private final int line;
@@ -37,8 +37,7 @@ public final class IdentityrefTypeBuilder extends AbstractTypeAwareBuilder
     private final SchemaPath schemaPath;
     private QName baseQName;
 
-    IdentityrefTypeBuilder(final String baseString,
-            final SchemaPath schemaPath, final int line) {
+    IdentityrefTypeBuilder(final String baseString, final SchemaPath schemaPath, final int line) {
         this.line = line;
         this.baseString = baseString;
         this.schemaPath = schemaPath;
@@ -102,10 +101,24 @@ public final class IdentityrefTypeBuilder extends AbstractTypeAwareBuilder
         throw new YangParseException(line, "Can not set status to " + NAME);
     }
 
+    @Override
+    public boolean isAddedByUses() {
+        return false;
+    }
+
+    @Override
+    public void setAddedByUses(final boolean addedByUses) {
+        throw new YangParseException(line, "Identityref type can not be added by uses.");
+    }
+
+    @Override
+    public List<UnknownSchemaNode> getUnknownNodes() {
+        return Collections.emptyList();
+    }
+
     @Override
     public void addUnknownSchemaNode(final UnknownSchemaNodeBuilder unknownNode) {
-        throw new YangParseException(line, "Can not add unknown node to "
-                + NAME);
+        throw new YangParseException(line, "Can not add unknown node to " + NAME);
     }
 
     @Override
@@ -170,12 +183,11 @@ public final class IdentityrefTypeBuilder extends AbstractTypeAwareBuilder
 
     @Override
     public void setFractionDigits(Integer fractionDigits) {
-        throw new YangParseException(line, "Can not set fraction digits to "
-                + NAME);
+        throw new YangParseException(line, "Can not set fraction digits to " + NAME);
     }
 
     @Override
-    public List<UnknownSchemaNodeBuilder> getUnknownNodes() {
+    public List<UnknownSchemaNodeBuilder> getUnknownNodeBuilders() {
         return Collections.emptyList();
     }
 
@@ -186,8 +198,7 @@ public final class IdentityrefTypeBuilder extends AbstractTypeAwareBuilder
 
     @Override
     public void setDefaultValue(Object defaultValue) {
-        throw new YangParseException(line, "Can not set default value to "
-                + NAME);
+        throw new YangParseException(line, "Can not set default value to " + NAME);
     }
 
     @Override
@@ -202,8 +213,7 @@ public final class IdentityrefTypeBuilder extends AbstractTypeAwareBuilder
 
     @Override
     public String toString() {
-        final StringBuilder result = new StringBuilder(
-                IdentityrefTypeBuilder.class.getSimpleName() + "[");
+        final StringBuilder result = new StringBuilder(IdentityrefTypeBuilder.class.getSimpleName() + "[");
         result.append(", base=" + baseQName);
         result.append("]");
         return result.toString();
index fdc8cd7..9bbe5e9 100644 (file)
@@ -19,9 +19,12 @@ import org.opendaylight.controller.yang.model.api.Status;
 import org.opendaylight.controller.yang.model.api.TypeDefinition;
 import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
 import org.opendaylight.controller.yang.parser.builder.api.AbstractTypeAwareBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.ConfigNode;
 import org.opendaylight.controller.yang.parser.builder.api.DataSchemaNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.GroupingMember;
 
-public final class LeafListSchemaNodeBuilder extends AbstractTypeAwareBuilder implements DataSchemaNodeBuilder {
+public final class LeafListSchemaNodeBuilder extends AbstractTypeAwareBuilder implements DataSchemaNodeBuilder,
+        GroupingMember, ConfigNode {
     private boolean isBuilt;
     private final LeafListSchemaNodeImpl instance;
     private final int line;
@@ -35,18 +38,41 @@ public final class LeafListSchemaNodeBuilder extends AbstractTypeAwareBuilder im
     private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
     // DataSchemaNode args
     private boolean augmenting;
-    private boolean configuration;
+    private boolean addedByUses;
+    private Boolean configuration;
     private final ConstraintsBuilder constraints;
     // LeafListSchemaNode args
     private boolean userOrdered;
 
-    public LeafListSchemaNodeBuilder(final QName qname, final int line) {
+    public LeafListSchemaNodeBuilder(final QName qname, final SchemaPath schemaPath, final int line) {
         this.qname = qname;
+        this.schemaPath = schemaPath;
         this.line = line;
         instance = new LeafListSchemaNodeImpl(qname);
         constraints = new ConstraintsBuilder(line);
     }
 
+    public LeafListSchemaNodeBuilder(final LeafListSchemaNodeBuilder b) {
+        qname = b.getQName();
+        line = b.getLine();
+        instance = new LeafListSchemaNodeImpl(qname);
+
+        type = b.getType();
+        typedef = b.getTypedef();
+
+        constraints = b.getConstraints();
+        schemaPath = b.getPath();
+        description = b.getDescription();
+        reference = b.getReference();
+        status = b.getStatus();
+        augmenting = b.isAugmenting();
+        addedByUses = b.isAddedByUses();
+        configuration = b.isConfiguration();
+        userOrdered = b.isUserOrdered();
+        unknownNodes = b.unknownNodes;
+        addedUnknownNodes.addAll(b.getUnknownNodes());
+    }
+
     @Override
     public LeafListSchemaNode build() {
         if (!isBuilt) {
@@ -56,6 +82,7 @@ public final class LeafListSchemaNodeBuilder extends AbstractTypeAwareBuilder im
             instance.setReference(reference);
             instance.setStatus(status);
             instance.setAugmenting(augmenting);
+            instance.setAddedByUses(addedByUses);
             instance.setConfiguration(configuration);
             instance.setUserOrdered(userOrdered);
 
@@ -136,12 +163,22 @@ public final class LeafListSchemaNodeBuilder extends AbstractTypeAwareBuilder im
         this.augmenting = augmenting;
     }
 
-    public boolean isConfiguration() {
+    @Override
+    public boolean isAddedByUses() {
+        return addedByUses;
+    }
+
+    @Override
+    public void setAddedByUses(final boolean addedByUses) {
+        this.addedByUses = addedByUses;
+    }
+
+    public Boolean isConfiguration() {
         return configuration;
     }
 
     @Override
-    public void setConfiguration(boolean configuration) {
+    public void setConfiguration(Boolean configuration) {
         this.configuration = configuration;
     }
 
@@ -178,6 +215,7 @@ public final class LeafListSchemaNodeBuilder extends AbstractTypeAwareBuilder im
         private String reference;
         private Status status = Status.CURRENT;
         private boolean augmenting;
+        private boolean addedByUses;
         private boolean configuration;
         private ConstraintDefinition constraintsDef;
         private TypeDefinition<?> type;
@@ -238,6 +276,15 @@ public final class LeafListSchemaNodeBuilder extends AbstractTypeAwareBuilder im
             this.augmenting = augmenting;
         }
 
+        @Override
+        public boolean isAddedByUses() {
+            return addedByUses;
+        }
+
+        private void setAddedByUses(final boolean addedByUses) {
+            this.addedByUses = addedByUses;
+        }
+
         @Override
         public boolean isConfiguration() {
             return configuration;
index 786f08d..54720b4 100644 (file)
@@ -19,9 +19,12 @@ import org.opendaylight.controller.yang.model.api.Status;
 import org.opendaylight.controller.yang.model.api.TypeDefinition;
 import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
 import org.opendaylight.controller.yang.parser.builder.api.AbstractTypeAwareBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.ConfigNode;
 import org.opendaylight.controller.yang.parser.builder.api.DataSchemaNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.GroupingMember;
 
-public final class LeafSchemaNodeBuilder extends AbstractTypeAwareBuilder implements DataSchemaNodeBuilder {
+public final class LeafSchemaNodeBuilder extends AbstractTypeAwareBuilder implements DataSchemaNodeBuilder,
+        GroupingMember, ConfigNode {
     private boolean isBuilt;
     private final LeafSchemaNodeImpl instance;
     private final int line;
@@ -35,19 +38,44 @@ public final class LeafSchemaNodeBuilder extends AbstractTypeAwareBuilder implem
     private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
     // DataSchemaNode args
     private boolean augmenting;
-    private boolean configuration;
+    private boolean addedByUses;
+    private Boolean configuration;
     private final ConstraintsBuilder constraints;
     // leaf args
     private String defaultStr;
     private String unitsStr;
 
-    public LeafSchemaNodeBuilder(final QName qname, final int line) {
+    public LeafSchemaNodeBuilder(final QName qname, final SchemaPath schemaPath, final int line) {
         this.qname = qname;
+        this.path = schemaPath;
         this.line = line;
         instance = new LeafSchemaNodeImpl(qname);
         constraints = new ConstraintsBuilder(line);
     }
 
+    public LeafSchemaNodeBuilder(final LeafSchemaNodeBuilder b) {
+        qname = b.getQName();
+        line = b.getLine();
+        instance = new LeafSchemaNodeImpl(qname);
+        constraints = b.getConstraints();
+        path = b.getPath();
+
+        type = b.getType();
+        typedef = b.getTypedef();
+
+        description = b.getDescription();
+        reference = b.getReference();
+        status = b.getStatus();
+        augmenting = b.isAugmenting();
+        addedByUses = b.isAddedByUses();
+        configuration = b.isConfiguration();
+        unknownNodes = b.unknownNodes;
+        addedUnknownNodes.addAll(b.getUnknownNodes());
+
+        defaultStr = b.getDefaultStr();
+        unitsStr = b.getUnits();
+    }
+
     @Override
     public LeafSchemaNode build() {
         if (!isBuilt) {
@@ -57,6 +85,7 @@ public final class LeafSchemaNodeBuilder extends AbstractTypeAwareBuilder implem
             instance.setReference(reference);
             instance.setStatus(status);
             instance.setAugmenting(augmenting);
+            instance.setAddedByUses(addedByUses);
             instance.setConfiguration(configuration);
             instance.setDefault(defaultStr);
             instance.setUnits(unitsStr);
@@ -157,13 +186,23 @@ public final class LeafSchemaNodeBuilder extends AbstractTypeAwareBuilder implem
         this.augmenting = augmenting;
     }
 
-    public boolean isConfiguration() {
+    @Override
+    public boolean isAddedByUses() {
+        return addedByUses;
+    }
+
+    @Override
+    public void setAddedByUses(final boolean addedByUses) {
+        this.addedByUses = addedByUses;
+    }
+
+    public Boolean isConfiguration() {
         return configuration;
     }
 
     @Override
-    public void setConfiguration(final boolean configuration) {
-        instance.setConfiguration(configuration);
+    public void setConfiguration(final Boolean configuration) {
+        this.configuration = configuration;
     }
 
     public String getDefaultStr() {
@@ -194,6 +233,7 @@ public final class LeafSchemaNodeBuilder extends AbstractTypeAwareBuilder implem
         private String reference;
         private Status status = Status.CURRENT;
         private boolean augmenting;
+        private boolean addedByUses;
         private boolean configuration;
         private ConstraintDefinition constraintsDef;
         private TypeDefinition<?> type;
@@ -257,6 +297,15 @@ public final class LeafSchemaNodeBuilder extends AbstractTypeAwareBuilder implem
             this.augmenting = augmenting;
         }
 
+        @Override
+        public boolean isAddedByUses() {
+            return addedByUses;
+        }
+
+        private void setAddedByUses(final boolean addedByUses) {
+            this.addedByUses = addedByUses;
+        }
+
         @Override
         public boolean isConfiguration() {
             return configuration;
index 63a66e0..ce87e3b 100644 (file)
@@ -29,15 +29,16 @@ import org.opendaylight.controller.yang.model.api.UsesNode;
 import org.opendaylight.controller.yang.parser.builder.api.AbstractDataNodeContainerBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.AugmentationSchemaBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.AugmentationTargetBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.ConfigNode;
 import org.opendaylight.controller.yang.parser.builder.api.DataSchemaNodeBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.GroupingBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.GroupingMember;
 import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionAwareBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.UsesNodeBuilder;
 
-public final class ListSchemaNodeBuilder extends AbstractDataNodeContainerBuilder
-        implements DataSchemaNodeBuilder, AugmentationTargetBuilder,
-        TypeDefinitionAwareBuilder {
+public final class ListSchemaNodeBuilder extends AbstractDataNodeContainerBuilder implements DataSchemaNodeBuilder,
+        AugmentationTargetBuilder, TypeDefinitionAwareBuilder, GroupingMember, ConfigNode {
     private boolean isBuilt;
     private final ListSchemaNodeImpl instance;
     private final int line;
@@ -50,7 +51,8 @@ public final class ListSchemaNodeBuilder extends AbstractDataNodeContainerBuilde
     private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
     // DataSchemaNode args
     private boolean augmenting;
-    private boolean configuration;
+    private boolean addedByUses;
+    private Boolean configuration;
     private final ConstraintsBuilder constraints;
     // DataNodeContainer args
     private Set<TypeDefinition<?>> typedefs;
@@ -64,13 +66,42 @@ public final class ListSchemaNodeBuilder extends AbstractDataNodeContainerBuilde
     private List<QName> keyDefinition = Collections.emptyList();
     private boolean userOrdered;
 
-    public ListSchemaNodeBuilder(final QName qname, final int line) {
+    public ListSchemaNodeBuilder(final QName qname, final SchemaPath schemaPath, final int line) {
         super(qname);
+        this.schemaPath = schemaPath;
         this.line = line;
         instance = new ListSchemaNodeImpl(qname);
         constraints = new ConstraintsBuilder(line);
     }
 
+    public ListSchemaNodeBuilder(final ListSchemaNodeBuilder b) {
+        super(b.getQName());
+        line = b.getLine();
+        instance = new ListSchemaNodeImpl(b.getQName());
+        constraints = b.getConstraints();
+        schemaPath = b.getPath();
+        description = b.getDescription();
+        reference = b.getReference();
+        status = b.getStatus();
+        augmenting = b.isAugmenting();
+        addedByUses = b.isAddedByUses();
+        configuration = b.isConfiguration();
+        keyDefinition = b.getKeyDefinition();
+        userOrdered = b.isUserOrdered();
+        childNodes = b.getChildNodes();
+        addedChildNodes.addAll(b.getChildNodeBuilders());
+        groupings = b.getGroupings();
+        addedGroupings.addAll(b.getGroupingBuilders());
+        typedefs = b.typedefs;
+        addedTypedefs.addAll(b.getTypeDefinitionBuilders());
+        usesNodes = b.usesNodes;
+        addedUsesNodes.addAll(b.getUsesNodes());
+        augmentations = b.augmentations;
+        addedAugmentations.addAll(b.getAugmentations());
+        unknownNodes = b.unknownNodes;
+        addedUnknownNodes.addAll(b.getUnknownNodes());
+    }
+
     @Override
     public ListSchemaNode build() {
         if (!isBuilt) {
@@ -80,24 +111,25 @@ public final class ListSchemaNodeBuilder extends AbstractDataNodeContainerBuilde
             instance.setReference(reference);
             instance.setStatus(status);
             instance.setAugmenting(augmenting);
+            instance.setAddedByUses(addedByUses);
             instance.setConfiguration(configuration);
             instance.setUserOrdered(userOrdered);
 
             // CHILD NODES
             final Map<QName, DataSchemaNode> childs = new HashMap<QName, DataSchemaNode>();
-            if(childNodes == null) {
+            if (childNodes == null) {
                 for (DataSchemaNodeBuilder node : addedChildNodes) {
                     childs.put(node.getQName(), node.build());
                 }
             } else {
-                for(DataSchemaNode node : childNodes) {
+                for (DataSchemaNode node : childNodes) {
                     childs.put(node.getQName(), node);
                 }
             }
             instance.setChildNodes(childs);
 
             // TYPEDEFS
-            if(typedefs == null) {
+            if (typedefs == null) {
                 typedefs = new HashSet<TypeDefinition<?>>();
                 for (TypeDefinitionBuilder entry : addedTypedefs) {
                     typedefs.add(entry.build());
@@ -106,7 +138,7 @@ public final class ListSchemaNodeBuilder extends AbstractDataNodeContainerBuilde
             instance.setTypeDefinitions(typedefs);
 
             // USES
-            if(usesNodes == null) {
+            if (usesNodes == null) {
                 usesNodes = new HashSet<UsesNode>();
                 for (UsesNodeBuilder builder : addedUsesNodes) {
                     usesNodes.add(builder.build());
@@ -115,7 +147,7 @@ public final class ListSchemaNodeBuilder extends AbstractDataNodeContainerBuilde
             instance.setUses(usesNodes);
 
             // GROUPINGS
-            if(groupings == null) {
+            if (groupings == null) {
                 groupings = new HashSet<GroupingDefinition>();
                 for (GroupingBuilder builder : addedGroupings) {
                     groupings.add(builder.build());
@@ -124,7 +156,7 @@ public final class ListSchemaNodeBuilder extends AbstractDataNodeContainerBuilde
             instance.setGroupings(groupings);
 
             // AUGMENTATIONS
-            if(augmentations == null) {
+            if (augmentations == null) {
                 augmentations = new HashSet<AugmentationSchema>();
                 for (AugmentationSchemaBuilder builder : addedAugmentations) {
                     augmentations.add(builder.build());
@@ -133,7 +165,7 @@ public final class ListSchemaNodeBuilder extends AbstractDataNodeContainerBuilde
             instance.setAvailableAugmentations(augmentations);
 
             // UNKNOWN NODES
-            if(unknownNodes == null) {
+            if (unknownNodes == null) {
                 unknownNodes = new ArrayList<UnknownSchemaNode>();
                 for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
                     unknownNodes.add(b.build());
@@ -161,7 +193,7 @@ public final class ListSchemaNodeBuilder extends AbstractDataNodeContainerBuilde
     }
 
     @Override
-    public Set<TypeDefinitionBuilder> getTypeDefinitions() {
+    public Set<TypeDefinitionBuilder> getTypeDefinitionBuilders() {
         return addedTypedefs;
     }
 
@@ -257,12 +289,22 @@ public final class ListSchemaNodeBuilder extends AbstractDataNodeContainerBuilde
         this.augmenting = augmenting;
     }
 
-    public boolean isConfiguration() {
+    @Override
+    public boolean isAddedByUses() {
+        return addedByUses;
+    }
+
+    @Override
+    public void setAddedByUses(final boolean addedByUses) {
+        this.addedByUses = addedByUses;
+    }
+
+    public Boolean isConfiguration() {
         return configuration;
     }
 
     @Override
-    public void setConfiguration(boolean configuration) {
+    public void setConfiguration(Boolean configuration) {
         this.configuration = configuration;
     }
 
@@ -292,7 +334,6 @@ public final class ListSchemaNodeBuilder extends AbstractDataNodeContainerBuilde
         this.unknownNodes = unknownNodes;
     }
 
-
     public final class ListSchemaNodeImpl implements ListSchemaNode {
         private final QName qname;
         private SchemaPath path;
@@ -301,6 +342,7 @@ public final class ListSchemaNodeBuilder extends AbstractDataNodeContainerBuilde
         private Status status = Status.CURRENT;
         private List<QName> keyDefinition = Collections.emptyList();
         private boolean augmenting;
+        private boolean addedByUses;
         private boolean configuration;
         private ConstraintDefinition constraints;
         private Set<AugmentationSchema> augmentations = Collections.emptySet();
@@ -376,6 +418,15 @@ public final class ListSchemaNodeBuilder extends AbstractDataNodeContainerBuilde
             this.augmenting = augmenting;
         }
 
+        @Override
+        public boolean isAddedByUses() {
+            return addedByUses;
+        }
+
+        private void setAddedByUses(final boolean addedByUses) {
+            this.addedByUses = addedByUses;
+        }
+
         @Override
         public boolean isConfiguration() {
             return configuration;
@@ -399,8 +450,7 @@ public final class ListSchemaNodeBuilder extends AbstractDataNodeContainerBuilde
             return augmentations;
         }
 
-        private void setAvailableAugmentations(
-                Set<AugmentationSchema> augmentations) {
+        private void setAvailableAugmentations(Set<AugmentationSchema> augmentations) {
             if (augmentations != null) {
                 this.augmentations = augmentations;
             }
@@ -531,8 +581,7 @@ public final class ListSchemaNodeBuilder extends AbstractDataNodeContainerBuilde
 
         @Override
         public String toString() {
-            StringBuilder sb = new StringBuilder(
-                    ListSchemaNodeImpl.class.getSimpleName());
+            StringBuilder sb = new StringBuilder(ListSchemaNodeImpl.class.getSimpleName());
             sb.append("[");
             sb.append("qname=" + qname);
             sb.append(", path=" + path);
index efa3849..0a9b6dd 100644 (file)
@@ -52,7 +52,7 @@ import org.opendaylight.controller.yang.parser.util.YangParseException;
  * module/modules, these dependencies must be resolved before module is built,
  * otherwise result may not be valid.
  */
-public class ModuleBuilder implements Builder {
+public class ModuleBuilder implements DataNodeContainerBuilder {
     private final ModuleImpl instance;
     private final String name;
     private URI namespace;
@@ -80,7 +80,7 @@ public class ModuleBuilder implements Builder {
     private final Map<List<String>, TypeDefinitionBuilder> addedTypedefs = new HashMap<List<String>, TypeDefinitionBuilder>();
     private final Map<List<String>, UnionTypeBuilder> addedUnionTypes = new HashMap<List<String>, UnionTypeBuilder>();
     private final List<ExtensionBuilder> addedExtensions = new ArrayList<ExtensionBuilder>();
-    private final Map<List<String>, UnknownSchemaNodeBuilder> addedUnknownNodes = new HashMap<List<String>, UnknownSchemaNodeBuilder>();
+    private final Map<List<String>, List<UnknownSchemaNodeBuilder>> addedUnknownNodes = new HashMap<List<String>, List<UnknownSchemaNodeBuilder>>();
 
     private final Map<List<String>, TypeAwareBuilder> dirtyNodes = new HashMap<List<String>, TypeAwareBuilder>();
 
@@ -172,6 +172,30 @@ public class ModuleBuilder implements Builder {
         return 0;
     }
 
+    @Override
+    public QName getQName() {
+        return new QName(namespace, revision, prefix, name);
+    }
+
+    @Override
+    public SchemaPath getPath() {
+        return null;
+    }
+
+    @Override
+    public Set<TypeDefinitionBuilder> getTypeDefinitionBuilders() {
+        final Set<TypeDefinitionBuilder> typeDefinitions = new HashSet<TypeDefinitionBuilder>();
+        for (final Map.Entry<List<String>, TypeDefinitionBuilder> entry : addedTypedefs.entrySet()) {
+            final List<String> key = entry.getKey();
+            final TypeDefinitionBuilder typedefBuilder = entry.getValue();
+            if (key.size() == 2) {
+                typeDefinitions.add(typedefBuilder);
+
+            }
+        }
+        return typeDefinitions;
+    }
+
     public void enterNode(final Builder node) {
         actualPath.push(node);
     }
@@ -188,6 +212,14 @@ public class ModuleBuilder implements Builder {
         }
     }
 
+    public Builder getActualParent() {
+        if (actualPath.size() < 2) {
+            return null;
+        } else {
+            return actualPath.get(1);
+        }
+    }
+
     public Builder getModuleNode(final List<String> path) {
         return childNodes.get(path);
     }
@@ -196,11 +228,32 @@ public class ModuleBuilder implements Builder {
         return addedGroupings.get(path);
     }
 
+    @Override
+    public Set<GroupingDefinition> getGroupings() {
+        return Collections.emptySet();
+    }
+
+    @Override
+    public Set<GroupingBuilder> getGroupingBuilders() {
+        final Set<GroupingBuilder> result = new HashSet<GroupingBuilder>();
+        for (Map.Entry<List<String>, GroupingBuilder> entry : addedGroupings.entrySet()) {
+            if (entry.getKey().size() == 2) {
+                result.add(entry.getValue());
+            }
+        }
+        return result;
+    }
+
     public Builder getModuleTypedef(final List<String> path) {
         return addedTypedefs.get(path);
     }
 
-    public Set<DataSchemaNodeBuilder> getChildNodes() {
+    @Override
+    public Set<DataSchemaNode> getChildNodes() {
+        return Collections.emptySet();
+    }
+
+    public Set<DataSchemaNodeBuilder> getChildNodeBuilders() {
         final Set<DataSchemaNodeBuilder> children = new HashSet<DataSchemaNodeBuilder>();
         for (Map.Entry<List<String>, DataSchemaNodeBuilder> entry : childNodes.entrySet()) {
             final List<String> path = entry.getKey();
@@ -228,8 +281,12 @@ public class ModuleBuilder implements Builder {
         return addedUsesNodes;
     }
 
-    public Set<UnknownSchemaNodeBuilder> getUnknownNodes() {
-        return new HashSet<UnknownSchemaNodeBuilder>(addedUnknownNodes.values());
+    public List<UnknownSchemaNodeBuilder> getUnknownNodes() {
+        List<UnknownSchemaNodeBuilder> result = new ArrayList<UnknownSchemaNodeBuilder>();
+        for (List<UnknownSchemaNodeBuilder> entry : addedUnknownNodes.values()) {
+            result.addAll(entry);
+        }
+        return result;
     }
 
     public Set<TypeDefinitionBuilder> getModuleTypedefs() {
@@ -329,10 +386,23 @@ public class ModuleBuilder implements Builder {
         return builder;
     }
 
-    public ContainerSchemaNodeBuilder addContainerNode(final QName containerName, final List<String> parentPath,
-            final int line) {
+    @Override
+    public void addChildNode(DataSchemaNodeBuilder child) {
+        final List<String> pathToChild = new ArrayList<String>();
+        for (QName qname : child.getPath().getPath()) {
+            pathToChild.add(qname.getLocalName());
+        }
+        if (childNodes.containsKey(pathToChild)) {
+            throw new YangParseException(this.name, child.getLine(), "Failed to add child node "
+                    + child.getQName().getLocalName() + ": node already exists in context.");
+        }
+        childNodes.put(pathToChild, child);
+    }
+
+    public ContainerSchemaNodeBuilder addContainerNode(final SchemaPath schemaPath, final QName containerName,
+            final List<String> parentPath, final int line) {
         final List<String> pathToNode = new ArrayList<String>(parentPath);
-        final ContainerSchemaNodeBuilder containerBuilder = new ContainerSchemaNodeBuilder(containerName, line);
+        final ContainerSchemaNodeBuilder containerBuilder = new ContainerSchemaNodeBuilder(containerName, schemaPath, line);
         updateParent(containerBuilder, line, "container");
 
         pathToNode.add(containerName.getLocalName());
@@ -341,9 +411,9 @@ public class ModuleBuilder implements Builder {
         return containerBuilder;
     }
 
-    public ListSchemaNodeBuilder addListNode(final QName listName, final List<String> parentPath, final int line) {
+    public ListSchemaNodeBuilder addListNode(final SchemaPath schemaPath, final QName listName, final List<String> parentPath, final int line) {
         final List<String> pathToNode = new ArrayList<String>(parentPath);
-        final ListSchemaNodeBuilder listBuilder = new ListSchemaNodeBuilder(listName, line);
+        final ListSchemaNodeBuilder listBuilder = new ListSchemaNodeBuilder(listName, schemaPath, line);
         updateParent(listBuilder, line, "list");
 
         pathToNode.add(listName.getLocalName());
@@ -352,9 +422,9 @@ public class ModuleBuilder implements Builder {
         return listBuilder;
     }
 
-    public LeafSchemaNodeBuilder addLeafNode(final QName leafName, final List<String> parentPath, final int line) {
+    public LeafSchemaNodeBuilder addLeafNode(final SchemaPath schemaPath, final QName leafName, final List<String> parentPath, final int line) {
         final List<String> pathToNode = new ArrayList<String>(parentPath);
-        final LeafSchemaNodeBuilder leafBuilder = new LeafSchemaNodeBuilder(leafName, line);
+        final LeafSchemaNodeBuilder leafBuilder = new LeafSchemaNodeBuilder(leafName, schemaPath, line);
         updateParent(leafBuilder, line, "leaf");
 
         pathToNode.add(leafName.getLocalName());
@@ -363,9 +433,9 @@ public class ModuleBuilder implements Builder {
         return leafBuilder;
     }
 
-    public LeafListSchemaNodeBuilder addLeafListNode(final QName qname, final List<String> parentPath, final int line) {
+    public LeafListSchemaNodeBuilder addLeafListNode(final SchemaPath schemaPath, final QName qname, final List<String> parentPath, final int line) {
         final List<String> pathToNode = new ArrayList<String>(parentPath);
-        final LeafListSchemaNodeBuilder leafListBuilder = new LeafListSchemaNodeBuilder(qname, line);
+        final LeafListSchemaNodeBuilder leafListBuilder = new LeafListSchemaNodeBuilder(qname, schemaPath, line);
         updateParent(leafListBuilder, line, "leaf-list");
 
         pathToNode.add(qname.getLocalName());
@@ -374,6 +444,19 @@ public class ModuleBuilder implements Builder {
         return leafListBuilder;
     }
 
+    @Override
+    public void addGrouping(GroupingBuilder groupingBuilder) {
+        final List<String> pathToGroup = new ArrayList<String>();
+        for (QName qname : groupingBuilder.getPath().getPath()) {
+            pathToGroup.add(qname.getLocalName());
+        }
+        if (addedGroupings.containsKey(pathToGroup)) {
+            throw new YangParseException(this.name, groupingBuilder.getLine(), "Failed to add grouping "
+                    + groupingBuilder.getQName().getLocalName() + ": grouping already exists in context.");
+        }
+        addedGroupings.put(pathToGroup, groupingBuilder);
+    }
+
     public GroupingBuilder addGrouping(final QName qname, final List<String> parentPath, final int line) {
         final List<String> pathToGroup = new ArrayList<String>(parentPath);
         final GroupingBuilder builder = new GroupingBuilderImpl(qname, line);
@@ -395,11 +478,14 @@ public class ModuleBuilder implements Builder {
 
     public AugmentationSchemaBuilder addAugment(final String name, final List<String> parentPath, final int line) {
         final List<String> pathToAugment = new ArrayList<String>(parentPath);
-        final AugmentationSchemaBuilder builder = new AugmentationSchemaBuilderImpl(name, line);
+        Builder parent = null;
+        if (!(actualPath.isEmpty())) {
+            parent = actualPath.getFirst();
+        }
+        final AugmentationSchemaBuilder builder = new AugmentationSchemaBuilderImpl(name, line, parent);
 
         // augment can only be in 'module' or 'uses' statement
-        if (!(actualPath.isEmpty())) {
-            final Builder parent = actualPath.getFirst();
+        if (parent != null) {
             if (parent instanceof UsesNodeBuilder) {
                 ((UsesNodeBuilder) parent).addAugment(builder);
             } else {
@@ -413,20 +499,37 @@ public class ModuleBuilder implements Builder {
         return builder;
     }
 
+    @Override
+    public void addUsesNode(UsesNodeBuilder usesBuilder) {
+        final List<String> pathToTypedef = new ArrayList<String>();
+        for (QName qname : usesBuilder.getParent().getPath().getPath()) {
+            pathToTypedef.add(qname.getLocalName());
+        }
+        if (addedUsesNodes.containsKey(pathToTypedef)) {
+            throw new YangParseException(this.name, usesBuilder.getLine(), "Failed to add uses node "
+                    + usesBuilder.getGroupingName() + ": uses already exists in context.");
+        }
+        addedUsesNodes.put(pathToTypedef, usesBuilder);
+    }
+
     public UsesNodeBuilder addUsesNode(final String groupingPathStr, final List<String> parentPath, final int line) {
         final List<String> pathToUses = new ArrayList<String>(parentPath);
-        final UsesNodeBuilder usesBuilder = new UsesNodeBuilderImpl(groupingPathStr, line);
-
-        if (!(actualPath.isEmpty())) {
-            final Builder parent = actualPath.getFirst();
-            if (parent instanceof DataNodeContainerBuilder) {
-                if (parent instanceof AugmentationSchemaBuilder) {
-                    usesBuilder.setAugmenting(true);
-                }
-                ((DataNodeContainerBuilder) parent).addUsesNode(usesBuilder);
-            } else {
-                throw new YangParseException(name, line, "Unresolved parent of uses " + groupingPathStr);
+        Builder parent = null;
+        if (!actualPath.isEmpty()) {
+            parent = actualPath.getFirst();
+        }
+        if (parent != null && !(parent instanceof DataNodeContainerBuilder)) {
+            throw new YangParseException(name, line, "Unresolved parent of uses " + groupingPathStr);
+        }
+        final UsesNodeBuilder usesBuilder;
+        if (parent == null) {
+            usesBuilder = new UsesNodeBuilderImpl(groupingPathStr, line, this);
+        } else {
+            usesBuilder = new UsesNodeBuilderImpl(groupingPathStr, line, (DataNodeContainerBuilder) parent);
+            if (parent instanceof AugmentationSchemaBuilder) {
+                usesBuilder.setAugmenting(true);
             }
+            ((DataNodeContainerBuilder) parent).addUsesNode(usesBuilder);
         }
 
         pathToUses.add(groupingPathStr);
@@ -466,26 +569,26 @@ public class ModuleBuilder implements Builder {
         return rpcBuilder;
     }
 
-    public ContainerSchemaNodeBuilder addRpcInput(final QName inputQName, final int line) {
+    public ContainerSchemaNodeBuilder addRpcInput(final SchemaPath schemaPath, final QName inputQName, final int line) {
         final Builder parent = actualPath.getFirst();
         if (!(parent instanceof RpcDefinitionBuilder)) {
             throw new YangParseException(name, line, "input can be defined only in rpc statement");
         }
         final RpcDefinitionBuilder rpc = (RpcDefinitionBuilder) parent;
 
-        final ContainerSchemaNodeBuilder inputBuilder = new ContainerSchemaNodeBuilder(inputQName, line);
+        final ContainerSchemaNodeBuilder inputBuilder = new ContainerSchemaNodeBuilder(inputQName, schemaPath, line);
         rpc.setInput(inputBuilder);
         return inputBuilder;
     }
 
-    public ContainerSchemaNodeBuilder addRpcOutput(final QName outputQName, final int line) {
+    public ContainerSchemaNodeBuilder addRpcOutput(final SchemaPath schemaPath, final QName outputQName, final int line) {
         final Builder parent = actualPath.getFirst();
         if (!(parent instanceof RpcDefinitionBuilder)) {
             throw new YangParseException(name, line, "output can be defined only in rpc statement");
         }
         final RpcDefinitionBuilder rpc = (RpcDefinitionBuilder) parent;
 
-        final ContainerSchemaNodeBuilder outputBuilder = new ContainerSchemaNodeBuilder(outputQName, line);
+        final ContainerSchemaNodeBuilder outputBuilder = new ContainerSchemaNodeBuilder(outputQName, schemaPath, line);
         rpc.setOutput(outputBuilder);
         return outputBuilder;
     }
@@ -540,13 +643,19 @@ public class ModuleBuilder implements Builder {
     }
 
     public ChoiceCaseBuilder addCase(final QName caseName, final List<String> parentPath, final int line) {
+        Builder parent = getActualNode();
+
         final List<String> pathToCase = new ArrayList<String>(parentPath);
-        final ChoiceCaseBuilder builder = new ChoiceCaseBuilder(caseName, line);
+        ChoiceCaseBuilder builder = null;
+        if (parent instanceof ChoiceBuilder) {
+            builder = new ChoiceCaseBuilder((ChoiceBuilder) parent, caseName, line);
+        } else {
+            builder = new ChoiceCaseBuilder(null, caseName, line);
+        }
 
         if (actualPath.isEmpty()) {
             throw new YangParseException(name, line, "'case' parent not found");
         } else {
-            final Builder parent = actualPath.getFirst();
             if (parent instanceof ChoiceBuilder) {
                 ((ChoiceBuilder) parent).addChildNode(builder);
             } else if (parent instanceof AugmentationSchemaBuilder) {
@@ -563,9 +672,9 @@ public class ModuleBuilder implements Builder {
         return builder;
     }
 
-    public AnyXmlBuilder addAnyXml(final QName anyXmlName, final List<String> parentPath, final int line) {
+    public AnyXmlBuilder addAnyXml(final SchemaPath schemaPath, final QName anyXmlName, final List<String> parentPath, final int line) {
         final List<String> pathToAnyXml = new ArrayList<String>(parentPath);
-        final AnyXmlBuilder builder = new AnyXmlBuilder(anyXmlName, line);
+        final AnyXmlBuilder builder = new AnyXmlBuilder(anyXmlName, schemaPath, line);
         updateParent(builder, line, "anyxml");
 
         pathToAnyXml.add(anyXmlName.getLocalName());
@@ -574,6 +683,19 @@ public class ModuleBuilder implements Builder {
         return builder;
     }
 
+    @Override
+    public void addTypedef(TypeDefinitionBuilder typedefBuilder) {
+        final List<String> pathToTypedef = new ArrayList<String>();
+        for (QName qname : typedefBuilder.getPath().getPath()) {
+            pathToTypedef.add(qname.getLocalName());
+        }
+        if (addedTypedefs.containsKey(pathToTypedef)) {
+            throw new YangParseException(this.name, typedefBuilder.getLine(), "Failed to add typedef "
+                    + typedefBuilder.getQName().getLocalName() + ": typedef already exists in context.");
+        }
+        addedTypedefs.put(pathToTypedef, typedefBuilder);
+    }
+
     public TypeDefinitionBuilderImpl addTypedef(final QName typeDefName, final List<String> parentPath, final int line) {
         final List<String> pathToType = new ArrayList<String>(parentPath);
         final TypeDefinitionBuilderImpl builder = new TypeDefinitionBuilderImpl(typeDefName, line);
@@ -671,22 +793,19 @@ public class ModuleBuilder implements Builder {
         return builder;
     }
 
-    public void addConfiguration(final boolean configuration, final List<String> parentPath, final int line) {
-        if (actualPath.isEmpty()) {
-            throw new YangParseException(name, line, "Parent node of config statement not found.");
+    @Override
+    public void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownNode) {
+        final List<String> unPath = new ArrayList<String>();
+        for (QName qname : unknownNode.getPath().getPath()) {
+            unPath.add(qname.getLocalName());
+        }
+
+        if (addedUnknownNodes.containsKey(unPath)) {
+            addedUnknownNodes.get(unPath).add(unknownNode);
         } else {
-            final Builder parent = actualPath.getFirst();
-            if (parent instanceof DataSchemaNodeBuilder) {
-                ((DataSchemaNodeBuilder) parent).setConfiguration(configuration);
-            } else if (parent instanceof RefineHolder) {
-                ((RefineHolder) parent).setConfig(configuration);
-            } else if (parent instanceof DeviationBuilder) {
-                // skip: set config to deviation (deviate stmt) not supported by
-                // current api
-                return;
-            } else {
-                throw new YangParseException(name, line, "Unresolved parent of config statement.");
-            }
+            List<UnknownSchemaNodeBuilder> nodes = new ArrayList<UnknownSchemaNodeBuilder>();
+            nodes.add(unknownNode);
+            addedUnknownNodes.put(unPath, nodes);
         }
     }
 
@@ -707,7 +826,14 @@ public class ModuleBuilder implements Builder {
         }
         final List<String> unPath = new ArrayList<String>(parentPath);
         unPath.add(qname.getLocalName());
-        addedUnknownNodes.put(unPath, builder);
+
+        if (addedUnknownNodes.containsKey(unPath)) {
+            addedUnknownNodes.get(unPath).add(builder);
+        } else {
+            List<UnknownSchemaNodeBuilder> nodes = new ArrayList<UnknownSchemaNodeBuilder>();
+            nodes.add(builder);
+            addedUnknownNodes.put(unPath, nodes);
+        }
         return builder;
     }
 
@@ -1259,14 +1385,16 @@ public class ModuleBuilder implements Builder {
     }
 
     private List<UnknownSchemaNode> buildModuleUnknownNodes(
-            final Map<List<String>, UnknownSchemaNodeBuilder> addedUnknownNodes) {
+            final Map<List<String>, List<UnknownSchemaNodeBuilder>> addedUnknownNodes) {
         final List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();
-        for (Map.Entry<List<String>, UnknownSchemaNodeBuilder> entry : addedUnknownNodes.entrySet()) {
+        for (Map.Entry<List<String>, List<UnknownSchemaNodeBuilder>> entry : addedUnknownNodes.entrySet()) {
             final List<String> path = entry.getKey();
-            final UnknownSchemaNodeBuilder child = entry.getValue();
-            if (path.size() == 2) {
-                final UnknownSchemaNode node = child.build();
-                unknownNodes.add(node);
+            final List<UnknownSchemaNodeBuilder> child = entry.getValue();
+            for (UnknownSchemaNodeBuilder un : child) {
+                if (path.size() == 2) {
+                    final UnknownSchemaNode node = un.build();
+                    unknownNodes.add(node);
+                }
             }
         }
         return unknownNodes;
index 956d8fe..534ba2c 100644 (file)
@@ -35,8 +35,8 @@ import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionAwareBu
 import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.UsesNodeBuilder;
 
-public final class NotificationBuilder extends AbstractDataNodeContainerBuilder
-        implements TypeDefinitionAwareBuilder, SchemaNodeBuilder, AugmentationTargetBuilder {
+public final class NotificationBuilder extends AbstractDataNodeContainerBuilder implements TypeDefinitionAwareBuilder,
+        SchemaNodeBuilder, AugmentationTargetBuilder {
     private boolean isBuilt;
     private final NotificationDefinitionImpl instance;
     private final int line;
@@ -93,7 +93,7 @@ public final class NotificationBuilder extends AbstractDataNodeContainerBuilder
             instance.setUses(uses);
 
             // AUGMENTATIONS
-            if(augmentations == null) {
+            if (augmentations == null) {
                 augmentations = new HashSet<AugmentationSchema>();
                 for (AugmentationSchemaBuilder builder : addedAugmentations) {
                     augmentations.add(builder.build());
@@ -126,7 +126,7 @@ public final class NotificationBuilder extends AbstractDataNodeContainerBuilder
     }
 
     @Override
-    public Set<TypeDefinitionBuilder> getTypeDefinitions() {
+    public Set<TypeDefinitionBuilder> getTypeDefinitionBuilders() {
         return addedTypedefs;
     }
 
@@ -177,7 +177,7 @@ public final class NotificationBuilder extends AbstractDataNodeContainerBuilder
 
     @Override
     public void setStatus(final Status status) {
-        if(status != null) {
+        if (status != null) {
             this.status = status;
         }
     }
@@ -303,8 +303,7 @@ public final class NotificationBuilder extends AbstractDataNodeContainerBuilder
             return typeDefinitions;
         }
 
-        private void setTypeDefinitions(
-                final Set<TypeDefinition<?>> typeDefinitions) {
+        private void setTypeDefinitions(final Set<TypeDefinition<?>> typeDefinitions) {
             if (typeDefinitions != null) {
                 this.typeDefinitions = typeDefinitions;
             }
@@ -315,8 +314,7 @@ public final class NotificationBuilder extends AbstractDataNodeContainerBuilder
             return augmentations;
         }
 
-        private void setAvailableAugmentations(
-                Set<AugmentationSchema> augmentations) {
+        private void setAvailableAugmentations(Set<AugmentationSchema> augmentations) {
             if (augmentations != null) {
                 this.augmentations = augmentations;
             }
@@ -327,8 +325,7 @@ public final class NotificationBuilder extends AbstractDataNodeContainerBuilder
             return unknownNodes;
         }
 
-        private void setUnknownSchemaNodes(
-                final List<UnknownSchemaNode> unknownNodes) {
+        private void setUnknownSchemaNodes(final List<UnknownSchemaNode> unknownNodes) {
             if (unknownNodes != null) {
                 this.unknownNodes = unknownNodes;
             }
@@ -395,8 +392,7 @@ public final class NotificationBuilder extends AbstractDataNodeContainerBuilder
 
         @Override
         public String toString() {
-            StringBuilder sb = new StringBuilder(
-                    NotificationDefinitionImpl.class.getSimpleName());
+            StringBuilder sb = new StringBuilder(NotificationDefinitionImpl.class.getSimpleName());
             sb.append("[qname=" + qname + ", path=" + path + "]");
             return sb.toString();
         }
index e36adbd..8cb4a6e 100644 (file)
@@ -21,29 +21,21 @@ 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.api.UnknownSchemaNode;
+import org.opendaylight.controller.yang.parser.builder.api.AbstractSchemaNodeBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.GroupingBuilder;
-import org.opendaylight.controller.yang.parser.builder.api.SchemaNodeBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionAwareBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionBuilder;
 
-public final class RpcDefinitionBuilder implements SchemaNodeBuilder, TypeDefinitionAwareBuilder {
+public final class RpcDefinitionBuilder extends AbstractSchemaNodeBuilder implements TypeDefinitionAwareBuilder {
     private boolean isBuilt;
     private final RpcDefinitionImpl instance;
-    private final int line;
-    private final QName qname;
-    private SchemaPath schemaPath;
-    private String description;
-    private String reference;
-    private Status status = Status.CURRENT;
     private ContainerSchemaNodeBuilder inputBuilder;
     private ContainerSchemaNodeBuilder outputBuilder;
     private final Set<TypeDefinitionBuilder> addedTypedefs = new HashSet<TypeDefinitionBuilder>();
     private final Set<GroupingBuilder> addedGroupings = new HashSet<GroupingBuilder>();
-    private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
 
     RpcDefinitionBuilder(final QName qname, final int line) {
-        this.qname = qname;
-        this.line = line;
+        super(qname, line);
         this.instance = new RpcDefinitionImpl(qname);
     }
 
@@ -59,7 +51,7 @@ public final class RpcDefinitionBuilder implements SchemaNodeBuilder, TypeDefini
             instance.setInput(input);
             instance.setOutput(output);
 
-            instance.setPath(schemaPath);
+            instance.setPath(path);
 
             // TYPEDEFS
             final Set<TypeDefinition<?>> typedefs = new HashSet<TypeDefinition<?>>();
@@ -87,11 +79,6 @@ public final class RpcDefinitionBuilder implements SchemaNodeBuilder, TypeDefini
         return instance;
     }
 
-    @Override
-    public int getLine() {
-        return line;
-    }
-
     void setInput(final ContainerSchemaNodeBuilder inputBuilder) {
         this.inputBuilder = inputBuilder;
     }
@@ -117,64 +104,12 @@ public final class RpcDefinitionBuilder implements SchemaNodeBuilder, TypeDefini
         addedGroupings.add(grouping);
     }
 
-    @Override
-    public SchemaPath getPath() {
-        return schemaPath;
-    }
-
-    @Override
-    public void setPath(SchemaPath schemaPath) {
-        this.schemaPath = schemaPath;
-    }
-
-    @Override
-    public String getDescription() {
-        return description;
-    }
-
-    @Override
-    public void setDescription(final String description) {
-        this.description = description;
-    }
-
-    @Override
-    public String getReference() {
-        return reference;
-    }
-
-    @Override
-    public void setReference(String reference) {
-        this.reference = reference;
-    }
-
-    @Override
-    public Status getStatus() {
-        return status;
-    }
-
-    @Override
-    public void setStatus(final Status status) {
-        if (status != null) {
-            this.status = status;
-        }
-    }
-
-    @Override
-    public QName getQName() {
-        return null;
-    }
-
-    @Override
-    public void addUnknownSchemaNode(final UnknownSchemaNodeBuilder unknownNode) {
-        addedUnknownNodes.add(unknownNode);
-    }
-
     @Override
     public int hashCode() {
         final int prime = 31;
         int result = 1;
         result = prime * result + ((qname == null) ? 0 : qname.hashCode());
-        result = prime * result + ((schemaPath == null) ? 0 : schemaPath.hashCode());
+        result = prime * result + ((path == null) ? 0 : path.hashCode());
         return result;
     }
 
@@ -194,11 +129,11 @@ public final class RpcDefinitionBuilder implements SchemaNodeBuilder, TypeDefini
         } else if (!other.qname.equals(this.qname)) {
             return false;
         }
-        if (other.schemaPath == null) {
-            if (this.schemaPath != null) {
+        if (other.path == null) {
+            if (this.path != null) {
                 return false;
             }
-        } else if (!other.schemaPath.equals(this.schemaPath)) {
+        } else if (!other.path.equals(this.path)) {
             return false;
         }
         return true;
index a8628ea..6ca07bc 100644 (file)
@@ -25,14 +25,13 @@ import org.opendaylight.controller.yang.parser.builder.api.AbstractTypeAwareBuil
 import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionBuilder;
 import org.opendaylight.controller.yang.parser.util.YangParseException;
 
-public final class TypeDefinitionBuilderImpl extends AbstractTypeAwareBuilder
-        implements TypeDefinitionBuilder {
+public final class TypeDefinitionBuilderImpl extends AbstractTypeAwareBuilder implements TypeDefinitionBuilder {
     private final int line;
     private final QName qname;
     private SchemaPath schemaPath;
 
-    private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
     private List<UnknownSchemaNode> unknownNodes;
+    private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
     private List<RangeConstraint> ranges = Collections.emptyList();
     private List<LengthConstraint> lengths = Collections.emptyList();
     private List<PatternConstraint> patterns = Collections.emptyList();
@@ -43,30 +42,55 @@ public final class TypeDefinitionBuilderImpl extends AbstractTypeAwareBuilder
     private Status status = Status.CURRENT;
     private String units;
     private Object defaultValue;
+    private boolean addedByUses;
 
     public TypeDefinitionBuilderImpl(final QName qname, final int line) {
         this.qname = qname;
         this.line = line;
     }
 
+    public TypeDefinitionBuilderImpl(TypeDefinitionBuilder tdb) {
+        qname = tdb.getQName();
+        line = tdb.getLine();
+        schemaPath = tdb.getPath();
+
+        type = tdb.getType();
+        typedef = tdb.getTypedef();
+
+        unknownNodes = tdb.getUnknownNodes();
+        for (UnknownSchemaNodeBuilder usnb : tdb.getUnknownNodeBuilders()) {
+            addedUnknownNodes.add(usnb);
+        }
+        ranges = tdb.getRanges();
+        lengths = tdb.getLengths();
+        patterns = tdb.getPatterns();
+        fractionDigits = tdb.getFractionDigits();
+
+        description = tdb.getDescription();
+        reference = tdb.getReference();
+        status = tdb.getStatus();
+        units = tdb.getUnits();
+        defaultValue = tdb.getDefaultValue();
+        addedByUses = tdb.isAddedByUses();
+    }
+
     @Override
     public TypeDefinition<? extends TypeDefinition<?>> build() {
         TypeDefinition<?> result = null;
         ExtendedType.Builder typeBuilder = null;
         if ((type == null || type instanceof UnknownType) && typedef == null) {
-            throw new YangParseException("Unresolved type: '"
-                    + qname.getLocalName() + "'.");
+            throw new YangParseException("Unresolved type: '" + qname.getLocalName() + "'.");
         }
         if (type == null || type instanceof UnknownType) {
             type = typedef.build();
         }
 
-        typeBuilder = new ExtendedType.Builder(qname, type, description,
-                reference, schemaPath);
+        typeBuilder = new ExtendedType.Builder(qname, type, description, reference, schemaPath);
 
         typeBuilder.status(status);
         typeBuilder.units(units);
         typeBuilder.defaultValue(defaultValue);
+        typeBuilder.addedByUses(addedByUses);
 
         typeBuilder.ranges(ranges);
         typeBuilder.lengths(lengths);
@@ -137,6 +161,16 @@ public final class TypeDefinitionBuilderImpl extends AbstractTypeAwareBuilder
         }
     }
 
+    @Override
+    public boolean isAddedByUses() {
+        return addedByUses;
+    }
+
+    @Override
+    public void setAddedByUses(final boolean addedByUses) {
+        this.addedByUses = addedByUses;
+    }
+
     @Override
     public String getUnits() {
         return units;
@@ -158,7 +192,12 @@ public final class TypeDefinitionBuilderImpl extends AbstractTypeAwareBuilder
     }
 
     @Override
-    public List<UnknownSchemaNodeBuilder> getUnknownNodes() {
+    public List<UnknownSchemaNode> getUnknownNodes() {
+        return Collections.emptyList();
+    }
+
+    @Override
+    public List<UnknownSchemaNodeBuilder> getUnknownNodeBuilders() {
         return addedUnknownNodes;
     }
 
@@ -219,8 +258,7 @@ public final class TypeDefinitionBuilderImpl extends AbstractTypeAwareBuilder
 
     @Override
     public String toString() {
-        final StringBuilder result = new StringBuilder("TypedefBuilder["
-                + qname.getLocalName());
+        final StringBuilder result = new StringBuilder("TypedefBuilder[" + qname.getLocalName());
         result.append(", type=");
         if (type == null) {
             result.append(typedef);
index 07db699..433ae96 100644 (file)
@@ -15,6 +15,7 @@ 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.api.UnknownSchemaNode;
 import org.opendaylight.controller.yang.model.api.type.LengthConstraint;
 import org.opendaylight.controller.yang.model.api.type.PatternConstraint;
 import org.opendaylight.controller.yang.model.api.type.RangeConstraint;
@@ -29,8 +30,7 @@ import org.opendaylight.controller.yang.parser.util.YangParseException;
  * When build is called, types in builder form will be built and add to resolved
  * types.
  */
-public final class UnionTypeBuilder extends AbstractTypeAwareBuilder implements
-        TypeDefinitionBuilder {
+public final class UnionTypeBuilder extends AbstractTypeAwareBuilder implements TypeDefinitionBuilder {
     private final static String NAME = "union";
 
     private final int line;
@@ -112,10 +112,24 @@ public final class UnionTypeBuilder extends AbstractTypeAwareBuilder implements
         throw new YangParseException(line, "Can not set status to " + NAME);
     }
 
+    @Override
+    public boolean isAddedByUses() {
+        return false;
+    }
+
+    @Override
+    public void setAddedByUses(final boolean addedByUses) {
+        throw new YangParseException(line, "Union type can not be added by uses.");
+    }
+
+    @Override
+    public List<UnknownSchemaNode> getUnknownNodes() {
+        return Collections.emptyList();
+    }
+
     @Override
     public void addUnknownSchemaNode(final UnknownSchemaNodeBuilder unknownNode) {
-        throw new YangParseException(line, "Can not add unknown node to "
-                + NAME);
+        // not supported
     }
 
     @Override
@@ -180,12 +194,11 @@ public final class UnionTypeBuilder extends AbstractTypeAwareBuilder implements
 
     @Override
     public void setFractionDigits(Integer fractionDigits) {
-        throw new YangParseException(line, "Can not set fraction digits to "
-                + NAME);
+        throw new YangParseException(line, "Can not set fraction digits to " + NAME);
     }
 
     @Override
-    public List<UnknownSchemaNodeBuilder> getUnknownNodes() {
+    public List<UnknownSchemaNodeBuilder> getUnknownNodeBuilders() {
         return Collections.emptyList();
     }
 
@@ -196,8 +209,7 @@ public final class UnionTypeBuilder extends AbstractTypeAwareBuilder implements
 
     @Override
     public void setDefaultValue(Object defaultValue) {
-        throw new YangParseException(line, "Can not set default value to "
-                + NAME);
+        throw new YangParseException(line, "Can not set default value to " + NAME);
     }
 
     @Override
@@ -212,8 +224,7 @@ public final class UnionTypeBuilder extends AbstractTypeAwareBuilder implements
 
     @Override
     public String toString() {
-        final StringBuilder result = new StringBuilder(
-                UnionTypeBuilder.class.getSimpleName() + "[");
+        final StringBuilder result = new StringBuilder(UnionTypeBuilder.class.getSimpleName() + "[");
         result.append(", types=" + types);
         result.append(", typedefs=" + typedefs);
         result.append("]");
index 3d3ad28..14cf3a9 100644 (file)
@@ -15,41 +15,52 @@ 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.UnknownSchemaNode;
-import org.opendaylight.controller.yang.parser.builder.api.SchemaNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.AbstractSchemaNodeBuilder;
 
-public final class UnknownSchemaNodeBuilder implements SchemaNodeBuilder {
+public final class UnknownSchemaNodeBuilder extends AbstractSchemaNodeBuilder {
     private boolean isBuilt;
     private final UnknownSchemaNodeImpl instance;
-    private final int line;
-    private final QName qname;
-    private SchemaPath schemaPath;
-    private String description;
-    private String reference;
-    private Status status = Status.CURRENT;
-    private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
+    private boolean addedByUses;
+    private List<UnknownSchemaNode> unknownNodes;
     private QName nodeType;
     private String nodeParameter;
 
-    UnknownSchemaNodeBuilder(final QName qname, final int line) {
-        this.qname = qname;
-        this.line = line;
+    public UnknownSchemaNodeBuilder(final QName qname, final int line) {
+        super(qname, line);
         instance = new UnknownSchemaNodeImpl(qname);
     }
 
+    public UnknownSchemaNodeBuilder(UnknownSchemaNodeBuilder b) {
+        super(b.getQName(), b.getLine());
+        instance = new UnknownSchemaNodeImpl(qname);
+        path = b.getPath();
+        description = b.getDescription();
+        reference = b.getReference();
+        status = b.getStatus();
+        addedByUses = b.isAddedByUses();
+        unknownNodes = b.unknownNodes;
+        addedUnknownNodes.addAll(b.addedUnknownNodes);
+        nodeType = b.getNodeType();
+        nodeParameter = b.getNodeParameter();
+    }
+
     @Override
     public UnknownSchemaNode build() {
         if (!isBuilt) {
-            instance.setPath(schemaPath);
+            instance.setPath(path);
             instance.setNodeType(nodeType);
             instance.setNodeParameter(nodeParameter);
             instance.setDescription(description);
             instance.setReference(reference);
             instance.setStatus(status);
+            instance.setAddedByUses(addedByUses);
 
             // UNKNOWN NODES
-            final List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();
-            for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
-                unknownNodes.add(b.build());
+            if (unknownNodes == null) {
+                unknownNodes = new ArrayList<UnknownSchemaNode>();
+                for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
+                    unknownNodes.add(b.build());
+                }
             }
             instance.setUnknownSchemaNodes(unknownNodes);
 
@@ -59,61 +70,16 @@ public final class UnknownSchemaNodeBuilder implements SchemaNodeBuilder {
         return instance;
     }
 
-    @Override
-    public int getLine() {
-        return line;
-    }
-
-    @Override
-    public QName getQName() {
-        return qname;
-    }
-
-    @Override
-    public SchemaPath getPath() {
-        return schemaPath;
-    }
-
-    @Override
-    public void setPath(SchemaPath schemaPath) {
-        this.schemaPath = schemaPath;
-    }
-
-    @Override
-    public String getDescription() {
-        return description;
+    public boolean isAddedByUses() {
+        return addedByUses;
     }
 
-    @Override
-    public void setDescription(final String description) {
-        this.description = description;
+    public void setAddedByUses(final boolean addedByUses) {
+        this.addedByUses = addedByUses;
     }
 
-    @Override
-    public String getReference() {
-        return reference;
-    }
-
-    @Override
-    public void setReference(String reference) {
-        this.reference = reference;
-    }
-
-    @Override
-    public Status getStatus() {
-        return status;
-    }
-
-    @Override
-    public void setStatus(Status status) {
-        if (status != null) {
-            this.status = status;
-        }
-    }
-
-    @Override
-    public void addUnknownSchemaNode(final UnknownSchemaNodeBuilder unknownNode) {
-        addedUnknownNodes.add(unknownNode);
+    public void setUnknownNodes(final List<UnknownSchemaNode> unknownNodes) {
+        this.unknownNodes = unknownNodes;
     }
 
     public QName getNodeType() {
@@ -141,6 +107,7 @@ public final class UnknownSchemaNodeBuilder implements SchemaNodeBuilder {
         private List<UnknownSchemaNode> unknownNodes = Collections.emptyList();
         private QName nodeType;
         private String nodeParameter;
+        private boolean addedByUses;
 
         private UnknownSchemaNodeImpl(final QName qname) {
             this.qname = qname;
@@ -189,6 +156,15 @@ public final class UnknownSchemaNodeBuilder implements SchemaNodeBuilder {
             }
         }
 
+        @Override
+        public boolean isAddedByUses() {
+            return addedByUses;
+        }
+
+        private void setAddedByUses(final boolean addedByUses) {
+            this.addedByUses = addedByUses;
+        }
+
         @Override
         public List<UnknownSchemaNode> getUnknownSchemaNodes() {
             return unknownNodes;
@@ -217,6 +193,15 @@ public final class UnknownSchemaNodeBuilder implements SchemaNodeBuilder {
         private void setNodeParameter(final String nodeParameter) {
             this.nodeParameter = nodeParameter;
         }
+
+        @Override
+        public String toString() {
+            StringBuilder sb = new StringBuilder(UnknownSchemaNodeImpl.class.getSimpleName());
+            sb.append("[");
+            sb.append(qname);
+            sb.append("]");
+            return sb.toString();
+        }
     }
 
 }
index 8509381..77a465d 100644 (file)
@@ -18,8 +18,10 @@ import java.util.Set;
 import org.opendaylight.controller.yang.model.api.AugmentationSchema;\r
 import org.opendaylight.controller.yang.model.api.SchemaNode;\r
 import org.opendaylight.controller.yang.model.api.SchemaPath;\r
+import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;\r
 import org.opendaylight.controller.yang.model.api.UsesNode;\r
 import org.opendaylight.controller.yang.parser.builder.api.AugmentationSchemaBuilder;\r
+import org.opendaylight.controller.yang.parser.builder.api.DataNodeContainerBuilder;\r
 import org.opendaylight.controller.yang.parser.builder.api.SchemaNodeBuilder;\r
 import org.opendaylight.controller.yang.parser.builder.api.UsesNodeBuilder;\r
 import org.opendaylight.controller.yang.parser.util.RefineHolder;\r
@@ -28,17 +30,32 @@ public final class UsesNodeBuilderImpl implements UsesNodeBuilder {
     private boolean isBuilt;\r
     private UsesNodeImpl instance;\r
     private final int line;\r
-    private SchemaPath schemaPath;\r
+    private final DataNodeContainerBuilder parent;\r
     private final String groupingName;\r
     private SchemaPath groupingPath;\r
     private boolean augmenting;\r
+    private boolean addedByUses;\r
     private final Set<AugmentationSchemaBuilder> addedAugments = new HashSet<AugmentationSchemaBuilder>();\r
-    private List<SchemaNodeBuilder> refineBuilders = new ArrayList<SchemaNodeBuilder>();\r
-    private List<RefineHolder> refines = new ArrayList<RefineHolder>();\r
+    private final List<SchemaNodeBuilder> refineBuilders = new ArrayList<SchemaNodeBuilder>();\r
+    private final List<RefineHolder> refines = new ArrayList<RefineHolder>();\r
+    private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();\r
 \r
-    public UsesNodeBuilderImpl(final String groupingName, final int line) {\r
+    public UsesNodeBuilderImpl(final String groupingName, final int line, final DataNodeContainerBuilder parent) {\r
         this.groupingName = groupingName;\r
         this.line = line;\r
+        this.parent = parent;\r
+    }\r
+\r
+    public UsesNodeBuilderImpl(UsesNodeBuilder b) {\r
+        groupingName = b.getGroupingName();\r
+        line = b.getLine();\r
+        parent = b.getParent();\r
+        groupingPath = b.getGroupingPath();\r
+        augmenting = b.isAugmenting();\r
+        addedByUses = b.isAddedByUses();\r
+        addedAugments.addAll(b.getAugmentations());\r
+        refineBuilders.addAll(b.getRefineNodes());\r
+        refines.addAll(b.getRefines());\r
     }\r
 \r
     @Override\r
@@ -46,6 +63,7 @@ public final class UsesNodeBuilderImpl implements UsesNodeBuilder {
         if (!isBuilt) {\r
             instance = new UsesNodeImpl(groupingPath);\r
             instance.setAugmenting(augmenting);\r
+            instance.setAddedByUses(addedByUses);\r
 \r
             // AUGMENTATIONS\r
             final Set<AugmentationSchema> augments = new HashSet<AugmentationSchema>();\r
@@ -62,6 +80,13 @@ public final class UsesNodeBuilderImpl implements UsesNodeBuilder {
             }\r
             instance.setRefines(refineNodes);\r
 \r
+            // UNKNOWN NODES\r
+            List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();\r
+            for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {\r
+                unknownNodes.add(b.build());\r
+            }\r
+            instance.setUnknownSchemaNodes(unknownNodes);\r
+\r
             isBuilt = true;\r
         }\r
         return instance;\r
@@ -73,18 +98,18 @@ public final class UsesNodeBuilderImpl implements UsesNodeBuilder {
     }\r
 \r
     @Override\r
-    public void setGroupingPath(SchemaPath groupingPath) {\r
-        this.groupingPath = groupingPath;\r
+    public DataNodeContainerBuilder getParent() {\r
+        return parent;\r
     }\r
 \r
     @Override\r
-    public SchemaPath getPath() {\r
-        return schemaPath;\r
+    public SchemaPath getGroupingPath() {\r
+        return groupingPath;\r
     }\r
 \r
     @Override\r
-    public void setPath(SchemaPath path) {\r
-        this.schemaPath = path;\r
+    public void setGroupingPath(SchemaPath groupingPath) {\r
+        this.groupingPath = groupingPath;\r
     }\r
 \r
     @Override\r
@@ -112,6 +137,16 @@ public final class UsesNodeBuilderImpl implements UsesNodeBuilder {
         this.augmenting = augmenting;\r
     }\r
 \r
+    @Override\r
+    public boolean isAddedByUses() {\r
+        return addedByUses;\r
+    }\r
+\r
+    @Override\r
+    public void setAddedByUses(final boolean addedByUses) {\r
+        this.addedByUses = addedByUses;\r
+    }\r
+\r
     @Override\r
     public List<SchemaNodeBuilder> getRefineNodes() {\r
         return refineBuilders;\r
@@ -132,12 +167,22 @@ public final class UsesNodeBuilderImpl implements UsesNodeBuilder {
         refines.add(refine);\r
     }\r
 \r
+    public List<UnknownSchemaNodeBuilder> getUnknownNodes() {\r
+        return addedUnknownNodes;\r
+    }\r
+\r
+    @Override\r
+    public void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownNode) {\r
+        addedUnknownNodes.add(unknownNode);\r
+    }\r
 \r
-    private final class UsesNodeImpl implements UsesNode {\r
+    public final class UsesNodeImpl implements UsesNode {\r
         private final SchemaPath groupingPath;\r
         private Set<AugmentationSchema> augmentations = Collections.emptySet();\r
         private boolean augmenting;\r
+        private boolean addedByUses;\r
         private Map<SchemaPath, SchemaNode> refines = Collections.emptyMap();\r
+        private List<UnknownSchemaNode> unknownNodes = Collections.emptyList();\r
 \r
         private UsesNodeImpl(final SchemaPath groupingPath) {\r
             this.groupingPath = groupingPath;\r
@@ -153,8 +198,7 @@ public final class UsesNodeBuilderImpl implements UsesNodeBuilder {
             return augmentations;\r
         }\r
 \r
-        private void setAugmentations(\r
-                final Set<AugmentationSchema> augmentations) {\r
+        private void setAugmentations(final Set<AugmentationSchema> augmentations) {\r
             if (augmentations != null) {\r
                 this.augmentations = augmentations;\r
             }\r
@@ -169,6 +213,15 @@ public final class UsesNodeBuilderImpl implements UsesNodeBuilder {
             this.augmenting = augmenting;\r
         }\r
 \r
+        @Override\r
+        public boolean isAddedByUses() {\r
+            return addedByUses;\r
+        }\r
+\r
+        private void setAddedByUses(final boolean addedByUses) {\r
+            this.addedByUses = addedByUses;\r
+        }\r
+\r
         @Override\r
         public Map<SchemaPath, SchemaNode> getRefines() {\r
             return refines;\r
@@ -180,14 +233,26 @@ public final class UsesNodeBuilderImpl implements UsesNodeBuilder {
             }\r
         }\r
 \r
+        public List<UnknownSchemaNode> getUnknownSchemaNodes() {\r
+            return unknownNodes;\r
+        }\r
+\r
+        private void setUnknownSchemaNodes(List<UnknownSchemaNode> unknownSchemaNodes) {\r
+            if (unknownSchemaNodes != null) {\r
+                this.unknownNodes = unknownSchemaNodes;\r
+            }\r
+        }\r
+\r
+        public UsesNodeBuilder toBuilder() {\r
+            return UsesNodeBuilderImpl.this;\r
+        }\r
+\r
         @Override\r
         public int hashCode() {\r
             final int prime = 31;\r
             int result = 1;\r
-            result = prime * result\r
-                    + ((groupingPath == null) ? 0 : groupingPath.hashCode());\r
-            result = prime * result\r
-                    + ((augmentations == null) ? 0 : augmentations.hashCode());\r
+            result = prime * result + ((groupingPath == null) ? 0 : groupingPath.hashCode());\r
+            result = prime * result + ((augmentations == null) ? 0 : augmentations.hashCode());\r
             result = prime * result + (augmenting ? 1231 : 1237);\r
             return result;\r
         }\r
@@ -226,8 +291,7 @@ public final class UsesNodeBuilderImpl implements UsesNodeBuilder {
 \r
         @Override\r
         public String toString() {\r
-            StringBuilder sb = new StringBuilder(\r
-                    UsesNodeImpl.class.getSimpleName());\r
+            StringBuilder sb = new StringBuilder(UsesNodeImpl.class.getSimpleName());\r
             sb.append("[groupingPath=" + groupingPath + "]");\r
             return sb.toString();\r
         }\r
index e74029b..5dedd3c 100644 (file)
@@ -36,12 +36,21 @@ import org.antlr.v4.runtime.tree.ParseTreeWalker;
 import org.opendaylight.controller.antlrv4.code.gen.YangLexer;
 import org.opendaylight.controller.antlrv4.code.gen.YangParser;
 import org.opendaylight.controller.yang.common.QName;
+import org.opendaylight.controller.yang.model.api.AnyXmlSchemaNode;
+import org.opendaylight.controller.yang.model.api.ChoiceNode;
+import org.opendaylight.controller.yang.model.api.ContainerSchemaNode;
+import org.opendaylight.controller.yang.model.api.DataSchemaNode;
 import org.opendaylight.controller.yang.model.api.GroupingDefinition;
 import org.opendaylight.controller.yang.model.api.IdentitySchemaNode;
+import org.opendaylight.controller.yang.model.api.LeafListSchemaNode;
+import org.opendaylight.controller.yang.model.api.LeafSchemaNode;
+import org.opendaylight.controller.yang.model.api.ListSchemaNode;
 import org.opendaylight.controller.yang.model.api.Module;
 import org.opendaylight.controller.yang.model.api.SchemaContext;
 import org.opendaylight.controller.yang.model.api.SchemaPath;
 import org.opendaylight.controller.yang.model.api.TypeDefinition;
+import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.controller.yang.model.api.UsesNode;
 import org.opendaylight.controller.yang.model.parser.api.YangModelParser;
 import org.opendaylight.controller.yang.model.util.ExtendedType;
 import org.opendaylight.controller.yang.model.util.IdentityrefType;
@@ -49,17 +58,29 @@ import org.opendaylight.controller.yang.model.util.UnknownType;
 import org.opendaylight.controller.yang.parser.builder.api.AugmentationSchemaBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.Builder;
 import org.opendaylight.controller.yang.parser.builder.api.DataNodeContainerBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.DataSchemaNodeBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.GroupingBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.GroupingMember;
 import org.opendaylight.controller.yang.parser.builder.api.SchemaNodeBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.TypeAwareBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.UsesNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.impl.AnyXmlBuilder;
+import org.opendaylight.controller.yang.parser.builder.impl.ChoiceBuilder;
+import org.opendaylight.controller.yang.parser.builder.impl.ContainerSchemaNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.impl.GroupingBuilderImpl;
 import org.opendaylight.controller.yang.parser.builder.impl.IdentitySchemaNodeBuilder;
 import org.opendaylight.controller.yang.parser.builder.impl.IdentityrefTypeBuilder;
+import org.opendaylight.controller.yang.parser.builder.impl.LeafListSchemaNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.impl.LeafSchemaNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.impl.ListSchemaNodeBuilder;
 import org.opendaylight.controller.yang.parser.builder.impl.ModuleBuilder;
 import org.opendaylight.controller.yang.parser.builder.impl.RpcDefinitionBuilder;
+import org.opendaylight.controller.yang.parser.builder.impl.TypeDefinitionBuilderImpl;
 import org.opendaylight.controller.yang.parser.builder.impl.UnionTypeBuilder;
 import org.opendaylight.controller.yang.parser.builder.impl.UnknownSchemaNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.impl.UsesNodeBuilderImpl;
+import org.opendaylight.controller.yang.parser.builder.impl.UsesNodeBuilderImpl.UsesNodeImpl;
 import org.opendaylight.controller.yang.parser.util.ModuleDependencySort;
 import org.opendaylight.controller.yang.parser.util.RefineHolder;
 import org.opendaylight.controller.yang.parser.util.RefineUtils;
@@ -74,7 +95,6 @@ import com.google.common.collect.Maps;
 import com.google.common.collect.Sets;
 
 public final class YangParserImpl implements YangModelParser {
-
     private static final Logger logger = LoggerFactory.getLogger(YangParserImpl.class);
 
     @Override
@@ -471,9 +491,10 @@ public final class YangParserImpl implements YangModelParser {
 
                 nodeToResolve.setTypedef(newType);
             } else {
-                if(nodeToResolve instanceof TypeDefinitionBuilder) {
-                    TypeDefinitionBuilder tdb = (TypeDefinitionBuilder)nodeToResolve;
-                    TypeConstraints tc = findConstraintsFromTypeBuilder(nodeToResolve, new TypeConstraints(module.getName(), nodeToResolve.getLine()), modules, module, context);
+                if (nodeToResolve instanceof TypeDefinitionBuilder) {
+                    TypeDefinitionBuilder tdb = (TypeDefinitionBuilder) nodeToResolve;
+                    TypeConstraints tc = findConstraintsFromTypeBuilder(nodeToResolve,
+                            new TypeConstraints(module.getName(), nodeToResolve.getLine()), modules, module, context);
                     tdb.setLengths(tc.getLength());
                     tdb.setPatterns(tc.getPatterns());
                     tdb.setRanges(tc.getRange());
@@ -673,8 +694,8 @@ public final class YangParserImpl implements YangModelParser {
 
     /**
      * Go through all augment definitions and resolve them. This method works in
-     * same way as {@link #resolveAugments(Map)} except that if target node is not
-     * found in loaded modules, it search for target node in given context.
+     * same way as {@link #resolveAugments(Map)} except that if target node is
+     * not found in loaded modules, it search for target node in given context.
      *
      * @param modules
      *            all loaded modules
@@ -804,7 +825,7 @@ public final class YangParserImpl implements YangModelParser {
      *            SchemaContext containing already resolved modules
      */
     private void resolveIdentitiesWithContext(final Map<String, TreeMap<Date, ModuleBuilder>> modules,
-            final ModuleBuilder module, SchemaContext context) {
+            final ModuleBuilder module, final SchemaContext context) {
         final Set<IdentitySchemaNodeBuilder> identities = module.getIdentities();
         for (IdentitySchemaNodeBuilder identity : identities) {
             final String baseIdentityName = identity.getBaseIdentityName();
@@ -856,6 +877,7 @@ public final class YangParserImpl implements YangModelParser {
     private void resolveUsesRefine(final Map<String, TreeMap<Date, ModuleBuilder>> modules, final ModuleBuilder module) {
         final Map<List<String>, UsesNodeBuilder> moduleUses = module.getUsesNodes();
         for (Map.Entry<List<String>, UsesNodeBuilder> entry : moduleUses.entrySet()) {
+            // refine
             final UsesNodeBuilder usesNode = entry.getValue();
             final int line = usesNode.getLine();
             final GroupingBuilder targetGrouping = getTargetGroupingFromModules(usesNode, modules, module);
@@ -863,9 +885,15 @@ public final class YangParserImpl implements YangModelParser {
             for (RefineHolder refine : usesNode.getRefines()) {
                 final SchemaNodeBuilder nodeToRefine = RefineUtils.getRefineNodeFromGroupingBuilder(targetGrouping,
                         refine, module.getName());
+                if(nodeToRefine instanceof GroupingMember) {
+                    ((GroupingMember)nodeToRefine).setAddedByUses(true);
+                }
                 RefineUtils.performRefine(nodeToRefine, refine, line);
                 usesNode.addRefineNode(nodeToRefine);
             }
+
+            // child nodes
+            processUsesNode(usesNode, targetGrouping);
         }
     }
 
@@ -882,7 +910,7 @@ public final class YangParserImpl implements YangModelParser {
      *            SchemaContext containing already resolved modules
      */
     private void resolveUsesRefineWithContext(final Map<String, TreeMap<Date, ModuleBuilder>> modules,
-            final ModuleBuilder module, SchemaContext context) {
+            final ModuleBuilder module, final SchemaContext context) {
         final Map<List<String>, UsesNodeBuilder> moduleUses = module.getUsesNodes();
         for (Map.Entry<List<String>, UsesNodeBuilder> entry : moduleUses.entrySet()) {
             final UsesNodeBuilder usesNode = entry.getValue();
@@ -895,17 +923,27 @@ public final class YangParserImpl implements YangModelParser {
                 for (RefineHolder refine : usesNode.getRefines()) {
                     final SchemaNodeBuilder nodeToRefine = RefineUtils.getRefineNodeFromGroupingDefinition(
                             targetGrouping, refine, module.getName());
+                    if(nodeToRefine instanceof GroupingMember) {
+                        ((GroupingMember)nodeToRefine).setAddedByUses(true);
+                    }
                     RefineUtils.performRefine(nodeToRefine, refine, line);
                     usesNode.addRefineNode(nodeToRefine);
                 }
+
+                processUsesNode(usesNode, targetGrouping);
             } else {
                 usesNode.setGroupingPath(targetGroupingBuilder.getPath());
                 for (RefineHolder refine : usesNode.getRefines()) {
                     final SchemaNodeBuilder nodeToRefine = RefineUtils.getRefineNodeFromGroupingBuilder(
                             targetGroupingBuilder, refine, module.getName());
+                    if(nodeToRefine instanceof GroupingMember) {
+                        ((GroupingMember)nodeToRefine).setAddedByUses(true);
+                    }
                     RefineUtils.performRefine(nodeToRefine, refine, line);
                     usesNode.addRefineNode(nodeToRefine);
                 }
+
+                processUsesNode(usesNode, targetGroupingBuilder);
             }
         }
     }
@@ -951,7 +989,7 @@ public final class YangParserImpl implements YangModelParser {
             return null;
         }
 
-        List<QName> path = usesBuilder.getPath().getPath();
+        List<QName> path = usesBuilder.getParent().getPath().getPath();
         GroupingBuilder result = null;
         Set<GroupingBuilder> groupings = dependentModule.getModuleGroupings();
         result = findGroupingBuilder(groupings, groupingName);
@@ -969,7 +1007,7 @@ public final class YangParserImpl implements YangModelParser {
                 if (currentNode instanceof RpcDefinitionBuilder) {
                     groupings = ((RpcDefinitionBuilder) currentNode).getGroupings();
                 } else if (currentNode instanceof DataNodeContainerBuilder) {
-                    groupings = ((DataNodeContainerBuilder) currentNode).getGroupings();
+                    groupings = ((DataNodeContainerBuilder) currentNode).getGroupingBuilders();
                 } else {
                     groupings = Collections.emptySet();
                 }
@@ -996,7 +1034,7 @@ public final class YangParserImpl implements YangModelParser {
      * @return grouping with given name if found, null otherwise
      */
     private GroupingDefinition getTargetGroupingFromContext(final UsesNodeBuilder usesBuilder,
-            final ModuleBuilder module, SchemaContext context) {
+            final ModuleBuilder module, final SchemaContext context) {
         final int line = usesBuilder.getLine();
         String groupingString = usesBuilder.getGroupingName();
         String groupingPrefix;
@@ -1018,6 +1056,135 @@ public final class YangParserImpl implements YangModelParser {
         return findGroupingDefinition(dependentModule.getGroupings(), groupingName);
     }
 
+    /**
+     * Add nodes defined in target grouping to current context.
+     *
+     * @param usesNode
+     * @param targetGrouping
+     */
+    private void processUsesNode(final UsesNodeBuilder usesNode, final GroupingBuilder targetGrouping) {
+        List<SchemaNodeBuilder> refineNodes = usesNode.getRefineNodes();
+        DataNodeContainerBuilder parent = usesNode.getParent();
+        SchemaPath parentPath = parent.getPath();
+        for (DataSchemaNodeBuilder child : targetGrouping.getChildNodeBuilders()) {
+            // if node is refined, take it from refined nodes and continue
+            SchemaNodeBuilder refined = getRefined(child.getQName(), refineNodes);
+            if(refined != null) {
+                refined.setPath(createSchemaPath(parentPath, refined.getQName().getLocalName()));
+                parent.addChildNode((DataSchemaNodeBuilder)refined);
+                continue;
+            }
+
+            DataSchemaNodeBuilder newChild = null;
+            if (child instanceof AnyXmlBuilder) {
+                newChild = new AnyXmlBuilder((AnyXmlBuilder) child);
+            } else if (child instanceof ChoiceBuilder) {
+                newChild = new ChoiceBuilder((ChoiceBuilder) child);
+            } else if (child instanceof ContainerSchemaNodeBuilder) {
+                newChild = new ContainerSchemaNodeBuilder((ContainerSchemaNodeBuilder) child);
+            } else if (child instanceof LeafListSchemaNodeBuilder) {
+                newChild = new LeafListSchemaNodeBuilder((LeafListSchemaNodeBuilder) child);
+            } else if (child instanceof LeafSchemaNodeBuilder) {
+                newChild = new LeafSchemaNodeBuilder((LeafSchemaNodeBuilder) child);
+            } else if (child instanceof ListSchemaNodeBuilder) {
+                newChild = new ListSchemaNodeBuilder((ListSchemaNodeBuilder) child);
+            }
+
+            if (newChild instanceof GroupingMember) {
+                ((GroupingMember) newChild).setAddedByUses(true);
+            }
+            newChild.setPath(createSchemaPath(parentPath, newChild.getQName().getLocalName()));
+            parent.addChildNode(newChild);
+        }
+        for (GroupingBuilder g : targetGrouping.getGroupingBuilders()) {
+            GroupingBuilder newGrouping = new GroupingBuilderImpl(g);
+            newGrouping.setAddedByUses(true);
+            newGrouping.setPath(createSchemaPath(parentPath, newGrouping.getQName().getLocalName()));
+            parent.addGrouping(newGrouping);
+        }
+        for (TypeDefinitionBuilder td : targetGrouping.getTypeDefinitionBuilders()) {
+            TypeDefinitionBuilder newType = new TypeDefinitionBuilderImpl(td);
+            newType.setAddedByUses(true);
+            newType.setPath(createSchemaPath(parentPath, newType.getQName().getLocalName()));
+            parent.addTypedef(newType);
+        }
+        for (UsesNodeBuilder un : targetGrouping.getUses()) {
+            UsesNodeBuilder newUses = new UsesNodeBuilderImpl(un);
+            newUses.setAddedByUses(true);
+            // uses has not path
+            parent.addUsesNode(newUses);
+        }
+        for (UnknownSchemaNodeBuilder un : targetGrouping.getUnknownNodes()) {
+            UnknownSchemaNodeBuilder newUn = new UnknownSchemaNodeBuilder(un);
+            newUn.setAddedByUses(true);
+            newUn.setPath(createSchemaPath(parentPath, un.getQName().getLocalName()));
+            parent.addUnknownSchemaNode(newUn);
+        }
+    }
+
+    private void processUsesNode(final UsesNodeBuilder usesNode, final GroupingDefinition targetGrouping) {
+        final int line = usesNode.getLine();
+        List<SchemaNodeBuilder> refineNodes = usesNode.getRefineNodes();
+        DataNodeContainerBuilder parent = usesNode.getParent();
+        SchemaPath parentPath = parent.getPath();
+        for (DataSchemaNode child : targetGrouping.getChildNodes()) {
+            // if node is refined, take it from refined nodes and continue
+            SchemaNodeBuilder refined = getRefined(child.getQName(), refineNodes);
+            if(refined != null) {
+                refined.setPath(createSchemaPath(parentPath, refined.getQName().getLocalName()));
+                parent.addChildNode((DataSchemaNodeBuilder)refined);
+                continue;
+            }
+
+            DataSchemaNodeBuilder newChild = null;
+            if (child instanceof AnyXmlSchemaNode) {
+                newChild = createAnyXml((AnyXmlSchemaNode) child, line);
+            } else if (child instanceof ChoiceNode) {
+                newChild = createChoice((ChoiceNode) child, line);
+            } else if (child instanceof ContainerSchemaNode) {
+                newChild = createContainer((ContainerSchemaNode) child, line);
+            } else if (child instanceof LeafListSchemaNode) {
+                newChild = createLeafList((LeafListSchemaNode) child, line);
+            } else if (child instanceof LeafSchemaNode) {
+                newChild = createLeafBuilder((LeafSchemaNode) child, line);
+            } else if (child instanceof ListSchemaNode) {
+                newChild = createList((ListSchemaNode) child, line);
+            }
+
+            if (newChild instanceof GroupingMember) {
+                ((GroupingMember) newChild).setAddedByUses(true);
+            }
+            newChild.setPath(createSchemaPath(parentPath, newChild.getQName().getLocalName()));
+            parent.addChildNode(newChild);
+        }
+        for (GroupingDefinition g : targetGrouping.getGroupings()) {
+            GroupingBuilder newGrouping = createGrouping(g, line);
+            newGrouping.setAddedByUses(true);
+            newGrouping.setPath(createSchemaPath(parentPath, newGrouping.getQName().getLocalName()));
+            parent.addGrouping(newGrouping);
+        }
+        for (TypeDefinition<?> td : targetGrouping.getTypeDefinitions()) {
+            TypeDefinitionBuilder newType = createTypedef((ExtendedType) td, line);
+            newType.setAddedByUses(true);
+            newType.setPath(createSchemaPath(parentPath, newType.getQName().getLocalName()));
+            parent.addTypedef(newType);
+        }
+        for (UsesNode un : targetGrouping.getUses()) {
+            if (un instanceof UsesNodeImpl) {
+                UsesNodeBuilder newUses = new UsesNodeBuilderImpl(((UsesNodeImpl) un).toBuilder());
+                newUses.setAddedByUses(true);
+                // uses has not path
+                parent.addUsesNode(newUses);
+            }
+        }
+        for (UnknownSchemaNode un : targetGrouping.getUnknownSchemaNodes()) {
+            UnknownSchemaNodeBuilder newNode = createUnknownSchemaNode(un, line);
+            newNode.setAddedByUses(true);
+            newNode.setPath(createSchemaPath(parentPath, un.getQName().getLocalName()));
+            parent.addUnknownSchemaNode(newNode);
+        }
+    }
+
     private QName findFullQName(final Map<String, TreeMap<Date, ModuleBuilder>> modules, final ModuleBuilder module,
             final IdentityrefTypeBuilder idref) {
         QName result = null;
index 5bd46d1..28095b5 100644 (file)
@@ -19,7 +19,7 @@ import java.util.List;
 import java.util.Stack;
 
 import org.antlr.v4.runtime.tree.ParseTree;
-import org.opendaylight.controller.antlrv4.code.gen.YangParser;
+import org.opendaylight.controller.antlrv4.code.gen.*;
 import org.opendaylight.controller.antlrv4.code.gen.YangParser.Argument_stmtContext;
 import org.opendaylight.controller.antlrv4.code.gen.YangParser.Base_stmtContext;
 import org.opendaylight.controller.antlrv4.code.gen.YangParser.Contact_stmtContext;
@@ -50,7 +50,6 @@ import org.opendaylight.controller.antlrv4.code.gen.YangParser.Type_body_stmtsCo
 import org.opendaylight.controller.antlrv4.code.gen.YangParser.Units_stmtContext;
 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;
@@ -337,15 +336,15 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
                     SchemaPath path = createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix);
                     moduleBuilder.addIdentityrefType(getIdentityrefBase(typeBody), actualPath, path, line);
                 } else {
-                    type = parseTypeBody(moduleName, typeName, typeBody, actualPath, namespace, revision,
+                    type = parseTypeWithBody(moduleName, typeName, typeBody, actualPath, namespace, revision,
                             yangModelPrefix, moduleBuilder.getActualNode());
                     moduleBuilder.setType(type, actualPath);
                 }
             }
         } else {
-            type = parseUnknownTypeBody(typeQName, typeBody, actualPath, namespace, revision, yangModelPrefix,
-                    moduleBuilder.getActualNode(), moduleBuilder);
-            // mark parent node of this type statement as dirty
+            type = parseUnknownTypeWithBody(typeQName, typeBody, actualPath, namespace, revision, yangModelPrefix,
+                    moduleBuilder.getActualNode());
+            // add parent node of this type statement to dirty nodes
             moduleBuilder.addDirtyNode(actualPath);
             moduleBuilder.setType(type, actualPath);
         }
@@ -401,16 +400,19 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
 
     @Override
     public void enterContainer_stmt(Container_stmtContext ctx) {
+        final int line = ctx.getStart().getLine();
         final String containerName = stringFromNode(ctx);
         QName containerQName = new QName(namespace, revision, yangModelPrefix, containerName);
-        ContainerSchemaNodeBuilder builder = moduleBuilder.addContainerNode(containerQName, actualPath, ctx.getStart()
-                .getLine());
+
+        SchemaPath path = createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix, containerName);
+
+        ContainerSchemaNodeBuilder builder = moduleBuilder.addContainerNode(path, containerQName, actualPath, line);
         moduleBuilder.enterNode(builder);
         updatePath(containerName);
 
-        builder.setPath(createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix));
         parseSchemaNodeArgs(ctx, builder);
         parseConstraints(ctx, builder.getConstraints());
+        builder.setConfiguration(getConfig(ctx, moduleBuilder.getActualParent(), moduleName, line));
 
         for (int i = 0; i < ctx.getChildCount(); ++i) {
             final ParseTree childNode = ctx.getChild(i);
@@ -432,13 +434,15 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
     public void enterLeaf_stmt(Leaf_stmtContext ctx) {
         final String leafName = stringFromNode(ctx);
         QName leafQName = new QName(namespace, revision, yangModelPrefix, leafName);
-        LeafSchemaNodeBuilder builder = moduleBuilder.addLeafNode(leafQName, actualPath, ctx.getStart().getLine());
+        SchemaPath schemaPath = createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix, leafName);
+
+        LeafSchemaNodeBuilder builder = moduleBuilder.addLeafNode(schemaPath, leafQName, actualPath, ctx.getStart().getLine());
         moduleBuilder.enterNode(builder);
         updatePath(leafName);
 
-        builder.setPath(createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix));
         parseSchemaNodeArgs(ctx, builder);
         parseConstraints(ctx, builder.getConstraints());
+        builder.setConfiguration(getConfig(ctx, moduleBuilder.getActualParent(), moduleName, ctx.getStart().getLine()));
 
         String defaultStr = null;
         String unitsStr = null;
@@ -468,7 +472,6 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
 
         moduleBuilder.enterNode(builder);
         updatePath(groupingPathStr);
-        builder.setPath(createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix));
     }
 
     @Override
@@ -498,14 +501,16 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
     public void enterLeaf_list_stmt(Leaf_list_stmtContext ctx) {
         final String leafListName = stringFromNode(ctx);
         QName leafListQName = new QName(namespace, revision, yangModelPrefix, leafListName);
-        LeafListSchemaNodeBuilder builder = moduleBuilder.addLeafListNode(leafListQName, actualPath, ctx.getStart()
+        SchemaPath schemaPath = createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix, leafListName);
+
+        LeafListSchemaNodeBuilder builder = moduleBuilder.addLeafListNode(schemaPath, leafListQName, actualPath, ctx.getStart()
                 .getLine());
         moduleBuilder.enterNode(builder);
         updatePath(leafListName);
 
-        builder.setPath(createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix));
         parseSchemaNodeArgs(ctx, builder);
         parseConstraints(ctx, builder.getConstraints());
+        builder.setConfiguration(getConfig(ctx, moduleBuilder.getActualParent(), moduleName, ctx.getStart().getLine()));
 
         for (int i = 0; i < ctx.getChildCount(); ++i) {
             final ParseTree childNode = ctx.getChild(i);
@@ -527,15 +532,17 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
 
     @Override
     public void enterList_stmt(List_stmtContext ctx) {
-        final String containerName = stringFromNode(ctx);
-        QName containerQName = new QName(namespace, revision, yangModelPrefix, containerName);
-        ListSchemaNodeBuilder builder = moduleBuilder.addListNode(containerQName, actualPath, ctx.getStart().getLine());
+        final String listName = stringFromNode(ctx);
+        QName listQName = new QName(namespace, revision, yangModelPrefix, listName);
+        SchemaPath schemaPath = createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix, listName);
+
+        ListSchemaNodeBuilder builder = moduleBuilder.addListNode(schemaPath, listQName, actualPath, ctx.getStart().getLine());
         moduleBuilder.enterNode(builder);
-        updatePath(containerName);
+        updatePath(listName);
 
-        builder.setPath(createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix));
         parseSchemaNodeArgs(ctx, builder);
         parseConstraints(ctx, builder.getConstraints());
+        builder.setConfiguration(getConfig(ctx, moduleBuilder.getActualParent(), moduleName, ctx.getStart().getLine()));
 
         String keyDefinition = "";
         for (int i = 0; i < ctx.getChildCount(); ++i) {
@@ -563,13 +570,15 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
     public void enterAnyxml_stmt(YangParser.Anyxml_stmtContext ctx) {
         final String anyXmlName = stringFromNode(ctx);
         QName anyXmlQName = new QName(namespace, revision, yangModelPrefix, anyXmlName);
-        AnyXmlBuilder builder = moduleBuilder.addAnyXml(anyXmlQName, actualPath, ctx.getStart().getLine());
+        SchemaPath schemaPath = createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix, anyXmlName);
+
+        AnyXmlBuilder builder = moduleBuilder.addAnyXml(schemaPath, anyXmlQName, actualPath, ctx.getStart().getLine());
         moduleBuilder.enterNode(builder);
         updatePath(anyXmlName);
 
-        builder.setPath(createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix));
         parseSchemaNodeArgs(ctx, builder);
         parseConstraints(ctx, builder.getConstraints());
+        builder.setConfiguration(getConfig(ctx, moduleBuilder.getActualParent(), moduleName, ctx.getStart().getLine()));
     }
 
     @Override
@@ -590,6 +599,7 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
         builder.setPath(createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix));
         parseSchemaNodeArgs(ctx, builder);
         parseConstraints(ctx, builder.getConstraints());
+        builder.setConfiguration(getConfig(ctx, moduleBuilder.getActualParent(), moduleName, ctx.getStart().getLine()));
 
         // set 'default' case
         for (int i = 0; i < ctx.getChildCount(); i++) {
@@ -715,11 +725,12 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
     public void enterInput_stmt(YangParser.Input_stmtContext ctx) {
         final String input = "input";
         QName rpcQName = new QName(namespace, revision, yangModelPrefix, input);
-        ContainerSchemaNodeBuilder builder = moduleBuilder.addRpcInput(rpcQName, ctx.getStart().getLine());
+        SchemaPath path = createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix, input);
+
+        ContainerSchemaNodeBuilder builder = moduleBuilder.addRpcInput(path, rpcQName, ctx.getStart().getLine());
         moduleBuilder.enterNode(builder);
         updatePath(input);
 
-        builder.setPath(createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix));
         parseSchemaNodeArgs(ctx, builder);
         parseConstraints(ctx, builder.getConstraints());
     }
@@ -735,11 +746,12 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
     public void enterOutput_stmt(YangParser.Output_stmtContext ctx) {
         final String output = "output";
         QName rpcQName = new QName(namespace, revision, yangModelPrefix, output);
-        ContainerSchemaNodeBuilder builder = moduleBuilder.addRpcOutput(rpcQName, ctx.getStart().getLine());
+        SchemaPath path = createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix, output);
+
+        ContainerSchemaNodeBuilder builder = moduleBuilder.addRpcOutput(path, rpcQName, ctx.getStart().getLine());
         moduleBuilder.enterNode(builder);
         updatePath(output);
 
-        builder.setPath(createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix));
         parseSchemaNodeArgs(ctx, builder);
         parseConstraints(ctx, builder.getConstraints());
     }
@@ -804,12 +816,6 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
         moduleBuilder.exitNode();
     }
 
-    @Override
-    public void enterConfig_stmt(YangParser.Config_stmtContext ctx) {
-        boolean configuration = parseConfig(ctx);
-        moduleBuilder.addConfiguration(configuration, actualPath, ctx.getStart().getLine());
-    }
-
     @Override
     public void enterIdentity_stmt(YangParser.Identity_stmtContext ctx) {
         final String identityName = stringFromNode(ctx);
index ba3599c..5548667 100644 (file)
@@ -17,7 +17,6 @@ import java.util.TreeMap;
 
 import org.opendaylight.controller.yang.common.QName;
 import org.opendaylight.controller.yang.model.api.AnyXmlSchemaNode;
-import org.opendaylight.controller.yang.model.api.ChoiceCaseNode;
 import org.opendaylight.controller.yang.model.api.ChoiceNode;
 import org.opendaylight.controller.yang.model.api.ConstraintDefinition;
 import org.opendaylight.controller.yang.model.api.ContainerSchemaNode;
@@ -36,6 +35,7 @@ import org.opendaylight.controller.yang.model.api.SchemaContext;
 import org.opendaylight.controller.yang.model.api.SchemaNode;
 import org.opendaylight.controller.yang.model.api.SchemaPath;
 import org.opendaylight.controller.yang.model.api.TypeDefinition;
+import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
 import org.opendaylight.controller.yang.model.api.type.BinaryTypeDefinition;
 import org.opendaylight.controller.yang.model.api.type.BitsTypeDefinition;
 import org.opendaylight.controller.yang.model.api.type.BooleanTypeDefinition;
@@ -80,6 +80,7 @@ import org.opendaylight.controller.yang.parser.builder.api.Builder;
 import org.opendaylight.controller.yang.parser.builder.api.DataNodeContainerBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.DataSchemaNodeBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.GroupingBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.GroupingMember;
 import org.opendaylight.controller.yang.parser.builder.api.SchemaNodeBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.TypeAwareBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionBuilder;
@@ -104,13 +105,31 @@ import org.opendaylight.controller.yang.parser.builder.impl.RpcDefinitionBuilder
 import org.opendaylight.controller.yang.parser.builder.impl.TypeDefinitionBuilderImpl;
 import org.opendaylight.controller.yang.parser.builder.impl.UnionTypeBuilder;
 import org.opendaylight.controller.yang.parser.builder.impl.UnknownSchemaNodeBuilder;
-import org.opendaylight.controller.yang.parser.builder.impl.UsesNodeBuilderImpl;
 
 public final class ParserUtils {
 
     private ParserUtils() {
     }
 
+    /**
+     * Create new SchemaPath from given path and name.
+     *
+     * Append new qname to schema path created from name argument. New QName
+     * gets namespace, revision and prefix same as last qname in current schema
+     * path.
+     *
+     * @param schemaPath
+     * @param name
+     * @return
+     */
+    public static SchemaPath createSchemaPath(SchemaPath schemaPath, String name) {
+        List<QName> path = new ArrayList<QName>(schemaPath.getPath());
+        QName last = path.get(path.size() - 1);
+        QName newQName = new QName(last.getNamespace(), last.getRevision(), last.getPrefix(), name);
+        path.add(newQName);
+        return new SchemaPath(path, schemaPath.isAbsolute());
+    }
+
     /**
      * Get module import referenced by given prefix.
      *
@@ -318,6 +337,24 @@ public final class ParserUtils {
         return new SchemaPath(path, absolute);
     }
 
+    /**
+     * Check if node is present in refine nodes.
+     *
+     * @param nodeQName
+     *            qname of node
+     * @param refineNodes
+     *            collections of refined nodes
+     * @return true, if node with given qname was found, false otherwise
+     */
+    public static SchemaNodeBuilder getRefined(QName nodeQName, List<SchemaNodeBuilder> refineNodes) {
+        for (SchemaNodeBuilder rn : refineNodes) {
+            if (rn.getQName().equals(nodeQName)) {
+                return rn;
+            }
+        }
+        return null;
+    }
+
     /**
      * Pull restriction from type and add them to constraints.
      *
@@ -353,7 +390,7 @@ public final class ParserUtils {
         Builder result = grouping.getChildNode(refineNodeName);
         // search groupings
         if (result == null) {
-            Set<GroupingBuilder> grps = grouping.getGroupings();
+            Set<GroupingBuilder> grps = grouping.getGroupingBuilders();
             for (GroupingBuilder gr : grps) {
                 if (gr.getQName().getLocalName().equals(refineNodeName)) {
                     result = gr;
@@ -363,7 +400,7 @@ public final class ParserUtils {
         }
         // search typedefs
         if (result == null) {
-            Set<TypeDefinitionBuilder> typedefs = grouping.getTypeDefinitions();
+            Set<TypeDefinitionBuilder> typedefs = grouping.getTypeDefinitionBuilders();
             for (TypeDefinitionBuilder typedef : typedefs) {
                 if (typedef.getQName().getLocalName().equals(refineNodeName)) {
                     result = typedef;
@@ -415,8 +452,14 @@ public final class ParserUtils {
      *            augmentation target node
      */
     public static void fillAugmentTarget(final AugmentationSchemaBuilder augment, final DataNodeContainerBuilder target) {
-        for (DataSchemaNodeBuilder builder : augment.getChildNodes()) {
+        boolean usesAugment = augment.getParent() instanceof UsesNodeBuilder;
+        for (DataSchemaNodeBuilder builder : augment.getChildNodeBuilders()) {
             builder.setAugmenting(true);
+            if (usesAugment) {
+                if (builder instanceof GroupingMember) {
+                    ((GroupingMember) builder).setAddedByUses(true);
+                }
+            }
             correctAugmentChildPath(builder, target.getPath());
             target.addChildNode(builder);
         }
@@ -431,8 +474,14 @@ public final class ParserUtils {
      *            augmentation target choice node
      */
     public static void fillAugmentTarget(final AugmentationSchemaBuilder augment, final ChoiceBuilder target) {
-        for (DataSchemaNodeBuilder builder : augment.getChildNodes()) {
+        boolean usesAugment = augment.getParent() instanceof UsesNodeBuilder;
+        for (DataSchemaNodeBuilder builder : augment.getChildNodeBuilders()) {
             builder.setAugmenting(true);
+            if (usesAugment) {
+                if (builder instanceof GroupingMember) {
+                    ((GroupingMember) builder).setAddedByUses(true);
+                }
+            }
             correctAugmentChildPath(builder, target.getPath());
             target.addChildNode(builder);
         }
@@ -447,7 +496,7 @@ public final class ParserUtils {
         // set correct path for all child nodes
         if (childNode instanceof DataNodeContainerBuilder) {
             DataNodeContainerBuilder dataNodeContainer = (DataNodeContainerBuilder) childNode;
-            for (DataSchemaNodeBuilder child : dataNodeContainer.getChildNodes()) {
+            for (DataSchemaNodeBuilder child : dataNodeContainer.getChildNodeBuilders()) {
                 correctAugmentChildPath(child, childNode.getPath());
             }
         }
@@ -684,211 +733,6 @@ public final class ParserUtils {
         return new SchemaPath(newPath, schemaPath.isAbsolute());
     }
 
-    public static LeafSchemaNodeBuilder copyLeafBuilder(final LeafSchemaNodeBuilder old) {
-        final LeafSchemaNodeBuilder copy = new LeafSchemaNodeBuilder(old.getQName(), old.getLine());
-        final TypeDefinition<?> type = old.getType();
-        if (type == null) {
-            copy.setTypedef(old.getTypedef());
-        } else {
-            copy.setType(type);
-        }
-        copyDataSchemaNodeArgs(old, copy);
-        copyConstraintsFromBuilder(old, copy);
-        for (UnknownSchemaNodeBuilder unknown : old.getUnknownNodes()) {
-            copy.addUnknownSchemaNode(unknown);
-        }
-        copy.setDefaultStr(old.getDefaultStr());
-        copy.setUnits(old.getUnits());
-        return copy;
-    }
-
-    public static ContainerSchemaNodeBuilder copyContainerBuilder(final ContainerSchemaNodeBuilder old) {
-        final ContainerSchemaNodeBuilder copy = new ContainerSchemaNodeBuilder(old.getQName(), old.getLine());
-        copyDataSchemaNodeArgs(old, copy);
-        copyConstraintsFromBuilder(old, copy);
-        for (UnknownSchemaNodeBuilder unknown : old.getUnknownNodes()) {
-            copy.addUnknownSchemaNode(unknown);
-        }
-        for (DataSchemaNodeBuilder child : old.getChildNodes()) {
-            copy.addChildNode(child);
-        }
-        for (GroupingBuilder grouping : old.getGroupings()) {
-            copy.addGrouping(grouping);
-        }
-        for (TypeDefinitionBuilder typedef : old.getTypeDefinitions()) {
-            copy.addTypedef(typedef);
-        }
-        for (AugmentationSchemaBuilder augment : old.getAugmentations()) {
-            copy.addAugmentation(augment);
-        }
-        for (UsesNodeBuilder use : old.getUsesNodes()) {
-            copy.addUsesNode(use);
-        }
-        copy.setPresence(old.isPresence());
-        return copy;
-    }
-
-    public static ListSchemaNodeBuilder copyListBuilder(final ListSchemaNodeBuilder old) {
-        final ListSchemaNodeBuilder copy = new ListSchemaNodeBuilder(old.getQName(), old.getLine());
-        copyDataSchemaNodeArgs(old, copy);
-        copyConstraintsFromBuilder(old, copy);
-        for (UnknownSchemaNodeBuilder unknown : old.getUnknownNodes()) {
-            copy.addUnknownSchemaNode(unknown);
-        }
-        for (DataSchemaNodeBuilder child : old.getChildNodes()) {
-            copy.addChildNode(child);
-        }
-        for (GroupingBuilder grouping : old.getGroupings()) {
-            copy.addGrouping(grouping);
-        }
-        for (TypeDefinitionBuilder typedef : old.getTypeDefinitions()) {
-            copy.addTypedef(typedef);
-        }
-        for (AugmentationSchemaBuilder augment : old.getAugmentations()) {
-            copy.addAugmentation(augment);
-        }
-        for (UsesNodeBuilder use : old.getUsesNodes()) {
-            copy.addUsesNode(use);
-        }
-        copy.setUserOrdered(old.isUserOrdered());
-        return copy;
-    }
-
-    public static LeafListSchemaNodeBuilder copyLeafListBuilder(final LeafListSchemaNodeBuilder old) {
-        final LeafListSchemaNodeBuilder copy = new LeafListSchemaNodeBuilder(old.getQName(), old.getLine());
-        copyDataSchemaNodeArgs(old, copy);
-        copyConstraintsFromBuilder(old, copy);
-        final TypeDefinition<?> type = old.getType();
-        if (type == null) {
-            copy.setTypedef(old.getTypedef());
-        } else {
-            copy.setType(type);
-        }
-        for (UnknownSchemaNodeBuilder unknown : old.getUnknownNodes()) {
-            copy.addUnknownSchemaNode(unknown);
-        }
-        copy.setUserOrdered(old.isUserOrdered());
-        return copy;
-    }
-
-    public static ChoiceBuilder copyChoiceBuilder(final ChoiceBuilder old) {
-        final ChoiceBuilder copy = new ChoiceBuilder(old.getQName(), old.getLine());
-        copyDataSchemaNodeArgs(old, copy);
-        copyConstraintsFromBuilder(old, copy);
-        for (ChoiceCaseBuilder caseBuilder : old.getCases()) {
-            copy.addChildNode(caseBuilder);
-        }
-        for (UnknownSchemaNodeBuilder unknown : old.getUnknownNodes()) {
-            copy.addUnknownSchemaNode(unknown);
-        }
-        copy.setDefaultCase(old.getDefaultCase());
-        return copy;
-    }
-
-    public static AnyXmlBuilder copyAnyXmlBuilder(final AnyXmlBuilder old) {
-        final AnyXmlBuilder copy = new AnyXmlBuilder(old.getQName(), old.getLine());
-        copyDataSchemaNodeArgs(old, copy);
-        copyConstraintsFromBuilder(old, copy);
-        for (UnknownSchemaNodeBuilder unknown : old.getUnknownNodes()) {
-            copy.addUnknownSchemaNode(unknown);
-        }
-        return copy;
-    }
-
-    public static GroupingBuilder copyGroupingBuilder(final GroupingBuilder old) {
-        final GroupingBuilder copy = new GroupingBuilderImpl(old.getQName(), old.getLine());
-        copy.setPath(old.getPath());
-        for (DataSchemaNodeBuilder child : old.getChildNodes()) {
-            copy.addChildNode(child);
-        }
-        for (GroupingBuilder grouping : old.getGroupings()) {
-            copy.addGrouping(grouping);
-        }
-        for (TypeDefinitionBuilder typedef : old.getTypeDefinitions()) {
-            copy.addTypedef(typedef);
-        }
-        for (UsesNodeBuilder use : old.getUses()) {
-            copy.addUsesNode(use);
-        }
-        for (UnknownSchemaNodeBuilder unknown : old.getUnknownNodes()) {
-            copy.addUnknownSchemaNode(unknown);
-        }
-        copy.setDescription(old.getDescription());
-        copy.setReference(old.getReference());
-        copy.setStatus(old.getStatus());
-        return copy;
-    }
-
-    public static TypeDefinitionBuilderImpl copyTypedefBuilder(final TypeDefinitionBuilderImpl old) {
-        final TypeDefinitionBuilderImpl copy = new TypeDefinitionBuilderImpl(old.getQName(), old.getLine());
-        copy.setPath(old.getPath());
-        copy.setDefaultValue(old.getDefaultValue());
-        copy.setUnits(old.getUnits());
-        copy.setDescription(old.getDescription());
-        copy.setReference(old.getReference());
-        copy.setStatus(old.getStatus());
-
-        copy.setRanges(old.getRanges());
-        copy.setLengths(old.getLengths());
-        copy.setPatterns(old.getPatterns());
-        copy.setFractionDigits(old.getFractionDigits());
-
-        TypeDefinition<?> type = old.getType();
-        if (type == null) {
-            copy.setTypedef(old.getTypedef());
-        } else {
-            copy.setType(old.getType());
-        }
-        copy.setUnits(old.getUnits());
-        for (UnknownSchemaNodeBuilder unknown : old.getUnknownNodes()) {
-            copy.addUnknownSchemaNode(unknown);
-        }
-        return copy;
-    }
-
-    public static UsesNodeBuilder copyUsesNodeBuilder(final UsesNodeBuilder old) {
-        final UsesNodeBuilder copy = new UsesNodeBuilderImpl(old.getGroupingName(), old.getLine());
-        for (AugmentationSchemaBuilder augment : old.getAugmentations()) {
-            copy.addAugment(augment);
-        }
-        copy.setAugmenting(old.isAugmenting());
-        for (SchemaNodeBuilder refineNode : old.getRefineNodes()) {
-            copy.addRefineNode(refineNode);
-        }
-        return copy;
-    }
-
-    private static void copyDataSchemaNodeArgs(final DataSchemaNodeBuilder oldBuilder,
-            final DataSchemaNodeBuilder newBuilder) {
-        newBuilder.setPath(oldBuilder.getPath());
-        newBuilder.setDescription(oldBuilder.getDescription());
-        newBuilder.setReference(oldBuilder.getReference());
-        newBuilder.setStatus(oldBuilder.getStatus());
-        newBuilder.setAugmenting(oldBuilder.isAugmenting());
-        if (!(oldBuilder instanceof ChoiceCaseNode)) {
-            newBuilder.setConfiguration(oldBuilder.isConfiguration());
-        }
-    }
-
-    /**
-     * Copy constraints from old builder to new builder.
-     *
-     * @param oldBuilder
-     * @param newBuilder
-     */
-    private static void copyConstraintsFromBuilder(final DataSchemaNodeBuilder oldBuilder,
-            final DataSchemaNodeBuilder newBuilder) {
-        final ConstraintsBuilder oldConstraints = oldBuilder.getConstraints();
-        final ConstraintsBuilder newConstraints = newBuilder.getConstraints();
-        newConstraints.addWhenCondition(oldConstraints.getWhenCondition());
-        for (MustDefinition must : oldConstraints.getMustDefinitions()) {
-            newConstraints.addMustDefinition(must);
-        }
-        newConstraints.setMandatory(oldConstraints.isMandatory());
-        newConstraints.setMinElements(oldConstraints.getMinElements());
-        newConstraints.setMaxElements(oldConstraints.getMaxElements());
-    }
-
     /**
      * Create LeafSchemaNodeBuilder from given LeafSchemaNode.
      *
@@ -899,8 +743,9 @@ public final class ParserUtils {
      * @return builder object from leaf
      */
     public static LeafSchemaNodeBuilder createLeafBuilder(LeafSchemaNode leaf, int line) {
-        final LeafSchemaNodeBuilder builder = new LeafSchemaNodeBuilder(leaf.getQName(), line);
+        final LeafSchemaNodeBuilder builder = new LeafSchemaNodeBuilder(leaf.getQName(), leaf.getPath(), line);
         convertDataSchemaNode(leaf, builder);
+        builder.setConfiguration(leaf.isConfiguration());
         final TypeDefinition<?> type = leaf.getType();
         builder.setType(type);
         builder.setPath(leaf.getPath());
@@ -911,8 +756,10 @@ public final class ParserUtils {
     }
 
     public static ContainerSchemaNodeBuilder createContainer(ContainerSchemaNode container, int line) {
-        final ContainerSchemaNodeBuilder builder = new ContainerSchemaNodeBuilder(container.getQName(), line);
+        final ContainerSchemaNodeBuilder builder = new ContainerSchemaNodeBuilder(container.getQName(),
+                container.getPath(), line);
         convertDataSchemaNode(container, builder);
+        builder.setConfiguration(container.isConfiguration());
         builder.setUnknownNodes(container.getUnknownSchemaNodes());
         builder.setChildNodes(container.getChildNodes());
         builder.setGroupings(container.getGroupings());
@@ -924,8 +771,9 @@ public final class ParserUtils {
     }
 
     public static ListSchemaNodeBuilder createList(ListSchemaNode list, int line) {
-        ListSchemaNodeBuilder builder = new ListSchemaNodeBuilder(list.getQName(), line);
+        ListSchemaNodeBuilder builder = new ListSchemaNodeBuilder(list.getQName(), list.getPath(), line);
         convertDataSchemaNode(list, builder);
+        builder.setConfiguration(list.isConfiguration());
         builder.setUnknownNodes(list.getUnknownSchemaNodes());
         builder.setTypedefs(list.getTypeDefinitions());
         builder.setChildNodes(list.getChildNodes());
@@ -937,8 +785,10 @@ public final class ParserUtils {
     }
 
     public static LeafListSchemaNodeBuilder createLeafList(LeafListSchemaNode leafList, int line) {
-        final LeafListSchemaNodeBuilder builder = new LeafListSchemaNodeBuilder(leafList.getQName(), line);
+        final LeafListSchemaNodeBuilder builder = new LeafListSchemaNodeBuilder(leafList.getQName(),
+                leafList.getPath(), line);
         convertDataSchemaNode(leafList, builder);
+        builder.setConfiguration(leafList.isConfiguration());
         builder.setType(leafList.getType());
         builder.setUnknownNodes(leafList.getUnknownSchemaNodes());
         builder.setUserOrdered(leafList.isUserOrdered());
@@ -948,6 +798,7 @@ public final class ParserUtils {
     public static ChoiceBuilder createChoice(ChoiceNode choice, int line) {
         final ChoiceBuilder builder = new ChoiceBuilder(choice.getQName(), line);
         convertDataSchemaNode(choice, builder);
+        builder.setConfiguration(choice.isConfiguration());
         builder.setCases(choice.getCases());
         builder.setUnknownNodes(choice.getUnknownSchemaNodes());
         builder.setDefaultCase(choice.getDefaultCase());
@@ -955,8 +806,9 @@ public final class ParserUtils {
     }
 
     public static AnyXmlBuilder createAnyXml(AnyXmlSchemaNode anyxml, int line) {
-        final AnyXmlBuilder builder = new AnyXmlBuilder(anyxml.getQName(), line);
+        final AnyXmlBuilder builder = new AnyXmlBuilder(anyxml.getQName(), anyxml.getPath(), line);
         convertDataSchemaNode(anyxml, builder);
+        builder.setConfiguration(anyxml.isConfiguration());
         builder.setUnknownNodes(anyxml.getUnknownSchemaNodes());
         return builder;
     }
@@ -994,6 +846,19 @@ public final class ParserUtils {
         return builder;
     }
 
+    public static UnknownSchemaNodeBuilder createUnknownSchemaNode(UnknownSchemaNode grouping, int line) {
+        final UnknownSchemaNodeBuilder builder = new UnknownSchemaNodeBuilder(grouping.getQName(), line);
+        builder.setPath(grouping.getPath());
+        builder.setUnknownNodes(grouping.getUnknownSchemaNodes());
+        builder.setDescription(grouping.getDescription());
+        builder.setReference(grouping.getReference());
+        builder.setStatus(grouping.getStatus());
+        builder.setAddedByUses(grouping.isAddedByUses());
+        builder.setNodeType(grouping.getNodeType());
+        builder.setNodeParameter(grouping.getNodeParameter());
+        return builder;
+    }
+
     /**
      * Set DataSchemaNode arguments to builder object
      *
@@ -1008,9 +873,6 @@ public final class ParserUtils {
         builder.setReference(node.getReference());
         builder.setStatus(node.getStatus());
         builder.setAugmenting(node.isAugmenting());
-        if (!(node instanceof ChoiceCaseNode)) {
-            builder.setConfiguration(node.isConfiguration());
-        }
         copyConstraintsFromDefinition(node.getConstraints(), builder.getConstraints());
     }
 
@@ -1132,7 +994,7 @@ public final class ParserUtils {
     public static void processAugmentation(final AugmentationSchemaBuilder augmentBuilder, final List<QName> path,
             final ModuleBuilder module, final QName qname, final ModuleBuilder dependentModuleBuilder) {
         DataSchemaNodeBuilder currentParent = null;
-        for (DataSchemaNodeBuilder child : dependentModuleBuilder.getChildNodes()) {
+        for (DataSchemaNodeBuilder child : dependentModuleBuilder.getChildNodeBuilders()) {
             final QName childQName = child.getQName();
             if (childQName.getLocalName().equals(qname.getLocalName())) {
                 currentParent = child;
@@ -1147,7 +1009,7 @@ public final class ParserUtils {
         for (int i = 1; i < path.size(); i++) {
             final QName currentQName = path.get(i);
             DataSchemaNodeBuilder newParent = null;
-            for (DataSchemaNodeBuilder child : ((DataNodeContainerBuilder) currentParent).getChildNodes()) {
+            for (DataSchemaNodeBuilder child : ((DataNodeContainerBuilder) currentParent).getChildNodeBuilders()) {
                 final QName childQName = child.getQName();
                 if (childQName.getLocalName().equals(currentQName.getLocalName())) {
                     newParent = child;
@@ -1395,7 +1257,7 @@ public final class ParserUtils {
                 if (currentNode instanceof RpcDefinitionBuilder) {
                     typedefs = ((RpcDefinitionBuilder) currentNode).getTypeDefinitions();
                 } else if (currentNode instanceof DataNodeContainerBuilder) {
-                    typedefs = ((DataNodeContainerBuilder) currentNode).getTypeDefinitions();
+                    typedefs = ((DataNodeContainerBuilder) currentNode).getTypeDefinitionBuilders();
                 } else {
                     typedefs = Collections.emptySet();
                 }
index 4dd4676..7d22891 100644 (file)
@@ -12,9 +12,10 @@ import java.util.List;
 
 import org.opendaylight.controller.yang.model.api.MustDefinition;
 import org.opendaylight.controller.yang.parser.builder.api.Builder;
+import org.opendaylight.controller.yang.parser.builder.api.ConfigNode;
 import org.opendaylight.controller.yang.parser.builder.impl.UnknownSchemaNodeBuilder;
 
-public final class RefineHolder implements Builder {
+public final class RefineHolder implements Builder, ConfigNode {
     private final String name;
     private final int line;
     private String defaultStr;
@@ -62,11 +63,13 @@ public final class RefineHolder implements Builder {
         this.reference = reference;
     }
 
-    public Boolean isConfig() {
+    @Override
+    public Boolean isConfiguration() {
         return config;
     }
 
-    public void setConfig(final Boolean config) {
+    @Override
+    public void setConfiguration(final Boolean config) {
         this.config = config;
     }
 
index 8db4e8e..73acebf 100644 (file)
@@ -30,6 +30,7 @@ import org.opendaylight.controller.yang.parser.builder.api.UsesNodeBuilder;
 import org.opendaylight.controller.yang.parser.builder.impl.AnyXmlBuilder;
 import org.opendaylight.controller.yang.parser.builder.impl.ChoiceBuilder;
 import org.opendaylight.controller.yang.parser.builder.impl.ContainerSchemaNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.impl.GroupingBuilderImpl;
 import org.opendaylight.controller.yang.parser.builder.impl.LeafListSchemaNodeBuilder;
 import org.opendaylight.controller.yang.parser.builder.impl.LeafSchemaNodeBuilder;
 import org.opendaylight.controller.yang.parser.builder.impl.ListSchemaNodeBuilder;
@@ -66,21 +67,21 @@ public class RefineUtils {
         Builder result = null;
         final Builder lookedUpBuilder = findRefineTargetBuilder(targetGrouping, refine.getName());
         if (lookedUpBuilder instanceof LeafSchemaNodeBuilder) {
-            result = copyLeafBuilder((LeafSchemaNodeBuilder) lookedUpBuilder);
+            result = new LeafSchemaNodeBuilder((LeafSchemaNodeBuilder) lookedUpBuilder);
         } else if (lookedUpBuilder instanceof ContainerSchemaNodeBuilder) {
-            result = copyContainerBuilder((ContainerSchemaNodeBuilder) lookedUpBuilder);
+            result = new ContainerSchemaNodeBuilder((ContainerSchemaNodeBuilder) lookedUpBuilder);
         } else if (lookedUpBuilder instanceof ListSchemaNodeBuilder) {
-            result = copyListBuilder((ListSchemaNodeBuilder) lookedUpBuilder);
+            result = new ListSchemaNodeBuilder((ListSchemaNodeBuilder) lookedUpBuilder);
         } else if (lookedUpBuilder instanceof LeafListSchemaNodeBuilder) {
-            result = copyLeafListBuilder((LeafListSchemaNodeBuilder) lookedUpBuilder);
+            result = new LeafListSchemaNodeBuilder((LeafListSchemaNodeBuilder) lookedUpBuilder);
         } else if (lookedUpBuilder instanceof ChoiceBuilder) {
-            result = copyChoiceBuilder((ChoiceBuilder) lookedUpBuilder);
+            result = new ChoiceBuilder((ChoiceBuilder) lookedUpBuilder);
         } else if (lookedUpBuilder instanceof AnyXmlBuilder) {
-            result = copyAnyXmlBuilder((AnyXmlBuilder) lookedUpBuilder);
+            result = new AnyXmlBuilder((AnyXmlBuilder) lookedUpBuilder);
         } else if (lookedUpBuilder instanceof GroupingBuilder) {
-            result = copyGroupingBuilder((GroupingBuilder) lookedUpBuilder);
+            result = new GroupingBuilderImpl((GroupingBuilder) lookedUpBuilder);
         } else if (lookedUpBuilder instanceof TypeDefinitionBuilder) {
-            result = copyTypedefBuilder((TypeDefinitionBuilderImpl) lookedUpBuilder);
+            result = new TypeDefinitionBuilderImpl((TypeDefinitionBuilder) lookedUpBuilder);
         } else {
             throw new YangParseException(moduleName, refine.getLine(), "Target '" + refine.getName()
                     + "' can not be refined");
@@ -368,10 +369,10 @@ public class RefineUtils {
             }
         }
 
-        Boolean config = refine.isConfig();
+        Boolean config = refine.isConfiguration();
         if (config != null) {
             try {
-                Method method = cls.getDeclaredMethod("setConfiguration", Boolean.TYPE);
+                Method method = cls.getDeclaredMethod("setConfiguration", Boolean.class);
                 method.invoke(node, config);
             } catch (Exception e) {
                 throw new YangParseException(line, "Cannot refine config in " + cls.getName(), e);
index 5423e48..856f8e2 100644 (file)
@@ -15,7 +15,7 @@ import java.util.List;
 import java.util.Stack;
 
 import org.antlr.v4.runtime.tree.ParseTree;
-import org.opendaylight.controller.antlrv4.code.gen.YangParser;
+import org.opendaylight.controller.antlrv4.code.gen.*;
 import org.opendaylight.controller.antlrv4.code.gen.YangParser.Argument_stmtContext;
 import org.opendaylight.controller.antlrv4.code.gen.YangParser.Base_stmtContext;
 import org.opendaylight.controller.antlrv4.code.gen.YangParser.Bit_stmtContext;
@@ -108,16 +108,17 @@ import org.opendaylight.controller.yang.model.util.Uint64;
 import org.opendaylight.controller.yang.model.util.Uint8;
 import org.opendaylight.controller.yang.model.util.UnknownType;
 import org.opendaylight.controller.yang.parser.builder.api.Builder;
+import org.opendaylight.controller.yang.parser.builder.api.ConfigNode;
 import org.opendaylight.controller.yang.parser.builder.api.SchemaNodeBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionBuilder;
+import org.opendaylight.controller.yang.parser.builder.impl.ChoiceBuilder;
+import org.opendaylight.controller.yang.parser.builder.impl.ChoiceCaseBuilder;
 import org.opendaylight.controller.yang.parser.builder.impl.ConstraintsBuilder;
-import org.opendaylight.controller.yang.parser.builder.impl.ModuleBuilder;
 import org.opendaylight.controller.yang.parser.builder.impl.UnionTypeBuilder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public final class YangModelBuilderUtil {
-
     private static final Logger logger = LoggerFactory.getLogger(YangModelBuilderUtil.class);
 
     private YangModelBuilderUtil() {
@@ -216,18 +217,18 @@ public final class YangModelBuilderUtil {
     }
 
     /**
-     * Create SchemaPath object from given path list with namespace, revision
-     * and prefix based on given values.
+     * Create SchemaPath from actualPath and names.
      *
      * @param actualPath
      *            current position in model
      * @param namespace
      * @param revision
      * @param prefix
+     * @param names
      * @return SchemaPath object.
      */
     public static SchemaPath createActualSchemaPath(final List<String> actualPath, final URI namespace,
-            final Date revision, final String prefix) {
+            final Date revision, final String prefix, final String... names) {
         final List<QName> path = new ArrayList<QName>();
         QName qname;
         // start from index 1 - module name omited
@@ -235,6 +236,10 @@ public final class YangModelBuilderUtil {
             qname = new QName(namespace, revision, prefix, actualPath.get(i));
             path.add(qname);
         }
+        for (String name : names) {
+            qname = new QName(namespace, revision, prefix, name);
+            path.add(qname);
+        }
         return new SchemaPath(path, true);
     }
 
@@ -867,11 +872,15 @@ public final class YangModelBuilderUtil {
     }
 
     /**
-     * Parse orderedby statement.
+     * Parse 'ordered-by' statement.
+     *
+     * The 'ordered-by' statement defines whether the order of entries within a
+     * list are determined by the user or the system. The argument is one of the
+     * strings "system" or "user". If not present, order defaults to "system".
      *
      * @param childNode
      *            Ordered_by_stmtContext
-     * @return true, if orderedby contains value 'user' or false otherwise
+     * @return true, if ordered-by contains value 'user', false otherwise
      */
     public static boolean parseUserOrdered(Ordered_by_stmtContext childNode) {
         boolean result = false;
@@ -891,16 +900,66 @@ public final class YangModelBuilderUtil {
         return result;
     }
 
+    public static Boolean getConfig(final ParseTree ctx, final Builder parent, final String moduleName, final int line) {
+        Boolean result = null;
+        // parse configuration statement
+        Boolean configuration = null;
+        for (int i = 0; i < ctx.getChildCount(); i++) {
+            ParseTree child = ctx.getChild(i);
+            if (child instanceof Config_stmtContext) {
+                configuration = parseConfig((Config_stmtContext) child);
+                break;
+            }
+        }
+
+        // If 'config' is not specified, the default is the same as the parent
+        // schema node's 'config' value
+        if (configuration == null) {
+            if (parent instanceof ConfigNode) {
+                Boolean parentConfig = ((ConfigNode) parent).isConfiguration();
+                // If the parent node is a rpc input or output, it can has
+                // config set to null
+                result = parentConfig == null ? true : parentConfig;
+            } else if (parent instanceof ChoiceCaseBuilder) {
+                // If the parent node is a 'case' node, the value is the same as
+                // the 'case' node's parent 'choice' node
+                ChoiceCaseBuilder choiceCase = (ChoiceCaseBuilder) parent;
+                ChoiceBuilder choice = choiceCase.getParent();
+                Boolean parentConfig = null;
+                if (choice == null) {
+                    parentConfig = true;
+                } else {
+                    parentConfig = choice.isConfiguration();
+                }
+                result = parentConfig;
+            } else {
+                result = true;
+            }
+        } else {
+            // Check first: if a node has 'config' set to 'false', no node
+            // underneath it can have 'config' set to 'true'
+            if (parent instanceof ConfigNode) {
+                Boolean parentConfig = ((ConfigNode) parent).isConfiguration();
+                if (parentConfig == false && configuration == true) {
+                    throw new YangParseException(moduleName, line,
+                            "Can not set 'config' to 'true' if parent node has 'config' set to 'false'");
+                }
+            }
+            result = configuration;
+        }
+
+        return result;
+    }
+
     /**
-     * Parse given config context and return true if it contains string 'true',
-     * false otherwise.
+     * Parse config statement.
      *
      * @param ctx
      *            config context to parse.
      * @return true if given context contains string 'true', false otherwise
      */
-    public static boolean parseConfig(final Config_stmtContext ctx) {
-        boolean result = false;
+    private static Boolean parseConfig(final Config_stmtContext ctx) {
+        Boolean result = null;
         if (ctx != null) {
             for (int i = 0; i < ctx.getChildCount(); ++i) {
                 final ParseTree configContext = ctx.getChild(i);
@@ -909,6 +968,12 @@ public final class YangModelBuilderUtil {
                     if ("true".equals(value)) {
                         result = true;
                         break;
+                    } else if ("false".equals(value)) {
+                        result = false;
+                        break;
+                    } else {
+                        throw new YangParseException(ctx.getStart().getLine(),
+                                "Failed to parse 'config' statement value: '" + value + "'.");
                     }
                 }
             }
@@ -917,17 +982,22 @@ public final class YangModelBuilderUtil {
     }
 
     /**
-     * Parse given type body and creates UnknownType definition.
+     * Parse type body and create UnknownType definition.
      *
      * @param typedefQName
      *            qname of current type
      * @param ctx
      *            type body
+     * @param actualPath
+     * @param namespace
+     * @param revision
+     * @param prefix
+     * @param parent
      * @return UnknownType object with constraints from parsed type body
      */
-    public static TypeDefinition<?> parseUnknownTypeBody(QName typedefQName, Type_body_stmtsContext ctx,
-            final List<String> actualPath, final URI namespace, final Date revision, final String prefix,
-            Builder parent, ModuleBuilder moduleBuilder) {
+    public static TypeDefinition<?> parseUnknownTypeWithBody(final QName typedefQName,
+            final Type_body_stmtsContext ctx, final List<String> actualPath, final URI namespace, final Date revision,
+            final String prefix, final Builder parent) {
         String typeName = typedefQName.getLocalName();
 
         UnknownType.Builder unknownType = new UnknownType.Builder(typedefQName);
@@ -972,10 +1042,12 @@ public final class YangModelBuilderUtil {
     /**
      * Create TypeDefinition object based on given type name and type body.
      *
+     * @param moduleName
+     *            current module name
      * @param typeName
      *            name of type
      * @param typeBody
-     *            type body
+     *            type body context
      * @param actualPath
      *            current path in schema
      * @param namespace
@@ -984,19 +1056,19 @@ public final class YangModelBuilderUtil {
      *            current revision
      * @param prefix
      *            current prefix
+     * @param parent
+     *            parent builder
      * @return TypeDefinition object based on parsed values.
      */
-    public static TypeDefinition<?> parseTypeBody(final String moduleName, final String typeName,
+    public static TypeDefinition<?> parseTypeWithBody(final String moduleName, final String typeName,
             final Type_body_stmtsContext typeBody, final List<String> actualPath, final URI namespace,
-            final Date revision, final String prefix, Builder parent) {
+            final Date revision, final String prefix, final Builder parent) {
         TypeDefinition<?> baseType = null;
 
-        List<RangeConstraint> rangeStatements = getRangeConstraints(typeBody);
         Integer fractionDigits = getFractionDigits(typeBody);
         List<LengthConstraint> lengthStatements = getLengthConstraints(typeBody);
         List<PatternConstraint> patternStatements = getPatternConstraint(typeBody);
-        List<EnumTypeDefinition.EnumPair> enumConstants = getEnumConstants(typeBody, actualPath, namespace, revision,
-                prefix);
+        List<RangeConstraint> rangeStatements = getRangeConstraints(typeBody);
 
         TypeConstraints constraints = new TypeConstraints(moduleName, typeBody.getStart().getLine());
         constraints.addFractionDigits(fractionDigits);
@@ -1042,6 +1114,8 @@ public final class YangModelBuilderUtil {
             constraints.addRanges(uintType.getRangeStatements());
             baseType = uintType;
         } else if ("enumeration".equals(typeName)) {
+            List<EnumTypeDefinition.EnumPair> enumConstants = getEnumConstants(typeBody, actualPath, namespace,
+                    revision, prefix);
             return new EnumerationType(baseTypePathFinal, enumConstants);
         } else if ("string".equals(typeName)) {
             StringTypeDefinition stringType = new StringType(baseTypePath);
@@ -1154,10 +1228,10 @@ public final class YangModelBuilderUtil {
     }
 
     /**
-     * Parse given context and find require-instance value.
+     * Parse type body statement and find require-instance value.
      *
      * @param ctx
-     *            type body
+     *            type body context
      * @return require-instance value
      */
     private static boolean isRequireInstance(Type_body_stmtsContext ctx) {
@@ -1176,10 +1250,10 @@ public final class YangModelBuilderUtil {
     }
 
     /**
-     * Parse given context and find leafref path.
+     * Parse type body statement and find leafref path.
      *
      * @param ctx
-     *            type body
+     *            type body context
      * @return leafref path as String
      */
     private static String parseLeafrefPath(Type_body_stmtsContext ctx) {
@@ -1198,7 +1272,7 @@ public final class YangModelBuilderUtil {
     }
 
     /**
-     * Internal helper method for parsing Must_stmtContext.
+     * Internal helper method for parsing must statement.
      *
      * @param ctx
      *            Must_stmtContext
@@ -1247,10 +1321,10 @@ public final class YangModelBuilderUtil {
     }
 
     /**
-     * Parse given tree and set constraints to given builder.
+     * Parse given context and set constraints to constraints builder.
      *
      * @param ctx
-     *            context to search
+     *            context to parse
      * @param constraints
      *            ConstraintsBuilder to fill
      */
@@ -1423,8 +1497,8 @@ public final class YangModelBuilderUtil {
                 String reference = stringFromNode(refineArg);
                 refine.setReference(reference);
             } else if (refineArg instanceof Config_stmtContext) {
-                boolean config = parseConfig((Config_stmtContext) refineArg);
-                refine.setConfig(config);
+                Boolean config = parseConfig((Config_stmtContext) refineArg);
+                refine.setConfiguration(config);
             }
         }
     }
diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/parser/impl/GroupingTest.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/parser/impl/GroupingTest.java
new file mode 100644 (file)
index 0000000..2442f51
--- /dev/null
@@ -0,0 +1,229 @@
+/*
+ * 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.parser.impl;
+
+import static org.junit.Assert.*;
+
+import java.io.FileNotFoundException;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.controller.yang.model.api.AnyXmlSchemaNode;
+import org.opendaylight.controller.yang.model.api.ChoiceNode;
+import org.opendaylight.controller.yang.model.api.ContainerSchemaNode;
+import org.opendaylight.controller.yang.model.api.DataSchemaNode;
+import org.opendaylight.controller.yang.model.api.GroupingDefinition;
+import org.opendaylight.controller.yang.model.api.LeafSchemaNode;
+import org.opendaylight.controller.yang.model.api.ListSchemaNode;
+import org.opendaylight.controller.yang.model.api.Module;
+import org.opendaylight.controller.yang.model.api.MustDefinition;
+import org.opendaylight.controller.yang.model.api.SchemaNode;
+import org.opendaylight.controller.yang.model.api.SchemaPath;
+import org.opendaylight.controller.yang.model.api.TypeDefinition;
+import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.controller.yang.model.api.UsesNode;
+import org.opendaylight.controller.yang.model.util.ExtendedType;
+
+public class GroupingTest {
+    private Set<Module> modules;
+
+    @Before
+    public void init() throws FileNotFoundException {
+        modules = TestUtils.loadModules(getClass().getResource("/model").getPath());
+        assertEquals(3, modules.size());
+    }
+
+    @Test
+    public void testRefine() {
+        Module testModule = TestUtils.findModule(modules, "types2");
+
+        ContainerSchemaNode peer = (ContainerSchemaNode) testModule.getDataChildByName("peer");
+        ContainerSchemaNode destination = (ContainerSchemaNode) peer.getDataChildByName("destination");
+        Set<UsesNode> usesNodes = destination.getUses();
+        assertEquals(1, usesNodes.size());
+        UsesNode usesNode = usesNodes.iterator().next();
+        Map<SchemaPath, SchemaNode> refines = usesNode.getRefines();
+        assertEquals(5, refines.size());
+
+        LeafSchemaNode refineLeaf = null;
+        ContainerSchemaNode refineContainer = null;
+        ListSchemaNode refineList = null;
+        GroupingDefinition refineGrouping = null;
+        TypeDefinition<?> typedef = null;
+        for (Map.Entry<SchemaPath, SchemaNode> entry : refines.entrySet()) {
+            SchemaNode value = entry.getValue();
+            if (value instanceof LeafSchemaNode) {
+                refineLeaf = (LeafSchemaNode) value;
+            } else if (value instanceof ContainerSchemaNode) {
+                refineContainer = (ContainerSchemaNode) value;
+            } else if (value instanceof ListSchemaNode) {
+                refineList = (ListSchemaNode) value;
+            } else if (value instanceof GroupingDefinition) {
+                refineGrouping = (GroupingDefinition) value;
+            } else if (value instanceof TypeDefinition<?>) {
+                typedef = (TypeDefinition<?>) value;
+            }
+        }
+
+        // leaf address
+        assertNotNull(refineLeaf);
+        assertEquals("address", refineLeaf.getQName().getLocalName());
+        assertEquals("IP address of target node", refineLeaf.getDescription());
+        assertEquals("address reference added by refine", refineLeaf.getReference());
+        assertFalse(refineLeaf.isConfiguration());
+        assertTrue(refineLeaf.getConstraints().isMandatory());
+        Set<MustDefinition> leafMustConstraints = refineLeaf.getConstraints().getMustConstraints();
+        assertEquals(1, leafMustConstraints.size());
+        MustDefinition leafMust = leafMustConstraints.iterator().next();
+        assertEquals("\"ifType != 'ethernet' or (ifType = 'ethernet' and ifMTU = 1500)\"", leafMust.toString());
+
+        // container port
+        assertNotNull(refineContainer);
+        Set<MustDefinition> mustConstraints = refineContainer.getConstraints().getMustConstraints();
+        assertTrue(mustConstraints.isEmpty());
+        assertEquals("description of port defined by refine", refineContainer.getDescription());
+        assertEquals("port reference added by refine", refineContainer.getReference());
+        assertFalse(refineContainer.isConfiguration());
+        assertTrue(refineContainer.isPresenceContainer());
+
+        // list addresses
+        assertNotNull(refineList);
+        assertEquals("description of addresses defined by refine", refineList.getDescription());
+        assertEquals("addresses reference added by refine", refineList.getReference());
+        assertFalse(refineList.isConfiguration());
+        assertEquals(2, (int) refineList.getConstraints().getMinElements());
+        assertEquals(12, (int) refineList.getConstraints().getMaxElements());
+
+        // grouping target-inner
+        assertNotNull(refineGrouping);
+        Set<DataSchemaNode> refineGroupingChildren = refineGrouping.getChildNodes();
+        assertEquals(1, refineGroupingChildren.size());
+        LeafSchemaNode refineGroupingLeaf = (LeafSchemaNode) refineGroupingChildren.iterator().next();
+        assertEquals("inner-grouping-id", refineGroupingLeaf.getQName().getLocalName());
+        assertEquals("new target-inner grouping description", refineGrouping.getDescription());
+
+        // typedef group-type
+        assertNotNull(typedef);
+        assertEquals("new group-type description", typedef.getDescription());
+        assertEquals("new group-type reference", typedef.getReference());
+        assertTrue(typedef.getBaseType() instanceof ExtendedType);
+    }
+
+    @Test
+    public void testGrouping() {
+        Module testModule = TestUtils.findModule(modules, "types2");
+        Set<GroupingDefinition> groupings = testModule.getGroupings();
+        assertEquals(1, groupings.size());
+        GroupingDefinition grouping = groupings.iterator().next();
+        Set<DataSchemaNode> children = grouping.getChildNodes();
+        assertEquals(5, children.size());
+    }
+
+    @Test
+    public void testUses() {
+        // suffix _u = added by uses
+        // suffix _g = defined in grouping
+
+        Module testModule = TestUtils.findModule(modules, "types2");
+
+        // get grouping
+        Set<GroupingDefinition> groupings = testModule.getGroupings();
+        assertEquals(1, groupings.size());
+        GroupingDefinition grouping = groupings.iterator().next();
+
+        // get node containing uses
+        ContainerSchemaNode peer = (ContainerSchemaNode) testModule.getDataChildByName("peer");
+        ContainerSchemaNode destination = (ContainerSchemaNode) peer.getDataChildByName("destination");
+
+        // check uses
+        Set<UsesNode> uses = destination.getUses();
+        assertEquals(1, uses.size());
+
+        // check uses process
+        AnyXmlSchemaNode data_u = (AnyXmlSchemaNode) destination.getDataChildByName("data");
+        assertNotNull(data_u);
+        assertTrue(data_u.isAddedByUses());
+
+        AnyXmlSchemaNode data_g = (AnyXmlSchemaNode) grouping.getDataChildByName("data");
+        assertNotNull(data_g);
+        assertFalse(data_g.isAddedByUses());
+        assertFalse(data_u.equals(data_g));
+
+        ChoiceNode how_u = (ChoiceNode) destination.getDataChildByName("how");
+        assertNotNull(how_u);
+        assertTrue(how_u.isAddedByUses());
+
+        ChoiceNode how_g = (ChoiceNode) grouping.getDataChildByName("how");
+        assertNotNull(how_g);
+        assertFalse(how_g.isAddedByUses());
+        assertFalse(how_u.equals(how_g));
+
+        LeafSchemaNode address_u = (LeafSchemaNode) destination.getDataChildByName("address");
+        assertNotNull(address_u);
+        assertEquals("1.2.3.4", address_u.getDefault());
+        assertEquals("IP address of target node", address_u.getDescription());
+        assertEquals("address reference added by refine", address_u.getReference());
+        assertFalse(address_u.isConfiguration());
+        assertTrue(address_u.isAddedByUses());
+
+        LeafSchemaNode address_g = (LeafSchemaNode) grouping.getDataChildByName("address");
+        assertNotNull(address_g);
+        assertFalse(address_g.isAddedByUses());
+        assertNull(address_g.getDefault());
+        assertEquals("Target IP address", address_g.getDescription());
+        assertNull(address_g.getReference());
+        assertTrue(address_g.isConfiguration());
+        assertFalse(address_u.equals(address_g));
+
+        ContainerSchemaNode port_u = (ContainerSchemaNode) destination.getDataChildByName("port");
+        assertNotNull(port_u);
+        assertTrue(port_u.isAddedByUses());
+
+        ContainerSchemaNode port_g = (ContainerSchemaNode) grouping.getDataChildByName("port");
+        assertNotNull(port_g);
+        assertFalse(port_g.isAddedByUses());
+        assertFalse(port_u.equals(port_g));
+
+        ListSchemaNode addresses_u = (ListSchemaNode) destination.getDataChildByName("addresses");
+        assertNotNull(addresses_u);
+        assertTrue(addresses_u.isAddedByUses());
+
+        ListSchemaNode addresses_g = (ListSchemaNode) grouping.getDataChildByName("addresses");
+        assertNotNull(addresses_g);
+        assertFalse(addresses_g.isAddedByUses());
+        assertFalse(addresses_u.equals(addresses_g));
+
+        // grouping defined by 'uses'
+        Set<GroupingDefinition> groupings_u = destination.getGroupings();
+        assertEquals(1, groupings_u.size());
+        GroupingDefinition grouping_u = groupings_u.iterator().next();
+        assertTrue(grouping_u.isAddedByUses());
+
+        // grouping defined in 'grouping' node
+        Set<GroupingDefinition> groupings_g = grouping.getGroupings();
+        assertEquals(1, groupings_g.size());
+        GroupingDefinition grouping_g = groupings_g.iterator().next();
+        assertFalse(grouping_g.isAddedByUses());
+        assertFalse(grouping_u.equals(grouping_g));
+
+        List<UnknownSchemaNode> nodes_u = destination.getUnknownSchemaNodes();
+        assertEquals(1, nodes_u.size());
+        UnknownSchemaNode node_u = nodes_u.get(0);
+        assertTrue(node_u.isAddedByUses());
+
+        List<UnknownSchemaNode> nodes_g = grouping.getUnknownSchemaNodes();
+        assertEquals(1, nodes_g.size());
+        UnknownSchemaNode node_g = nodes_g.get(0);
+        assertFalse(node_g.isAddedByUses());
+        assertFalse(node_u.equals(node_g));
+    }
+
+}
index 9006f93..d331cff 100644 (file)
@@ -17,7 +17,6 @@ import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
-import java.util.Map;
 import java.util.Set;
 
 import org.junit.Before;
@@ -29,26 +28,21 @@ import org.opendaylight.controller.yang.model.api.ChoiceCaseNode;
 import org.opendaylight.controller.yang.model.api.ChoiceNode;
 import org.opendaylight.controller.yang.model.api.ConstraintDefinition;
 import org.opendaylight.controller.yang.model.api.ContainerSchemaNode;
-import org.opendaylight.controller.yang.model.api.DataSchemaNode;
 import org.opendaylight.controller.yang.model.api.Deviation;
 import org.opendaylight.controller.yang.model.api.Deviation.Deviate;
 import org.opendaylight.controller.yang.model.api.ExtensionDefinition;
 import org.opendaylight.controller.yang.model.api.FeatureDefinition;
-import org.opendaylight.controller.yang.model.api.GroupingDefinition;
 import org.opendaylight.controller.yang.model.api.LeafListSchemaNode;
 import org.opendaylight.controller.yang.model.api.LeafSchemaNode;
 import org.opendaylight.controller.yang.model.api.ListSchemaNode;
 import org.opendaylight.controller.yang.model.api.Module;
 import org.opendaylight.controller.yang.model.api.ModuleImport;
-import org.opendaylight.controller.yang.model.api.MustDefinition;
 import org.opendaylight.controller.yang.model.api.NotificationDefinition;
 import org.opendaylight.controller.yang.model.api.RpcDefinition;
-import org.opendaylight.controller.yang.model.api.SchemaNode;
 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.api.UnknownSchemaNode;
-import org.opendaylight.controller.yang.model.api.UsesNode;
 import org.opendaylight.controller.yang.model.api.type.LengthConstraint;
 import org.opendaylight.controller.yang.model.api.type.PatternConstraint;
 import org.opendaylight.controller.yang.model.api.type.RangeConstraint;
@@ -64,7 +58,6 @@ import org.opendaylight.controller.yang.model.util.UnionType;
 
 public class YangParserTest {
     private final DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
-
     private Set<Module> modules;
 
     @Before
@@ -121,7 +114,7 @@ public class YangParserTest {
         assertEquals(0, interfaces.getUnknownSchemaNodes().size());
         // test DataSchemaNode args
         assertFalse(interfaces.isAugmenting());
-        assertFalse(interfaces.isConfiguration());
+        assertTrue(interfaces.isConfiguration());
         ConstraintDefinition constraints = interfaces.getConstraints();
         assertNull(constraints.getWhenCondition());
         assertEquals(0, constraints.getMustConstraints().size());
@@ -164,7 +157,7 @@ public class YangParserTest {
         assertEquals(0, ifEntry.getUnknownSchemaNodes().size());
         // test DataSchemaNode args
         assertFalse(ifEntry.isAugmenting());
-        assertFalse(ifEntry.isConfiguration());
+        assertTrue(ifEntry.isConfiguration());
         ConstraintDefinition constraints = ifEntry.getConstraints();
         assertNull(constraints.getWhenCondition());
         assertEquals(0, constraints.getMustConstraints().size());
@@ -565,89 +558,26 @@ public class YangParserTest {
         assertEquals(100L, range.getMax());
     }
 
-    @Test
-    public void testRefine() {
-        Module testModule = TestUtils.findModule(modules, "types2");
-
-        ContainerSchemaNode peer = (ContainerSchemaNode) testModule.getDataChildByName("peer");
-        ContainerSchemaNode destination = (ContainerSchemaNode) peer.getDataChildByName("destination");
-        Set<UsesNode> usesNodes = destination.getUses();
-        assertEquals(1, usesNodes.size());
-        UsesNode usesNode = usesNodes.iterator().next();
-        Map<SchemaPath, SchemaNode> refines = usesNode.getRefines();
-        assertEquals(5, refines.size());
-
-        LeafSchemaNode refineLeaf = null;
-        ContainerSchemaNode refineContainer = null;
-        ListSchemaNode refineList = null;
-        GroupingDefinition refineGrouping = null;
-        TypeDefinition<?> typedef = null;
-        for (Map.Entry<SchemaPath, SchemaNode> entry : refines.entrySet()) {
-            SchemaNode value = entry.getValue();
-            if (value instanceof LeafSchemaNode) {
-                refineLeaf = (LeafSchemaNode) value;
-            } else if (value instanceof ContainerSchemaNode) {
-                refineContainer = (ContainerSchemaNode) value;
-            } else if (value instanceof ListSchemaNode) {
-                refineList = (ListSchemaNode) value;
-            } else if (value instanceof GroupingDefinition) {
-                refineGrouping = (GroupingDefinition) value;
-            } else if (value instanceof TypeDefinition<?>) {
-                typedef = (TypeDefinition<?>) value;
-            }
-        }
-
-        // leaf address
-        assertNotNull(refineLeaf);
-        assertEquals("address", refineLeaf.getQName().getLocalName());
-        assertEquals("description of address defined by refine", refineLeaf.getDescription());
-        assertEquals("address reference added by refine", refineLeaf.getReference());
-        assertFalse(refineLeaf.isConfiguration());
-        assertTrue(refineLeaf.getConstraints().isMandatory());
-        Set<MustDefinition> leafMustConstraints = refineLeaf.getConstraints().getMustConstraints();
-        assertEquals(1, leafMustConstraints.size());
-        MustDefinition leafMust = leafMustConstraints.iterator().next();
-        assertEquals("\"ifType != 'ethernet' or (ifType = 'ethernet' and ifMTU = 1500)\"", leafMust.toString());
-
-        // container port
-        assertNotNull(refineContainer);
-        Set<MustDefinition> mustConstraints = refineContainer.getConstraints().getMustConstraints();
-        assertTrue(mustConstraints.isEmpty());
-        assertEquals("description of port defined by refine", refineContainer.getDescription());
-        assertEquals("port reference added by refine", refineContainer.getReference());
-        assertFalse(refineContainer.isConfiguration());
-        assertTrue(refineContainer.isPresenceContainer());
-
-        // list addresses
-        assertNotNull(refineList);
-        assertEquals("description of addresses defined by refine", refineList.getDescription());
-        assertEquals("addresses reference added by refine", refineList.getReference());
-        assertFalse(refineList.isConfiguration());
-        assertEquals(2, (int) refineList.getConstraints().getMinElements());
-        assertEquals(12, (int) refineList.getConstraints().getMaxElements());
-
-        // grouping target-inner
-        assertNotNull(refineGrouping);
-        Set<DataSchemaNode> refineGroupingChildren = refineGrouping.getChildNodes();
-        assertEquals(1, refineGroupingChildren.size());
-        LeafSchemaNode refineGroupingLeaf = (LeafSchemaNode) refineGroupingChildren.iterator().next();
-        assertEquals("inner-grouping-id", refineGroupingLeaf.getQName().getLocalName());
-        assertEquals("new target-inner grouping description", refineGrouping.getDescription());
-
-        // typedef group-type
-        assertNotNull(typedef);
-        assertEquals("new group-type description", typedef.getDescription());
-        assertEquals("new group-type reference", typedef.getReference());
-        assertTrue(typedef.getBaseType() instanceof ExtendedType);
-    }
-
     @Test
     public void testChoice() {
         Module testModule = TestUtils.findModule(modules, "types1");
         ContainerSchemaNode peer = (ContainerSchemaNode) testModule.getDataChildByName("transfer");
         ChoiceNode how = (ChoiceNode) peer.getDataChildByName("how");
         Set<ChoiceCaseNode> cases = how.getCases();
-        assertEquals(3, cases.size());
+        assertEquals(5, cases.size());
+        ChoiceCaseNode input = null;
+        ChoiceCaseNode output = null;
+        for(ChoiceCaseNode caseNode : cases) {
+            if("input".equals(caseNode.getQName().getLocalName())) {
+                input = caseNode;
+            } else if("output".equals(caseNode.getQName().getLocalName())) {
+                output = caseNode;
+            }
+        }
+        assertNotNull(input);
+        assertNotNull(input.getPath());
+        assertNotNull(output);
+        assertNotNull(output.getPath());
     }
 
     @Test
@@ -750,16 +680,6 @@ public class YangParserTest {
         assertNotNull(output.getDataChildByName("data"));
     }
 
-    @Test
-    public void testGrouping() {
-        Module testModule = TestUtils.findModule(modules, "types2");
-        Set<GroupingDefinition> groupings = testModule.getGroupings();
-        assertEquals(1, groupings.size());
-        GroupingDefinition grouping = groupings.iterator().next();
-        Set<DataSchemaNode> children = grouping.getChildNodes();
-        assertEquals(5, children.size());
-    }
-
     @Test
     public void testAugmentNodesTypesSchemaPath() throws Exception {
         Module testModule = TestUtils.findModule(modules, "types1");
index ff32ee1..be7b7ef 100644 (file)
@@ -21,6 +21,8 @@ import java.util.Set;
 
 import org.junit.Test;
 import org.opendaylight.controller.yang.common.QName;
+import org.opendaylight.controller.yang.model.api.AnyXmlSchemaNode;
+import org.opendaylight.controller.yang.model.api.ChoiceNode;
 import org.opendaylight.controller.yang.model.api.ContainerSchemaNode;
 import org.opendaylight.controller.yang.model.api.DataSchemaNode;
 import org.opendaylight.controller.yang.model.api.GroupingDefinition;
@@ -81,11 +83,111 @@ public class YangParserWithContextTest {
         RangeConstraint range = ranges.get(0);
         assertEquals(0L, range.getMin());
         assertEquals(63L, range.getMax());
+    }
 
+    @Test
+    public void testUsesFromContext() throws Exception {
+        SchemaContext context = null;
+        try (InputStream stream = new FileInputStream(getClass().getResource("/model/testfile2.yang").getPath())) {
+            context = parser.resolveSchemaContext(TestUtils.loadModules(Lists.newArrayList(stream)));
+        }
+        Module testModule = null;
+        try (InputStream stream = new FileInputStream(getClass().getResource("/context-test/test2.yang").getPath())) {
+            testModule = TestUtils.loadModuleWithContext(stream, context);
+        }
+        assertNotNull(testModule);
+
+        // suffix _u = added by uses
+        // suffix _g = defined in grouping from context
+
+        // get grouping
+        Module contextModule = context.findModuleByNamespace(URI.create("urn:simple.types.data.demo"));
+        assertNotNull(contextModule);
+        Set<GroupingDefinition> groupings = contextModule.getGroupings();
+        assertEquals(1, groupings.size());
+        GroupingDefinition grouping = groupings.iterator().next();
+
+        // get node containing uses
+        ContainerSchemaNode peer = (ContainerSchemaNode)testModule.getDataChildByName("peer");
+        ContainerSchemaNode destination = (ContainerSchemaNode)peer.getDataChildByName("destination");
+
+        // check uses
+        Set<UsesNode> uses = destination.getUses();
+        assertEquals(1, uses.size());
+
+        // check uses process
+        AnyXmlSchemaNode data_u = (AnyXmlSchemaNode)destination.getDataChildByName("data");
+        assertNotNull(data_u);
+        assertTrue(data_u.isAddedByUses());
+
+        AnyXmlSchemaNode data_g = (AnyXmlSchemaNode)grouping.getDataChildByName("data");
+        assertNotNull(data_g);
+        assertFalse(data_g.isAddedByUses());
+        assertFalse(data_u.equals(data_g));
+
+        ChoiceNode how_u = (ChoiceNode)destination.getDataChildByName("how");
+        assertNotNull(how_u);
+        assertTrue(how_u.isAddedByUses());
+
+        ChoiceNode how_g = (ChoiceNode)grouping.getDataChildByName("how");
+        assertNotNull(how_g);
+        assertFalse(how_g.isAddedByUses());
+        assertFalse(how_u.equals(how_g));
+
+        LeafSchemaNode address_u = (LeafSchemaNode)destination.getDataChildByName("address");
+        assertNotNull(address_u);
+        assertTrue(address_u.isAddedByUses());
+
+        LeafSchemaNode address_g = (LeafSchemaNode)grouping.getDataChildByName("address");
+        assertNotNull(address_g);
+        assertFalse(address_g.isAddedByUses());
+        assertFalse(address_u.equals(address_g));
+
+        ContainerSchemaNode port_u = (ContainerSchemaNode)destination.getDataChildByName("port");
+        assertNotNull(port_u);
+        assertTrue(port_u.isAddedByUses());
+
+        ContainerSchemaNode port_g = (ContainerSchemaNode)grouping.getDataChildByName("port");
+        assertNotNull(port_g);
+        assertFalse(port_g.isAddedByUses());
+        assertFalse(port_u.equals(p