Merge "Custom Node Type jaxb string to id"
authorGiovanni Meo <gmeo@cisco.com>
Wed, 5 Jun 2013 14:40:02 +0000 (14:40 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Wed, 5 Jun 2013 14:40:02 +0000 (14:40 +0000)
42 files changed:
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/packet/ARP.java
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/packet/IPv4.java
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/packet/LLDPTLV.java
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/packet/Packet.java
opendaylight/sal/yang-prototype/code-generator/maven-yang-plugin-it/src/test/resources/GenerateTest1/src/main/resources/testfile2.yang
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/api/AbstractDataNodeContainerBuilder.java [moved from opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/api/AbstractChildNodeBuilder.java with 88% similarity]
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/api/AbstractTypeAwareBuilder.java
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/DataNodeContainerBuilder.java [moved from opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/api/ChildNodeBuilder.java with 89% similarity]
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/TypeAwareBuilder.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/ContainerSchemaNodeBuilder.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/IdentityrefTypeBuilder.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 [moved from opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/impl/TypedefBuilder.java with 96% similarity]
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/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/test/java/org/opendaylight/controller/yang/parser/impl/TestUtils.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/parser/impl/YangParserNegativeTest.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/resources/model/testfile1.yang
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/model/testfile2.yang
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/negative-scenario/testfile0.yang [new file with mode: 0644]
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/negative-scenario/testfile1.yang [new file with mode: 0644]
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/negative-scenario/testfile2.yang [new file with mode: 0644]
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/negative-scenario/testfile3.yang [new file with mode: 0644]
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/negative-scenario/testfile4.yang [new file with mode: 0644]
opendaylight/security/src/main/java/org/opendaylight/controller/security/ControllerCustomRealm.java
opendaylight/switchmanager/implementation/src/main/java/org/opendaylight/controller/switchmanager/internal/SwitchManagerImpl.java
opendaylight/usermanager/src/main/java/org/opendaylight/controller/usermanager/IUserManager.java
opendaylight/usermanager/src/main/java/org/opendaylight/controller/usermanager/internal/UserManagerImpl.java

index f3aa35f..dd51e85 100644 (file)
@@ -13,8 +13,6 @@ import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.Map;
 
-import org.apache.commons.lang3.builder.EqualsBuilder;
-import org.apache.commons.lang3.builder.HashCodeBuilder;
 import org.apache.commons.lang3.tuple.ImmutablePair;
 import org.apache.commons.lang3.tuple.Pair;
 
@@ -249,11 +247,27 @@ public class ARP extends Packet {
 
     @Override
     public int hashCode() {
-        return HashCodeBuilder.reflectionHashCode(this);
+        final int prime = 31;
+        int result = super.hashCode();
+        result = prime * result
+                + ((fieldValues == null) ? 0 : fieldValues.hashCode());
+        return result;
     }
 
     @Override
     public boolean equals(Object obj) {
-        return EqualsBuilder.reflectionEquals(this, obj);
+        if (this == obj)
+            return true;
+        if (!super.equals(obj))
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        ARP other = (ARP) obj;
+        if (fieldValues == null) {
+            if (other.fieldValues != null)
+                return false;
+        } else if (!fieldValues.equals(other.fieldValues))
+            return false;
+        return true;
     }
 }
index c7b97e9..44318aa 100644 (file)
@@ -542,10 +542,12 @@ public class IPv4 extends Packet {
          * Deriving the Total Length here
          */
         int payloadLength = 0;
-        try {
-            payloadLength = payload.serialize().length;
-        } catch (PacketException e) {
-            logger.error("", e);
+        if (payload != null) {
+            try {
+                payloadLength = payload.serialize().length;
+            } catch (PacketException e) {
+                logger.error("", e);
+            }
         }
 
         this.setTotalLength((short) (this.getHeaderLen() + payloadLength));
index 9254e82..bf67402 100644 (file)
@@ -10,13 +10,11 @@ package org.opendaylight.controller.sal.packet;
 
 import java.io.UnsupportedEncodingException;
 import java.nio.charset.Charset;
-import java.util.HashMap;
-
 import java.util.Arrays;
+import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.Map;
-import org.apache.commons.lang3.builder.EqualsBuilder;
-import org.apache.commons.lang3.builder.HashCodeBuilder;
+
 import org.apache.commons.lang3.tuple.MutablePair;
 import org.apache.commons.lang3.tuple.Pair;
 import org.opendaylight.controller.sal.utils.HexEncode;
@@ -144,12 +142,28 @@ public class LLDPTLV extends Packet {
 
     @Override
     public int hashCode() {
-        return HashCodeBuilder.reflectionHashCode(this);
+        final int prime = 31;
+        int result = super.hashCode();
+        result = prime * result
+                + ((fieldValues == null) ? 0 : fieldValues.hashCode());
+        return result;
     }
 
     @Override
     public boolean equals(Object obj) {
-        return EqualsBuilder.reflectionEquals(this, obj);
+        if (this == obj)
+            return true;
+        if (!super.equals(obj))
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        LLDPTLV other = (LLDPTLV) obj;
+        if (fieldValues == null) {
+            if (other.fieldValues != null)
+                return false;
+        } else if (!fieldValues.equals(other.fieldValues))
+            return false;
+        return true;
     }
 
     @Override
@@ -164,7 +178,7 @@ public class LLDPTLV extends Packet {
 
     /**
      * Returns the size in bits of the whole TLV
-     * 
+     *
      * @return int - size in bits of full TLV
      */
     public int getTLVSize() {
@@ -176,7 +190,7 @@ public class LLDPTLV extends Packet {
     /**
      * Creates the ChassisID TLV value including the subtype and ChassisID
      * string
-     * 
+     *
      * @param nodeId
      *            node identifier string
      * @return the ChassisID TLV value in byte array
@@ -204,7 +218,7 @@ public class LLDPTLV extends Packet {
 
     /**
      * Creates the PortID TLV value including the subtype and PortID string
-     * 
+     *
      * @param portId
      *            port identifier string
      * @return the PortID TLV value in byte array
@@ -221,7 +235,7 @@ public class LLDPTLV extends Packet {
 
     /**
      * Creates the custom TLV value including OUI, subtype and custom string
-     * 
+     *
      * @param portId
      *            port identifier string
      * @return the custom TLV value in byte array
@@ -241,7 +255,7 @@ public class LLDPTLV extends Packet {
 
     /**
      * Retrieves the string from TLV value and returns it in HexString format
-     * 
+     *
      * @param tlvValue
      *            the TLV value
      * @param tlvLen
@@ -257,7 +271,7 @@ public class LLDPTLV extends Packet {
 
     /**
      * Retrieves the string from TLV value
-     * 
+     *
      * @param tlvValue
      *            the TLV value
      * @param tlvLen
@@ -274,7 +288,7 @@ public class LLDPTLV extends Packet {
     /**
      * Retrieves the custom string from the Custom TLV value which includes OUI,
      * subtype and custom string
-     * 
+     *
      * @param customTlvValue
      *            the custom TLV value
      * @param customTlvLen
index b19c0f8..58b5d39 100644 (file)
@@ -77,7 +77,7 @@ public abstract class Packet {
     /**
      * This method deserializes the data bits obtained from the wire into the
      * respective header and payload which are of type Packet
-     * 
+     *
      * @param byte[] data - data from wire to deserialize
      * @param int bitOffset bit position where packet header starts in data
      *        array
@@ -151,7 +151,7 @@ public abstract class Packet {
     /**
      * This method serializes the header and payload from the respective
      * packet class, into a single stream of bytes to be sent on the wire
-     * 
+     *
      * @return The byte array representing the serialized Packet
      * @throws PacketException
      */
@@ -206,7 +206,7 @@ public abstract class Packet {
      * byte stream which cannot be done or cannot be done efficiently during the
      * normal Packet.serialize() path. An example is the checksum computation
      * for IPv4
-     * 
+     *
      * @param byte[] - serialized bytes
      * @throws PacketException
      */
@@ -221,7 +221,7 @@ public abstract class Packet {
      * of checksum varies based on the protocol, this method is overridden.
      * Currently only IPv4 and ICMP do checksum computation and validation. TCP
      * and UDP need to implement these if required.
-     * 
+     *
      * @param byte[] data The byte stream representing the Ethernet frame
      * @param int startBitOffset The bit offset from where the byte array corresponding to this Packet starts in the frame
      * @throws PacketException
@@ -233,7 +233,7 @@ public abstract class Packet {
 
     /**
      * Gets the header length in bits
-     * 
+     *
      * @return int the header length in bits
      */
     public int getHeaderSize() {
@@ -256,7 +256,7 @@ public abstract class Packet {
      * This method fetches the start bit offset for header field specified by
      * 'fieldname'. The offset is present in the hdrFieldCoordMap of the
      * respective packet class
-     * 
+     *
      * @param String
      *            fieldName
      * @return Integer - startOffset of the requested field
@@ -269,7 +269,7 @@ public abstract class Packet {
      * This method fetches the number of bits for header field specified by
      * 'fieldname'. The numBits are present in the hdrFieldCoordMap of the
      * respective packet class
-     * 
+     *
      * @param String
      *            fieldName
      * @return Integer - number of bits of the requested field
@@ -297,7 +297,7 @@ public abstract class Packet {
     /**
      * Returns the raw payload carried by this packet in case payload was not
      * parsed. Caller can call this function in case the getPaylod() returns null.
-     * 
+     *
      * @return The raw payload if not parsable as an array of bytes, null otherwise
      */
     public byte[] getRawPayload() {
@@ -306,7 +306,7 @@ public abstract class Packet {
 
     /**
      * Set a raw payload in the packet class
-     * 
+     *
      * @param payload The raw payload as byte array
      */
     public void setRawPayload(byte[] payload) {
@@ -319,8 +319,8 @@ public abstract class Packet {
      * packet received from wire is not equal to the checksum read from the
      * stream. For the Packet class which do not have a checksum field, this
      * function will always return false.
-     * 
-     * 
+     *
+     *
      * @return true if the deserialized packet's recomputed checksum is not
      *         equal to the packet carried checksum
      */
index 1a7b45e..7f7b306 100644 (file)
@@ -152,10 +152,7 @@ module types2 {
                     default "1.2.3.4";
                 }
                 refine port {
-                    must "must-condition" {
-                        error-message "An error message test";
-                        error-app-tag "An error app tag test";
-                    }
+                    description "new port description updated by refine";
                 }
             }
         }
@@ -12,13 +12,13 @@ import java.util.Set;
 
 import org.opendaylight.controller.yang.common.QName;
 
-public abstract class AbstractChildNodeBuilder implements ChildNodeBuilder {
+public abstract class AbstractDataNodeContainerBuilder implements DataNodeContainerBuilder {
 
     private final QName qname;
     protected final Set<DataSchemaNodeBuilder> childNodes = new HashSet<DataSchemaNodeBuilder>();
     protected final Set<GroupingBuilder> groupings = new HashSet<GroupingBuilder>();
 
-    protected AbstractChildNodeBuilder(QName qname) {
+    protected AbstractDataNodeContainerBuilder(QName qname) {
         this.qname = qname;
     }
 
@@ -16,19 +16,21 @@ import org.opendaylight.controller.yang.model.api.SchemaPath;
  * Interface for all yang data-node containers [augment, case, container,
  * grouping, list, module, notification].
  */
-public interface ChildNodeBuilder extends Builder {
+public interface DataNodeContainerBuilder extends Builder {
 
     QName getQName();
 
+    Set<DataSchemaNodeBuilder> getChildNodes();
+
     void addChildNode(DataSchemaNodeBuilder childNode);
 
     void addGrouping(GroupingBuilder groupingBuilder);
 
     void addUsesNode(UsesNodeBuilder usesBuilder);
 
-    void addTypedef(TypeDefinitionBuilder typedefBuilder);
+    Set<TypeDefinitionBuilder> getTypeDefinitions();
 
-    Set<DataSchemaNodeBuilder> getChildNodes();
+    void addTypedef(TypeDefinitionBuilder typedefBuilder);
 
     SchemaPath getPath();
 
index 2c1f94d..e4088a8 100644 (file)
@@ -17,7 +17,7 @@ import org.opendaylight.controller.yang.parser.builder.impl.UnknownSchemaNodeBui
 /**
  * Interface for builders of 'grouping' statement.
  */
-public interface GroupingBuilder extends ChildNodeBuilder, SchemaNodeBuilder,
+public interface GroupingBuilder extends DataNodeContainerBuilder, SchemaNodeBuilder,
         TypeDefinitionAwareBuilder {
 
     String getDescription();
@@ -34,8 +34,6 @@ public interface GroupingBuilder extends ChildNodeBuilder, SchemaNodeBuilder,
 
     Set<GroupingBuilder> getGroupings();
 
-    Set<TypeDefinitionBuilder> getTypedefs();
-
     Set<UsesNodeBuilder> getUses();
 
 }
index 559eedb..ad92b22 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.controller.yang.parser.builder.api;
 
 import org.opendaylight.controller.yang.common.QName;
+import org.opendaylight.controller.yang.model.api.SchemaPath;
 import org.opendaylight.controller.yang.model.api.TypeDefinition;
 
 /**
@@ -18,12 +19,14 @@ public interface TypeAwareBuilder extends Builder {
 
     QName getQName();
 
+    SchemaPath getPath();
+
     TypeDefinition<?> getType();
 
     TypeDefinitionBuilder getTypedef();
 
     void setType(TypeDefinition<?> type);
 
-    void setType(TypeDefinitionBuilder typedef);
+    void setTypedef(TypeDefinitionBuilder typedef);
 
 }
index ba1ea9c..d82cbe2 100644 (file)
@@ -18,7 +18,6 @@ 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.DataSchemaNodeBuilder;
-import org.opendaylight.controller.yang.parser.util.YangParseException;
 
 public final class AnyXmlBuilder implements DataSchemaNodeBuilder {
     private boolean built;
@@ -33,6 +32,7 @@ public final class AnyXmlBuilder implements DataSchemaNodeBuilder {
     private String reference;
     private Status status = Status.CURRENT;
     private boolean configuration;
+    private boolean augmenting;
 
     public AnyXmlBuilder(final QName qname, final int line) {
         this.qname = qname;
@@ -50,6 +50,7 @@ public final class AnyXmlBuilder implements DataSchemaNodeBuilder {
             instance.setReference(reference);
             instance.setStatus(status);
             instance.setConfiguration(configuration);
+            instance.setAugmenting(augmenting);
 
             // UNKNOWN NODES
             final List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();
@@ -127,8 +128,7 @@ public final class AnyXmlBuilder implements DataSchemaNodeBuilder {
 
     @Override
     public void setAugmenting(final boolean augmenting) {
-        throw new YangParseException(line,
-                "An anyxml node cannot be augmented.");
+        this.augmenting = augmenting;
     }
 
     public boolean isConfiguration() {
@@ -148,6 +148,7 @@ public final class AnyXmlBuilder implements DataSchemaNodeBuilder {
         private Status status = Status.CURRENT;
         private boolean configuration;
         private ConstraintDefinition constraintsDef;
+        private boolean augmenting;
         private List<UnknownSchemaNode> unknownNodes = Collections.emptyList();
 
         private AnyXmlSchemaNodeImpl(final QName qname) {
@@ -199,7 +200,11 @@ public final class AnyXmlBuilder implements DataSchemaNodeBuilder {
 
         @Override
         public boolean isAugmenting() {
-            return false;
+            return augmenting;
+        }
+
+        private void setAugmenting(boolean augmenting) {
+            this.augmenting = augmenting;
         }
 
         @Override
index 54f69c8..e5ba8b1 100644 (file)
@@ -151,6 +151,11 @@ public final class AugmentationSchemaBuilderImpl implements AugmentationSchemaBu
         this.whenCondition = whenCondition;
     }
 
+    @Override
+    public Set<TypeDefinitionBuilder> getTypeDefinitions() {
+        return Collections.emptySet();
+    }
+
     @Override
     public void addTypedef(TypeDefinitionBuilder type) {
         throw new YangParseException(line,
index e3ab083..a9e2b3b 100644 (file)
@@ -23,15 +23,9 @@ import org.opendaylight.controller.yang.model.api.Status;
 import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
 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.ChildNodeBuilder;
 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;
-import org.opendaylight.controller.yang.parser.builder.api.UsesNodeBuilder;
-import org.opendaylight.controller.yang.parser.util.YangParseException;
 
-public final class ChoiceBuilder implements DataSchemaNodeBuilder,
-        ChildNodeBuilder, AugmentationTargetBuilder {
+public final class ChoiceBuilder implements DataSchemaNodeBuilder, AugmentationTargetBuilder {
     private boolean built;
     private final ChoiceNodeImpl instance;
     private final int line;
@@ -46,9 +40,6 @@ public final class ChoiceBuilder implements DataSchemaNodeBuilder,
     private boolean augmenting;
     private boolean configuration;
     private final ConstraintsBuilder constraints;
-    // DataNodeContainer args
-    private final Set<TypeDefinitionBuilder> addedTypedefs = new HashSet<TypeDefinitionBuilder>();
-    private final Set<UsesNodeBuilder> addedUsesNodes = new HashSet<UsesNodeBuilder>();
     // AugmentationTarget args
     private final Set<AugmentationSchemaBuilder> addedAugmentations = new HashSet<AugmentationSchemaBuilder>();
     // ChoiceNode args
@@ -109,7 +100,6 @@ public final class ChoiceBuilder implements DataSchemaNodeBuilder,
         return cases;
     }
 
-    @Override
     public void addChildNode(DataSchemaNodeBuilder childNode) {
         if (!(childNode instanceof ChoiceCaseBuilder)) {
             ChoiceCaseBuilder caseBuilder = new ChoiceCaseBuilder(
@@ -126,31 +116,6 @@ public final class ChoiceBuilder implements DataSchemaNodeBuilder,
         return qname;
     }
 
-    /**
-     * Choice can not contains grouping statements, so this method always
-     * returns an empty set.
-     *
-     * @return empty set
-     */
-    public Set<GroupingBuilder> getGroupings() {
-        return Collections.emptySet();
-    }
-
-    @Override
-    public void addGrouping(GroupingBuilder groupingBuilder) {
-        throw new YangParseException(line,
-                "Can not add grouping to 'choice' node.");
-    }
-
-    public Set<TypeDefinitionBuilder> getTypedefs() {
-        return addedTypedefs;
-    }
-
-    @Override
-    public void addTypedef(final TypeDefinitionBuilder type) {
-        addedTypedefs.add(type);
-    }
-
     public SchemaPath getPath() {
         return schemaPath;
     }
@@ -212,15 +177,6 @@ public final class ChoiceBuilder implements DataSchemaNodeBuilder,
         return constraints;
     }
 
-    public Set<UsesNodeBuilder> getUsesNodes() {
-        return addedUsesNodes;
-    }
-
-    @Override
-    public void addUsesNode(UsesNodeBuilder usesNodeBuilder) {
-        addedUsesNodes.add(usesNodeBuilder);
-    }
-
     public List<UnknownSchemaNodeBuilder> getUnknownNodes() {
         return addedUnknownNodes;
     }
@@ -247,10 +203,6 @@ public final class ChoiceBuilder implements DataSchemaNodeBuilder,
         this.defaultCase = defaultCase;
     }
 
-    @Override
-    public Set<DataSchemaNodeBuilder> getChildNodes() {
-        return new HashSet<DataSchemaNodeBuilder>(cases);
-    }
 
     private final class ChoiceNodeImpl implements ChoiceNode {
         private final QName qname;
index 11a1b31..7117afe 100644 (file)
@@ -19,13 +19,13 @@ 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.parser.builder.api.AbstractChildNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.AbstractDataNodeContainerBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.DataSchemaNodeBuilder;
 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 AbstractChildNodeBuilder implements
+public final class ChoiceCaseBuilder extends AbstractDataNodeContainerBuilder implements
         DataSchemaNodeBuilder {
     private final ChoiceCaseNodeImpl instance;
     private final int line;
@@ -150,6 +150,11 @@ public final class ChoiceCaseBuilder extends AbstractChildNodeBuilder implements
         addedUsesNodes.add(usesNodeBuilder);
     }
 
+    @Override
+    public Set<TypeDefinitionBuilder> getTypeDefinitions() {
+        return Collections.emptySet();
+    }
+
     @Override
     public void addTypedef(TypeDefinitionBuilder typedefBuilder) {
         throw new YangParseException(line,
index 7fcdb6f..4831a22 100644 (file)
@@ -26,7 +26,7 @@ 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.parser.builder.api.AbstractChildNodeBuilder;
+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.DataSchemaNodeBuilder;
@@ -35,7 +35,7 @@ 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 ContainerSchemaNodeBuilder extends AbstractChildNodeBuilder
+public final class ContainerSchemaNodeBuilder extends AbstractDataNodeContainerBuilder
         implements TypeDefinitionAwareBuilder, AugmentationTargetBuilder,
         DataSchemaNodeBuilder {
     private boolean isBuilt;
@@ -128,7 +128,8 @@ public final class ContainerSchemaNodeBuilder extends AbstractChildNodeBuilder
         return line;
     }
 
-    public Set<TypeDefinitionBuilder> getTypedefs() {
+    @Override
+    public Set<TypeDefinitionBuilder> getTypeDefinitions() {
         return addedTypedefs;
     }
 
@@ -233,6 +234,11 @@ public final class ContainerSchemaNodeBuilder extends AbstractChildNodeBuilder
         addedUnknownNodes.add(unknownNode);
     }
 
+    @Override
+    public String toString() {
+        return "container " + getQName().getLocalName();
+    }
+
     private final class ContainerSchemaNodeImpl implements ContainerSchemaNode {
         private final QName qname;
         private SchemaPath path;
index 99d4ffb..ba9609b 100644 (file)
@@ -177,6 +177,11 @@ public final class LeafSchemaNodeBuilder extends AbstractTypeAwareBuilder
         this.unitsStr = unitsStr;
     }
 
+    @Override
+    public String toString() {
+        return "leaf " + qname.getLocalName();
+    }
+
     private final class LeafSchemaNodeImpl implements LeafSchemaNode {
         private final QName qname;
         private SchemaPath path;
index db0e37b..65839d3 100644 (file)
@@ -26,7 +26,7 @@ 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.parser.builder.api.AbstractChildNodeBuilder;
+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.DataSchemaNodeBuilder;
@@ -35,7 +35,7 @@ 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 ListSchemaNodeBuilder extends AbstractChildNodeBuilder
+public final class ListSchemaNodeBuilder extends AbstractDataNodeContainerBuilder
         implements DataSchemaNodeBuilder, AugmentationTargetBuilder,
         TypeDefinitionAwareBuilder {
     private boolean isBuilt;
@@ -134,7 +134,8 @@ public final class ListSchemaNodeBuilder extends AbstractChildNodeBuilder
         return line;
     }
 
-    public Set<TypeDefinitionBuilder> getTypedefs() {
+    @Override
+    public Set<TypeDefinitionBuilder> getTypeDefinitions() {
         return addedTypedefs;
     }
 
index 0d47d7a..6940e91 100644 (file)
@@ -13,6 +13,7 @@ import java.util.Collections;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -34,7 +35,7 @@ import org.opendaylight.controller.yang.model.api.TypeDefinition;
 import org.opendaylight.controller.yang.model.api.UsesNode;
 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.ChildNodeBuilder;
+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.SchemaNodeBuilder;
@@ -61,31 +62,30 @@ public class ModuleBuilder implements Builder {
 
     private final Set<ModuleImport> imports = new HashSet<ModuleImport>();
 
-    /**
-     * All nodes, that can contain other nodes
-     */
-    private final Map<List<String>, Builder> moduleNodes = new HashMap<List<String>, Builder>();
-
     /**
      * Holds all child (DataSchemaNode) nodes: anyxml, choice, case, container,
      * list, leaf, leaf-list.
      */
-    private final Map<List<String>, DataSchemaNodeBuilder> addedChilds = new HashMap<List<String>, DataSchemaNodeBuilder>();
+    private final Map<List<String>, DataSchemaNodeBuilder> childNodes = new HashMap<List<String>, DataSchemaNodeBuilder>();
 
     private final Map<List<String>, GroupingBuilder> addedGroupings = new HashMap<List<String>, GroupingBuilder>();
     private final List<AugmentationSchemaBuilder> addedAugments = new ArrayList<AugmentationSchemaBuilder>();
     private final Map<List<String>, UsesNodeBuilder> addedUsesNodes = new HashMap<List<String>, UsesNodeBuilder>();
+    //private final Map<List<String>, RefineHolder> addedRefines = new HashMap<List<String>, RefineHolder>();
     private final Map<List<String>, RpcDefinitionBuilder> addedRpcs = new HashMap<List<String>, RpcDefinitionBuilder>();
     private final Set<NotificationBuilder> addedNotifications = new HashSet<NotificationBuilder>();
     private final Set<IdentitySchemaNodeBuilder> addedIdentities = new HashSet<IdentitySchemaNodeBuilder>();
     private final Map<List<String>, FeatureBuilder> addedFeatures = new HashMap<List<String>, FeatureBuilder>();
-    private final Map<String, DeviationBuilder> addedDeviations = new HashMap<String, DeviationBuilder>();
+    private final Map<List<String>, DeviationBuilder> addedDeviations = new HashMap<List<String>, DeviationBuilder>();
     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 Set<UnknownSchemaNodeBuilder> addedUnknownNodes = new HashSet<UnknownSchemaNodeBuilder>();
 
     private final Map<List<String>, TypeAwareBuilder> dirtyNodes = new HashMap<List<String>, TypeAwareBuilder>();
 
+    private final LinkedList<Builder> actualPath = new LinkedList<Builder>();
+
     public ModuleBuilder(final String name) {
         this.name = name;
         instance = new ModuleImpl(name);
@@ -106,8 +106,8 @@ public class ModuleBuilder implements Builder {
         instance.setTypeDefinitions(typedefs);
 
         // CHILD NODES
-        final Map<QName, DataSchemaNode> childNodes = buildModuleChildNodes(addedChilds);
-        instance.setChildNodes(childNodes);
+        final Map<QName, DataSchemaNode> children = buildModuleChildNodes(childNodes);
+        instance.setChildNodes(children);
 
         // GROUPINGS
         final Set<GroupingDefinition> groupings = buildModuleGroupings(addedGroupings);
@@ -141,7 +141,7 @@ public class ModuleBuilder implements Builder {
 
         // DEVIATIONS
         final Set<Deviation> deviations = new HashSet<Deviation>();
-        for (Map.Entry<String, DeviationBuilder> entry : addedDeviations
+        for (Map.Entry<List<String>, DeviationBuilder> entry : addedDeviations
                 .entrySet()) {
             deviations.add(entry.getValue().build());
         }
@@ -169,45 +169,61 @@ public class ModuleBuilder implements Builder {
         return 0;
     }
 
-    public Builder getNode(final List<String> path) {
-        return moduleNodes.get(path);
+    public void enterNode(final Builder node) {
+        actualPath.push(node);
+    }
+
+    public void exitNode() {
+        actualPath.pop();
+    }
+
+    public Builder getModuleNode(final List<String> path) {
+        return childNodes.get(path);
+    }
+
+    public GroupingBuilder getGrouping(final List<String> path) {
+        return addedGroupings.get(path);
+    }
+
+    public Builder getModuleTypedef(final List<String> path) {
+        return addedTypedefs.get(path);
     }
 
     public Set<DataSchemaNodeBuilder> getChildNodes() {
-        final Set<DataSchemaNodeBuilder> childNodes = new HashSet<DataSchemaNodeBuilder>();
-        for (Map.Entry<List<String>, DataSchemaNodeBuilder> entry : addedChilds
+        final Set<DataSchemaNodeBuilder> children = new HashSet<DataSchemaNodeBuilder>();
+        for (Map.Entry<List<String>, DataSchemaNodeBuilder> entry : childNodes
                 .entrySet()) {
-            List<String> path = entry.getKey();
-            DataSchemaNodeBuilder child = entry.getValue();
+            final List<String> path = entry.getKey();
+            final DataSchemaNodeBuilder child = entry.getValue();
             if (path.size() == 2) {
-                childNodes.add(child);
+                children.add(child);
             }
         }
-        return childNodes;
+        return children;
     }
 
     public Map<List<String>, TypeAwareBuilder> getDirtyNodes() {
         return dirtyNodes;
     }
 
-    public List<AugmentationSchemaBuilder> getAddedAugments() {
+    public List<AugmentationSchemaBuilder> getAugments() {
         return addedAugments;
     }
 
-    public Set<IdentitySchemaNodeBuilder> getAddedIdentities() {
+    public Set<IdentitySchemaNodeBuilder> getIdentities() {
         return addedIdentities;
     }
 
-    public Map<List<String>, UsesNodeBuilder> getAddedUsesNodes() {
+    public Map<List<String>, UsesNodeBuilder> getUsesNodes() {
         return addedUsesNodes;
     }
 
-    public Set<UnknownSchemaNodeBuilder> getAddedUnknownNodes() {
+    public Set<UnknownSchemaNodeBuilder> getUnknownNodes() {
         return addedUnknownNodes;
     }
 
     public Set<TypeDefinitionBuilder> getModuleTypedefs() {
-        Set<TypeDefinitionBuilder> typedefs = new HashSet<TypeDefinitionBuilder>();
+        final Set<TypeDefinitionBuilder> typedefs = new HashSet<TypeDefinitionBuilder>();
         for (Map.Entry<List<String>, TypeDefinitionBuilder> entry : addedTypedefs
                 .entrySet()) {
             if (entry.getKey().size() == 2) {
@@ -247,8 +263,8 @@ public class ModuleBuilder implements Builder {
 
     public void addDirtyNode(final List<String> path) {
         final List<String> dirtyNodePath = new ArrayList<String>(path);
-        final TypeAwareBuilder nodeBuilder = (TypeAwareBuilder) moduleNodes
-                .get(dirtyNodePath);
+        final TypeAwareBuilder nodeBuilder = (TypeAwareBuilder) actualPath
+                .getFirst();
         dirtyNodes.put(dirtyNodePath, nodeBuilder);
     }
 
@@ -303,18 +319,10 @@ public class ModuleBuilder implements Builder {
         final List<String> pathToNode = new ArrayList<String>(parentPath);
         final ContainerSchemaNodeBuilder containerBuilder = new ContainerSchemaNodeBuilder(
                 containerName, line);
-        final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes
-                .get(pathToNode);
-        if (parent != null) {
-            if (parent instanceof AugmentationSchemaBuilder) {
-                containerBuilder.setAugmenting(true);
-            }
-            parent.addChildNode(containerBuilder);
-        }
+        updateParent(containerBuilder, line, "container");
 
         pathToNode.add(containerName.getLocalName());
-        moduleNodes.put(pathToNode, containerBuilder);
-        addedChilds.put(pathToNode, containerBuilder);
+        childNodes.put(pathToNode, containerBuilder);
 
         return containerBuilder;
     }
@@ -324,18 +332,10 @@ public class ModuleBuilder implements Builder {
         final List<String> pathToNode = new ArrayList<String>(parentPath);
         final ListSchemaNodeBuilder listBuilder = new ListSchemaNodeBuilder(
                 listName, line);
-        final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes
-                .get(pathToNode);
-        if (parent != null) {
-            if (parent instanceof AugmentationSchemaBuilder) {
-                listBuilder.setAugmenting(true);
-            }
-            parent.addChildNode(listBuilder);
-        }
+        updateParent(listBuilder, line, "list");
 
         pathToNode.add(listName.getLocalName());
-        moduleNodes.put(pathToNode, listBuilder);
-        addedChilds.put(pathToNode, listBuilder);
+        childNodes.put(pathToNode, listBuilder);
 
         return listBuilder;
     }
@@ -345,39 +345,23 @@ public class ModuleBuilder implements Builder {
         final List<String> pathToNode = new ArrayList<String>(parentPath);
         final LeafSchemaNodeBuilder leafBuilder = new LeafSchemaNodeBuilder(
                 leafName, line);
-        final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes
-                .get(pathToNode);
-        if (parent != null) {
-            if (parent instanceof AugmentationSchemaBuilder) {
-                leafBuilder.setAugmenting(true);
-            }
-            parent.addChildNode(leafBuilder);
-        }
+        updateParent(leafBuilder, line, "leaf");
 
         pathToNode.add(leafName.getLocalName());
-        addedChilds.put(pathToNode, leafBuilder);
-        moduleNodes.put(pathToNode, leafBuilder);
+        childNodes.put(pathToNode, leafBuilder);
 
         return leafBuilder;
     }
 
-    public LeafListSchemaNodeBuilder addLeafListNode(final QName leafListName,
+    public LeafListSchemaNodeBuilder addLeafListNode(final QName qname,
             final List<String> parentPath, final int line) {
         final List<String> pathToNode = new ArrayList<String>(parentPath);
         final LeafListSchemaNodeBuilder leafListBuilder = new LeafListSchemaNodeBuilder(
-                leafListName, line);
-        final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes
-                .get(pathToNode);
-        if (parent != null) {
-            if (parent instanceof AugmentationSchemaBuilder) {
-                leafListBuilder.setAugmenting(true);
-            }
-            parent.addChildNode(leafListBuilder);
-        }
+                qname, line);
+        updateParent(leafListBuilder, line, "leaf-list");
 
-        pathToNode.add(leafListName.getLocalName());
-        addedChilds.put(pathToNode, leafListBuilder);
-        moduleNodes.put(pathToNode, leafListBuilder);
+        pathToNode.add(qname.getLocalName());
+        childNodes.put(pathToNode, leafListBuilder);
 
         return leafListBuilder;
     }
@@ -386,15 +370,18 @@ public class ModuleBuilder implements Builder {
             final List<String> parentPath, final int line) {
         final List<String> pathToGroup = new ArrayList<String>(parentPath);
         final GroupingBuilder builder = new GroupingBuilderImpl(qname, line);
-        final ChildNodeBuilder parentNodeBuilder = (ChildNodeBuilder) moduleNodes
-                .get(pathToGroup);
-        if (parentNodeBuilder != null) {
-            parentNodeBuilder.addGrouping(builder);
+
+        if (!(actualPath.isEmpty())) {
+            final Builder parent = actualPath.getFirst();
+            if (parent instanceof DataNodeContainerBuilder) {
+                ((DataNodeContainerBuilder) parent).addGrouping(builder);
+            } else {
+                throw new YangParseException(name, line,
+                        "Unresolved parent of grouping " + qname.getLocalName());
+            }
         }
 
-        pathToGroup.add("grouping");
         pathToGroup.add(qname.getLocalName());
-        moduleNodes.put(pathToGroup, builder);
         addedGroupings.put(pathToGroup, builder);
 
         return builder;
@@ -407,13 +394,17 @@ public class ModuleBuilder implements Builder {
                 name, line);
 
         // augment can only be in 'module' or 'uses' statement
-        final UsesNodeBuilder parent = addedUsesNodes.get(pathToAugment);
-        if (parent != null) {
-            parent.addAugment(builder);
+        if (!(actualPath.isEmpty())) {
+            final Builder parent = actualPath.getFirst();
+            if (parent instanceof UsesNodeBuilder) {
+                ((UsesNodeBuilder) parent).addAugment(builder);
+            } else {
+                throw new YangParseException(this.name, line,
+                        "Unresolved parent of augment " + name);
+            }
         }
 
         pathToAugment.add(name);
-        moduleNodes.put(pathToAugment, builder);
         addedAugments.add(builder);
 
         return builder;
@@ -424,34 +415,53 @@ public class ModuleBuilder implements Builder {
         final List<String> pathToUses = new ArrayList<String>(parentPath);
         final UsesNodeBuilder usesBuilder = new UsesNodeBuilderImpl(
                 groupingPathStr, line);
-        final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes
-                .get(pathToUses);
-        if (parent != null) {
-            parent.addUsesNode(usesBuilder);
+
+        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);
+            }
         }
 
         pathToUses.add(groupingPathStr);
         addedUsesNodes.put(pathToUses, usesBuilder);
-        moduleNodes.put(pathToUses, usesBuilder);
         return usesBuilder;
     }
 
     public void addRefine(final RefineHolder refine,
             final List<String> parentPath) {
         final List<String> path = new ArrayList<String>(parentPath);
-        final Builder parent = moduleNodes.get(path);
-        if (!(parent instanceof UsesNodeBuilder)) {
-            throw new YangParseException("Failed to parse refine "
-                    + refine.getName());
+
+        if (actualPath.isEmpty()) {
+            throw new YangParseException(name, refine.getLine(),
+                    "refine can be defined only in uses statement");
+        } else {
+            final Builder parent = actualPath.getFirst();
+            if (parent instanceof UsesNodeBuilder) {
+                ((UsesNodeBuilder) parent).addRefine(refine);
+            } else {
+                throw new YangParseException(name, refine.getLine(),
+                        "refine can be defined only in uses statement");
+            }
         }
-        UsesNodeBuilder usesBuilder = (UsesNodeBuilder) parent;
-        usesBuilder.addRefine(refine);
+
         path.add(refine.getName());
-        moduleNodes.put(path, refine);
     }
 
     public RpcDefinitionBuilder addRpc(final QName qname,
             final List<String> parentPath, final int line) {
+
+        if (!(actualPath.isEmpty())) {
+            throw new YangParseException(name, line,
+                    "rpc can be defined only in module or submodule");
+        }
+
         final List<String> pathToRpc = new ArrayList<String>(parentPath);
         final RpcDefinitionBuilder rpcBuilder = new RpcDefinitionBuilder(qname,
                 line);
@@ -459,37 +469,51 @@ public class ModuleBuilder implements Builder {
         pathToRpc.add(qname.getLocalName());
         addedRpcs.put(pathToRpc, rpcBuilder);
 
-        final QName inputQName = new QName(qname.getNamespace(),
-                qname.getRevision(), qname.getPrefix(), "input");
+        return rpcBuilder;
+    }
+
+    public ContainerSchemaNodeBuilder addRpcInput(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 List<String> pathToInput = new ArrayList<String>(pathToRpc);
-        pathToInput.add("input");
-        moduleNodes.put(pathToInput, inputBuilder);
-        rpcBuilder.setInput(inputBuilder);
+        rpc.setInput(inputBuilder);
+        return inputBuilder;
+    }
+
+    public ContainerSchemaNodeBuilder addRpcOutput(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 QName outputQName = new QName(qname.getNamespace(),
-                qname.getRevision(), qname.getPrefix(), "output");
         final ContainerSchemaNodeBuilder outputBuilder = new ContainerSchemaNodeBuilder(
                 outputQName, line);
-        final List<String> pathToOutput = new ArrayList<String>(pathToRpc);
-        pathToOutput.add("output");
-        moduleNodes.put(pathToOutput, outputBuilder);
-        rpcBuilder.setOutput(outputBuilder);
-
-        return rpcBuilder;
+        rpc.setOutput(outputBuilder);
+        return outputBuilder;
     }
 
     public NotificationBuilder addNotification(final QName notificationName,
             final List<String> parentPath, final int line) {
-        final List<String> pathToNotification = new ArrayList<String>(
-                parentPath);
+        if (!(actualPath.isEmpty())) {
+            throw new YangParseException(name, line,
+                    "notification can be defined only in module or submodule");
+        }
 
-        NotificationBuilder builder = new NotificationBuilder(notificationName,
-                line);
+        final NotificationBuilder builder = new NotificationBuilder(
+                notificationName, line);
 
-        pathToNotification.add(notificationName.getLocalName());
-        moduleNodes.put(pathToNotification, builder);
+        final List<String> notificationPath = new ArrayList<String>(parentPath);
+        notificationPath.add(notificationName.getLocalName());
         addedNotifications.add(builder);
 
         return builder;
@@ -497,174 +521,237 @@ public class ModuleBuilder implements Builder {
 
     public FeatureBuilder addFeature(final QName featureName,
             final List<String> parentPath, final int line) {
-        List<String> pathToFeature = new ArrayList<String>(parentPath);
+        if (!(actualPath.isEmpty())) {
+            throw new YangParseException(name, line,
+                    "feature can be defined only in module or submodule");
+        }
+
+        final List<String> pathToFeature = new ArrayList<String>(parentPath);
         pathToFeature.add(featureName.getLocalName());
 
-        FeatureBuilder builder = new FeatureBuilder(featureName, line);
+        final FeatureBuilder builder = new FeatureBuilder(featureName, line);
         addedFeatures.put(pathToFeature, builder);
         return builder;
     }
 
     public ChoiceBuilder addChoice(final QName choiceName,
             final List<String> parentPath, final int line) {
-        List<String> pathToChoice = new ArrayList<String>(parentPath);
-        ChoiceBuilder builder = new ChoiceBuilder(choiceName, line);
-
-        final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes
-                .get(pathToChoice);
-        if (parent != null) {
-            if (parent instanceof AugmentationSchemaBuilder) {
-                builder.setAugmenting(true);
+        final List<String> pathToChoice = new ArrayList<String>(parentPath);
+        final ChoiceBuilder builder = new ChoiceBuilder(choiceName, line);
+
+        if (!(actualPath.isEmpty())) {
+            Builder parent = actualPath.getFirst();
+            if (parent instanceof DataNodeContainerBuilder) {
+                if (parent instanceof AugmentationSchemaBuilder) {
+                    builder.setAugmenting(true);
+                }
+                ((DataNodeContainerBuilder) parent).addChildNode(builder);
+            } else {
+                throw new YangParseException(name, line,
+                        "Unresolved parent of choice "
+                                + choiceName.getLocalName());
             }
-            parent.addChildNode(builder);
         }
 
         pathToChoice.add(choiceName.getLocalName());
-        addedChilds.put(pathToChoice, builder);
-        moduleNodes.put(pathToChoice, builder);
+        childNodes.put(pathToChoice, builder);
 
         return builder;
     }
 
     public ChoiceCaseBuilder addCase(final QName caseName,
             final List<String> parentPath, final int line) {
-        List<String> pathToCase = new ArrayList<String>(parentPath);
-        ChoiceCaseBuilder builder = new ChoiceCaseBuilder(caseName, line);
-
-        final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes
-                .get(pathToCase);
-        if (parent != null) {
-            if (parent instanceof AugmentationSchemaBuilder) {
+        final List<String> pathToCase = new ArrayList<String>(parentPath);
+        final ChoiceCaseBuilder builder = new ChoiceCaseBuilder(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) {
                 builder.setAugmenting(true);
+                ((AugmentationSchemaBuilder) parent).addChildNode(builder);
+            } else {
+                throw new YangParseException(name, line,
+                        "Unresolved parent of 'case' "
+                                + caseName.getLocalName());
             }
-            parent.addChildNode(builder);
         }
 
         pathToCase.add(caseName.getLocalName());
-        moduleNodes.put(pathToCase, builder);
+        childNodes.put(pathToCase, builder);
 
         return builder;
     }
 
     public AnyXmlBuilder addAnyXml(final QName anyXmlName,
             final List<String> parentPath, final int line) {
-        List<String> pathToAnyXml = new ArrayList<String>(parentPath);
-        AnyXmlBuilder builder = new AnyXmlBuilder(anyXmlName, line);
-
-        final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes
-                .get(pathToAnyXml);
-        if (parent != null) {
-            if (parent instanceof AugmentationSchemaBuilder) {
-                throw new YangParseException(
-                        "An anyxml node cannot be augmented.");
-            }
-            parent.addChildNode(builder);
-        }
+        final List<String> pathToAnyXml = new ArrayList<String>(parentPath);
+        final AnyXmlBuilder builder = new AnyXmlBuilder(anyXmlName, line);
+        updateParent(builder, line, "anyxml");
 
         pathToAnyXml.add(anyXmlName.getLocalName());
-        addedChilds.put(pathToAnyXml, builder);
-        moduleNodes.put(pathToAnyXml, builder);
+        childNodes.put(pathToAnyXml, builder);
 
         return builder;
     }
 
-    public TypedefBuilder addTypedef(final QName typeDefName,
+    public TypeDefinitionBuilderImpl addTypedef(final QName typeDefName,
             final List<String> parentPath, final int line) {
-        List<String> pathToType = new ArrayList<String>(parentPath);
-        TypedefBuilder builder = new TypedefBuilder(typeDefName, line);
-        TypeDefinitionAwareBuilder parent = (TypeDefinitionAwareBuilder) moduleNodes
-                .get(pathToType);
-        if (parent != null) {
-            parent.addTypedef(builder);
+        final List<String> pathToType = new ArrayList<String>(parentPath);
+        final TypeDefinitionBuilderImpl builder = new TypeDefinitionBuilderImpl(
+                typeDefName, line);
+
+        if (!(actualPath.isEmpty())) {
+            final Builder parent = actualPath.getFirst();
+            if (parent instanceof TypeDefinitionAwareBuilder) {
+                ((TypeDefinitionAwareBuilder) parent).addTypedef(builder);
+            } else {
+                throw new YangParseException(name, line,
+                        "Unresolved parent of typedef "
+                                + typeDefName.getLocalName());
+            }
         }
+
         pathToType.add(typeDefName.getLocalName());
         addedTypedefs.put(pathToType, builder);
-        moduleNodes.put(pathToType, builder);
         return builder;
     }
 
-    public void setType(TypeDefinition<?> type, List<String> parentPath) {
-        TypeAwareBuilder parent = (TypeAwareBuilder) moduleNodes
-                .get(parentPath);
-        if (parent == null) {
-            throw new YangParseException("Failed to set type '"
-                    + type.getQName().getLocalName()
-                    + "'. Parent node not found.");
+    public void setType(final TypeDefinition<?> type,
+            final List<String> parentPath) {
+
+        if (!(actualPath.isEmpty())) {
+            final Builder parent = actualPath.getFirst();
+            if (parent instanceof TypeAwareBuilder) {
+                ((TypeAwareBuilder) parent).setType(type);
+            } else {
+                throw new YangParseException("Failed to set type '"
+                        + type.getQName().getLocalName()
+                        + "'. Unknown parent node: " + parent);
+            }
         }
-        parent.setType(type);
     }
 
-    public UnionTypeBuilder addUnionType(final List<String> actualPath,
+    public UnionTypeBuilder addUnionType(final List<String> currentPath,
             final URI namespace, final Date revision, final int line) {
-        List<String> pathToUnion = new ArrayList<String>(actualPath);
-        TypeAwareBuilder parent = (TypeAwareBuilder) moduleNodes
-                .get(pathToUnion);
-        UnionTypeBuilder union = new UnionTypeBuilder(line);
-        parent.setType(union);
+        final List<String> pathToUnion = new ArrayList<String>(currentPath);
+        final UnionTypeBuilder union = new UnionTypeBuilder(line);
+
+        if (actualPath.isEmpty()) {
+            throw new YangParseException(line, "union error");
+        } else {
+            final Builder parent = actualPath.getFirst();
+            if (parent instanceof TypeAwareBuilder) {
 
-        List<String> path = new ArrayList<String>(pathToUnion);
-        path.add("union");
+                ((TypeAwareBuilder) parent).setTypedef(union);
 
-        moduleNodes.put(path, union);
-        return union;
+                final List<String> path = new ArrayList<String>(pathToUnion);
+                path.add("union");
+
+                addedUnionTypes.put(path, union);
+                return union;
+            } else {
+                throw new YangParseException(name, line,
+                        "Unresolved parent of union type.");
+            }
+        }
     }
 
     public void addIdentityrefType(final String baseString,
             final List<String> parentPath, final SchemaPath schemaPath,
             final int line) {
-        List<String> pathToIdentityref = new ArrayList<String>(parentPath);
-        TypeAwareBuilder parent = (TypeAwareBuilder) moduleNodes
-                .get(pathToIdentityref);
-        IdentityrefTypeBuilder identityref = new IdentityrefTypeBuilder(
+        final List<String> pathToIdentityref = new ArrayList<String>(parentPath);
+        final IdentityrefTypeBuilder identityref = new IdentityrefTypeBuilder(
                 baseString, schemaPath, line);
-        parent.setType(identityref);
-        dirtyNodes.put(pathToIdentityref, parent);
+
+        if (actualPath.isEmpty()) {
+            throw new YangParseException(line, "identityref error");
+        } else {
+            final Builder parent = actualPath.getFirst();
+            if (parent instanceof TypeAwareBuilder) {
+                final TypeAwareBuilder typeParent = (TypeAwareBuilder) parent;
+                typeParent.setTypedef(identityref);
+                dirtyNodes.put(pathToIdentityref, typeParent);
+            } else {
+                throw new YangParseException(name, line,
+                        "Unresolved parent of identityref type.");
+            }
+        }
     }
 
     public DeviationBuilder addDeviation(final String targetPath,
             final List<String> parentPath, final int line) {
+        if (!(actualPath.isEmpty())) {
+            throw new YangParseException(name, line,
+                    "deviation can be defined only in module or submodule");
+        }
+
         final List<String> pathToDeviation = new ArrayList<String>(parentPath);
         pathToDeviation.add(targetPath);
-        DeviationBuilder builder = new DeviationBuilder(targetPath, line);
-        addedDeviations.put(targetPath, builder);
-        moduleNodes.put(pathToDeviation, builder);
+        final DeviationBuilder builder = new DeviationBuilder(targetPath, line);
+        addedDeviations.put(pathToDeviation, builder);
         return builder;
     }
 
     public IdentitySchemaNodeBuilder addIdentity(final QName qname,
             final List<String> parentPath, final int line) {
+        if (!(actualPath.isEmpty())) {
+            throw new YangParseException(name, line,
+                    "identity can be defined only in module or submodule");
+        }
+
         final List<String> pathToIdentity = new ArrayList<String>(parentPath);
         final IdentitySchemaNodeBuilder builder = new IdentitySchemaNodeBuilder(
                 qname, line);
         pathToIdentity.add(qname.getLocalName());
-        moduleNodes.put(pathToIdentity, builder);
         addedIdentities.add(builder);
         return builder;
     }
 
-    public void addConfiguration(boolean configuration, List<String> parentPath) {
-        Builder builder = moduleNodes.get(parentPath);
-        // current api did not support adding config to deviate
-        if (!(builder instanceof DeviationBuilder)) {
-            if(builder instanceof RefineHolder) {
-                ((RefineHolder)builder).setConfig(configuration);
+    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.");
+        } 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 {
-                ((DataSchemaNodeBuilder)builder).setConfiguration(configuration);
+                throw new YangParseException(name, line,
+                        "Unresolved parent of config statement.");
             }
         }
     }
 
     public UnknownSchemaNodeBuilder addUnknownSchemaNode(final QName qname,
             final List<String> parentPath, final int line) {
-        final List<String> pathToUnknown = new ArrayList<String>(parentPath);
         final UnknownSchemaNodeBuilder builder = new UnknownSchemaNodeBuilder(
                 qname, line);
-        final Builder parent = moduleNodes.get(pathToUnknown);
-        if (parent instanceof RefineHolder) {
-            ((RefineHolder) parent).addUnknownSchemaNode(builder);
-        } else if (parent instanceof SchemaNodeBuilder) {
-            ((SchemaNodeBuilder) parent).addUnknownSchemaNode(builder);
+
+        if (!(actualPath.isEmpty())) {
+            final Builder parent = actualPath.getFirst();
+            if (parent instanceof SchemaNodeBuilder) {
+                ((SchemaNodeBuilder) parent).addUnknownSchemaNode(builder);
+            } else if (parent instanceof RefineHolder) {
+                ((RefineHolder) parent).addUnknownSchemaNode(builder);
+            } else {
+                throw new YangParseException(name, line,
+                        "Unresolved parent of unknown node '"
+                                + qname.getLocalName() + "'");
+            }
         }
+
         addedUnknownNodes.add(builder);
         return builder;
     }
@@ -1006,6 +1093,26 @@ public class ModuleBuilder implements Builder {
         }
     }
 
+    private void updateParent(DataSchemaNodeBuilder nodeBuilder, int line,
+            String nodeTypeName) {
+        if (!(actualPath.isEmpty())) {
+            final Builder parent = actualPath.getFirst();
+            if (parent instanceof DataNodeContainerBuilder) {
+                if (parent instanceof AugmentationSchemaBuilder) {
+                    nodeBuilder.setAugmenting(true);
+                }
+                ((DataNodeContainerBuilder) parent)
+                        .addChildNode(nodeBuilder);
+            } else if (parent instanceof ChoiceBuilder) {
+                ((ChoiceBuilder) parent).addChildNode(nodeBuilder);
+            } else {
+                throw new YangParseException(name, line,
+                        "Unresolved parent of " + nodeTypeName + " "
+                                + nodeBuilder.getQName().getLocalName());
+            }
+        }
+    }
+
     private ModuleImport createModuleImport(final String moduleName,
             final Date revision, final String prefix) {
         ModuleImport moduleImport = new ModuleImport() {
@@ -1119,7 +1226,7 @@ public class ModuleBuilder implements Builder {
         final Set<GroupingDefinition> groupings = new HashSet<GroupingDefinition>();
         for (Map.Entry<List<String>, GroupingBuilder> entry : addedGroupings
                 .entrySet()) {
-            if (entry.getKey().size() == 3) {
+            if (entry.getKey().size() == 2) {
                 groupings.add(entry.getValue().build());
             }
         }
index e058efc..f75b97d 100644 (file)
@@ -25,7 +25,7 @@ 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.parser.builder.api.AbstractChildNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.AbstractDataNodeContainerBuilder;
 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.SchemaNodeBuilder;
@@ -33,7 +33,7 @@ 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 AbstractChildNodeBuilder
+public final class NotificationBuilder extends AbstractDataNodeContainerBuilder
         implements TypeDefinitionAwareBuilder, SchemaNodeBuilder {
     private boolean isBuilt;
     private final NotificationDefinitionImpl instance;
@@ -100,6 +100,11 @@ public final class NotificationBuilder extends AbstractChildNodeBuilder
         return line;
     }
 
+    @Override
+    public Set<TypeDefinitionBuilder> getTypeDefinitions() {
+        return addedTypedefs;
+    }
+
     @Override
     public void addTypedef(final TypeDefinitionBuilder type) {
         addedTypedefs.add(type);
@@ -140,6 +145,11 @@ public final class NotificationBuilder extends AbstractChildNodeBuilder
         addedUnknownNodes.add(unknownNode);
     }
 
+    @Override
+    public String toString() {
+        return "notification " + getQName().getLocalName();
+    }
+
     private final class NotificationDefinitionImpl implements NotificationDefinition {
         private final QName qname;
         private SchemaPath path;
index 914ebc7..5b9638e 100644 (file)
@@ -94,11 +94,19 @@ public final class RpcDefinitionBuilder implements SchemaNodeBuilder,
         this.outputBuilder = outputBuilder;
     }
 
+    public Set<TypeDefinitionBuilder> getTypeDefinitions() {
+        return addedTypedefs;
+    }
+
     @Override
     public void addTypedef(final TypeDefinitionBuilder type) {
         addedTypedefs.add(type);
     }
 
+    public void addGrouping(GroupingBuilder grouping) {
+        addedGroupings.add(grouping);
+    }
+
     @Override
     public SchemaPath getPath() {
         return schemaPath;
@@ -25,8 +25,8 @@ 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 TypedefBuilder extends AbstractTypeAwareBuilder implements
-        TypeDefinitionBuilder {
+public final class TypeDefinitionBuilderImpl extends AbstractTypeAwareBuilder
+        implements TypeDefinitionBuilder {
     private final int line;
     private final QName qname;
     private SchemaPath schemaPath;
@@ -43,7 +43,7 @@ public final class TypedefBuilder extends AbstractTypeAwareBuilder implements
     private String units;
     private Object defaultValue;
 
-    public TypedefBuilder(final QName qname, final int line) {
+    public TypeDefinitionBuilderImpl(final QName qname, final int line) {
         this.qname = qname;
         this.line = line;
     }
index 61aec1a..07db699 100644 (file)
@@ -76,7 +76,7 @@ public final class UnionTypeBuilder extends AbstractTypeAwareBuilder implements
     }
 
     @Override
-    public void setType(final TypeDefinitionBuilder tdb) {
+    public void setTypedef(final TypeDefinitionBuilder tdb) {
         typedefs.add(tdb);
     }
 
@@ -125,7 +125,7 @@ public final class UnionTypeBuilder extends AbstractTypeAwareBuilder implements
 
     @Override
     public SchemaPath getPath() {
-        return null;
+        return path;
     }
 
     @Override
index 14ef491..ac2b533 100644 (file)
@@ -52,9 +52,10 @@ 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.AugmentationTargetBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.Builder;
-import org.opendaylight.controller.yang.parser.builder.api.ChildNodeBuilder;
+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.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;
@@ -67,7 +68,8 @@ import org.opendaylight.controller.yang.parser.builder.impl.LeafListSchemaNodeBu
 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.TypedefBuilder;
+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.util.ModuleDependencySort;
@@ -190,7 +192,7 @@ public final class YangParserImpl implements YangModelParser {
         resolveAugments(modules);
 
         // build
-        // Linked Hash Set MUST be used otherwise the Set will not maintain
+        // LinkedHashSet MUST be used otherwise the Set will not maintain
         // order!
         // http://docs.oracle.com/javase/6/docs/api/java/util/LinkedHashSet.html
         final Set<Module> result = new LinkedHashSet<Module>();
@@ -213,7 +215,7 @@ public final class YangParserImpl implements YangModelParser {
             final ModuleBuilder builder) {
         resolveDirtyNodes(modules, builder);
         resolveIdentities(modules, builder);
-        resolveUses(modules, builder);
+        resolveUsesRefines(modules, builder);
         resolveUnknownNodes(modules, builder);
     }
 
@@ -246,12 +248,13 @@ public final class YangParserImpl implements YangModelParser {
                             final UnknownType unknownType = (UnknownType) td;
                             final TypeDefinitionBuilder resolvedType = resolveTypeUnion(
                                     nodeToResolve, unknownType, modules, module);
-                            union.setType(resolvedType);
+                            union.setTypedef(resolvedType);
                             toRemove.add(unknownType);
                         }
                     }
                     unionTypes.removeAll(toRemove);
                 } else if (nodeToResolve.getTypedef() instanceof IdentityrefTypeBuilder) {
+                    // different handling for identityref types
                     IdentityrefTypeBuilder idref = (IdentityrefTypeBuilder) nodeToResolve
                             .getTypedef();
                     nodeToResolve.setType(new IdentityrefType(findFullQName(
@@ -259,28 +262,28 @@ public final class YangParserImpl implements YangModelParser {
                 } else {
                     final TypeDefinitionBuilder resolvedType = resolveType(
                             nodeToResolve, modules, module);
-                    nodeToResolve.setType(resolvedType);
+                    nodeToResolve.setTypedef(resolvedType);
                 }
             }
         }
     }
 
     private TypeDefinitionBuilder resolveType(
-            final TypeAwareBuilder typeToResolve,
+            final TypeAwareBuilder nodeToResolve,
             final Map<String, TreeMap<Date, ModuleBuilder>> modules,
             final ModuleBuilder builder) {
         final TypeConstraints constraints = new TypeConstraints();
 
-        final TypeDefinitionBuilder targetType = getTypedefBuilder(
-                typeToResolve, modules, builder);
-        final TypeConstraints tConstraints = findConstraints(typeToResolve,
+        final TypeDefinitionBuilder targetTypeBuilder = getTypeDefinitionBuilderFromDirtyNode(
+                nodeToResolve, modules, builder);
+        final TypeConstraints tConstraints = findConstraints(nodeToResolve,
                 constraints, modules, builder);
-        targetType.setRanges(tConstraints.getRange());
-        targetType.setLengths(tConstraints.getLength());
-        targetType.setPatterns(tConstraints.getPatterns());
-        targetType.setFractionDigits(tConstraints.getFractionDigits());
+        targetTypeBuilder.setRanges(tConstraints.getRange());
+        targetTypeBuilder.setLengths(tConstraints.getLength());
+        targetTypeBuilder.setPatterns(tConstraints.getPatterns());
+        targetTypeBuilder.setFractionDigits(tConstraints.getFractionDigits());
 
-        return targetType;
+        return targetTypeBuilder;
     }
 
     private TypeDefinitionBuilder resolveTypeUnion(
@@ -290,38 +293,34 @@ public final class YangParserImpl implements YangModelParser {
             final ModuleBuilder builder) {
         final TypeConstraints constraints = new TypeConstraints();
 
-        final TypeDefinitionBuilder targetType = getUnionBuilder(typeToResolve,
-                unknownType, modules, builder);
+        final TypeDefinitionBuilder targetTypeBuilder = getUnionBuilder(
+                typeToResolve, unknownType, modules, builder);
         final TypeConstraints tConstraints = findConstraints(typeToResolve,
                 constraints, modules, builder);
-        targetType.setRanges(tConstraints.getRange());
-        targetType.setLengths(tConstraints.getLength());
-        targetType.setPatterns(tConstraints.getPatterns());
-        targetType.setFractionDigits(tConstraints.getFractionDigits());
+        targetTypeBuilder.setRanges(tConstraints.getRange());
+        targetTypeBuilder.setLengths(tConstraints.getLength());
+        targetTypeBuilder.setPatterns(tConstraints.getPatterns());
+        targetTypeBuilder.setFractionDigits(tConstraints.getFractionDigits());
 
-        return targetType;
+        return targetTypeBuilder;
     }
 
-    private TypeDefinitionBuilder getTypedefBuilder(
+    private TypeDefinitionBuilder getTypeDefinitionBuilderFromDirtyNode(
             final TypeAwareBuilder nodeToResolve,
             final Map<String, TreeMap<Date, ModuleBuilder>> modules,
-            final ModuleBuilder builder) {
-
-        final TypeDefinition<?> nodeToResolveBase = nodeToResolve.getType();
-        if (nodeToResolveBase != null
-                && !(nodeToResolveBase instanceof UnknownType)) {
-            return (TypeDefinitionBuilder) nodeToResolve;
-        }
+            final ModuleBuilder module) {
 
         final UnknownType unknownType = (UnknownType) nodeToResolve.getType();
         final QName unknownTypeQName = unknownType.getQName();
 
         // search for module which contains referenced typedef
         final ModuleBuilder dependentModule = findDependentModule(modules,
-                builder, unknownTypeQName.getPrefix(), nodeToResolve.getLine());
-        final TypeDefinitionBuilder lookedUpBuilder = findTypedefBuilderByName(
-                dependentModule, unknownTypeQName.getLocalName(),
-                builder.getName(), nodeToResolve.getLine());
+                module, unknownTypeQName.getPrefix(), nodeToResolve.getLine());
+
+        final TypeDefinitionBuilder lookedUpBuilder = findTypeDefinitionBuilder(
+                nodeToResolve.getPath(), dependentModule,
+                unknownTypeQName.getLocalName(), module.getName(),
+                nodeToResolve.getLine());
 
         final TypeDefinitionBuilder lookedUpBuilderCopy = copyTypedefBuilder(
                 lookedUpBuilder, nodeToResolve instanceof TypeDefinitionBuilder);
@@ -346,9 +345,10 @@ public final class YangParserImpl implements YangModelParser {
         // search for module which contains referenced typedef
         final ModuleBuilder dependentModule = findDependentModule(modules,
                 module, unknownTypeQName.getPrefix(), nodeToResolve.getLine());
-        final TypeDefinitionBuilder lookedUpBuilder = findTypedefBuilderByName(
-                dependentModule, unknownTypeQName.getLocalName(),
-                module.getName(), nodeToResolve.getLine());
+        final TypeDefinitionBuilder lookedUpBuilder = findTypeDefinitionBuilder(
+                nodeToResolve.getPath(), dependentModule,
+                unknownTypeQName.getLocalName(), module.getName(),
+                nodeToResolve.getLine());
 
         final TypeDefinitionBuilder lookedUpBuilderCopy = copyTypedefBuilder(
                 lookedUpBuilder, nodeToResolve instanceof TypeDefinitionBuilder);
@@ -361,12 +361,13 @@ public final class YangParserImpl implements YangModelParser {
             final TypeDefinitionBuilder old, final boolean seekByTypedefBuilder) {
         if (old instanceof UnionTypeBuilder) {
             final UnionTypeBuilder oldUnion = (UnionTypeBuilder) old;
-            final UnionTypeBuilder newUnion = new UnionTypeBuilder(old.getLine());
+            final UnionTypeBuilder newUnion = new UnionTypeBuilder(
+                    old.getLine());
             for (TypeDefinition<?> td : oldUnion.getTypes()) {
                 newUnion.setType(td);
             }
             for (TypeDefinitionBuilder tdb : oldUnion.getTypedefs()) {
-                newUnion.setType(copyTypedefBuilder(tdb, true));
+                newUnion.setTypedef(copyTypedefBuilder(tdb, true));
             }
             newUnion.setPath(old.getPath());
             return newUnion;
@@ -376,8 +377,8 @@ public final class YangParserImpl implements YangModelParser {
         final QName newName = new QName(oldName.getNamespace(),
                 oldName.getRevision(), oldName.getPrefix(),
                 oldName.getLocalName());
-        final TypeDefinitionBuilder tdb = new TypedefBuilder(newName,
-                old.getLine());
+        final TypeDefinitionBuilder tdb = new TypeDefinitionBuilderImpl(
+                newName, old.getLine());
 
         tdb.setRanges(old.getRanges());
         tdb.setLengths(old.getLengths());
@@ -387,7 +388,7 @@ public final class YangParserImpl implements YangModelParser {
 
         final TypeDefinition<?> oldType = old.getType();
         if (oldType == null) {
-            tdb.setType(old.getTypedef());
+            tdb.setTypedef(old.getTypedef());
         } else {
             tdb.setType(oldType);
         }
@@ -416,7 +417,7 @@ public final class YangParserImpl implements YangModelParser {
                     final UnknownType unknownType = (UnknownType) td;
                     final TypeDefinitionBuilder resolvedType = resolveTypeUnion(
                             union, unknownType, modules, builder);
-                    union.setType(resolvedType);
+                    union.setTypedef(resolvedType);
                     toRemove.add(unknownType);
                 }
             }
@@ -435,9 +436,9 @@ public final class YangParserImpl implements YangModelParser {
             final String unknownTypePrefix = unknownTypeQName.getPrefix();
             final ModuleBuilder dependentModule = findDependentModule(modules,
                     builder, unknownTypePrefix, copy.getLine());
-            final TypeDefinitionBuilder utBuilder = getTypedefBuilder(copy,
-                    modules, dependentModule);
-            copy.setType(utBuilder);
+            final TypeDefinitionBuilder utBuilder = getTypeDefinitionBuilderFromDirtyNode(
+                    copy, modules, dependentModule);
+            copy.setTypedef(utBuilder);
             return copy;
         } else if (base == null && baseTdb != null) {
             // make a copy of baseTypeDef and call again
@@ -445,27 +446,14 @@ public final class YangParserImpl implements YangModelParser {
                     baseTdb, true);
             final TypeDefinitionBuilder baseTdbCopyResolved = resolveCopiedBuilder(
                     baseTdbCopy, modules, builder);
-            copy.setType(baseTdbCopyResolved);
+            copy.setTypedef(baseTdbCopyResolved);
             return copy;
         } else {
-            throw new IllegalStateException("Failed to resolve type "
-                    + copy.getQName().getLocalName());
+            throw new YangParseException(copy.getLine(),
+                    "Failed to resolve type " + copy.getQName().getLocalName());
         }
     }
 
-    private TypeDefinitionBuilder findTypedefBuilder(
-            final QName unknownTypeQName,
-            final Map<String, TreeMap<Date, ModuleBuilder>> modules,
-            final ModuleBuilder builder, int line) {
-        // search for module which contains referenced typedef
-        final ModuleBuilder dependentModule = findDependentModule(modules,
-                builder, unknownTypeQName.getPrefix(), line);
-        final TypeDefinitionBuilder lookedUpBuilder = findTypedefBuilderByName(
-                dependentModule, unknownTypeQName.getLocalName(),
-                builder.getName(), line);
-        return copyTypedefBuilder(lookedUpBuilder, true);
-    }
-
     private TypeConstraints findConstraints(
             final TypeAwareBuilder nodeToResolve,
             final TypeConstraints constraints,
@@ -505,7 +493,8 @@ public final class YangParserImpl implements YangModelParser {
             fractionDigits = ext.getFractionDigits();
             constraints.setFractionDigits(fractionDigits);
             return findConstraints(
-                    findTypedefBuilder(ext.getQName(), modules, builder,
+                    findTypeDefinitionBuilder(nodeToResolve.getPath(), builder,
+                            ext.getQName().getLocalName(), builder.getName(),
                             nodeToResolve.getLine()), constraints, modules,
                     builder);
         } else if (referencedType instanceof UnknownType) {
@@ -526,8 +515,9 @@ public final class YangParserImpl implements YangModelParser {
             final ModuleBuilder dependentModule = findDependentModule(modules,
                     builder, unknown.getQName().getPrefix(),
                     nodeToResolve.getLine());
-            final TypeDefinitionBuilder utBuilder = findTypedefBuilder(
-                    unknown.getQName(), modules, builder,
+            final TypeDefinitionBuilder utBuilder = findTypeDefinitionBuilder(
+                    nodeToResolve.getPath(), dependentModule, unknown
+                            .getQName().getLocalName(), builder.getName(),
                     nodeToResolve.getLine());
             return findConstraints(utBuilder, constraints, modules,
                     dependentModule);
@@ -541,29 +531,71 @@ public final class YangParserImpl implements YangModelParser {
     /**
      * Search for type definition builder by name.
      *
+     * @param dirtyNodeSchemaPath
+     *            schema path of node which contains unresolved type
      * @param dependentModule
-     *            module to search
-     * @param name
+     *            module which should contains referenced type
+     * @param typeName
      *            name of type definition
      * @param currentModuleName
-     *            current module name
+     *            name of current module
      * @param line
      *            current line in yang model
      * @return
      */
-    private TypeDefinitionBuilder findTypedefBuilderByName(
-            final ModuleBuilder dependentModule, final String name,
+    private TypeDefinitionBuilder findTypeDefinitionBuilder(
+            SchemaPath dirtyNodeSchemaPath,
+            final ModuleBuilder dependentModule, final String typeName,
             final String currentModuleName, final int line) {
-        final Set<TypeDefinitionBuilder> typedefs = dependentModule
+        final List<QName> path = dirtyNodeSchemaPath.getPath();
+        TypeDefinitionBuilder result = null;
+
+        Set<TypeDefinitionBuilder> typedefs = dependentModule
                 .getModuleTypedefs();
-        for (TypeDefinitionBuilder td : typedefs) {
+        result = findTdb(typedefs, typeName);
+
+        if (result == null) {
+            Builder currentNode = null;
+            final List<String> currentPath = new ArrayList<String>();
+            currentPath.add(dependentModule.getName());
+
+            for (int i = 0; i < path.size(); i++) {
+                QName qname = path.get(i);
+                currentPath.add(qname.getLocalName());
+                currentNode = dependentModule.getModuleNode(currentPath);
+
+                if (currentNode instanceof RpcDefinitionBuilder) {
+                    typedefs = ((RpcDefinitionBuilder) currentNode)
+                            .getTypeDefinitions();
+                } else if (currentNode instanceof DataNodeContainerBuilder) {
+                    typedefs = ((DataNodeContainerBuilder) currentNode)
+                            .getTypeDefinitions();
+                } else {
+                    typedefs = Collections.emptySet();
+                }
+
+                result = findTdb(typedefs, typeName);
+                if (result != null) {
+                    break;
+                }
+            }
+        }
+
+        if (result != null) {
+            return result;
+        }
+        throw new YangParseException(currentModuleName, line,
+                "Referenced type '" + typeName + "' not found.");
+    }
+
+    private TypeDefinitionBuilder findTdb(Set<TypeDefinitionBuilder> types,
+            String name) {
+        for (TypeDefinitionBuilder td : types) {
             if (td.getQName().getLocalName().equals(name)) {
                 return td;
             }
         }
-        throw new YangParseException(currentModuleName, line, "Target module '"
-                + dependentModule.getName() + "' does not contain typedef '"
-                + name + "'.");
+        return null;
     }
 
     /**
@@ -622,7 +654,7 @@ public final class YangParserImpl implements YangModelParser {
             // while all augments are not resolved
             final Iterator<ModuleBuilder> allModulesIterator = allModulesSet
                     .iterator();
-            while (!(module.getAugmentsResolved() == module.getAddedAugments()
+            while (!(module.getAugmentsResolved() == module.getAugments()
                     .size())) {
                 ModuleBuilder nextModule = null;
                 // try resolve other module augments
@@ -650,9 +682,9 @@ public final class YangParserImpl implements YangModelParser {
     private void resolveAugment(
             final Map<String, TreeMap<Date, ModuleBuilder>> modules,
             final ModuleBuilder module) {
-        if (module.getAugmentsResolved() < module.getAddedAugments().size()) {
+        if (module.getAugmentsResolved() < module.getAugments().size()) {
             for (AugmentationSchemaBuilder augmentBuilder : module
-                    .getAddedAugments()) {
+                    .getAugments()) {
 
                 if (!augmentBuilder.isResolved()) {
                     final SchemaPath augmentTargetSchemaPath = augmentBuilder
@@ -678,10 +710,14 @@ public final class YangParserImpl implements YangModelParser {
                         }
                     }
 
+                    if (currentParent == null) {
+                        continue;
+                    }
+
                     for (int i = 1; i < path.size(); i++) {
                         final QName currentQName = path.get(i);
                         DataSchemaNodeBuilder newParent = null;
-                        for (DataSchemaNodeBuilder child : ((ChildNodeBuilder) currentParent)
+                        for (DataSchemaNodeBuilder child : ((DataNodeContainerBuilder) currentParent)
                                 .getChildNodes()) {
                             final QName childQName = child.getQName();
                             if (childQName.getLocalName().equals(
@@ -702,8 +738,14 @@ public final class YangParserImpl implements YangModelParser {
                             .get(path.size() - 1);
                     if (currentQName.getLocalName().equals(
                             lastAugmentPathElement.getLocalName())) {
-                        ParserUtils.fillAugmentTarget(augmentBuilder,
-                                (ChildNodeBuilder) currentParent);
+
+                        if(currentParent instanceof ChoiceBuilder) {
+                            ParserUtils.fillAugmentTarget(augmentBuilder,
+                                    (ChoiceBuilder) currentParent);
+                        } else {
+                            ParserUtils.fillAugmentTarget(augmentBuilder,
+                                    (DataNodeContainerBuilder) currentParent);
+                        }
                         ((AugmentationTargetBuilder) currentParent)
                                 .addAugmentation(augmentBuilder);
                         SchemaPath oldPath = currentParent.getPath();
@@ -731,7 +773,7 @@ public final class YangParserImpl implements YangModelParser {
             final Map<String, TreeMap<Date, ModuleBuilder>> modules,
             final ModuleBuilder module) {
         final Set<IdentitySchemaNodeBuilder> identities = module
-                .getAddedIdentities();
+                .getIdentities();
         for (IdentitySchemaNodeBuilder identity : identities) {
             final String baseIdentityName = identity.getBaseIdentityName();
             if (baseIdentityName != null) {
@@ -749,7 +791,7 @@ public final class YangParserImpl implements YangModelParser {
                         modules, module, baseIdentityPrefix, identity.getLine());
 
                 final Set<IdentitySchemaNodeBuilder> dependentModuleIdentities = dependentModule
-                        .getAddedIdentities();
+                        .getIdentities();
                 for (IdentitySchemaNodeBuilder idBuilder : dependentModuleIdentities) {
                     if (idBuilder.getQName().getLocalName()
                             .equals(baseIdentityLocalName)) {
@@ -769,11 +811,11 @@ public final class YangParserImpl implements YangModelParser {
      * @param module
      *            module being resolved
      */
-    private void resolveUses(
+    private void resolveUsesRefines(
             final Map<String, TreeMap<Date, ModuleBuilder>> modules,
             final ModuleBuilder module) {
         final Map<List<String>, UsesNodeBuilder> moduleUses = module
-                .getAddedUsesNodes();
+                .getUsesNodes();
         for (Map.Entry<List<String>, UsesNodeBuilder> entry : moduleUses
                 .entrySet()) {
             final List<String> key = entry.getKey();
@@ -783,8 +825,9 @@ public final class YangParserImpl implements YangModelParser {
             final String groupingName = key.get(key.size() - 1);
 
             for (RefineHolder refine : usesNode.getRefines()) {
-                Builder refineTarget = getRefineNodeBuilderCopy(groupingName,
-                        refine, modules, module);
+                SchemaNodeBuilder refineTarget = getRefineNodeBuilderCopy(
+                        groupingName, refine, modules, module);
+                ParserUtils.checkRefine(refineTarget, refine);
                 ParserUtils.refineDefault(refineTarget, refine, line);
                 if (refineTarget instanceof LeafSchemaNodeBuilder) {
                     final LeafSchemaNodeBuilder leaf = (LeafSchemaNodeBuilder) refineTarget;
@@ -810,10 +853,10 @@ public final class YangParserImpl implements YangModelParser {
                     final AnyXmlBuilder anyXml = (AnyXmlBuilder) refineTarget;
                     ParserUtils.refineAnyxml(anyXml, refine, line);
                     usesNode.addRefineNode(anyXml);
-                } else if(refineTarget instanceof GroupingBuilder) {
-                    usesNode.addRefineNode((GroupingBuilder)refineTarget);
-                } else if(refineTarget instanceof TypedefBuilder) {
-                    usesNode.addRefineNode((TypedefBuilder)refineTarget);
+                } else if (refineTarget instanceof GroupingBuilder) {
+                    usesNode.addRefineNode(refineTarget);
+                } else if (refineTarget instanceof TypeDefinitionBuilder) {
+                    usesNode.addRefineNode(refineTarget);
                 }
             }
         }
@@ -822,8 +865,8 @@ public final class YangParserImpl implements YangModelParser {
     /**
      * Find original builder of node to refine and return copy of this builder.
      * <p>
-     * We must make a copy of builder to preserve original builder, because this
-     * object will be refined (modified) and later added to
+     * We must create and use a copy of builder to preserve original builder
+     * state, because this object will be refined (modified) and later added to
      * {@link UsesNodeBuilder}.
      * </p>
      *
@@ -838,8 +881,8 @@ public final class YangParserImpl implements YangModelParser {
      * @return copy of node to be refined if it is present in grouping, null
      *         otherwise
      */
-    private Builder getRefineNodeBuilderCopy(final String groupingPath,
-            final RefineHolder refine,
+    private SchemaNodeBuilder getRefineNodeBuilderCopy(
+            final String groupingPath, final RefineHolder refine,
             final Map<String, TreeMap<Date, ModuleBuilder>> modules,
             final ModuleBuilder module) {
         Builder result = null;
@@ -868,12 +911,12 @@ public final class YangParserImpl implements YangModelParser {
                     .copyGroupingBuilder((GroupingBuilder) lookedUpBuilder);
         } else if (lookedUpBuilder instanceof TypeDefinitionBuilder) {
             result = ParserUtils
-                    .copyTypedefBuilder((TypedefBuilder) lookedUpBuilder);
+                    .copyTypedefBuilder((TypeDefinitionBuilderImpl) lookedUpBuilder);
         } else {
             throw new YangParseException(module.getName(), refine.getLine(),
                     "Target '" + refine.getName() + "' can not be refined");
         }
-        return result;
+        return (SchemaNodeBuilder) result;
     }
 
     /**
@@ -908,25 +951,24 @@ public final class YangParserImpl implements YangModelParser {
 
         final ModuleBuilder dependentModule = findDependentModule(modules,
                 module, prefix, refine.getLine());
-        builderPath.add(0, "grouping");
         builderPath.add(0, dependentModule.getName());
-        final GroupingBuilder builder = (GroupingBuilder) dependentModule
-                .getNode(builderPath);
+        final GroupingBuilder builder = dependentModule
+                .getGrouping(builderPath);
 
         Builder result = builder.getChildNode(refineNodeName);
-        if(result == null) {
+        if (result == null) {
             Set<GroupingBuilder> grps = builder.getGroupings();
-            for(GroupingBuilder gr : grps) {
-                if(gr.getQName().getLocalName().equals(refineNodeName)) {
+            for (GroupingBuilder gr : grps) {
+                if (gr.getQName().getLocalName().equals(refineNodeName)) {
                     result = gr;
                     break;
                 }
             }
         }
-        if(result == null) {
-            Set<TypeDefinitionBuilder> typedefs = builder.getTypedefs();
-            for(TypeDefinitionBuilder typedef : typedefs) {
-                if(typedef.getQName().getLocalName().equals(refineNodeName)) {
+        if (result == null) {
+            Set<TypeDefinitionBuilder> typedefs = builder.getTypeDefinitions();
+            for (TypeDefinitionBuilder typedef : typedefs) {
+                if (typedef.getQName().getLocalName().equals(refineNodeName)) {
                     result = typedef;
                     break;
                 }
@@ -962,7 +1004,7 @@ public final class YangParserImpl implements YangModelParser {
     private void resolveUnknownNodes(
             final Map<String, TreeMap<Date, ModuleBuilder>> modules,
             final ModuleBuilder module) {
-        for (UnknownSchemaNodeBuilder usnb : module.getAddedUnknownNodes()) {
+        for (UnknownSchemaNodeBuilder usnb : module.getUnknownNodes()) {
             QName nodeType = usnb.getNodeType();
             if (nodeType.getNamespace() == null
                     || nodeType.getRevision() == null) {
@@ -992,6 +1034,8 @@ public final class YangParserImpl implements YangModelParser {
      *            current module
      * @param prefix
      *            target module prefix
+     * @param line
+     *            current line in yang model
      * @return
      */
     private ModuleBuilder findDependentModule(
index b853dcf..8b73909 100644 (file)
@@ -58,6 +58,8 @@ import org.opendaylight.controller.yang.model.api.TypeDefinition;
 import org.opendaylight.controller.yang.model.util.YangTypesConverter;
 import org.opendaylight.controller.yang.parser.builder.api.AugmentationSchemaBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.GroupingBuilder;
+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.ChoiceCaseBuilder;
@@ -72,7 +74,6 @@ import org.opendaylight.controller.yang.parser.builder.impl.ListSchemaNodeBuilde
 import org.opendaylight.controller.yang.parser.builder.impl.ModuleBuilder;
 import org.opendaylight.controller.yang.parser.builder.impl.NotificationBuilder;
 import org.opendaylight.controller.yang.parser.builder.impl.RpcDefinitionBuilder;
-import org.opendaylight.controller.yang.parser.builder.impl.TypedefBuilder;
 import org.opendaylight.controller.yang.parser.builder.impl.UnionTypeBuilder;
 import org.opendaylight.controller.yang.parser.builder.impl.UnknownSchemaNodeBuilder;
 import org.opendaylight.controller.yang.parser.util.RefineHolder;
@@ -240,6 +241,7 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
         final String augmentPath = stringFromNode(ctx);
         AugmentationSchemaBuilder builder = moduleBuilder.addAugment(
                 augmentPath, actualPath, ctx.getStart().getLine());
+        moduleBuilder.enterNode(builder);
         updatePath(augmentPath);
 
         for (int i = 0; i < ctx.getChildCount(); i++) {
@@ -264,6 +266,7 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
     public void exitAugment_stmt(YangParser.Augment_stmtContext ctx) {
         final String augment = actualPath.pop();
         logger.debug("exiting augment " + augment);
+        moduleBuilder.exitNode();
     }
 
     @Override
@@ -293,8 +296,9 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
         final String typedefName = stringFromNode(ctx);
         QName typedefQName = new QName(namespace, revision, yangModelPrefix,
                 typedefName);
-        TypedefBuilder builder = moduleBuilder.addTypedef(typedefQName,
+        TypeDefinitionBuilder builder = moduleBuilder.addTypedef(typedefQName,
                 actualPath, ctx.getStart().getLine());
+        moduleBuilder.enterNode(builder);
         updatePath(typedefName);
 
         builder.setPath(createActualSchemaPath(actualPath, namespace, revision,
@@ -307,6 +311,7 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
     public void exitTypedef_stmt(YangParser.Typedef_stmtContext ctx) {
         final String actContainer = actualPath.pop();
         logger.debug("exiting " + actContainer);
+        moduleBuilder.exitNode();
     }
 
     @Override
@@ -338,9 +343,11 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
                     List<String> typePath = new ArrayList<String>(actualPath);
                     typePath.add(typeName);
 
-                    SchemaPath p = createActualSchemaPath(typePath, namespace, revision, yangModelPrefix);
-                    UnionTypeBuilder unionBuilder = moduleBuilder.addUnionType(actualPath, namespace, revision,
-                            line);
+                    SchemaPath p = createActualSchemaPath(typePath, namespace,
+                            revision, yangModelPrefix);
+                    UnionTypeBuilder unionBuilder = moduleBuilder.addUnionType(
+                            actualPath, namespace, revision, line);
+                    moduleBuilder.enterNode(unionBuilder);
                     unionBuilder.setPath(p);
                 } else if ("identityref".equals(typeName)) {
                     SchemaPath path = createActualSchemaPath(actualPath,
@@ -389,6 +396,11 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
     public void exitType_stmt(YangParser.Type_stmtContext ctx) {
         final String actContainer = actualPath.pop();
         logger.debug("exiting " + actContainer);
+
+        final String typeName = stringFromNode(ctx);
+        if ("union".equals(typeName)) {
+            moduleBuilder.exitNode();
+        }
     }
 
     @Override
@@ -396,11 +408,12 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
         final String groupName = stringFromNode(ctx);
         QName groupQName = new QName(namespace, revision, yangModelPrefix,
                 groupName);
-        GroupingBuilder groupBuilder = moduleBuilder.addGrouping(groupQName,
+        GroupingBuilder builder = moduleBuilder.addGrouping(groupQName,
                 actualPath, ctx.getStart().getLine());
+        moduleBuilder.enterNode(builder);
         updatePath("grouping");
         updatePath(groupName);
-        parseSchemaNodeArgs(ctx, groupBuilder);
+        parseSchemaNodeArgs(ctx, builder);
     }
 
     @Override
@@ -408,6 +421,7 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
         String actContainer = actualPath.pop();
         actContainer += "-" + actualPath.pop();
         logger.debug("exiting " + actContainer);
+        moduleBuilder.exitNode();
     }
 
     @Override
@@ -415,19 +429,20 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
         final String containerName = stringFromNode(ctx);
         QName containerQName = new QName(namespace, revision, yangModelPrefix,
                 containerName);
-        ContainerSchemaNodeBuilder containerBuilder = moduleBuilder
-                .addContainerNode(containerQName, actualPath, ctx.getStart().getLine());
+        ContainerSchemaNodeBuilder builder = moduleBuilder.addContainerNode(
+                containerQName, actualPath, ctx.getStart().getLine());
+        moduleBuilder.enterNode(builder);
         updatePath(containerName);
 
-        containerBuilder.setPath(createActualSchemaPath(actualPath, namespace,
-                revision, yangModelPrefix));
-        parseSchemaNodeArgs(ctx, containerBuilder);
-        parseConstraints(ctx, containerBuilder.getConstraints());
+        builder.setPath(createActualSchemaPath(actualPath, namespace, revision,
+                yangModelPrefix));
+        parseSchemaNodeArgs(ctx, builder);
+        parseConstraints(ctx, builder.getConstraints());
 
         for (int i = 0; i < ctx.getChildCount(); ++i) {
             final ParseTree childNode = ctx.getChild(i);
             if (childNode instanceof Presence_stmtContext) {
-                containerBuilder.setPresence(true);
+                builder.setPresence(true);
                 break;
             }
         }
@@ -437,6 +452,7 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
     public void exitContainer_stmt(Container_stmtContext ctx) {
         final String actContainer = actualPath.pop();
         logger.debug("exiting " + actContainer);
+        moduleBuilder.exitNode();
     }
 
     @Override
@@ -444,14 +460,15 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
         final String leafName = stringFromNode(ctx);
         QName leafQName = new QName(namespace, revision, yangModelPrefix,
                 leafName);
-        LeafSchemaNodeBuilder leafBuilder = moduleBuilder.addLeafNode(
-                leafQName, actualPath, ctx.getStart().getLine());
+        LeafSchemaNodeBuilder builder = moduleBuilder.addLeafNode(leafQName,
+                actualPath, ctx.getStart().getLine());
+        moduleBuilder.enterNode(builder);
         updatePath(leafName);
 
-        leafBuilder.setPath(createActualSchemaPath(actualPath, namespace,
-                revision, yangModelPrefix));
-        parseSchemaNodeArgs(ctx, leafBuilder);
-        parseConstraints(ctx, leafBuilder.getConstraints());
+        builder.setPath(createActualSchemaPath(actualPath, namespace, revision,
+                yangModelPrefix));
+        parseSchemaNodeArgs(ctx, builder);
+        parseConstraints(ctx, builder.getConstraints());
 
         String defaultStr = null;
         String unitsStr = null;
@@ -463,21 +480,23 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
                 unitsStr = stringFromNode(child);
             }
         }
-        leafBuilder.setDefaultStr(defaultStr);
-        leafBuilder.setUnits(unitsStr);
+        builder.setDefaultStr(defaultStr);
+        builder.setUnits(unitsStr);
     }
 
     @Override
     public void exitLeaf_stmt(YangParser.Leaf_stmtContext ctx) {
         final String actLeaf = actualPath.pop();
         logger.debug("exiting " + actLeaf);
+        moduleBuilder.exitNode();
     }
 
     @Override
     public void enterUses_stmt(YangParser.Uses_stmtContext ctx) {
         final String groupingPathStr = stringFromNode(ctx);
-        moduleBuilder.addUsesNode(groupingPathStr, actualPath, ctx.getStart()
-                .getLine());
+        UsesNodeBuilder builder = moduleBuilder.addUsesNode(groupingPathStr,
+                actualPath, ctx.getStart().getLine());
+        moduleBuilder.enterNode(builder);
         updatePath(groupingPathStr);
     }
 
@@ -485,6 +504,7 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
     public void exitUses_stmt(YangParser.Uses_stmtContext ctx) {
         final String actContainer = actualPath.pop();
         logger.debug("exiting " + actContainer);
+        moduleBuilder.exitNode();
     }
 
     @Override
@@ -492,6 +512,7 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
         String refineString = stringFromNode(ctx);
         RefineHolder refine = parseRefine(ctx);
         moduleBuilder.addRefine(refine, actualPath);
+        moduleBuilder.enterNode(refine);
         updatePath(refineString);
     }
 
@@ -499,6 +520,7 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
     public void exitRefine_stmt(YangParser.Refine_stmtContext ctx) {
         final String actContainer = actualPath.pop();
         logger.debug("exiting " + actContainer);
+        moduleBuilder.exitNode();
     }
 
     @Override
@@ -506,20 +528,22 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
         final String leafListName = stringFromNode(ctx);
         QName leafListQName = new QName(namespace, revision, yangModelPrefix,
                 leafListName);
-        LeafListSchemaNodeBuilder leafListBuilder = moduleBuilder
-                .addLeafListNode(leafListQName, actualPath, ctx.getStart()
-                        .getLine());
+        LeafListSchemaNodeBuilder builder = moduleBuilder.addLeafListNode(
+                leafListQName, actualPath, ctx.getStart().getLine());
+        moduleBuilder.enterNode(builder);
         updatePath(leafListName);
 
-        parseSchemaNodeArgs(ctx, leafListBuilder);
-        parseConstraints(ctx, leafListBuilder.getConstraints());
+        builder.setPath(createActualSchemaPath(actualPath, namespace, revision,
+                yangModelPrefix));
+        parseSchemaNodeArgs(ctx, builder);
+        parseConstraints(ctx, builder.getConstraints());
 
         for (int i = 0; i < ctx.getChildCount(); ++i) {
             final ParseTree childNode = ctx.getChild(i);
             if (childNode instanceof Ordered_by_stmtContext) {
                 final Ordered_by_stmtContext orderedBy = (Ordered_by_stmtContext) childNode;
                 final boolean userOrdered = parseUserOrdered(orderedBy);
-                leafListBuilder.setUserOrdered(userOrdered);
+                builder.setUserOrdered(userOrdered);
                 break;
             }
         }
@@ -529,6 +553,7 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
     public void exitLeaf_list_stmt(YangParser.Leaf_list_stmtContext ctx) {
         final String actContainer = actualPath.pop();
         logger.debug("exiting " + actContainer);
+        moduleBuilder.exitNode();
     }
 
     @Override
@@ -536,14 +561,15 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
         final String containerName = stringFromNode(ctx);
         QName containerQName = new QName(namespace, revision, yangModelPrefix,
                 containerName);
-        ListSchemaNodeBuilder listBuilder = moduleBuilder.addListNode(
+        ListSchemaNodeBuilder builder = moduleBuilder.addListNode(
                 containerQName, actualPath, ctx.getStart().getLine());
+        moduleBuilder.enterNode(builder);
         updatePath(containerName);
 
-        listBuilder.setPath(createActualSchemaPath(actualPath, namespace,
-                revision, yangModelPrefix));
-        parseSchemaNodeArgs(ctx, listBuilder);
-        parseConstraints(ctx, listBuilder.getConstraints());
+        builder.setPath(createActualSchemaPath(actualPath, namespace, revision,
+                yangModelPrefix));
+        parseSchemaNodeArgs(ctx, builder);
+        parseConstraints(ctx, builder.getConstraints());
 
         String keyDefinition = "";
         for (int i = 0; i < ctx.getChildCount(); ++i) {
@@ -551,12 +577,12 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
             if (childNode instanceof Ordered_by_stmtContext) {
                 final Ordered_by_stmtContext orderedBy = (Ordered_by_stmtContext) childNode;
                 final boolean userOrdered = parseUserOrdered(orderedBy);
-                listBuilder.setUserOrdered(userOrdered);
+                builder.setUserOrdered(userOrdered);
             } else if (childNode instanceof Key_stmtContext) {
                 keyDefinition = stringFromNode(childNode);
                 List<QName> key = createListKey(keyDefinition, namespace,
                         revision, yangModelPrefix);
-                listBuilder.setKeyDefinition(key);
+                builder.setKeyDefinition(key);
             }
         }
     }
@@ -565,6 +591,7 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
     public void exitList_stmt(List_stmtContext ctx) {
         final String actContainer = actualPath.pop();
         logger.debug("exiting " + actContainer);
+        moduleBuilder.exitNode();
     }
 
     @Override
@@ -572,20 +599,22 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
         final String anyXmlName = stringFromNode(ctx);
         QName anyXmlQName = new QName(namespace, revision, yangModelPrefix,
                 anyXmlName);
-        AnyXmlBuilder anyXmlBuilder = moduleBuilder.addAnyXml(anyXmlQName,
+        AnyXmlBuilder builder = moduleBuilder.addAnyXml(anyXmlQName,
                 actualPath, ctx.getStart().getLine());
+        moduleBuilder.enterNode(builder);
         updatePath(anyXmlName);
 
-        anyXmlBuilder.setPath(createActualSchemaPath(actualPath, namespace,
-                revision, yangModelPrefix));
-        parseSchemaNodeArgs(ctx, anyXmlBuilder);
-        parseConstraints(ctx, anyXmlBuilder.getConstraints());
+        builder.setPath(createActualSchemaPath(actualPath, namespace, revision,
+                yangModelPrefix));
+        parseSchemaNodeArgs(ctx, builder);
+        parseConstraints(ctx, builder.getConstraints());
     }
 
     @Override
     public void exitAnyxml_stmt(YangParser.Anyxml_stmtContext ctx) {
         final String actContainer = actualPath.pop();
         logger.debug("exiting " + actContainer);
+        moduleBuilder.exitNode();
     }
 
     @Override
@@ -593,21 +622,22 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
         final String choiceName = stringFromNode(ctx);
         QName choiceQName = new QName(namespace, revision, yangModelPrefix,
                 choiceName);
-        ChoiceBuilder choiceBuilder = moduleBuilder.addChoice(choiceQName,
+        ChoiceBuilder builder = moduleBuilder.addChoice(choiceQName,
                 actualPath, ctx.getStart().getLine());
+        moduleBuilder.enterNode(builder);
 
         updatePath(choiceName);
-        choiceBuilder.setPath(createActualSchemaPath(actualPath, namespace,
-                revision, yangModelPrefix));
-        parseSchemaNodeArgs(ctx, choiceBuilder);
-        parseConstraints(ctx, choiceBuilder.getConstraints());
+        builder.setPath(createActualSchemaPath(actualPath, namespace, revision,
+                yangModelPrefix));
+        parseSchemaNodeArgs(ctx, builder);
+        parseConstraints(ctx, builder.getConstraints());
 
         // set 'default' case
         for (int i = 0; i < ctx.getChildCount(); i++) {
             ParseTree child = ctx.getChild(i);
             if (child instanceof Default_stmtContext) {
                 String defaultCase = stringFromNode(child);
-                choiceBuilder.setDefaultCase(defaultCase);
+                builder.setDefaultCase(defaultCase);
                 break;
             }
         }
@@ -617,6 +647,7 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
     public void exitChoice_stmt(YangParser.Choice_stmtContext ctx) {
         final String actContainer = actualPath.pop();
         logger.debug("exiting " + actContainer);
+        moduleBuilder.exitNode();
     }
 
     @Override
@@ -624,20 +655,22 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
         final String caseName = stringFromNode(ctx);
         QName choiceQName = new QName(namespace, revision, yangModelPrefix,
                 caseName);
-        ChoiceCaseBuilder caseBuilder = moduleBuilder.addCase(choiceQName,
+        ChoiceCaseBuilder builder = moduleBuilder.addCase(choiceQName,
                 actualPath, ctx.getStart().getLine());
+        moduleBuilder.enterNode(builder);
 
         updatePath(caseName);
-        caseBuilder.setPath(createActualSchemaPath(actualPath, namespace,
-                revision, yangModelPrefix));
-        parseSchemaNodeArgs(ctx, caseBuilder);
-        parseConstraints(ctx, caseBuilder.getConstraints());
+        builder.setPath(createActualSchemaPath(actualPath, namespace, revision,
+                yangModelPrefix));
+        parseSchemaNodeArgs(ctx, builder);
+        parseConstraints(ctx, builder.getConstraints());
     }
 
     @Override
     public void exitCase_stmt(YangParser.Case_stmtContext ctx) {
         final String actContainer = actualPath.pop();
         logger.debug("exiting " + actContainer);
+        moduleBuilder.exitNode();
     }
 
     @Override
@@ -645,20 +678,21 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
         final String notificationName = stringFromNode(ctx);
         QName notificationQName = new QName(namespace, revision,
                 yangModelPrefix, notificationName);
-        NotificationBuilder notificationBuilder = moduleBuilder
-                .addNotification(notificationQName, actualPath, ctx.getStart()
-                        .getLine());
+        NotificationBuilder builder = moduleBuilder.addNotification(
+                notificationQName, actualPath, ctx.getStart().getLine());
+        moduleBuilder.enterNode(builder);
         updatePath(notificationName);
 
-        notificationBuilder.setPath(createActualSchemaPath(actualPath,
-                namespace, revision, yangModelPrefix));
-        parseSchemaNodeArgs(ctx, notificationBuilder);
+        builder.setPath(createActualSchemaPath(actualPath, namespace, revision,
+                yangModelPrefix));
+        parseSchemaNodeArgs(ctx, builder);
     }
 
     @Override
     public void exitNotification_stmt(YangParser.Notification_stmtContext ctx) {
         final String actContainer = actualPath.pop();
         logger.debug("exiting " + actContainer);
+        moduleBuilder.exitNode();
     }
 
     // Unknown types
@@ -699,12 +733,14 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
         builder.setPath(createActualSchemaPath(actualPath, namespace, revision,
                 yangModelPrefix));
         parseSchemaNodeArgs(ctx, builder);
+        moduleBuilder.enterNode(builder);
     }
 
     @Override
     public void exitIdentifier_stmt(YangParser.Identifier_stmtContext ctx) {
         final String actContainer = actualPath.pop();
         logger.debug("exiting " + actContainer);
+        moduleBuilder.exitNode();
     }
 
     @Override
@@ -714,6 +750,7 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
                 rpcName);
         RpcDefinitionBuilder rpcBuilder = moduleBuilder.addRpc(rpcQName,
                 actualPath, ctx.getStart().getLine());
+        moduleBuilder.enterNode(rpcBuilder);
         updatePath(rpcName);
 
         rpcBuilder.setPath(createActualSchemaPath(actualPath, namespace,
@@ -725,28 +762,51 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
     public void exitRpc_stmt(YangParser.Rpc_stmtContext ctx) {
         final String actContainer = actualPath.pop();
         logger.debug("exiting " + actContainer);
+        moduleBuilder.exitNode();
     }
 
     @Override
     public void enterInput_stmt(YangParser.Input_stmtContext ctx) {
-        updatePath("input");
+        final String input = "input";
+        QName rpcQName = new QName(namespace, revision, yangModelPrefix, input);
+        ContainerSchemaNodeBuilder builder = moduleBuilder.addRpcInput(
+                rpcQName, ctx.getStart().getLine());
+        moduleBuilder.enterNode(builder);
+        updatePath(input);
+
+        builder.setPath(createActualSchemaPath(actualPath, namespace, revision,
+                yangModelPrefix));
+        parseSchemaNodeArgs(ctx, builder);
+        parseConstraints(ctx, builder.getConstraints());
     }
 
     @Override
     public void exitInput_stmt(YangParser.Input_stmtContext ctx) {
         final String actContainer = actualPath.pop();
         logger.debug("exiting " + actContainer);
+        moduleBuilder.exitNode();
     }
 
     @Override
     public void enterOutput_stmt(YangParser.Output_stmtContext ctx) {
-        updatePath("output");
+        final String output = "output";
+        QName rpcQName = new QName(namespace, revision, yangModelPrefix, output);
+        ContainerSchemaNodeBuilder builder = moduleBuilder.addRpcOutput(
+                rpcQName, ctx.getStart().getLine());
+        moduleBuilder.enterNode(builder);
+        updatePath(output);
+
+        builder.setPath(createActualSchemaPath(actualPath, namespace, revision,
+                yangModelPrefix));
+        parseSchemaNodeArgs(ctx, builder);
+        parseConstraints(ctx, builder.getConstraints());
     }
 
     @Override
     public void exitOutput_stmt(YangParser.Output_stmtContext ctx) {
         final String actContainer = actualPath.pop();
         logger.debug("exiting " + actContainer);
+        moduleBuilder.exitNode();
     }
 
     @Override
@@ -756,6 +816,7 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
                 featureName);
         FeatureBuilder featureBuilder = moduleBuilder.addFeature(featureQName,
                 actualPath, ctx.getStart().getLine());
+        moduleBuilder.enterNode(featureBuilder);
         updatePath(featureName);
 
         featureBuilder.setPath(createActualSchemaPath(actualPath, namespace,
@@ -767,6 +828,7 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
     public void exitFeature_stmt(YangParser.Feature_stmtContext ctx) {
         final String actContainer = actualPath.pop();
         logger.debug("exiting " + actContainer);
+        moduleBuilder.exitNode();
     }
 
     @Override
@@ -776,6 +838,7 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
         String deviate = null;
         DeviationBuilder builder = moduleBuilder.addDeviation(targetPath,
                 actualPath, ctx.getStart().getLine());
+        moduleBuilder.enterNode(builder);
         updatePath(targetPath);
 
         for (int i = 0; i < ctx.getChildCount(); i++) {
@@ -800,12 +863,14 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
     public void exitDeviation_stmt(YangParser.Deviation_stmtContext ctx) {
         final String actContainer = actualPath.pop();
         logger.debug("exiting " + actContainer);
+        moduleBuilder.exitNode();
     }
 
     @Override
     public void enterConfig_stmt(YangParser.Config_stmtContext ctx) {
         boolean configuration = parseConfig(ctx);
-        moduleBuilder.addConfiguration(configuration, actualPath);
+        moduleBuilder.addConfiguration(configuration, actualPath, ctx
+                .getStart().getLine());
     }
 
     @Override
@@ -815,6 +880,7 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
                 yangModelPrefix, identityName);
         IdentitySchemaNodeBuilder builder = moduleBuilder.addIdentity(
                 identityQName, actualPath, ctx.getStart().getLine());
+        moduleBuilder.enterNode(builder);
         updatePath(identityName);
 
         builder.setPath(createActualSchemaPath(actualPath, namespace, revision,
@@ -834,6 +900,7 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
     public void exitIdentity_stmt(YangParser.Identity_stmtContext ctx) {
         final String actContainer = actualPath.pop();
         logger.debug("exiting " + actContainer);
+        moduleBuilder.exitNode();
     }
 
     public ModuleBuilder getModuleBuilder() {
index b4e250d..2e3f0cc 100644 (file)
@@ -51,7 +51,7 @@ import org.opendaylight.controller.yang.model.util.StringType;
 import org.opendaylight.controller.yang.model.util.UnionType;
 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.ChildNodeBuilder;
+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.SchemaNodeBuilder;
@@ -68,7 +68,7 @@ import org.opendaylight.controller.yang.parser.builder.impl.LeafListSchemaNodeBu
 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.TypedefBuilder;
+import org.opendaylight.controller.yang.parser.builder.impl.TypeDefinitionBuilderImpl;
 import org.opendaylight.controller.yang.parser.builder.impl.UnknownSchemaNodeBuilder;
 import org.opendaylight.controller.yang.parser.builder.impl.UsesNodeBuilderImpl;
 
@@ -133,7 +133,7 @@ public final class ParserUtils {
      */
     public static void fillAugmentTarget(
             final AugmentationSchemaBuilder augment,
-            final ChildNodeBuilder target) {
+            final DataNodeContainerBuilder target) {
         for (DataSchemaNodeBuilder builder : augment.getChildNodes()) {
             builder.setAugmenting(true);
             correctAugmentChildPath(augment, target.getPath());
@@ -141,7 +141,17 @@ public final class ParserUtils {
         }
     }
 
-    private static void correctAugmentChildPath(final ChildNodeBuilder node,
+    public static void fillAugmentTarget(
+            final AugmentationSchemaBuilder augment,
+            final ChoiceBuilder target) {
+        for (DataSchemaNodeBuilder builder : augment.getChildNodes()) {
+            builder.setAugmenting(true);
+            correctAugmentChildPath(augment, target.getPath());
+            target.addChildNode(builder);
+        }
+    }
+
+    private static void correctAugmentChildPath(final DataNodeContainerBuilder node,
             final SchemaPath parentSchemaPath) {
         for (DataSchemaNodeBuilder builder : node.getChildNodes()) {
 
@@ -151,149 +161,189 @@ public final class ParserUtils {
             targetNodePath.add(builder.getQName());
             builder.setPath(new SchemaPath(targetNodePath, true));
 
-            if (builder instanceof ChildNodeBuilder) {
-                ChildNodeBuilder cnb = (ChildNodeBuilder) builder;
+            if (builder instanceof DataNodeContainerBuilder) {
+                DataNodeContainerBuilder cnb = (DataNodeContainerBuilder) builder;
                 correctAugmentChildPath(cnb, builder.getPath());
             }
 
             // if child can contains type, correct path for this type too
-            if(builder instanceof TypeAwareBuilder) {
-                TypeAwareBuilder nodeBuilder = (TypeAwareBuilder)builder;
+            if (builder instanceof TypeAwareBuilder) {
+                TypeAwareBuilder nodeBuilder = (TypeAwareBuilder) builder;
                 QName nodeBuilderQName = nodeBuilder.getQName();
                 TypeDefinition<?> nodeBuilderType = nodeBuilder.getType();
-                if(nodeBuilderType != null) {
-                    TypeDefinition<?> newType = createCorrectTypeDefinition(parentSchemaPath, nodeBuilderQName, nodeBuilderType);
+                if (nodeBuilderType != null) {
+                    TypeDefinition<?> newType = createCorrectTypeDefinition(
+                            parentSchemaPath, nodeBuilderQName, nodeBuilderType);
                     nodeBuilder.setType(newType);
                 } else {
-                    TypeDefinitionBuilder nodeBuilderTypedef = nodeBuilder.getTypedef();
-                    SchemaPath newSchemaPath = createNewSchemaPath(nodeBuilderTypedef.getPath(), nodeBuilderQName, nodeBuilderTypedef.getQName());
+                    TypeDefinitionBuilder nodeBuilderTypedef = nodeBuilder
+                            .getTypedef();
+                    SchemaPath newSchemaPath = createNewSchemaPath(
+                            nodeBuilderTypedef.getPath(), nodeBuilderQName,
+                            nodeBuilderTypedef.getQName());
                     nodeBuilderTypedef.setPath(newSchemaPath);
                 }
             }
         }
     }
 
-    private static TypeDefinition<?> createCorrectTypeDefinition(SchemaPath parentSchemaPath, QName nodeQName, TypeDefinition<?> nodeType) {
+    private static TypeDefinition<?> createCorrectTypeDefinition(
+            SchemaPath parentSchemaPath, QName nodeQName,
+            TypeDefinition<?> nodeType) {
         TypeDefinition<?> result = null;
         SchemaPath newSchemaPath = null;
-        if(nodeType != null) {
-            if(nodeType instanceof BinaryTypeDefinition) {
-                BinaryTypeDefinition binType = (BinaryTypeDefinition)nodeType;
-                newSchemaPath = createNewSchemaPath(parentSchemaPath, nodeQName, binType.getQName());
-                List<Byte> bytes = (List<Byte>)binType.getDefaultValue();
-                result = new BinaryType(newSchemaPath, bytes, binType.getLengthConstraints(), binType.getUnits());
-            } else if(nodeType instanceof BitsTypeDefinition) {
-                BitsTypeDefinition bitsType = (BitsTypeDefinition)nodeType;
-                newSchemaPath = createNewSchemaPath(parentSchemaPath, nodeQName, nodeType.getQName());
-                result = new BitsType(newSchemaPath, bitsType.getBits(), bitsType.getUnits());
-            } else if(nodeType instanceof BooleanTypeDefinition) {
-                BooleanTypeDefinition booleanType = (BooleanTypeDefinition)nodeType;
-                newSchemaPath = createNewSchemaPath(parentSchemaPath, nodeQName, booleanType.getQName());
-                result = new BooleanType(newSchemaPath, (Boolean)booleanType.getDefaultValue(), booleanType.getUnits());
-            } else if(nodeType instanceof DecimalTypeDefinition) {
-                DecimalTypeDefinition decimalType = (DecimalTypeDefinition)nodeType;
-                newSchemaPath = createNewSchemaPath(parentSchemaPath, nodeQName, decimalType.getQName());
-                BigDecimal defaultValue = (BigDecimal)decimalType.getDefaultValue();
-                result = new Decimal64(newSchemaPath, decimalType.getUnits(), defaultValue, decimalType.getRangeStatements(), decimalType.getFractionDigits());
-            } else if(nodeType instanceof EmptyTypeDefinition) {
-                newSchemaPath = createNewSchemaPath(parentSchemaPath, nodeQName, nodeType.getQName());
+        if (nodeType != null) {
+            if (nodeType instanceof BinaryTypeDefinition) {
+                BinaryTypeDefinition binType = (BinaryTypeDefinition) nodeType;
+                newSchemaPath = createNewSchemaPath(parentSchemaPath,
+                        nodeQName, binType.getQName());
+                List<Byte> bytes = (List<Byte>) binType.getDefaultValue();
+                result = new BinaryType(newSchemaPath, bytes,
+                        binType.getLengthConstraints(), binType.getUnits());
+            } else if (nodeType instanceof BitsTypeDefinition) {
+                BitsTypeDefinition bitsType = (BitsTypeDefinition) nodeType;
+                newSchemaPath = createNewSchemaPath(parentSchemaPath,
+                        nodeQName, nodeType.getQName());
+                result = new BitsType(newSchemaPath, bitsType.getBits(),
+                        bitsType.getUnits());
+            } else if (nodeType instanceof BooleanTypeDefinition) {
+                BooleanTypeDefinition booleanType = (BooleanTypeDefinition) nodeType;
+                newSchemaPath = createNewSchemaPath(parentSchemaPath,
+                        nodeQName, booleanType.getQName());
+                result = new BooleanType(newSchemaPath,
+                        (Boolean) booleanType.getDefaultValue(),
+                        booleanType.getUnits());
+            } else if (nodeType instanceof DecimalTypeDefinition) {
+                DecimalTypeDefinition decimalType = (DecimalTypeDefinition) nodeType;
+                newSchemaPath = createNewSchemaPath(parentSchemaPath,
+                        nodeQName, decimalType.getQName());
+                BigDecimal defaultValue = (BigDecimal) decimalType
+                        .getDefaultValue();
+                result = new Decimal64(newSchemaPath, decimalType.getUnits(),
+                        defaultValue, decimalType.getRangeStatements(),
+                        decimalType.getFractionDigits());
+            } else if (nodeType instanceof EmptyTypeDefinition) {
+                newSchemaPath = createNewSchemaPath(parentSchemaPath,
+                        nodeQName, nodeType.getQName());
                 result = new EmptyType(newSchemaPath);
-            } else if(nodeType instanceof EnumTypeDefinition) {
-                EnumTypeDefinition enumType = (EnumTypeDefinition)nodeType;
-                newSchemaPath = createNewSchemaPath(parentSchemaPath, nodeQName, enumType.getQName());
-                result = new EnumerationType(newSchemaPath, (EnumPair)enumType.getDefaultValue(), enumType.getValues(), enumType.getUnits());
-            } else if(nodeType instanceof IdentityrefTypeDefinition) {
-                IdentityrefTypeDefinition idrefType = (IdentityrefTypeDefinition)nodeType;
-                newSchemaPath = createNewSchemaPath(parentSchemaPath, nodeQName, idrefType.getQName());
-                result = new IdentityrefType(idrefType.getIdentity(), newSchemaPath);
-            } else if(nodeType instanceof InstanceIdentifierTypeDefinition) {
-                InstanceIdentifierTypeDefinition instIdType = (InstanceIdentifierTypeDefinition)nodeType;
-                newSchemaPath = createNewSchemaPath(parentSchemaPath, nodeQName, instIdType.getQName());
-                return new InstanceIdentifier(newSchemaPath, instIdType.getPathStatement(), instIdType.requireInstance());
-            } else if(nodeType instanceof StringTypeDefinition) {
-                result = copyStringType(parentSchemaPath, nodeQName, (StringTypeDefinition)nodeType);
-            } else if(nodeType instanceof IntegerTypeDefinition) {
-                result = copyIntType(parentSchemaPath, nodeQName, (IntegerTypeDefinition)nodeType);
-            } else if(nodeType instanceof UnsignedIntegerTypeDefinition) {
-                result = copyUIntType(parentSchemaPath, nodeQName, (UnsignedIntegerTypeDefinition)nodeType);
-            } else if(nodeType instanceof LeafrefTypeDefinition) {
-                newSchemaPath = createNewSchemaPath(parentSchemaPath, nodeQName, nodeType.getQName());
-                result = new Leafref(newSchemaPath, ((LeafrefTypeDefinition)nodeType).getPathStatement());
-            } else if(nodeType instanceof UnionTypeDefinition) {
-                UnionTypeDefinition unionType = (UnionTypeDefinition)nodeType;
-                newSchemaPath = createNewSchemaPath(parentSchemaPath, nodeQName, unionType.getQName());
+            } else if (nodeType instanceof EnumTypeDefinition) {
+                EnumTypeDefinition enumType = (EnumTypeDefinition) nodeType;
+                newSchemaPath = createNewSchemaPath(parentSchemaPath,
+                        nodeQName, enumType.getQName());
+                result = new EnumerationType(newSchemaPath,
+                        (EnumPair) enumType.getDefaultValue(),
+                        enumType.getValues(), enumType.getUnits());
+            } else if (nodeType instanceof IdentityrefTypeDefinition) {
+                IdentityrefTypeDefinition idrefType = (IdentityrefTypeDefinition) nodeType;
+                newSchemaPath = createNewSchemaPath(parentSchemaPath,
+                        nodeQName, idrefType.getQName());
+                result = new IdentityrefType(idrefType.getIdentity(),
+                        newSchemaPath);
+            } else if (nodeType instanceof InstanceIdentifierTypeDefinition) {
+                InstanceIdentifierTypeDefinition instIdType = (InstanceIdentifierTypeDefinition) nodeType;
+                newSchemaPath = createNewSchemaPath(parentSchemaPath,
+                        nodeQName, instIdType.getQName());
+                return new InstanceIdentifier(newSchemaPath,
+                        instIdType.getPathStatement(),
+                        instIdType.requireInstance());
+            } else if (nodeType instanceof StringTypeDefinition) {
+                result = copyStringType(parentSchemaPath, nodeQName,
+                        (StringTypeDefinition) nodeType);
+            } else if (nodeType instanceof IntegerTypeDefinition) {
+                result = copyIntType(parentSchemaPath, nodeQName,
+                        (IntegerTypeDefinition) nodeType);
+            } else if (nodeType instanceof UnsignedIntegerTypeDefinition) {
+                result = copyUIntType(parentSchemaPath, nodeQName,
+                        (UnsignedIntegerTypeDefinition) nodeType);
+            } else if (nodeType instanceof LeafrefTypeDefinition) {
+                newSchemaPath = createNewSchemaPath(parentSchemaPath,
+                        nodeQName, nodeType.getQName());
+                result = new Leafref(newSchemaPath,
+                        ((LeafrefTypeDefinition) nodeType).getPathStatement());
+            } else if (nodeType instanceof UnionTypeDefinition) {
+                UnionTypeDefinition unionType = (UnionTypeDefinition) nodeType;
+                newSchemaPath = createNewSchemaPath(parentSchemaPath,
+                        nodeQName, unionType.getQName());
                 return new UnionType(newSchemaPath, unionType.getTypes());
             }
         }
         return result;
     }
 
-    private static TypeDefinition<?> copyStringType(SchemaPath schemaPath, QName nodeQName, StringTypeDefinition nodeType) {
+    private static TypeDefinition<?> copyStringType(SchemaPath schemaPath,
+            QName nodeQName, StringTypeDefinition nodeType) {
         List<QName> path = schemaPath.getPath();
         List<QName> newPath = new ArrayList<QName>(path);
         newPath.add(nodeQName);
         newPath.add(nodeType.getQName());
-        SchemaPath newSchemaPath = new SchemaPath(newPath, schemaPath.isAbsolute());
+        SchemaPath newSchemaPath = new SchemaPath(newPath,
+                schemaPath.isAbsolute());
 
         String newDefault = nodeType.getDefaultValue().toString();
         String newUnits = nodeType.getUnits();
         List<LengthConstraint> lengths = nodeType.getLengthStatements();
         List<PatternConstraint> patterns = nodeType.getPatterns();
 
-        return new StringType(newSchemaPath, newDefault, lengths, patterns, newUnits);
+        return new StringType(newSchemaPath, newDefault, lengths, patterns,
+                newUnits);
     }
 
-    private static TypeDefinition<?> copyIntType(SchemaPath schemaPath, QName nodeQName, IntegerTypeDefinition type) {
+    private static TypeDefinition<?> copyIntType(SchemaPath schemaPath,
+            QName nodeQName, IntegerTypeDefinition type) {
         QName typeQName = type.getQName();
-        SchemaPath newSchemaPath = createNewSchemaPath(schemaPath, nodeQName, typeQName);
+        SchemaPath newSchemaPath = createNewSchemaPath(schemaPath, nodeQName,
+                typeQName);
 
         String localName = typeQName.getLocalName();
         List<RangeConstraint> ranges = type.getRangeStatements();
         String units = type.getUnits();
 
-        if("int8".equals(localName)) {
-            Byte defaultValue = (Byte)type.getDefaultValue();
+        if ("int8".equals(localName)) {
+            Byte defaultValue = (Byte) type.getDefaultValue();
             return new Int8(newSchemaPath, ranges, units, defaultValue);
-        } else if("int16".equals(localName)) {
-            Short defaultValue = (Short)type.getDefaultValue();
+        } else if ("int16".equals(localName)) {
+            Short defaultValue = (Short) type.getDefaultValue();
             return new Int16(newSchemaPath, ranges, units, defaultValue);
-        } else if("int32".equals(localName)) {
-            Integer defaultValue = (Integer)type.getDefaultValue();
+        } else if ("int32".equals(localName)) {
+            Integer defaultValue = (Integer) type.getDefaultValue();
             return new Int32(newSchemaPath, ranges, units, defaultValue);
-        } else if("int64".equals(localName)) {
-            Long defaultValue = (Long)type.getDefaultValue();
+        } else if ("int64".equals(localName)) {
+            Long defaultValue = (Long) type.getDefaultValue();
             return new Int64(newSchemaPath, ranges, units, defaultValue);
         } else {
             return null;
         }
     }
 
-    private static TypeDefinition<?> copyUIntType(SchemaPath schemaPath, QName nodeQName, UnsignedIntegerTypeDefinition type) {
+    private static TypeDefinition<?> copyUIntType(SchemaPath schemaPath,
+            QName nodeQName, UnsignedIntegerTypeDefinition type) {
         QName typeQName = type.getQName();
-        SchemaPath newSchemaPath = createNewSchemaPath(schemaPath, nodeQName, typeQName);
+        SchemaPath newSchemaPath = createNewSchemaPath(schemaPath, nodeQName,
+                typeQName);
 
         String localName = typeQName.getLocalName();
         List<RangeConstraint> ranges = type.getRangeStatements();
         String units = type.getUnits();
 
-        if("uint8".equals(localName)) {
-            Byte defaultValue = (Byte)type.getDefaultValue();
+        if ("uint8".equals(localName)) {
+            Byte defaultValue = (Byte) type.getDefaultValue();
             return new Int8(newSchemaPath, ranges, units, defaultValue);
-        } else if("uint16".equals(localName)) {
-            Short defaultValue = (Short)type.getDefaultValue();
+        } else if ("uint16".equals(localName)) {
+            Short defaultValue = (Short) type.getDefaultValue();
             return new Int16(newSchemaPath, ranges, units, defaultValue);
-        } else if("uint32".equals(localName)) {
-            Integer defaultValue = (Integer)type.getDefaultValue();
+        } else if ("uint32".equals(localName)) {
+            Integer defaultValue = (Integer) type.getDefaultValue();
             return new Int32(newSchemaPath, ranges, units, defaultValue);
-        } else if("uint64".equals(localName)) {
-            Long defaultValue = (Long)type.getDefaultValue();
+        } else if ("uint64".equals(localName)) {
+            Long defaultValue = (Long) type.getDefaultValue();
             return new Int64(newSchemaPath, ranges, units, defaultValue);
         } else {
             return null;
         }
     }
 
-    private static SchemaPath createNewSchemaPath(SchemaPath schemaPath, QName currentQName, QName qname) {
+    private static SchemaPath createNewSchemaPath(SchemaPath schemaPath,
+            QName currentQName, QName qname) {
         List<QName> newPath = new ArrayList<QName>(schemaPath.getPath());
         newPath.add(currentQName);
         newPath.add(qname);
@@ -426,6 +476,92 @@ public final class ParserUtils {
         }
     }
 
+    public static void checkRefine(SchemaNodeBuilder node, RefineHolder refine) {
+        String name = node.getQName().getLocalName();
+        int line = refine.getLine();
+
+        String defaultStr = refine.getDefaultStr();
+        Boolean mandatory = refine.isMandatory();
+        Boolean presence = refine.isPresence();
+        MustDefinition must = refine.getMust();
+        Integer min = refine.getMinElements();
+        Integer max = refine.getMaxElements();
+
+        if (node instanceof AnyXmlBuilder) {
+            checkRefineDefault(node, defaultStr, line);
+            checkRefinePresence(node, presence, line);
+            checkRefineMinMax(name, line, min, max);
+        } else if (node instanceof ChoiceBuilder) {
+            checkRefinePresence(node, presence, line);
+            checkRefineMust(node, must, line);
+            checkRefineMinMax(name, line, min, max);
+        } else if (node instanceof ContainerSchemaNodeBuilder) {
+            checkRefineDefault(node, defaultStr, line);
+            checkRefineMandatory(node, mandatory, line);
+            checkRefineMust(node, must, line);
+            checkRefineMinMax(name, line, min, max);
+        } else if (node instanceof LeafSchemaNodeBuilder) {
+            checkRefinePresence(node, presence, line);
+            checkRefineMinMax(name, line, min, max);
+        } else if (node instanceof LeafListSchemaNodeBuilder
+                || node instanceof ListSchemaNodeBuilder) {
+            checkRefineDefault(node, defaultStr, line);
+            checkRefinePresence(node, presence, line);
+            checkRefineMandatory(node, mandatory, line);
+        } else if (node instanceof GroupingBuilder
+                || node instanceof TypeDefinitionBuilder
+                || node instanceof UsesNodeBuilder) {
+            checkRefineDefault(node, defaultStr, line);
+            checkRefinePresence(node, presence, line);
+            checkRefineMandatory(node, mandatory, line);
+            checkRefineMust(node, must, line);
+            checkRefineMinMax(name, line, min, max);
+        }
+    }
+
+    private static void checkRefineDefault(SchemaNodeBuilder node,
+            String defaultStr, int line) {
+        if (defaultStr != null) {
+            throw new YangParseException(line, "Can not refine 'default' for '"
+                    + node.getQName().getLocalName() + "'.");
+        }
+    }
+
+    private static void checkRefineMandatory(SchemaNodeBuilder node,
+            Boolean mandatory, int line) {
+        if (mandatory != null) {
+            throw new YangParseException(line,
+                    "Can not refine 'mandatory' for '"
+                            + node.getQName().getLocalName() + "'.");
+        }
+    }
+
+    private static void checkRefinePresence(SchemaNodeBuilder node,
+            Boolean presence, int line) {
+        if (presence != null) {
+            throw new YangParseException(line,
+                    "Can not refine 'presence' for '"
+                            + node.getQName().getLocalName() + "'.");
+        }
+    }
+
+    private static void checkRefineMust(SchemaNodeBuilder node,
+            MustDefinition must, int line) {
+        if (must != null) {
+            throw new YangParseException(line, "Can not refine 'must' for '"
+                    + node.getQName().getLocalName() + "'.");
+        }
+    }
+
+    private static void checkRefineMinMax(String refineTargetName,
+            int refineLine, Integer min, Integer max) {
+        if (min != null || max != null) {
+            throw new YangParseException(refineLine,
+                    "Can not refine 'min-elements' or 'max-elements' for '"
+                            + refineTargetName + "'.");
+        }
+    }
+
     /**
      * Perform refine operation of following parameters:
      * <ul>
@@ -490,7 +626,7 @@ public final class ParserUtils {
         final TypeDefinition<?> type = old.getType();
 
         if (type == null) {
-            copy.setType(old.getTypedef());
+            copy.setTypedef(old.getTypedef());
         } else {
             copy.setType(type);
         }
@@ -524,7 +660,7 @@ public final class ParserUtils {
         for (GroupingBuilder grouping : old.getGroupings()) {
             copy.addGrouping(grouping);
         }
-        for (TypeDefinitionBuilder typedef : old.getTypedefs()) {
+        for (TypeDefinitionBuilder typedef : old.getTypeDefinitions()) {
             copy.addTypedef(typedef);
         }
         for (AugmentationSchemaBuilder augment : old.getAugmentations()) {
@@ -557,7 +693,7 @@ public final class ParserUtils {
         for (GroupingBuilder grouping : old.getGroupings()) {
             copy.addGrouping(grouping);
         }
-        for (TypeDefinitionBuilder typedef : old.getTypedefs()) {
+        for (TypeDefinitionBuilder typedef : old.getTypeDefinitions()) {
             copy.addTypedef(typedef);
         }
         for (AugmentationSchemaBuilder augment : old.getAugmentations()) {
@@ -583,7 +719,7 @@ public final class ParserUtils {
         copyConstraints(old, copy);
         final TypeDefinition<?> type = old.getType();
         if (type == null) {
-            copy.setType(old.getTypedef());
+            copy.setTypedef(old.getTypedef());
         } else {
             copy.setType(type);
         }
@@ -610,12 +746,6 @@ public final class ParserUtils {
         for (UnknownSchemaNodeBuilder unknown : old.getUnknownNodes()) {
             copy.addUnknownSchemaNode(unknown);
         }
-        for (TypeDefinitionBuilder typedef : old.getTypedefs()) {
-            copy.addTypedef(typedef);
-        }
-        for (UsesNodeBuilder use : old.getUsesNodes()) {
-            copy.addUsesNode(use);
-        }
         copy.setDefaultCase(old.getDefaultCase());
         copy.setDescription(old.getDescription());
         copy.setReference(old.getReference());
@@ -650,7 +780,7 @@ public final class ParserUtils {
         for (GroupingBuilder grouping : old.getGroupings()) {
             copy.addGrouping(grouping);
         }
-        for (TypeDefinitionBuilder typedef : old.getTypedefs()) {
+        for (TypeDefinitionBuilder typedef : old.getTypeDefinitions()) {
             copy.addTypedef(typedef);
         }
         for (UsesNodeBuilder use : old.getUses()) {
@@ -665,9 +795,10 @@ public final class ParserUtils {
         return copy;
     }
 
-    public static TypedefBuilder copyTypedefBuilder(TypedefBuilder old) {
-        final TypedefBuilder copy = new TypedefBuilder(old.getQName(),
-                old.getLine());
+    public static TypeDefinitionBuilderImpl copyTypedefBuilder(
+            TypeDefinitionBuilderImpl old) {
+        final TypeDefinitionBuilderImpl copy = new TypeDefinitionBuilderImpl(
+                old.getQName(), old.getLine());
         copy.setPath(old.getPath());
         copy.setDefaultValue(old.getDefaultValue());
         copy.setUnits(old.getUnits());
@@ -681,8 +812,8 @@ public final class ParserUtils {
         copy.setFractionDigits(old.getFractionDigits());
 
         TypeDefinition<?> type = old.getType();
-        if(type == null) {
-            copy.setType(old.getTypedef());
+        if (type == null) {
+            copy.setTypedef(old.getTypedef());
         } else {
             copy.setType(old.getType());
         }
index babd0d0..3d9df34 100644 (file)
@@ -9,11 +9,14 @@ package org.opendaylight.controller.yang.parser.impl;
 
 import java.io.File;
 import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
 import java.net.URI;
 import java.text.DateFormat;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.Date;
 import java.util.List;
 import java.util.Set;
@@ -45,6 +48,28 @@ final class TestUtils {
         return parser.parseYangModels(testFiles);
     }
 
+    public static Set<Module> loadModules(String... pathToYangFile) throws IOException {
+        YangModelParser parser = new YangParserImpl();
+        List<InputStream> input = new ArrayList<InputStream>();
+        for(String path : pathToYangFile) {
+            input.add(TestUtils.class.getResourceAsStream(path));
+        }
+        Set<Module> modules = parser.parseYangModelsFromStreams(input);
+        for(InputStream stream : input) {
+            stream.close();
+        }
+        return modules;
+    }
+
+    public static Module loadModule(String pathToYangFile) throws IOException {
+        YangModelParser parser = new YangParserImpl();
+        InputStream stream = TestUtils.class.getResourceAsStream(pathToYangFile);
+        List<InputStream> input = Collections.singletonList(stream);
+        Set<Module> modules = parser.parseYangModelsFromStreams(input);
+        stream.close();
+        return modules.iterator().next();
+    }
+
     public static Module findModule(Set<Module> modules, String moduleName) {
         Module result = null;
         for (Module module : modules) {
diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/parser/impl/YangParserNegativeTest.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/parser/impl/YangParserNegativeTest.java
new file mode 100644 (file)
index 0000000..be44c6f
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * 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.IOException;
+
+import org.junit.Test;
+import org.opendaylight.controller.yang.parser.util.YangParseException;
+import org.opendaylight.controller.yang.parser.util.YangValidationException;
+
+public class YangParserNegativeTest {
+
+    @Test
+    public void testInvalidImport() throws IOException {
+        try {
+            TestUtils.loadModule("/negative-scenario/testfile1.yang");
+            fail("ValidationException should by thrown");
+        } catch(YangValidationException e) {
+            assertTrue(e.getMessage().contains("Not existing module imported"));
+        }
+    }
+
+    @Test
+    public void testTypeNotFound() throws IOException {
+        try {
+            TestUtils.loadModule("/negative-scenario/testfile2.yang");
+            fail("YangParseException should by thrown");
+        } catch(YangParseException e) {
+            assertTrue(e.getMessage().contains("Error in module 'test2' on line 24: Referenced type 'int-ext' not found."));
+        }
+    }
+
+    @Test
+    public void testInvalidAugmentTarget() throws IOException {
+        try {
+            TestUtils.loadModules("/negative-scenario/testfile0.yang", "/negative-scenario/testfile3.yang");
+            fail("YangParseException should by thrown");
+        } catch(YangParseException e) {
+            assertTrue(e.getMessage().contains("Failed to resolve augments in module 'test3'."));
+        }
+    }
+
+    @Test
+    public void testInvalidRefine() throws IOException {
+        try {
+            TestUtils.loadModule("/negative-scenario/testfile4.yang");
+            fail("YangParseException should by thrown");
+        } catch(YangParseException e) {
+            assertTrue(e.getMessage().contains("Can not refine 'presence' for 'node'."));
+        }
+    }
+
+}
index 9463410..fd2593b 100644 (file)
@@ -601,11 +601,7 @@ public class YangParserTest {
         assertNotNull(refineContainer);
         Set<MustDefinition> mustConstraints = refineContainer.getConstraints()
                 .getMustConstraints();
-        assertEquals(1, mustConstraints.size());
-        MustDefinition must = mustConstraints.iterator().next();
-        assertEquals("must-condition", must.toString());
-        assertEquals("An error message test", must.getErrorMessage());
-        assertEquals(("An error app tag test"), must.getErrorAppTag());
+        assertTrue(mustConstraints.isEmpty());
         assertEquals("description of port defined by refine",
                 refineContainer.getDescription());
         assertEquals("port reference added by refine",
index 619a5c3..4ec69c1 100644 (file)
@@ -124,5 +124,17 @@ module types1 {
             }
         }
     }
-
+    
+    container mycont {
+        container innercont {
+            typedef mytype {
+                type string;
+            }
+        
+            leaf myleaf {
+                type mytype;
+            }
+        }
+    }
+    
 }
index b779c3c..8860e06 100644 (file)
@@ -205,10 +205,6 @@ module types2 {
                     }
                 }
                 refine port {
-                    must "must-condition" {
-                        error-message "An error message test";
-                        error-app-tag "An error app tag test";
-                    }
                     description "description of port defined by refine";
                     reference "port reference added by refine";
                     config false;
diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/negative-scenario/testfile0.yang b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/negative-scenario/testfile0.yang
new file mode 100644 (file)
index 0000000..ea60ba9
--- /dev/null
@@ -0,0 +1,9 @@
+module test0 {
+    yang-version 1;
+    namespace "urn:simple.container.demo";
+    prefix "t1";
+    
+    container interfaces {
+    
+    }
+}
diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/negative-scenario/testfile1.yang b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/negative-scenario/testfile1.yang
new file mode 100644 (file)
index 0000000..fdc7e71
--- /dev/null
@@ -0,0 +1,11 @@
+module test1 {
+    yang-version 1;
+    namespace "urn:simple.container.demo";
+    prefix "t1";
+
+    import some-module {
+        prefix "data";
+        revision-date 2013-02-27;
+    }
+
+}
diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/negative-scenario/testfile2.yang b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/negative-scenario/testfile2.yang
new file mode 100644 (file)
index 0000000..ea5a11f
--- /dev/null
@@ -0,0 +1,29 @@
+module test2 {
+    yang-version 1;
+    namespace "urn:simple.types.data.demo";
+    prefix "t2";
+    
+    organization "opendaylight";
+    contact "http://www.opendaylight.org/";
+    
+    description "This is types-data test description";
+
+    revision "2013-02-27" {
+        reference " WILL BE DEFINED LATER";
+    }
+    
+    container c1 {
+        typedef int-ext {
+            type int32 {
+                range "10..20";
+            }
+        }
+    }
+    
+    container top {
+        leaf id {
+            type int-ext;
+        }
+    }
+
+}
diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/negative-scenario/testfile3.yang b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/negative-scenario/testfile3.yang
new file mode 100644 (file)
index 0000000..187e9dd
--- /dev/null
@@ -0,0 +1,19 @@
+module test3 {
+    yang-version 1;
+    namespace "urn:simple.container.demo";
+    prefix "t1";
+
+    import test0 {
+        prefix "data";
+    }
+    
+    augment "/data:unknown" {
+        when "if:ifType='ds0'";
+        leaf interface-id {
+            type leafref {
+                path "/if:interfaces/if:interface/if:name";
+            }
+        }
+    }
+
+}
diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/negative-scenario/testfile4.yang b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/negative-scenario/testfile4.yang
new file mode 100644 (file)
index 0000000..c327de3
--- /dev/null
@@ -0,0 +1,26 @@
+module test4 {
+    yang-version 1;
+    namespace "urn:simple.container.demo";
+    prefix "t1";
+
+    grouping tree {
+        leaf-list node {
+            type string;
+        }
+        container holder {
+        
+        }
+    }
+
+    container schema {
+        uses tree {
+            refine node {
+                presence "true";
+            }
+            refine holder {
+                default "one";
+            }
+        }
+    }
+
+}
index f2e339f..a988673 100644 (file)
@@ -31,8 +31,9 @@ public class ControllerCustomRealm  extends RealmBase {
                 .getGlobalInstance(IUserManager.class, this);
         if (userManager != null) {
             return userManager.getPassword(username);
-        } else
+        } else {
             throw new RuntimeException("User Manager reference is null");
+        }
     }
 
     @Override
@@ -40,14 +41,14 @@ public class ControllerCustomRealm  extends RealmBase {
         IUserManager userManager = (IUserManager) ServiceHelper
                 .getGlobalInstance(IUserManager.class, this);
         if (userManager != null) {
-            final List<String> levels = new ArrayList<String>(); 
-            UserLevel level = userManager.getUserLevel(username);
-            if (level == null) level = UserLevel.NOUSER;
-            levels.add(level.toString());
-            return new GenericPrincipal(username, "", levels);
-        } else
+            List<String> controllerRoles = new ArrayList<String>();
+            for (UserLevel level : userManager.getUserLevels(username)) {
+                controllerRoles.add(level.toString());
+            }
+            return new GenericPrincipal(username, "", controllerRoles);
+        } else {
             throw new RuntimeException("User Manager reference is null");
-
+        }
     }
 
     @Override
@@ -66,8 +67,9 @@ public class ControllerCustomRealm  extends RealmBase {
                 logger.error("Authentication failed for user " + username);
                 return null;
             }
-        } else
+        } else {
             throw new RuntimeException("User Manager reference is null");
+        }
     }
 
 }
index 1b1a47b..8ea2190 100644 (file)
@@ -1646,7 +1646,8 @@ CommandProvider {
 
     @Override
     public byte[] getNodeMAC(Node node) {
-        MacAddress mac = (MacAddress) nodeProps.get(MacAddress.name);
+        MacAddress mac = (MacAddress) this.getNodeProp(node,
+                MacAddress.name);
         return (mac != null) ? mac.getMacAddress() : null;
     }
 
index 0ec9445..ed23b5f 100644 (file)
@@ -28,7 +28,7 @@ public interface IUserManager extends UserDetailsService {
 
     /**
      * Returns the list of roles associated to the passed user name
-     * 
+     *
      * @param userName
      * @return the role associated to the user name
      */
@@ -37,7 +37,7 @@ public interface IUserManager extends UserDetailsService {
     /**
      * Authenticate user with AAA server and return authentication and
      * authorization info
-     * 
+     *
      * @param username
      *            the username
      * @param password
@@ -49,7 +49,7 @@ public interface IUserManager extends UserDetailsService {
 
     /**
      * Add/remove AAA server
-     * 
+     *
      * @param configObject
      *            {@link org.opendaylight.controller.usermanager.internal.ServerConfig}
      *            Server Configuration
@@ -60,7 +60,7 @@ public interface IUserManager extends UserDetailsService {
 
     /**
      * Remove AAA server
-     * 
+     *
      * @param configObject
      *            refer to
      *            {@link org.opendaylight.controller.usermanager.internal.ServerConfig}
@@ -72,7 +72,7 @@ public interface IUserManager extends UserDetailsService {
 
     /**
      * Add a local user
-     * 
+     *
      * @param configObject
      *            {@link org.opendaylight.controller.usermanager.internal.UserConfig}
      *            User Configuration
@@ -83,7 +83,7 @@ public interface IUserManager extends UserDetailsService {
 
     /**
      * Remove a local user
-     * 
+     *
      * @param configObject
      *            {@link org.opendaylight.controller.usermanager.internal.UserConfig}
      *            UserConfig
@@ -94,7 +94,7 @@ public interface IUserManager extends UserDetailsService {
 
     /**
      * Remove a local user
-     * 
+     *
      * @param userName
      *            the user name
      * @return {@link org.opendaylight.controller.sal.utils.Status}
@@ -105,7 +105,7 @@ public interface IUserManager extends UserDetailsService {
     /**
      * Add the authorization information for a user that gets authenticated
      * remotely
-     * 
+     *
      * @param AAAconf
      *            {@link org.opendaylight.controller.usermanager.internal.AuthorizationConfig}
      *            Authorization Resources
@@ -117,7 +117,7 @@ public interface IUserManager extends UserDetailsService {
     /**
      * Remove the authorization information for a user that gets authenticated
      * remotely
-     * 
+     *
      * @param AAAconf
      *            {@link org.opendaylight.controller.usermanager.internal.AuthorizationConfig}
      *            Authorization Resource
@@ -128,7 +128,7 @@ public interface IUserManager extends UserDetailsService {
 
     /**
      * Return the list of authorization resources
-     * 
+     *
      * @return {@link org.opendaylight.controller.usermanager.internal.AuthorizationConfig}
      *         List of Authorization Resource
      */
@@ -136,14 +136,14 @@ public interface IUserManager extends UserDetailsService {
 
     /**
      * Returns a list of AAA Providers.
-     * 
+     *
      * @return Set of provider names.
      */
     public Set<String> getAAAProviderNames();
 
     /**
      * Change the current password for a locally configured user
-     * 
+     *
      * @param user
      *            the username
      * @param curPasssword
@@ -158,7 +158,7 @@ public interface IUserManager extends UserDetailsService {
 
     /**
      * Return a list of AAA servers currently configured
-     * 
+     *
      * @return {@link org.opendaylight.controller.usermanager.internal.ServerConfig}
      *         List of ServerConfig
      */
@@ -166,7 +166,7 @@ public interface IUserManager extends UserDetailsService {
 
     /**
      * Return a list of local users
-     * 
+     *
      * @return {@link org.opendaylight.controller.usermanager.internal.UserConfig}
      *         List of UserConfig
      */
@@ -174,7 +174,7 @@ public interface IUserManager extends UserDetailsService {
 
     /**
      * Save the local users to disk
-     * 
+     *
      * @return {@link org.opendaylight.controller.sal.utils.Status}
      *         status of this action
      */
@@ -182,7 +182,7 @@ public interface IUserManager extends UserDetailsService {
 
     /**
      * Save the AAA server configurations to disk
-     * 
+     *
      * @return {@link org.opendaylight.controller.sal.utils.Status}
      *         status of this action
      */
@@ -190,7 +190,7 @@ public interface IUserManager extends UserDetailsService {
 
     /**
      * Save the Authorization configurations to disk
-     * 
+     *
      * @return {@link org.opendaylight.controller.sal.utils.Status}
      *         status code
      */
@@ -198,7 +198,7 @@ public interface IUserManager extends UserDetailsService {
 
     /**
      * Remove user profile when user logs out
-     * 
+     *
      * @param username
      *            the user name
      */
@@ -206,7 +206,7 @@ public interface IUserManager extends UserDetailsService {
 
     /**
      * Remove user profile when user times out
-     * 
+     *
      * @param username
      *            the user name
      */
@@ -214,24 +214,24 @@ public interface IUserManager extends UserDetailsService {
 
     /**
      * Get the list of users currently logged in
-     * 
+     *
      * @return the list of users along with their administrative roles
      */
     public Map<String, List<String>> getUserLoggedIn();
 
     /**
      * Get date and time user was successfully authenticated
-     * 
+     *
      * @param user
      * @return Date in String format
      */
     public String getAccessDate(String user);
 
     /**
-     * Returns the user level for the passed user name. It checks the roles
+     * Returns the highest user level for the passed user name. It checks the roles
      * assigned to this user and checks against the well known Controller user
      * roles to determines the highest user level associated with the user
-     * 
+     *
      * @param userName
      *            the user name
      * @return {@link org.opendaylight.controller.sal.authorization.UserLevel}
@@ -239,9 +239,21 @@ public interface IUserManager extends UserDetailsService {
      */
     public UserLevel getUserLevel(String userName);
 
+    /**
+     * Returns the list of user level for the passed user name. It checks the roles
+     * assigned to this user and checks against the well known Controller user
+     * roles to determines the corresponding list of user level associated with the user
+     *
+     * @param userName
+     *            the user name
+     * @return
+     *          the list of user level for this user
+     */
+    public List<UserLevel> getUserLevels(String userName);
+
     /**
      * Returns the Security Context
-     * 
+     *
      * @returns {@link org.springframework.security.web.context.SecurityContextRepository}
      *          Security Context
      */
@@ -249,7 +261,7 @@ public interface IUserManager extends UserDetailsService {
 
     /**
      * Returns the Session Manager Interface Handler
-     * 
+     *
      * @return {@link org.opendaylight.controller.usermanager.ISessionManager}
      *         session manager interface handler
      */
@@ -257,7 +269,7 @@ public interface IUserManager extends UserDetailsService {
 
     /* non-Javadoc
      * Returns the password for a given user
-     * 
+     *
      * @param username
      *            the user name
      * @return password for the username
index 69c9a1a..5ddf6be 100644 (file)
@@ -83,11 +83,11 @@ public class UserManagerImpl implements IUserManager, IObjectReader,
     private ConcurrentMap<String, UserConfig> localUserConfigList;
     private ConcurrentMap<String, ServerConfig> remoteServerConfigList;
     // local authorization info for remotely authenticated users
-    private ConcurrentMap<String, AuthorizationConfig> authorizationConfList; 
+    private ConcurrentMap<String, AuthorizationConfig> authorizationConfList;
     private ConcurrentMap<String, AuthenticatedUser> activeUsers;
     private ConcurrentMap<String, IAAAProvider> authProviders;
     private ConcurrentMap<Long, String> localUserListSaveConfigEvent,
-            remoteServerSaveConfigEvent, authorizationSaveConfigEvent;
+    remoteServerSaveConfigEvent, authorizationSaveConfigEvent;
     private IClusterGlobalServices clusterGlobalService = null;
     private SecurityContextRepository securityContextRepo = new UserSecurityContextRepository();
     private IContainerAuthorization containerAuthorizationClient;
@@ -115,6 +115,7 @@ public class UserManagerImpl implements IUserManager, IObjectReader,
         return authProviders.get(name);
     }
 
+    @Override
     public Set<String> getAAAProviderNames() {
         return authProviders.keySet();
     }
@@ -272,13 +273,13 @@ public class UserManagerImpl implements IUserManager, IObjectReader,
                 } else if (rcResponse.getStatus() == AuthResultEnum.AUTH_REJECT) {
                     logger.info(
                             "Remote Authentication Rejected User: \"{}\", from Server: {}, Reason:{}",
-                            new Object[] {userName, aaaServer.getAddress(),
-                            rcResponse.getStatus().toString()});
+                            new Object[] { userName, aaaServer.getAddress(),
+                                    rcResponse.getStatus().toString() });
                 } else {
                     logger.info(
                             "Remote Authentication Failed for User: \"{}\", from Server: {}, Reason:{}",
-                            new Object[] {userName, aaaServer.getAddress(),
-                            rcResponse.getStatus().toString()});
+                            new Object[] { userName, aaaServer.getAddress(),
+                                    rcResponse.getStatus().toString() });
                 }
             }
         }
@@ -363,7 +364,7 @@ public class UserManagerImpl implements IUserManager, IObjectReader,
         putUserInActiveList(userName, result);
         if (authorized) {
             logger.info("User \"{}\" authorized for the following role(s): {}",
-                        userName, result.getUserRoles());
+                    userName, result.getUserRoles());
         } else {
             logger.info("User \"{}\" Not Authorized for any role ", userName);
         }
@@ -390,6 +391,7 @@ public class UserManagerImpl implements IUserManager, IObjectReader,
         activeUsers.remove(user);
     }
 
+    @Override
     public Status saveLocalUserList() {
         // Publish the save config event to the cluster nodes
         localUserListSaveConfigEvent.put(new Date().getTime(), SAVE);
@@ -402,6 +404,7 @@ public class UserManagerImpl implements IUserManager, IObjectReader,
                 localUserConfigList), usersFileName);
     }
 
+    @Override
     public Status saveAAAServerList() {
         // Publish the save config event to the cluster nodes
         remoteServerSaveConfigEvent.put(new Date().getTime(), SAVE);
@@ -414,6 +417,7 @@ public class UserManagerImpl implements IUserManager, IObjectReader,
                 remoteServerConfigList), serversFileName);
     }
 
+    @Override
     public Status saveAuthorizationList() {
         // Publish the save config event to the cluster nodes
         authorizationSaveConfigEvent.put(new Date().getTime(), SAVE);
@@ -628,7 +632,7 @@ public class UserManagerImpl implements IUserManager, IObjectReader,
             return status;
         }
         // Trigger cluster update
-        localUserConfigList.put(user, targetConfigEntry); 
+        localUserConfigList.put(user, targetConfigEntry);
 
         logger.info("Password changed for User \"{}\"", user);
 
@@ -703,7 +707,7 @@ public class UserManagerImpl implements IUserManager, IObjectReader,
         String userName = ci.nextArgument();
         String password = ci.nextArgument();
         String role = ci.nextArgument();
-        
+
         List<String> roles = new ArrayList<String>();
         while (role != null) {
             if (!role.trim().isEmpty()) {
@@ -734,7 +738,7 @@ public class UserManagerImpl implements IUserManager, IObjectReader,
         if (target == null) {
             ci.println("User not found");
             return;
-        }       
+        }
         ci.println(this.removeLocalUser(target));
     }
 
@@ -815,7 +819,7 @@ public class UserManagerImpl implements IUserManager, IObjectReader,
     /**
      * Function called by the dependency manager when all the required
      * dependencies are satisfied
-     * 
+     *
      */
     void init() {
     }
@@ -824,7 +828,7 @@ public class UserManagerImpl implements IUserManager, IObjectReader,
      * Function called by the dependency manager when at least one dependency
      * become unsatisfied or when the component is shutting down because for
      * example bundle is being stopped.
-     * 
+     *
      */
     void destroy() {
     }
@@ -832,7 +836,7 @@ public class UserManagerImpl implements IUserManager, IObjectReader,
     /**
      * Function called by dependency manager after "init ()" is called and after
      * the services provided by the class are registered in the service registry
-     * 
+     *
      */
     void start() {
         authProviders = new ConcurrentHashMap<String, IAAAProvider>();
@@ -855,7 +859,7 @@ public class UserManagerImpl implements IUserManager, IObjectReader,
      * Function called by the dependency manager before the services exported by
      * the component are unregistered, this will be followed by a "destroy ()"
      * calls
-     * 
+     *
      */
     void stop() {
     }
@@ -919,6 +923,58 @@ public class UserManagerImpl implements IUserManager, IObjectReader,
         return UserLevel.NOUSER;
     }
 
+
+    @Override
+    public List<UserLevel> getUserLevels(String username) {
+        // Returns the controller well-know user levels for the passed user
+        List<String> rolesNames = null;
+        List<UserLevel> levels = new ArrayList<UserLevel>();
+
+        if (activeUsers.containsKey(username)) {
+            List<String> roles = activeUsers.get(username).getUserRoles();
+            rolesNames = (roles == null || roles.isEmpty()) ? null : roles;
+        } else if (localUserConfigList.containsKey(username)) {
+            UserConfig config = localUserConfigList.get(username);
+            rolesNames = (config == null) ? null : config.getRoles();
+        }
+
+        if (rolesNames == null) {
+            return levels;
+        }
+
+        // Check against the well known controller roles first
+        if (rolesNames.contains(UserLevel.SYSTEMADMIN.toString())) {
+            levels.add(UserLevel.SYSTEMADMIN);
+        }
+        if (rolesNames.contains(UserLevel.NETWORKADMIN.toString())) {
+            levels.add(UserLevel.NETWORKADMIN);
+        }
+        if (rolesNames.contains(UserLevel.NETWORKOPERATOR.toString())) {
+            levels.add(UserLevel.NETWORKOPERATOR);
+        }
+        // Check if container user now
+        if (containerAuthorizationClient != null) {
+            for (String roleName : rolesNames) {
+                if (containerAuthorizationClient.isApplicationRole(roleName)) {
+                    levels.add(UserLevel.CONTAINERUSER);
+                    break;
+                }
+            }
+        }
+        // Finally check if application user
+        if (applicationAuthorizationClients != null) {
+            for (String roleName : rolesNames) {
+                for (IResourceAuthorization client : this.applicationAuthorizationClients) {
+                    if (client.isApplicationRole(roleName)) {
+                        levels.add(UserLevel.APPUSER);
+                        break;
+                    }
+                }
+            }
+        }
+        return levels;
+    }
+
     @Override
     public Status saveConfiguration() {
         boolean success = true;
@@ -958,8 +1014,9 @@ public class UserManagerImpl implements IUserManager, IObjectReader,
                     .getPassword(), enabled, accountNonExpired,
                     credentialsNonExpired, accountNonLocked,
                     user.getGrantedAuthorities(getUserLevel(username)));
-        } else
+        } else {
             throw new UsernameNotFoundException("User not found " + username);
+        }
     }
 
     @Override
@@ -1011,9 +1068,10 @@ public class UserManagerImpl implements IUserManager, IObjectReader,
                             .getName())));
             return authentication;
 
-        } else
+        } else {
             throw new BadCredentialsException(
                     "Username or credentials did not match");
+        }
 
     }
 
@@ -1057,6 +1115,7 @@ public class UserManagerImpl implements IUserManager, IObjectReader,
         this.sessionMgr = sessionMgr;
     }
 
+    @Override
     public String getPassword(String username) {
         return localUserConfigList.get(username).getPassword();
     }