Merge "BUG-994: do not use SchemaPath.getPath()"
authorRobert Varga <rovarga@cisco.com>
Mon, 30 Jun 2014 19:33:26 +0000 (19:33 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Mon, 30 Jun 2014 19:33:26 +0000 (19:33 +0000)
21 files changed:
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/nodes/AbstractImmutableNormalizedValueNode.java
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/DocumentedNode.java [new file with mode: 0644]
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/SchemaNode.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/api/DataNodeContainerBuilder.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/AugmentationSchemaBuilderImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/ChoiceCaseBuilder.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/ContainerSchemaNodeBuilder.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/GroupingBuilderImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/ListSchemaNodeBuilder.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/ModuleBuilder.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/ModuleImpl.java [new file with mode: 0644]
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/NotificationBuilder.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/RefineUtils.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/util/AbstractBuilder.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/util/AbstractDataNodeContainerBuilder.java [deleted file]
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/util/AbstractDocumentedDataNodeContainer.java [new file with mode: 0644]
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/util/AbstractDocumentedDataNodeContainerBuilder.java [new file with mode: 0644]
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/util/AbstractDocumentedNode.java [new file with mode: 0644]
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/util/AbstractDocumentedNodeBuilder.java [new file with mode: 0644]
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/YangParserImpl.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserNegativeTest.java

index 16ca637e2ca903cdf8bf349d23fdcb9ccf5d98e2..f5e9ba67ee65c79ac3a40a00d611a19e12df1ae6 100644 (file)
@@ -8,17 +8,21 @@
 package org.opendaylight.yangtools.yang.data.impl.schema.nodes;
 
 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
-import com.google.common.base.Preconditions;
-
-public abstract class AbstractImmutableNormalizedValueNode<K extends InstanceIdentifier.PathArgument,V>
-        extends AbstractImmutableNormalizedNode<K, V> {
+public abstract class AbstractImmutableNormalizedValueNode<K extends InstanceIdentifier.PathArgument, V> extends
+        AbstractImmutableNormalizedNode<K, V> {
 
+    private static final Logger LOGGER = LoggerFactory.getLogger(AbstractImmutableNormalizedValueNode.class);
     private final V value;
 
     protected AbstractImmutableNormalizedValueNode(final K nodeIdentifier, final V value) {
-       super(nodeIdentifier);
-        this.value = Preconditions.checkNotNull(value, "value");
+        super(nodeIdentifier);
+        if (value == null) {
+            LOGGER.warn("The value of node " + nodeIdentifier.getNodeType() + " is null");
+        }
+        this.value = value;
     }
 
     @Override
diff --git a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/DocumentedNode.java b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/DocumentedNode.java
new file mode 100644 (file)
index 0000000..bb923b6
--- /dev/null
@@ -0,0 +1,37 @@
+package org.opendaylight.yangtools.yang.model.api;
+
+/**
+ *
+ * Node which can have documentation assigned.
+ *
+ */
+public interface DocumentedNode {
+
+    /**
+     * Returns description of the instance of the type <code>SchemaNode</code>
+     *
+     * @return string with textual description the node which represents the
+     *         argument of the YANG <code>description</code> substatement
+     */
+    String getDescription();
+
+    /**
+     * Returns reference of the instance of the type <code>SchemaNode</code>
+     *
+     * The reference refers to external document that provides additional
+     * information relevant for the instance of this type.
+     *
+     * @return string with the reference to some external document which
+     *         represents the argument of the YANG <code>reference</code>
+     *         substatement
+     */
+    String getReference();
+
+    /**
+     * Returns status of the instance of the type <code>SchemaNode</code>
+     *
+     * @return status of this node which represents the argument of the YANG
+     *         <code>status</code> substatement
+     */
+    Status getStatus();
+}
index 146da3ae65ef5e9c53300d97cd1348473c4aa26e..7c96cbb6a5cde08bd080de454ac81ebfea255c39 100644 (file)
@@ -14,11 +14,11 @@ import org.opendaylight.yangtools.yang.common.QName;
 /**
  * SchemaNode represents a node in schema tree.
  */
-public interface SchemaNode {
+public interface SchemaNode extends DocumentedNode {
 
     /**
      * Returns QName of the instance of the type <code>SchemaNode</code>.
-     * 
+     *
      * @return QName with the name of the schema node
      */
     QName getQName();
@@ -26,44 +26,16 @@ public interface SchemaNode {
     /**
      * Returns the schema path of the instance of the type
      * <code>SchemaNode</code> <code>SchemaNode</code>.
-     * 
+     *
      * @return schema path of the schema node
      */
     SchemaPath getPath();
 
     /**
-     * Returns description of the instance of the type <code>SchemaNode</code>
-     * 
-     * @return string with textual description the node which represents the
-     *         argument of the YANG <code>description</code> substatement
-     */
-    String getDescription();
-
-    /**
-     * Returns reference of the instance of the type <code>SchemaNode</code>
-     * 
-     * The reference refers to external document that provides additional
-     * information relevant for the instance of this type.
-     * 
-     * @return string with the reference to some external document which
-     *         represents the argument of the YANG <code>reference</code>
-     *         substatement
-     */
-    String getReference();
-
-    /**
-     * Returns status of the instance of the type <code>SchemaNode</code>
-     * 
-     * @return status of this node which represents the argument of the YANG
-     *         <code>status</code> substatement
-     */
-    Status getStatus();
-
-    /**
-     * 
+     *
      * Returns unknown schema nodes which belongs to this instance of the type
      * <code>SchemaNode</code>.
-     * 
+     *
      * @return list of unknown schema nodes defined under this schema node.
      */
     List<UnknownSchemaNode> getUnknownSchemaNodes();
index 176bb9496da48980c9b5908d850d46bb8aab3628..2d451da501dfe4e0e3cd45fbdcf24ad2a7250b6f 100644 (file)
@@ -6,8 +6,8 @@
  */
 package org.opendaylight.yangtools.yang.parser.builder.api;
 
+import java.util.Map;
 import java.util.Set;
-
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
@@ -135,4 +135,6 @@ public interface DataNodeContainerBuilder extends Builder {
     @Override
     DataNodeContainer build();
 
+    Map<QName, DataSchemaNode> getChildNodes();
+
 }
index 2a73848c29c498828c67b1e94e9c3957e547fc38..91708c00da26ccae197cc35e3c1855ed3ab548ce 100644 (file)
@@ -7,52 +7,36 @@
  */
 package org.opendaylight.yangtools.yang.parser.builder.impl;
 
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
-
 import java.net.URI;
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.Date;
 import java.util.Iterator;
 import java.util.List;
-import java.util.Set;
 
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
-import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
 import org.opendaylight.yangtools.yang.model.api.NamespaceRevisionAware;
 import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-import org.opendaylight.yangtools.yang.model.api.Status;
-import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.UsesNode;
 import org.opendaylight.yangtools.yang.model.util.RevisionAwareXPathImpl;
 import org.opendaylight.yangtools.yang.parser.builder.api.AugmentationSchemaBuilder;
 import org.opendaylight.yangtools.yang.parser.builder.api.Builder;
-import org.opendaylight.yangtools.yang.parser.builder.api.DataSchemaNodeBuilder;
-import org.opendaylight.yangtools.yang.parser.builder.api.GroupingBuilder;
 import org.opendaylight.yangtools.yang.parser.builder.api.UnknownSchemaNodeBuilder;
-import org.opendaylight.yangtools.yang.parser.builder.api.TypeDefinitionBuilder;
 import org.opendaylight.yangtools.yang.parser.builder.api.UsesNodeBuilder;
-import org.opendaylight.yangtools.yang.parser.builder.util.AbstractDataNodeContainerBuilder;
-import org.opendaylight.yangtools.yang.parser.util.YangParseException;
+import org.opendaylight.yangtools.yang.parser.builder.util.AbstractDocumentedDataNodeContainer;
+import org.opendaylight.yangtools.yang.parser.builder.util.AbstractDocumentedDataNodeContainerBuilder;
 
-public final class AugmentationSchemaBuilderImpl extends AbstractDataNodeContainerBuilder implements
+import com.google.common.base.Optional;
+import com.google.common.collect.ImmutableList;
+
+public final class AugmentationSchemaBuilderImpl extends AbstractDocumentedDataNodeContainerBuilder implements
         AugmentationSchemaBuilder {
     private final int order;
     private AugmentationSchemaImpl instance;
     private String whenCondition;
 
-    private String description;
-    private String reference;
-    private Status status = Status.CURRENT;
-
     private final String augmentTargetStr;
     private final SchemaPath targetPath;
     private SchemaPath targetNodeSchemaPath;
@@ -68,18 +52,8 @@ public final class AugmentationSchemaBuilderImpl extends AbstractDataNodeContain
     }
 
     @Override
-    public Set<GroupingDefinition> getGroupings() {
-        return Collections.emptySet();
-    }
-
-    @Override
-    public Set<GroupingBuilder> getGroupingBuilders() {
-        return Collections.emptySet();
-    }
-
-    @Override
-    public void addGrouping(final GroupingBuilder grouping) {
-        throw new YangParseException(getModuleName(), grouping.getLine(), "augment can not contains grouping statement");
+    protected String getStatementName() {
+        return "augment";
     }
 
     @Override
@@ -93,11 +67,8 @@ public final class AugmentationSchemaBuilderImpl extends AbstractDataNodeContain
             return instance;
         }
 
-        instance = new AugmentationSchemaImpl(targetPath, order);
-
-        instance.description = description;
-        instance.reference = reference;
-        instance.status = status;
+        buildChildren();
+        instance = new AugmentationSchemaImpl(targetPath, order,this);
 
         Builder parent = getParent();
         if (parent instanceof ModuleBuilder) {
@@ -131,18 +102,6 @@ public final class AugmentationSchemaBuilderImpl extends AbstractDataNodeContain
         }
         instance.whenCondition = whenStmt;
 
-        // CHILD NODES
-        for (DataSchemaNodeBuilder node : addedChildNodes) {
-            childNodes.put(node.getQName(), node.build());
-        }
-        instance.childNodes = ImmutableSet.copyOf(childNodes.values());
-
-        // USES
-        for (UsesNodeBuilder builder : addedUsesNodes) {
-            usesNodes.add(builder.build());
-        }
-        instance.uses = ImmutableSet.copyOf(usesNodes);
-
         // UNKNOWN NODES
         for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
             unknownNodes.add(b.build());
@@ -172,46 +131,6 @@ public final class AugmentationSchemaBuilderImpl extends AbstractDataNodeContain
         this.whenCondition = whenCondition;
     }
 
-    @Override
-    public Set<TypeDefinitionBuilder> getTypeDefinitionBuilders() {
-        return Collections.emptySet();
-    }
-
-    @Override
-    public void addTypedef(final TypeDefinitionBuilder type) {
-        throw new YangParseException(getModuleName(), type.getLine(), "Augmentation can not contains typedef statement.");
-    }
-
-    @Override
-    public String getDescription() {
-        return description;
-    }
-
-    @Override
-    public void setDescription(final String description) {
-        this.description = description;
-    }
-
-    @Override
-    public String getReference() {
-        return reference;
-    }
-
-    @Override
-    public void setReference(final String reference) {
-        this.reference = reference;
-    }
-
-    @Override
-    public Status getStatus() {
-        return status;
-    }
-
-    @Override
-    public void setStatus(final Status status) {
-        this.status = Preconditions.checkNotNull(status, "status cannot be null");
-    }
-
     @Override
     public String getTargetPathAsString() {
         return augmentTargetStr;
@@ -243,7 +162,7 @@ public final class AugmentationSchemaBuilderImpl extends AbstractDataNodeContain
         int result = 1;
         result = prime * result + ((augmentTargetStr == null) ? 0 : augmentTargetStr.hashCode());
         result = prime * result + ((whenCondition == null) ? 0 : whenCondition.hashCode());
-        result = prime * result + ((addedChildNodes == null) ? 0 : addedChildNodes.hashCode());
+        result = prime * result + getChildNodeBuilders().hashCode();
         return result;
     }
 
@@ -273,11 +192,11 @@ public final class AugmentationSchemaBuilderImpl extends AbstractDataNodeContain
         } else if (!whenCondition.equals(other.whenCondition)) {
             return false;
         }
-        if (addedChildNodes == null) {
-            if (other.addedChildNodes != null) {
+        if (other.getChildNodeBuilders() == null) {
+            if (other.getChildNodeBuilders() != null) {
                 return false;
             }
-        } else if (!addedChildNodes.equals(other.addedChildNodes)) {
+        } else if (!getChildNodeBuilders().equals(other.getChildNodeBuilders())) {
             return false;
         }
         return true;
@@ -292,23 +211,19 @@ public final class AugmentationSchemaBuilderImpl extends AbstractDataNodeContain
         copyOf = old;
     }
 
-    private static final class AugmentationSchemaImpl implements AugmentationSchema, NamespaceRevisionAware,
+    private static final class AugmentationSchemaImpl extends AbstractDocumentedDataNodeContainer implements AugmentationSchema, NamespaceRevisionAware,
             Comparable<AugmentationSchemaImpl> {
         private final int order;
         private SchemaPath targetPath;
         private RevisionAwareXPath whenCondition;
-        private ImmutableSet<DataSchemaNode> childNodes;
-        private ImmutableSet<UsesNode> uses;
-        private String description;
-        private String reference;
-        private Status status;
 
         private URI namespace;
         private Date revision;
         private ImmutableList<UnknownSchemaNode> unknownNodes;
         private AugmentationSchema copyOf;
 
-        public AugmentationSchemaImpl(final SchemaPath targetPath, final int order) {
+        public AugmentationSchemaImpl(final SchemaPath targetPath, final int order, final AugmentationSchemaBuilderImpl builder) {
+            super(builder);
             this.targetPath = targetPath;
             this.order = order;
         }
@@ -332,64 +247,11 @@ public final class AugmentationSchemaBuilderImpl extends AbstractDataNodeContain
             return whenCondition;
         }
 
-        @Override
-        public Set<DataSchemaNode> getChildNodes() {
-            return childNodes;
-        }
-
-        /**
-         * Always returns an empty set, because augment can not contains
-         * grouping statement.
-         */
-        @Override
-        public Set<GroupingDefinition> getGroupings() {
-            return Collections.emptySet();
-        }
-
-        @Override
-        public Set<UsesNode> getUses() {
-            return uses;
-        }
-
-        /**
-         * Always returns an empty set, because augment can not contains type
-         * definitions.
-         */
-        @Override
-        public Set<TypeDefinition<?>> getTypeDefinitions() {
-            return Collections.emptySet();
-        }
-
-        @Override
-        public String getDescription() {
-            return description;
-        }
-
-        @Override
-        public String getReference() {
-            return reference;
-        }
-
-        @Override
-        public Status getStatus() {
-            return status;
-        }
-
         @Override
         public List<UnknownSchemaNode> getUnknownSchemaNodes() {
             return unknownNodes;
         }
 
-        @Override
-        public DataSchemaNode getDataChildByName(final QName name) {
-            return getChildNode(childNodes, name);
-        }
-
-        @Override
-        public DataSchemaNode getDataChildByName(final String name) {
-            return getChildNode(childNodes, name);
-        }
-
         @Override
         public URI getNamespace() {
             return namespace;
@@ -406,7 +268,7 @@ public final class AugmentationSchemaBuilderImpl extends AbstractDataNodeContain
             int result = 1;
             result = prime * result + ((targetPath == null) ? 0 : targetPath.hashCode());
             result = prime * result + ((whenCondition == null) ? 0 : whenCondition.hashCode());
-            result = prime * result + ((childNodes == null) ? 0 : childNodes.hashCode());
+            result = getChildNodes().hashCode();
             return result;
         }
 
@@ -436,11 +298,7 @@ public final class AugmentationSchemaBuilderImpl extends AbstractDataNodeContain
             } else if (!whenCondition.equals(other.whenCondition)) {
                 return false;
             }
-            if (childNodes == null) {
-                if (other.childNodes != null) {
-                    return false;
-                }
-            } else if (!childNodes.equals(other.childNodes)) {
+            if (!getChildNodes().equals(other.getChildNodes())) {
                 return false;
             }
             return true;
@@ -476,5 +334,4 @@ public final class AugmentationSchemaBuilderImpl extends AbstractDataNodeContain
             return this.order - o.order;
         }
     }
-
 }
index 643a22f6d4abc89e18e384b72e60fd25637d95a2..2a59e7279aa3ac1e3f0ce7d682f9f63c3f5e39d8 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.yangtools.yang.parser.builder.impl;
 
 import java.net.URI;
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.Date;
 import java.util.List;
 import java.util.Set;
@@ -18,28 +17,24 @@ import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
 import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
 import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition;
-import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 import org.opendaylight.yangtools.yang.model.api.Status;
-import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.UsesNode;
 import org.opendaylight.yangtools.yang.parser.builder.api.AugmentationSchemaBuilder;
 import org.opendaylight.yangtools.yang.parser.builder.api.AugmentationTargetBuilder;
 import org.opendaylight.yangtools.yang.parser.builder.api.ConstraintsBuilder;
 import org.opendaylight.yangtools.yang.parser.builder.api.DataSchemaNodeBuilder;
 import org.opendaylight.yangtools.yang.parser.builder.api.TypeDefinitionBuilder;
 import org.opendaylight.yangtools.yang.parser.builder.api.UnknownSchemaNodeBuilder;
-import org.opendaylight.yangtools.yang.parser.builder.api.UsesNodeBuilder;
-import org.opendaylight.yangtools.yang.parser.builder.util.AbstractDataNodeContainerBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.util.AbstractDocumentedDataNodeContainer;
+import org.opendaylight.yangtools.yang.parser.builder.util.AbstractDocumentedDataNodeContainerBuilder;
 import org.opendaylight.yangtools.yang.parser.util.YangParseException;
 
 import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
 
-public final class ChoiceCaseBuilder extends AbstractDataNodeContainerBuilder implements DataSchemaNodeBuilder,
+public final class ChoiceCaseBuilder extends AbstractDocumentedDataNodeContainerBuilder implements DataSchemaNodeBuilder,
         AugmentationTargetBuilder {
     private ChoiceCaseNodeImpl instance;
     // SchemaNode args
@@ -63,6 +58,7 @@ public final class ChoiceCaseBuilder extends AbstractDataNodeContainerBuilder im
 
     public ChoiceCaseBuilder(final String moduleName, final int line, final QName qname, final SchemaPath path,
             final ChoiceCaseNode base) {
+
         super(moduleName, line, qname);
         this.schemaPath = Preconditions.checkNotNull(path, "Schema Path must not be null");
         constraints = new ConstraintsBuilderImpl(moduleName, line, base.getConstraints());
@@ -76,13 +72,9 @@ public final class ChoiceCaseBuilder extends AbstractDataNodeContainerBuilder im
         URI ns = qname.getNamespace();
         Date rev = qname.getRevision();
         String pref = qname.getPrefix();
-        addedChildNodes.addAll(BuilderUtils.wrapChildNodes(moduleName, line, base.getChildNodes(), path, ns, rev, pref));
-        addedGroupings.addAll(BuilderUtils.wrapGroupings(moduleName, line, base.getGroupings(), path, ns, rev, pref));
         addedUnknownNodes.addAll(BuilderUtils.wrapUnknownNodes(moduleName, line, base.getUnknownSchemaNodes(), path, ns,
                 rev, pref));
-
         augmentations.addAll(base.getAvailableAugmentations());
-        usesNodes.addAll(base.getUses());
     }
 
     @Override
@@ -90,29 +82,14 @@ public final class ChoiceCaseBuilder extends AbstractDataNodeContainerBuilder im
         if (instance != null) {
             return instance;
         }
+        buildChildren();
+        instance = new ChoiceCaseNodeImpl(qname, schemaPath,this);
 
-        instance = new ChoiceCaseNodeImpl(qname, schemaPath);
-
-        instance.description = description;
-        instance.reference = reference;
-        instance.status = status;
         instance.augmenting = augmenting;
         instance.addedByUses = addedByUses;
 
         instance.constraints = constraints.toInstance();
 
-        // CHILD NODES
-        for (DataSchemaNodeBuilder node : addedChildNodes) {
-            childNodes.put(node.getQName(), node.build());
-        }
-        instance.childNodes = ImmutableSet.copyOf(childNodes.values());
-
-        // USES
-        for (UsesNodeBuilder builder : addedUsesNodes) {
-            usesNodes.add(builder.build());
-        }
-        instance.uses = ImmutableSet.copyOf(usesNodes);
-
         // UNKNOWN NODES
         for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
             unknownNodes.add(b.build());
@@ -137,37 +114,6 @@ public final class ChoiceCaseBuilder extends AbstractDataNodeContainerBuilder im
     public void setPath(final SchemaPath path) {
         this.schemaPath = path;
     }
-
-    @Override
-    public String getDescription() {
-        return description;
-    }
-
-    @Override
-    public void setDescription(final String description) {
-        this.description = description;
-    }
-
-    @Override
-    public String getReference() {
-        return reference;
-    }
-
-    @Override
-    public void setReference(final String reference) {
-        this.reference = reference;
-    }
-
-    @Override
-    public Status getStatus() {
-        return status;
-    }
-
-    @Override
-    public void setStatus(final Status status) {
-        this.status = Preconditions.checkNotNull(status, "status cannot be null");
-    }
-
     @Override
     public boolean isAugmenting() {
         return augmenting;
@@ -188,11 +134,6 @@ public final class ChoiceCaseBuilder extends AbstractDataNodeContainerBuilder im
         this.addedByUses = addedByUses;
     }
 
-    @Override
-    public Set<TypeDefinitionBuilder> getTypeDefinitionBuilders() {
-        return Collections.emptySet();
-    }
-
     @Override
     public void addTypedef(final TypeDefinitionBuilder typedefBuilder) {
         throw new YangParseException(getModuleName(), typedefBuilder.getLine(), "Can not add type definition to choice case.");
@@ -260,21 +201,22 @@ public final class ChoiceCaseBuilder extends AbstractDataNodeContainerBuilder im
         return "case " + getQName().getLocalName();
     }
 
-    private static final class ChoiceCaseNodeImpl implements ChoiceCaseNode {
+    @Override
+    protected String getStatementName() {
+        return "choice";
+    }
+
+    private static final class ChoiceCaseNodeImpl extends AbstractDocumentedDataNodeContainer implements ChoiceCaseNode {
         private final QName qname;
         private final SchemaPath path;
-        private String description;
-        private String reference;
-        private Status status = Status.CURRENT;
         private boolean augmenting;
         private boolean addedByUses;
         private ConstraintDefinition constraints;
-        private ImmutableSet<DataSchemaNode> childNodes;
         private ImmutableSet<AugmentationSchema> augmentations;
-        private ImmutableSet<UsesNode> uses;
         private ImmutableList<UnknownSchemaNode> unknownNodes;
 
-        private ChoiceCaseNodeImpl(final QName qname, final SchemaPath path) {
+        private ChoiceCaseNodeImpl(final QName qname, final SchemaPath path,final ChoiceCaseBuilder builder) {
+            super(builder);
             this.qname = qname;
             this.path = path;
         }
@@ -289,21 +231,6 @@ public final class ChoiceCaseBuilder extends AbstractDataNodeContainerBuilder im
             return path;
         }
 
-        @Override
-        public String getDescription() {
-            return description;
-        }
-
-        @Override
-        public String getReference() {
-            return reference;
-        }
-
-        @Override
-        public Status getStatus() {
-            return status;
-        }
-
         @Override
         public boolean isConfiguration() {
             return false;
@@ -329,40 +256,6 @@ public final class ChoiceCaseBuilder extends AbstractDataNodeContainerBuilder im
             return unknownNodes;
         }
 
-        /**
-         * Always returns an empty set, because case node can not contains type
-         * definitions.
-         */
-        @Override
-        public Set<TypeDefinition<?>> getTypeDefinitions() {
-            return Collections.emptySet();
-        }
-
-        @Override
-        public Set<DataSchemaNode> getChildNodes() {
-            return childNodes;
-        }
-
-        @Override
-        public Set<GroupingDefinition> getGroupings() {
-            return Collections.emptySet();
-        }
-
-        @Override
-        public DataSchemaNode getDataChildByName(final QName name) {
-            return getChildNode(childNodes, name);
-        }
-
-        @Override
-        public DataSchemaNode getDataChildByName(final String name) {
-            return getChildNode(childNodes, name);
-        }
-
-        @Override
-        public Set<UsesNode> getUses() {
-            return uses;
-        }
-
         @Override
         public Set<AugmentationSchema> getAvailableAugmentations() {
             return augmentations;
index 5de90e46b24a2174ed8a252aea2b294d11f0ba83..25602c0cc624202d25be85bc06f56719dfdb8fc7 100644 (file)
@@ -7,9 +7,7 @@
  */
 package org.opendaylight.yangtools.yang.parser.builder.impl;
 
-import java.net.URI;
 import java.util.ArrayList;
-import java.util.Date;
 import java.util.List;
 import java.util.Set;
 
@@ -17,37 +15,26 @@ import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
 import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-import org.opendaylight.yangtools.yang.model.api.Status;
-import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.UsesNode;
 import org.opendaylight.yangtools.yang.parser.builder.api.AugmentationSchemaBuilder;
 import org.opendaylight.yangtools.yang.parser.builder.api.AugmentationTargetBuilder;
 import org.opendaylight.yangtools.yang.parser.builder.api.ConstraintsBuilder;
 import org.opendaylight.yangtools.yang.parser.builder.api.DataSchemaNodeBuilder;
-import org.opendaylight.yangtools.yang.parser.builder.api.GroupingBuilder;
-import org.opendaylight.yangtools.yang.parser.builder.api.TypeDefinitionBuilder;
 import org.opendaylight.yangtools.yang.parser.builder.api.UnknownSchemaNodeBuilder;
-import org.opendaylight.yangtools.yang.parser.builder.api.UsesNodeBuilder;
-import org.opendaylight.yangtools.yang.parser.builder.util.AbstractDataNodeContainerBuilder;
-import org.opendaylight.yangtools.yang.parser.util.YangParseException;
+import org.opendaylight.yangtools.yang.parser.builder.util.AbstractDocumentedDataNodeContainer;
+import org.opendaylight.yangtools.yang.parser.builder.util.AbstractDocumentedDataNodeContainerBuilder;
 
 import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
 
-public final class ContainerSchemaNodeBuilder extends AbstractDataNodeContainerBuilder implements
+public final class ContainerSchemaNodeBuilder extends AbstractDocumentedDataNodeContainerBuilder implements
         AugmentationTargetBuilder, DataSchemaNodeBuilder {
     private ContainerSchemaNodeImpl instance;
     private boolean presence;
     // SchemaNode args
     private SchemaPath path;
-    private String description;
-    private String reference;
-    private Status status = Status.CURRENT;
     // DataSchemaNode args
     private boolean augmenting;
     private boolean addedByUses;
@@ -66,29 +53,23 @@ public final class ContainerSchemaNodeBuilder extends AbstractDataNodeContainerB
     // constructor for uses
     public ContainerSchemaNodeBuilder(final String moduleName, final int line, final QName qname,
             final SchemaPath path, final ContainerSchemaNode base) {
-        super(moduleName, line, qname);
+        super(moduleName, line, qname, path, base);
         this.path = Preconditions.checkNotNull(path, "Schema Path must not be null");
+
         constraints = new ConstraintsBuilderImpl(moduleName, line, base.getConstraints());
 
-        description = base.getDescription();
-        reference = base.getReference();
-        status = base.getStatus();
         augmenting = base.isAugmenting();
         addedByUses = base.isAddedByUses();
         configuration = base.isConfiguration();
         presence = base.isPresenceContainer();
 
-        URI ns = qname.getNamespace();
-        Date rev = qname.getRevision();
-        String pref = qname.getPrefix();
-        addedChildNodes.addAll(BuilderUtils.wrapChildNodes(moduleName, line, base.getChildNodes(), path, ns, rev, pref));
-        addedGroupings.addAll(BuilderUtils.wrapGroupings(moduleName, line, base.getGroupings(), path, ns, rev, pref));
-        addedTypedefs.addAll(BuilderUtils.wrapTypedefs(moduleName, line, base, path, ns, rev, pref));
-        addedUnknownNodes.addAll(BuilderUtils.wrapUnknownNodes(moduleName, line, base.getUnknownSchemaNodes(), path, ns,
-                rev, pref));
-
         augmentations.addAll(base.getAvailableAugmentations());
-        usesNodes.addAll(base.getUses());
+
+    }
+
+    @Override
+    protected String getStatementName() {
+        return "container";
     }
 
     @Override
@@ -97,41 +78,15 @@ public final class ContainerSchemaNodeBuilder extends AbstractDataNodeContainerB
             return instance;
         }
 
-        instance = new ContainerSchemaNodeImpl(qname, path);
+        buildChildren();
+        instance = new ContainerSchemaNodeImpl(this);
 
-        instance.description = description;
-        instance.reference = reference;
-        instance.status = status;
         instance.augmenting = augmenting;
         instance.addedByUses = addedByUses;
         instance.configuration = configuration;
         instance.constraints = constraints.toInstance();
         instance.presence = presence;
 
-        // CHILD NODES
-        for (DataSchemaNodeBuilder node : addedChildNodes) {
-            childNodes.put(node.getQName(), node.build());
-        }
-        instance.childNodes = ImmutableSet.copyOf(childNodes.values());
-
-        // GROUPINGS
-        for (GroupingBuilder builder : addedGroupings) {
-            groupings.add(builder.build());
-        }
-        instance.groupings = ImmutableSet.copyOf(groupings);
-
-        // TYPEDEFS
-        for (TypeDefinitionBuilder entry : addedTypedefs) {
-            typedefs.add(entry.build());
-        }
-        instance.typeDefinitions = ImmutableSet.copyOf(typedefs);
-
-        // USES
-        for (UsesNodeBuilder builder : addedUsesNodes) {
-            usesNodes.add(builder.build());
-        }
-        instance.uses = ImmutableSet.copyOf(usesNodes);
-
         // AUGMENTATIONS
         for (AugmentationSchemaBuilder builder : augmentationBuilders) {
             augmentations.add(builder.build());
@@ -147,23 +102,6 @@ public final class ContainerSchemaNodeBuilder extends AbstractDataNodeContainerB
         return instance;
     }
 
-    @Override
-    public Set<TypeDefinitionBuilder> getTypeDefinitionBuilders() {
-        return addedTypedefs;
-    }
-
-    @Override
-    public void addTypedef(final TypeDefinitionBuilder type) {
-        String typeName = type.getQName().getLocalName();
-        for (TypeDefinitionBuilder addedTypedef : addedTypedefs) {
-            if (addedTypedef.getQName().getLocalName().equals(typeName)) {
-                throw new YangParseException(getModuleName(), type.getLine(), "Can not add typedef '" + typeName
-                        + "': typedef with same name already declared at line " + addedTypedef.getLine());
-            }
-        }
-        addedTypedefs.add(type);
-    }
-
     public List<AugmentationSchemaBuilder> getAugmentationBuilders() {
         return augmentationBuilders;
     }
@@ -183,36 +121,6 @@ public final class ContainerSchemaNodeBuilder extends AbstractDataNodeContainerB
         this.path = path;
     }
 
-    @Override
-    public String getDescription() {
-        return description;
-    }
-
-    @Override
-    public void setDescription(final String description) {
-        this.description = description;
-    }
-
-    @Override
-    public String getReference() {
-        return reference;
-    }
-
-    @Override
-    public void setReference(final String reference) {
-        this.reference = reference;
-    }
-
-    @Override
-    public Status getStatus() {
-        return status;
-    }
-
-    @Override
-    public void setStatus(final Status status) {
-        this.status = Preconditions.checkNotNull(status, "status cannot be null");
-    }
-
     @Override
     public boolean isAugmenting() {
         return augmenting;
@@ -300,29 +208,25 @@ public final class ContainerSchemaNodeBuilder extends AbstractDataNodeContainerB
         return "container " + qname.getLocalName();
     }
 
-    private static final class ContainerSchemaNodeImpl implements ContainerSchemaNode {
+    private static final class ContainerSchemaNodeImpl extends AbstractDocumentedDataNodeContainer implements
+            ContainerSchemaNode {
         private final QName qname;
         private final SchemaPath path;
-        private String description;
-        private String reference;
-        private Status status;
+
         private boolean augmenting;
         private boolean addedByUses;
         private boolean configuration;
         private ConstraintDefinition constraints;
 
         private ImmutableSet<AugmentationSchema> augmentations;
-        private ImmutableSet<DataSchemaNode> childNodes;
-        private ImmutableSet<GroupingDefinition> groupings;
-        private ImmutableSet<TypeDefinition<?>> typeDefinitions;
-        private ImmutableSet<UsesNode> uses;
         private ImmutableList<UnknownSchemaNode> unknownNodes;
 
         private boolean presence;
 
-        private ContainerSchemaNodeImpl(final QName qname, final SchemaPath path) {
-            this.qname = qname;
-            this.path = path;
+        public ContainerSchemaNodeImpl(final ContainerSchemaNodeBuilder builder) {
+            super(builder);
+            this.qname = builder.getQName();
+            this.path = builder.getPath();
         }
 
         @Override
@@ -335,21 +239,6 @@ public final class ContainerSchemaNodeBuilder extends AbstractDataNodeContainerB
             return path;
         }
 
-        @Override
-        public String getDescription() {
-            return description;
-        }
-
-        @Override
-        public String getReference() {
-            return reference;
-        }
-
-        @Override
-        public Status getStatus() {
-            return status;
-        }
-
         @Override
         public boolean isAugmenting() {
             return augmenting;
@@ -375,41 +264,11 @@ public final class ContainerSchemaNodeBuilder extends AbstractDataNodeContainerB
             return augmentations;
         }
 
-        @Override
-        public Set<DataSchemaNode> getChildNodes() {
-            return childNodes;
-        }
-
-        @Override
-        public Set<GroupingDefinition> getGroupings() {
-            return groupings;
-        }
-
-        @Override
-        public DataSchemaNode getDataChildByName(final QName name) {
-            return getChildNode(childNodes, name);
-        }
-
-        @Override
-        public DataSchemaNode getDataChildByName(final String name) {
-            return getChildNode(childNodes, name);
-        }
-
-        @Override
-        public Set<UsesNode> getUses() {
-            return uses;
-        }
-
         @Override
         public boolean isPresenceContainer() {
             return presence;
         }
 
-        @Override
-        public Set<TypeDefinition<?>> getTypeDefinitions() {
-            return typeDefinitions;
-        }
-
         @Override
         public List<UnknownSchemaNode> getUnknownSchemaNodes() {
             return unknownNodes;
index 51239575fd5410c9f4c733b9f47e3d6c2c0dc7ea..9a5f9fb10d102068ac60d1e4858a669e7e83e877 100644 (file)
@@ -14,27 +14,22 @@ import java.util.List;
 import java.util.Set;
 
 import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 import org.opendaylight.yangtools.yang.model.api.Status;
-import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.UsesNode;
 import org.opendaylight.yangtools.yang.parser.builder.api.Builder;
 import org.opendaylight.yangtools.yang.parser.builder.api.DataSchemaNodeBuilder;
 import org.opendaylight.yangtools.yang.parser.builder.api.GroupingBuilder;
 import org.opendaylight.yangtools.yang.parser.builder.api.TypeDefinitionBuilder;
 import org.opendaylight.yangtools.yang.parser.builder.api.UnknownSchemaNodeBuilder;
-import org.opendaylight.yangtools.yang.parser.builder.api.UsesNodeBuilder;
-import org.opendaylight.yangtools.yang.parser.builder.util.AbstractDataNodeContainerBuilder;
-import org.opendaylight.yangtools.yang.parser.util.YangParseException;
+import org.opendaylight.yangtools.yang.parser.builder.util.AbstractDocumentedDataNodeContainer;
+import org.opendaylight.yangtools.yang.parser.builder.util.AbstractDocumentedDataNodeContainerBuilder;
 
 import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
 
-public final class GroupingBuilderImpl extends AbstractDataNodeContainerBuilder implements GroupingBuilder {
+public final class GroupingBuilderImpl extends AbstractDocumentedDataNodeContainerBuilder implements GroupingBuilder {
     private GroupingDefinitionImpl instance;
     // SchemaNode args
     private SchemaPath schemaPath;
@@ -51,7 +46,8 @@ public final class GroupingBuilderImpl extends AbstractDataNodeContainerBuilder
 
     public GroupingBuilderImpl(final String moduleName, final int line, final QName qname, final SchemaPath path,
             final GroupingDefinition base) {
-        this(moduleName, line, base.getQName(),path);
+        super(moduleName, line, base.getQName(), path, base);
+        schemaPath = path;
 
         description = base.getDescription();
         reference = base.getReference();
@@ -61,13 +57,8 @@ public final class GroupingBuilderImpl extends AbstractDataNodeContainerBuilder
         URI ns = qname.getNamespace();
         Date rev = qname.getRevision();
         String pref = qname.getPrefix();
-        addedChildNodes.addAll(BuilderUtils.wrapChildNodes(moduleName, line, base.getChildNodes(), path, ns, rev, pref));
-        addedGroupings.addAll(BuilderUtils.wrapGroupings(moduleName, line, base.getGroupings(), path, ns, rev, pref));
-        addedTypedefs.addAll(BuilderUtils.wrapTypedefs(moduleName, line, base, path, ns, rev, pref));
-        addedUnknownNodes.addAll(BuilderUtils.wrapUnknownNodes(moduleName, line, base.getUnknownSchemaNodes(), path, ns,
-                rev, pref));
-
-        usesNodes.addAll(base.getUses());
+        addedUnknownNodes.addAll(BuilderUtils.wrapUnknownNodes(moduleName, line, base.getUnknownSchemaNodes(), path,
+                ns, rev, pref));
     }
 
     @Override
@@ -75,38 +66,10 @@ public final class GroupingBuilderImpl extends AbstractDataNodeContainerBuilder
         if (instance != null) {
             return instance;
         }
-
-        instance = new GroupingDefinitionImpl(qname, schemaPath);
-
-        instance.description = description;
-        instance.reference = reference;
-        instance.status = status;
+        buildChildren();
+        instance = new GroupingDefinitionImpl(qname, schemaPath, this);
         instance.addedByUses = addedByUses;
 
-        // CHILD NODES
-        for (DataSchemaNodeBuilder node : addedChildNodes) {
-            childNodes.put(node.getQName(), node.build());
-        }
-        instance.childNodes = ImmutableSet.copyOf(childNodes.values());
-
-        // GROUPINGS
-        for (GroupingBuilder builder : addedGroupings) {
-            groupings.add(builder.build());
-        }
-        instance.groupings = ImmutableSet.copyOf(groupings);
-
-        // TYPEDEFS
-        for (TypeDefinitionBuilder entry : addedTypedefs) {
-            typedefs.add(entry.build());
-        }
-        instance.typeDefinitions = ImmutableSet.copyOf(typedefs);
-
-        // USES
-        for (UsesNodeBuilder builder : addedUsesNodes) {
-            usesNodes.add(builder.build());
-        }
-        instance.uses = ImmutableSet.copyOf(usesNodes);
-
         // UNKNOWN NODES
         for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
             unknownNodes.add(b.build());
@@ -119,7 +82,7 @@ public final class GroupingBuilderImpl extends AbstractDataNodeContainerBuilder
     @Override
     public Set<DataSchemaNodeBuilder> instantiateChildNodes(final Builder newParent) {
         final Set<DataSchemaNodeBuilder> nodes = new HashSet<>();
-        for (DataSchemaNodeBuilder node : addedChildNodes) {
+        for (DataSchemaNodeBuilder node : getChildNodeBuilders()) {
             DataSchemaNodeBuilder copy = CopyUtils.copy(node, newParent, true);
             BuilderUtils.setNodeAddedByUses(copy);
             nodes.add(copy);
@@ -130,7 +93,7 @@ public final class GroupingBuilderImpl extends AbstractDataNodeContainerBuilder
     @Override
     public Set<TypeDefinitionBuilder> instantiateTypedefs(final Builder newParent) {
         final Set<TypeDefinitionBuilder> nodes = new HashSet<>();
-        for (TypeDefinitionBuilder node : addedTypedefs) {
+        for (TypeDefinitionBuilder node : getTypeDefinitionBuilders()) {
             TypeDefinitionBuilder copy = CopyUtils.copy(node, newParent, true);
             nodes.add(copy);
         }
@@ -140,7 +103,7 @@ public final class GroupingBuilderImpl extends AbstractDataNodeContainerBuilder
     @Override
     public Set<GroupingBuilder> instantiateGroupings(final Builder newParent) {
         final Set<GroupingBuilder> nodes = new HashSet<>();
-        for (GroupingBuilder node : addedGroupings) {
+        for (GroupingBuilder node : getGroupingBuilders()) {
             GroupingBuilder copy = CopyUtils.copy(node, newParent, true);
             copy.setAddedByUses(true);
             for (DataSchemaNodeBuilder childNode : copy.getChildNodeBuilders()) {
@@ -162,21 +125,6 @@ public final class GroupingBuilderImpl extends AbstractDataNodeContainerBuilder
         return nodes;
     }
 
-    @Override
-    public Set<TypeDefinitionBuilder> getTypeDefinitionBuilders() {
-        return addedTypedefs;
-    }
-
-    @Override
-    public void addTypedef(final TypeDefinitionBuilder type) {
-        String typeName = type.getQName().getLocalName();
-        for (TypeDefinitionBuilder addedTypedef : addedTypedefs) {
-            throw new YangParseException(getModuleName(), type.getLine(), "Can not add typedef '" + typeName
-                    + "': typedef with same name already declared at line " + addedTypedef.getLine());
-        }
-        addedTypedefs.add(type);
-    }
-
     @Override
     public SchemaPath getPath() {
         return schemaPath;
@@ -187,36 +135,6 @@ public final class GroupingBuilderImpl extends AbstractDataNodeContainerBuilder
         this.schemaPath = path;
     }
 
-    @Override
-    public String getDescription() {
-        return description;
-    }
-
-    @Override
-    public void setDescription(final String description) {
-        this.description = description;
-    }
-
-    @Override
-    public String getReference() {
-        return reference;
-    }
-
-    @Override
-    public void setReference(final String reference) {
-        this.reference = reference;
-    }
-
-    @Override
-    public Status getStatus() {
-        return status;
-    }
-
-    @Override
-    public void setStatus(final Status status) {
-        this.status = Preconditions.checkNotNull(status, "status cannot be null");
-    }
-
     @Override
     public boolean isAddedByUses() {
         return addedByUses;
@@ -273,20 +191,21 @@ public final class GroupingBuilderImpl extends AbstractDataNodeContainerBuilder
         return true;
     }
 
-    private static final class GroupingDefinitionImpl implements GroupingDefinition {
+    @Override
+    protected String getStatementName() {
+        return "grouping";
+    }
+
+    private static final class GroupingDefinitionImpl extends AbstractDocumentedDataNodeContainer implements
+            GroupingDefinition {
         private final QName qname;
         private final SchemaPath path;
-        private String description;
-        private String reference;
-        private Status status;
+
         private boolean addedByUses;
-        private ImmutableSet<DataSchemaNode> childNodes;
-        private ImmutableSet<GroupingDefinition> groupings;
-        private ImmutableSet<TypeDefinition<?>> typeDefinitions;
-        private ImmutableSet<UsesNode> uses;
         private ImmutableList<UnknownSchemaNode> unknownNodes;
 
-        private GroupingDefinitionImpl(final QName qname, final SchemaPath path) {
+        private GroupingDefinitionImpl(final QName qname, final SchemaPath path, final GroupingBuilderImpl builder) {
+            super(builder);
             this.qname = qname;
             this.path = path;
         }
@@ -301,61 +220,16 @@ public final class GroupingBuilderImpl extends AbstractDataNodeContainerBuilder
             return path;
         }
 
-        @Override
-        public String getDescription() {
-            return description;
-        }
-
-        @Override
-        public String getReference() {
-            return reference;
-        }
-
-        @Override
-        public Status getStatus() {
-            return status;
-        }
-
         @Override
         public boolean isAddedByUses() {
             return addedByUses;
         }
 
-        @Override
-        public Set<DataSchemaNode> getChildNodes() {
-            return childNodes;
-        }
-
-        @Override
-        public Set<GroupingDefinition> getGroupings() {
-            return groupings;
-        }
-
-        @Override
-        public Set<UsesNode> getUses() {
-            return uses;
-        }
-
-        @Override
-        public Set<TypeDefinition<?>> getTypeDefinitions() {
-            return typeDefinitions;
-        }
-
         @Override
         public List<UnknownSchemaNode> getUnknownSchemaNodes() {
             return unknownNodes;
         }
 
-        @Override
-        public DataSchemaNode getDataChildByName(final QName name) {
-            return getChildNode(childNodes, name);
-        }
-
-        @Override
-        public DataSchemaNode getDataChildByName(final String name) {
-            return getChildNode(childNodes, name);
-        }
-
         @Override
         public int hashCode() {
             final int prime = 31;
index 8cff8ec7de7266da996b2d31007828d0e4b90a49..e099e668c56326dc5425b66e789b20f4e3b62730 100644 (file)
@@ -16,30 +16,22 @@ import java.util.Set;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
 import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition;
-import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-import org.opendaylight.yangtools.yang.model.api.Status;
-import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.UsesNode;
 import org.opendaylight.yangtools.yang.parser.builder.api.AugmentationSchemaBuilder;
 import org.opendaylight.yangtools.yang.parser.builder.api.AugmentationTargetBuilder;
 import org.opendaylight.yangtools.yang.parser.builder.api.ConstraintsBuilder;
 import org.opendaylight.yangtools.yang.parser.builder.api.DataSchemaNodeBuilder;
-import org.opendaylight.yangtools.yang.parser.builder.api.GroupingBuilder;
-import org.opendaylight.yangtools.yang.parser.builder.api.TypeDefinitionBuilder;
 import org.opendaylight.yangtools.yang.parser.builder.api.UnknownSchemaNodeBuilder;
-import org.opendaylight.yangtools.yang.parser.builder.api.UsesNodeBuilder;
-import org.opendaylight.yangtools.yang.parser.builder.util.AbstractDataNodeContainerBuilder;
-import org.opendaylight.yangtools.yang.parser.util.YangParseException;
+import org.opendaylight.yangtools.yang.parser.builder.util.AbstractDocumentedDataNodeContainer;
+import org.opendaylight.yangtools.yang.parser.builder.util.AbstractDocumentedDataNodeContainerBuilder;
 
 import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
 
-public final class ListSchemaNodeBuilder extends AbstractDataNodeContainerBuilder implements DataSchemaNodeBuilder,
+public final class ListSchemaNodeBuilder extends AbstractDocumentedDataNodeContainerBuilder implements DataSchemaNodeBuilder,
         AugmentationTargetBuilder {
     private ListSchemaNodeImpl instance;
     private boolean userOrdered;
@@ -47,9 +39,6 @@ public final class ListSchemaNodeBuilder extends AbstractDataNodeContainerBuilde
     private List<QName> keyDefinition;
     // SchemaNode args
     private SchemaPath schemaPath;
-    private String description;
-    private String reference;
-    private Status status = Status.CURRENT;
     // DataSchemaNode args
     private boolean augmenting;
     private boolean addedByUses;
@@ -67,16 +56,13 @@ public final class ListSchemaNodeBuilder extends AbstractDataNodeContainerBuilde
 
     public ListSchemaNodeBuilder(final String moduleName, final int line, final QName qname, final SchemaPath path,
             final ListSchemaNode base) {
-        super(moduleName, line, qname);
+        super(moduleName, line, qname,path,base);
         this.schemaPath = Preconditions.checkNotNull(path, "Schema Path must not be null");
         constraints = new ConstraintsBuilderImpl(moduleName, line, base.getConstraints());
 
         keyDefinition = ImmutableList.copyOf(base.getKeyDefinition());
         userOrdered = base.isUserOrdered();
 
-        description = base.getDescription();
-        reference = base.getReference();
-        status = base.getStatus();
         augmenting = base.isAugmenting();
         addedByUses = base.isAddedByUses();
         configuration = base.isConfiguration();
@@ -84,14 +70,10 @@ public final class ListSchemaNodeBuilder extends AbstractDataNodeContainerBuilde
         URI ns = qname.getNamespace();
         Date rev = qname.getRevision();
         String pref = qname.getPrefix();
-        addedChildNodes.addAll(BuilderUtils.wrapChildNodes(moduleName, line, base.getChildNodes(), path, ns, rev, pref));
-        addedGroupings.addAll(BuilderUtils.wrapGroupings(moduleName, line, base.getGroupings(), path, ns, rev, pref));
-        addedTypedefs.addAll(BuilderUtils.wrapTypedefs(moduleName, line, base, path, ns, rev, pref));
         addedUnknownNodes.addAll(BuilderUtils.wrapUnknownNodes(moduleName, line, base.getUnknownSchemaNodes(), path, ns,
                 rev, pref));
 
         augmentations.addAll(base.getAvailableAugmentations());
-        usesNodes.addAll(base.getUses());
     }
 
     @Override
@@ -99,24 +81,15 @@ public final class ListSchemaNodeBuilder extends AbstractDataNodeContainerBuilde
         if (instance != null) {
             return instance;
         }
+        buildChildren();
+        instance = new ListSchemaNodeImpl(qname, schemaPath,this);
 
-        instance = new ListSchemaNodeImpl(qname, schemaPath);
-
-        instance.description = description;
-        instance.reference = reference;
-        instance.status = status;
         instance.augmenting = augmenting;
         instance.addedByUses = addedByUses;
         instance.configuration = configuration;
         instance.constraints = constraints.toInstance();
         instance.userOrdered = userOrdered;
 
-        // CHILD NODES
-        for (DataSchemaNodeBuilder node : addedChildNodes) {
-            childNodes.put(node.getQName(), node.build());
-        }
-        instance.childNodes = ImmutableSet.copyOf(childNodes.values());
-
         // KEY
         if (keys == null) {
             instance.keyDefinition = ImmutableList.of();
@@ -128,24 +101,6 @@ public final class ListSchemaNodeBuilder extends AbstractDataNodeContainerBuilde
             instance.keyDefinition = ImmutableList.copyOf(keyDefinition);
         }
 
-        // GROUPINGS
-        for (GroupingBuilder builder : addedGroupings) {
-            groupings.add(builder.build());
-        }
-        instance.groupings = ImmutableSet.copyOf(groupings);
-
-        // TYPEDEFS
-        for (TypeDefinitionBuilder entry : addedTypedefs) {
-            typedefs.add(entry.build());
-        }
-        instance.typeDefinitions = ImmutableSet.copyOf(typedefs);
-
-        // USES
-        for (UsesNodeBuilder builder : addedUsesNodes) {
-            usesNodes.add(builder.build());
-        }
-        instance.uses = ImmutableSet.copyOf(usesNodes);
-
         // AUGMENTATIONS
         for (AugmentationSchemaBuilder builder : augmentationBuilders) {
             augmentations.add(builder.build());
@@ -162,20 +117,8 @@ public final class ListSchemaNodeBuilder extends AbstractDataNodeContainerBuilde
     }
 
     @Override
-    public Set<TypeDefinitionBuilder> getTypeDefinitionBuilders() {
-        return addedTypedefs;
-    }
-
-    @Override
-    public void addTypedef(final TypeDefinitionBuilder type) {
-        String typeName = type.getQName().getLocalName();
-        for (TypeDefinitionBuilder addedTypedef : addedTypedefs) {
-            if (addedTypedef.getQName().getLocalName().equals(typeName)) {
-                throw new YangParseException(getModuleName(), type.getLine(), "Can not add typedef '" + typeName
-                        + "': typedef with same name already declared at line " + addedTypedef.getLine());
-            }
-        }
-        addedTypedefs.add(type);
+    protected String getStatementName() {
+        return "list";
     }
 
     @Override
@@ -188,36 +131,6 @@ public final class ListSchemaNodeBuilder extends AbstractDataNodeContainerBuilde
         this.schemaPath = path;
     }
 
-    @Override
-    public String getDescription() {
-        return description;
-    }
-
-    @Override
-    public void setDescription(final String description) {
-        this.description = description;
-    }
-
-    @Override
-    public String getReference() {
-        return reference;
-    }
-
-    @Override
-    public void setReference(final String reference) {
-        this.reference = reference;
-    }
-
-    @Override
-    public Status getStatus() {
-        return status;
-    }
-
-    @Override
-    public void setStatus(final Status status) {
-        this.status = Preconditions.checkNotNull(status, "status cannot be null");
-    }
-
     @Override
     public void addAugmentation(final AugmentationSchemaBuilder augment) {
         augmentationBuilders.add(augment);
@@ -320,26 +233,20 @@ public final class ListSchemaNodeBuilder extends AbstractDataNodeContainerBuilde
         return "list " + qname.getLocalName();
     }
 
-    private static final class ListSchemaNodeImpl implements ListSchemaNode {
+    private static final class ListSchemaNodeImpl extends AbstractDocumentedDataNodeContainer implements ListSchemaNode {
         private final QName qname;
         private final SchemaPath path;
-        private String description;
-        private String reference;
-        private Status status;
         private ImmutableList<QName> keyDefinition;
         private boolean augmenting;
         private boolean addedByUses;
         private boolean configuration;
         private ConstraintDefinition constraints;
         private ImmutableSet<AugmentationSchema> augmentations;
-        private ImmutableSet<DataSchemaNode> childNodes;
-        private ImmutableSet<GroupingDefinition> groupings;
-        private ImmutableSet<TypeDefinition<?>> typeDefinitions;
-        private ImmutableSet<UsesNode> uses;
         private ImmutableList<UnknownSchemaNode> unknownNodes;
         private boolean userOrdered;
 
-        private ListSchemaNodeImpl(final QName qname, final SchemaPath path) {
+        private ListSchemaNodeImpl(final QName qname, final SchemaPath path, final ListSchemaNodeBuilder builder) {
+            super(builder);
             this.qname = qname;
             this.path = path;
         }
@@ -354,21 +261,6 @@ public final class ListSchemaNodeBuilder extends AbstractDataNodeContainerBuilde
             return path;
         }
 
-        @Override
-        public String getDescription() {
-            return description;
-        }
-
-        @Override
-        public String getReference() {
-            return reference;
-        }
-
-        @Override
-        public Status getStatus() {
-            return status;
-        }
-
         @Override
         public List<QName> getKeyDefinition() {
             return keyDefinition;
@@ -399,36 +291,6 @@ public final class ListSchemaNodeBuilder extends AbstractDataNodeContainerBuilde
             return augmentations;
         }
 
-        @Override
-        public Set<DataSchemaNode> getChildNodes() {
-            return childNodes;
-        }
-
-        @Override
-        public Set<GroupingDefinition> getGroupings() {
-            return groupings;
-        }
-
-        @Override
-        public Set<TypeDefinition<?>> getTypeDefinitions() {
-            return typeDefinitions;
-        }
-
-        @Override
-        public Set<UsesNode> getUses() {
-            return uses;
-        }
-
-        @Override
-        public DataSchemaNode getDataChildByName(final QName name) {
-            return getChildNode(childNodes, name);
-        }
-
-        @Override
-        public DataSchemaNode getDataChildByName(final String name) {
-            return getChildNode(childNodes, name);
-        }
-
         @Override
         public boolean isUserOrdered() {
             return userOrdered;
index a4ab83eeedb199b60204d076f2c4039b604a389d..628d7a244e3c31f8c656b401515b19cf9c14180a 100644 (file)
@@ -21,11 +21,9 @@ import java.util.TreeSet;
 
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
-import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.Deviation;
 import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition;
 import org.opendaylight.yangtools.yang.model.api.FeatureDefinition;
-import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
 import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.ModuleImport;
@@ -34,12 +32,12 @@ import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.UsesNode;
 import org.opendaylight.yangtools.yang.model.util.ModuleImportImpl;
 import org.opendaylight.yangtools.yang.parser.builder.api.AugmentationSchemaBuilder;
 import org.opendaylight.yangtools.yang.parser.builder.api.Builder;
 import org.opendaylight.yangtools.yang.parser.builder.api.DataNodeContainerBuilder;
 import org.opendaylight.yangtools.yang.parser.builder.api.DataSchemaNodeBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.api.DocumentedNodeBuilder;
 import org.opendaylight.yangtools.yang.parser.builder.api.ExtensionBuilder;
 import org.opendaylight.yangtools.yang.parser.builder.api.GroupingBuilder;
 import org.opendaylight.yangtools.yang.parser.builder.api.SchemaNodeBuilder;
@@ -47,7 +45,7 @@ import org.opendaylight.yangtools.yang.parser.builder.api.TypeAwareBuilder;
 import org.opendaylight.yangtools.yang.parser.builder.api.TypeDefinitionBuilder;
 import org.opendaylight.yangtools.yang.parser.builder.api.UnknownSchemaNodeBuilder;
 import org.opendaylight.yangtools.yang.parser.builder.api.UsesNodeBuilder;
-import org.opendaylight.yangtools.yang.parser.builder.util.AbstractDataNodeContainerBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.util.AbstractDocumentedDataNodeContainerBuilder;
 import org.opendaylight.yangtools.yang.parser.builder.util.Comparators;
 import org.opendaylight.yangtools.yang.parser.util.YangParseException;
 
@@ -56,12 +54,12 @@ import org.opendaylight.yangtools.yang.parser.util.YangParseException;
  * module/modules, these dependencies must be resolved before module is built,
  * otherwise result may not be valid.
  */
-public class ModuleBuilder extends AbstractDataNodeContainerBuilder {
+public class ModuleBuilder extends AbstractDocumentedDataNodeContainerBuilder implements DocumentedNodeBuilder {
 
-    private final ModuleImpl instance;
+    private ModuleImpl instance;
     private final String name;
     private final String sourcePath;
-    private final SchemaPath schemaPath;
+    private static final SchemaPath SCHEMA_PATH = SchemaPath.create(Collections.<QName> emptyList(), true);
     private URI namespace;
     private String prefix;
     private Date revision;
@@ -70,19 +68,10 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder {
     private String belongsTo;
     private ModuleBuilder parent;
 
-    @Override
-    public ModuleBuilder getParent() {
-        return parent;
-    }
-
-    public void setParent(final ModuleBuilder parent) {
-        this.parent = parent;
-    }
-
     private final Deque<Builder> actualPath = new LinkedList<>();
     private final Set<TypeAwareBuilder> dirtyNodes = new HashSet<>();
 
-    private final Set<ModuleImport> imports = new HashSet<ModuleImport>();
+    final Set<ModuleImport> imports = new HashSet<ModuleImport>();
 
     private final Set<AugmentationSchema> augments = new LinkedHashSet<>();
     private final List<AugmentationSchemaBuilder> augmentBuilders = new ArrayList<>();
@@ -114,7 +103,10 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder {
 
     private final List<ListSchemaNodeBuilder> allLists = new ArrayList<>();
 
-    private String source;
+    String source;
+    private String yangVersion;
+    private String organization;
+    private String contact;
 
     public ModuleBuilder(final String name, final String sourcePath) {
         this(name, false, sourcePath);
@@ -124,32 +116,23 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder {
         super(name, 0, null);
         this.name = name;
         this.sourcePath = sourcePath;
-        schemaPath = SchemaPath.create(Collections.<QName> emptyList(), true);
         this.submodule = submodule;
-        instance = new ModuleImpl(name, sourcePath);
         actualPath.push(this);
     }
 
     public ModuleBuilder(final Module base) {
-        super(base.getName(), 0, null);
+        super(base.getName(), 0, new QName(base.getNamespace(), base.getRevision(), base.getPrefix(), base.getName()),
+                SCHEMA_PATH, base);
         this.name = base.getName();
         this.sourcePath = base.getModuleSourcePath();
-        schemaPath = SchemaPath.create(Collections.<QName> emptyList(), true);
+
         submodule = false;
-        instance = new ModuleImpl(base.getName(), base.getModuleSourcePath());
-        instance.setYangVersion(base.getYangVersion());
+        yangVersion = base.getYangVersion();
         actualPath.push(this);
         namespace = base.getNamespace();
         prefix = base.getPrefix();
         revision = base.getRevision();
 
-        for (DataSchemaNode childNode : base.getChildNodes()) {
-            childNodes.put(childNode.getQName(), childNode);
-        }
-
-        typedefs.addAll(base.getTypeDefinitions());
-        groupings.addAll(base.getGroupings());
-        usesNodes.addAll(base.getUses());
         augments.addAll(base.getAugmentations());
         rpcs.addAll(base.getRpcs());
         notifications.addAll(base.getNotifications());
@@ -164,92 +147,66 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder {
         unknownNodes.addAll(base.getUnknownSchemaNodes());
     }
 
+    @Override
+    protected String getStatementName() {
+        return "module";
+    }
+
     /**
      * Build new Module object based on this builder.
      */
     @Override
     public Module build() {
-        instance.setPrefix(prefix);
-        instance.setRevision(revision);
-        instance.setImports(imports);
-        instance.setNamespace(namespace);
-
-        // TYPEDEFS
-        for (TypeDefinitionBuilder tdb : addedTypedefs) {
-            typedefs.add(tdb.build());
-        }
-        instance.setTypeDefinitions(typedefs);
-
-        // CHILD NODES
-        for (DataSchemaNodeBuilder child : addedChildNodes) {
-            childNodes.put(child.getQName(), child.build());
+        if(instance != null) {
+            return instance;
         }
-        instance.addChildNodes(childNodes.values());
 
-        // GROUPINGS
-        for (GroupingBuilder gb : addedGroupings) {
-            groupings.add(gb.build());
-        }
-        instance.setGroupings(groupings);
-
-        // USES
-        for (UsesNodeBuilder unb : addedUsesNodes) {
-            usesNodes.add(unb.build());
-        }
-        instance.setUses(usesNodes);
+        buildChildren();
 
         // FEATURES
         for (FeatureBuilder fb : addedFeatures) {
             features.add(fb.build());
         }
-        instance.setFeatures(features);
 
         // NOTIFICATIONS
         for (NotificationBuilder entry : addedNotifications) {
             notifications.add(entry.build());
         }
-        instance.setNotifications(notifications);
 
         // AUGMENTATIONS
         for (AugmentationSchemaBuilder builder : augmentBuilders) {
             augments.add(builder.build());
         }
-        instance.setAugmentations(augments);
 
         // RPCs
         for (RpcDefinitionBuilder rpc : addedRpcs) {
             rpcs.add(rpc.build());
         }
-        instance.setRpcs(rpcs);
 
         // DEVIATIONS
         for (DeviationBuilder entry : deviationBuilders) {
             deviations.add(entry.build());
         }
-        instance.setDeviations(deviations);
 
         // EXTENSIONS
         for (ExtensionBuilder eb : addedExtensions) {
             extensions.add(eb.build());
         }
         Collections.sort(extensions, Comparators.SCHEMA_NODE_COMP);
-        instance.setExtensionSchemaNodes(extensions);
+
 
         // IDENTITIES
         for (IdentitySchemaNodeBuilder id : addedIdentities) {
             identities.add(id.build());
         }
-        instance.setIdentities(identities);
 
         // UNKNOWN NODES
         for (UnknownSchemaNodeBuilder unb : addedUnknownNodes) {
             unknownNodes.add(unb.build());
         }
         Collections.sort(unknownNodes, Comparators.SCHEMA_NODE_COMP);
-        instance.setUnknownSchemaNodes(unknownNodes);
-
-        instance.setSource(source);
 
+        instance = new ModuleImpl(name, sourcePath, this);
         return instance;
     }
 
@@ -258,18 +215,22 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder {
     }
 
     @Override
-    public void setParent(final Builder parent) {
-        throw new YangParseException(name, 0, "Can not set parent to module");
+    public ModuleBuilder getParent() {
+        return parent;
+    }
+
+    public void setParent(final ModuleBuilder parent) {
+        this.parent = parent;
     }
 
     @Override
-    public SchemaPath getPath() {
-        return schemaPath;
+    public void setParent(final Builder parent) {
+        throw new YangParseException(name, 0, "Can not set parent to module");
     }
 
     @Override
-    public Set<TypeDefinitionBuilder> getTypeDefinitionBuilders() {
-        return addedTypedefs;
+    public SchemaPath getPath() {
+        return SCHEMA_PATH;
     }
 
     public void enterNode(final Builder node) {
@@ -372,6 +333,14 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder {
         return revision;
     }
 
+    protected Set<ModuleImport> getImports() {
+        return imports;
+    }
+
+    protected String getSource() {
+        return source;
+    }
+
     public boolean isSubmodule() {
         return submodule;
     }
@@ -398,26 +367,19 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder {
     }
 
     public void setYangVersion(final String yangVersion) {
-        instance.setYangVersion(yangVersion);
-    }
-
-    public void setDescription(final String description) {
-        instance.setDescription(description);
-    }
-
-    public void setReference(final String reference) {
-        instance.setReference(reference);
+        this.yangVersion = yangVersion;
     }
 
     public void setOrganization(final String organization) {
-        instance.setOrganization(organization);
+        this.organization = organization;
     }
 
     public void setContact(final String contact) {
-        instance.setContact(contact);
+        this.contact = contact;
     }
 
     public boolean addModuleImport(final String moduleName, final Date revision, final String prefix) {
+        checkNotSealed();
         final ModuleImport moduleImport = createModuleImport(moduleName, revision, prefix);
         return imports.add(moduleImport);
     }
@@ -427,6 +389,7 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder {
     }
 
     public ExtensionBuilder addExtension(final QName qname, final int line, final SchemaPath path) {
+        checkNotSealed();
         Builder parent = getActualNode();
         if (!(parent.equals(this))) {
             throw new YangParseException(name, line, "extension can be defined only in module or submodule");
@@ -445,6 +408,7 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder {
     }
 
     public ContainerSchemaNodeBuilder addContainerNode(final int line, final QName qname, final SchemaPath schemaPath) {
+        checkNotSealed();
         final ContainerSchemaNodeBuilder builder = new ContainerSchemaNodeBuilder(name, line, qname, schemaPath);
 
         Builder parent = getActualNode();
@@ -455,6 +419,7 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder {
     }
 
     public ListSchemaNodeBuilder addListNode(final int line, final QName qname, final SchemaPath schemaPath) {
+        checkNotSealed();
         final ListSchemaNodeBuilder builder = new ListSchemaNodeBuilder(name, line, qname, schemaPath);
 
         Builder parent = getActualNode();
@@ -466,6 +431,7 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder {
     }
 
     public LeafSchemaNodeBuilder addLeafNode(final int line, final QName qname, final SchemaPath schemaPath) {
+        checkNotSealed();
         final LeafSchemaNodeBuilder builder = new LeafSchemaNodeBuilder(name, line, qname, schemaPath);
 
         Builder parent = getActualNode();
@@ -476,6 +442,7 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder {
     }
 
     public LeafListSchemaNodeBuilder addLeafListNode(final int line, final QName qname, final SchemaPath schemaPath) {
+        checkNotSealed();
         final LeafListSchemaNodeBuilder builder = new LeafListSchemaNodeBuilder(name, line, qname, schemaPath);
 
         Builder parent = getActualNode();
@@ -486,6 +453,7 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder {
     }
 
     public GroupingBuilder addGrouping(final int line, final QName qname, final SchemaPath path) {
+        checkNotSealed();
         final GroupingBuilder builder = new GroupingBuilderImpl(name, line, qname, path);
 
         Builder parent = getActualNode();
@@ -493,12 +461,12 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder {
 
         String groupingName = qname.getLocalName();
         if (parent.equals(this)) {
-            for (GroupingBuilder addedGrouping : addedGroupings) {
+            for (GroupingBuilder addedGrouping : getGroupingBuilders()) {
                 if (addedGrouping.getQName().getLocalName().equals(groupingName)) {
                     raiseYangParserException("", "Grouping", groupingName, line, addedGrouping.getLine());
                 }
             }
-            addedGroupings.add(builder);
+            addGrouping(builder);
         } else {
             if (parent instanceof DataNodeContainerBuilder) {
                 DataNodeContainerBuilder parentNode = (DataNodeContainerBuilder) parent;
@@ -526,6 +494,7 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder {
     }
 
     public AugmentationSchemaBuilder addAugment(final int line, final String augmentTargetStr, final int order) {
+        checkNotSealed();
         final AugmentationSchemaBuilder builder = new AugmentationSchemaBuilderImpl(name, line, augmentTargetStr, order);
 
         Builder parent = getActualNode();
@@ -558,20 +527,15 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder {
         return builder;
     }
 
-    @Override
-    public void addUsesNode(final UsesNodeBuilder usesBuilder) {
-        addedUsesNodes.add(usesBuilder);
-        allUsesNodes.add(usesBuilder);
-    }
-
     public UsesNodeBuilder addUsesNode(final int line, final String groupingPathStr) {
+        checkNotSealed();
         final UsesNodeBuilder usesBuilder = new UsesNodeBuilderImpl(name, line, groupingPathStr);
 
         Builder parent = getActualNode();
         usesBuilder.setParent(parent);
 
         if (parent.equals(this)) {
-            addedUsesNodes.add(usesBuilder);
+            addUsesNode(usesBuilder);
         } else {
             if (!(parent instanceof DataNodeContainerBuilder)) {
                 throw new YangParseException(name, line, "Unresolved parent of uses '" + groupingPathStr + "'.");
@@ -587,6 +551,7 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder {
     }
 
     public void addRefine(final RefineHolderImpl refine) {
+        checkNotSealed();
         final Builder parent = getActualNode();
         if (!(parent instanceof UsesNodeBuilder)) {
             throw new YangParseException(name, refine.getLine(), "refine can be defined only in uses statement");
@@ -596,6 +561,7 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder {
     }
 
     public RpcDefinitionBuilder addRpc(final int line, final QName qname, final SchemaPath path) {
+        checkNotSealed();
         Builder parent = getActualNode();
         if (!(parent.equals(this))) {
             throw new YangParseException(name, line, "rpc can be defined only in module or submodule");
@@ -605,26 +571,31 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder {
         rpcBuilder.setParent(parent);
 
         String rpcName = qname.getLocalName();
+        checkNotConflictingInDataNamespace(rpcName, line);
+        addedRpcs.add(rpcBuilder);
+        return rpcBuilder;
+    }
+
+    private void checkNotConflictingInDataNamespace(final String rpcName, final int line) {
+        for (DataSchemaNodeBuilder addedChild : getChildNodeBuilders()) {
+            if (addedChild.getQName().getLocalName().equals(rpcName)) {
+                raiseYangParserException("rpc", "node", rpcName, line, addedChild.getLine());
+            }
+        }
         for (RpcDefinitionBuilder rpc : addedRpcs) {
             if (rpc.getQName().getLocalName().equals(rpcName)) {
                 raiseYangParserException("", "rpc", rpcName, line, rpc.getLine());
             }
         }
-        for (DataSchemaNodeBuilder addedChild : addedChildNodes) {
-            if (addedChild.getQName().getLocalName().equals(rpcName)) {
-                raiseYangParserException("rpc", "node", rpcName, line, addedChild.getLine());
-            }
-        }
         for (NotificationBuilder addedNotification : addedNotifications) {
             if (addedNotification.getQName().getLocalName().equals(rpcName)) {
                 raiseYangParserException("rpc", "notification", rpcName, line, addedNotification.getLine());
             }
         }
-        addedRpcs.add(rpcBuilder);
-        return rpcBuilder;
     }
 
     public ContainerSchemaNodeBuilder addRpcInput(final int line, final QName qname, final SchemaPath schemaPath) {
+        checkNotSealed();
         final Builder parent = getActualNode();
         if (!(parent instanceof RpcDefinitionBuilder)) {
             throw new YangParseException(name, line, "input can be defined only in rpc statement");
@@ -639,6 +610,7 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder {
     }
 
     public ContainerSchemaNodeBuilder addRpcOutput(final SchemaPath schemaPath, final QName qname, final int line) {
+        checkNotSealed();
         final Builder parent = getActualNode();
         if (!(parent instanceof RpcDefinitionBuilder)) {
             throw new YangParseException(name, line, "output can be defined only in rpc statement");
@@ -653,31 +625,19 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder {
     }
 
     public void addNotification(final NotificationDefinition notification) {
+        checkNotSealed();
         notifications.add(notification);
     }
 
     public NotificationBuilder addNotification(final int line, final QName qname, final SchemaPath path) {
+        checkNotSealed();
         final Builder parent = getActualNode();
         if (!(parent.equals(this))) {
             throw new YangParseException(name, line, "notification can be defined only in module or submodule");
         }
 
         String notificationName = qname.getLocalName();
-        for (NotificationBuilder nb : addedNotifications) {
-            if (nb.getQName().equals(qname)) {
-                raiseYangParserException("", "notification", notificationName, line, nb.getLine());
-            }
-        }
-        for (RpcDefinitionBuilder rpc : addedRpcs) {
-            if (rpc.getQName().getLocalName().equals(notificationName)) {
-                raiseYangParserException("notification", "rpc", notificationName, line, rpc.getLine());
-            }
-        }
-        for (DataSchemaNodeBuilder addedChild : addedChildNodes) {
-            if (addedChild.getQName().getLocalName().equals(notificationName)) {
-                raiseYangParserException("notification", "node", notificationName, line, addedChild.getLine());
-            }
-        }
+        checkNotConflictingInDataNamespace(notificationName, line);
 
         final NotificationBuilder builder = new NotificationBuilder(name, line, qname, path);
         builder.setParent(parent);
@@ -748,12 +708,12 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder {
     @Override
     public void addTypedef(final TypeDefinitionBuilder typedefBuilder) {
         String nodeName = typedefBuilder.getQName().getLocalName();
-        for (TypeDefinitionBuilder tdb : addedTypedefs) {
+        for (TypeDefinitionBuilder tdb : getTypeDefinitionBuilders()) {
             if (tdb.getQName().getLocalName().equals(nodeName)) {
                 raiseYangParserException("", "typedef", nodeName, typedefBuilder.getLine(), tdb.getLine());
             }
         }
-        addedTypedefs.add(typedefBuilder);
+        super.addTypedef(typedefBuilder);
     }
 
     public TypeDefinitionBuilderImpl addTypedef(final int line, final QName qname, final SchemaPath path) {
@@ -764,12 +724,7 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder {
 
         String typedefName = qname.getLocalName();
         if (parent.equals(this)) {
-            for (TypeDefinitionBuilder tdb : addedTypedefs) {
-                if (tdb.getQName().getLocalName().equals(typedefName)) {
-                    raiseYangParserException("", "typedef", typedefName, line, tdb.getLine());
-                }
-            }
-            addedTypedefs.add(builder);
+            addTypedef(builder);
         } else {
             if (parent instanceof DataNodeContainerBuilder) {
                 DataNodeContainerBuilder parentNode = (DataNodeContainerBuilder) parent;
@@ -921,349 +876,6 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder {
         this.source = source;
     }
 
-    public static final class ModuleImpl implements Module {
-        private URI namespace;
-        private final String name;
-        private final String sourcePath;
-        private Date revision;
-        private String prefix;
-        private String yangVersion;
-        private String description;
-        private String reference;
-        private String organization;
-        private String contact;
-        private final Set<ModuleImport> imports = new HashSet<>();
-        private final Set<FeatureDefinition> features = new TreeSet<>(Comparators.SCHEMA_NODE_COMP);
-        private final Set<TypeDefinition<?>> typeDefinitions = new TreeSet<>(Comparators.SCHEMA_NODE_COMP);
-        private final Set<NotificationDefinition> notifications = new TreeSet<>(Comparators.SCHEMA_NODE_COMP);
-        private final Set<AugmentationSchema> augmentations = new HashSet<>();
-        private final Set<RpcDefinition> rpcs = new TreeSet<>(Comparators.SCHEMA_NODE_COMP);
-        private final Set<Deviation> deviations = new HashSet<>();
-        private final Set<DataSchemaNode> childNodes = new TreeSet<>(Comparators.SCHEMA_NODE_COMP);
-        private final Set<GroupingDefinition> groupings = new TreeSet<>(Comparators.SCHEMA_NODE_COMP);
-        private final Set<UsesNode> uses = new HashSet<>();
-        private final List<ExtensionDefinition> extensionNodes = new ArrayList<>();
-        private final Set<IdentitySchemaNode> identities = new TreeSet<>(Comparators.SCHEMA_NODE_COMP);
-        private final List<UnknownSchemaNode> unknownNodes = new ArrayList<>();
-        private String source;
-
-        private ModuleImpl(final String name, final String sourcePath) {
-            this.name = name;
-            this.sourcePath = sourcePath;
-        }
-
-        @Override
-        public String getModuleSourcePath() {
-            return sourcePath;
-        }
-
-        @Override
-        public URI getNamespace() {
-            return namespace;
-        }
-
-        private void setNamespace(final URI namespace) {
-            this.namespace = namespace;
-        }
-
-        @Override
-        public String getName() {
-            return name;
-        }
-
-        @Override
-        public Date getRevision() {
-            return revision;
-        }
-
-        private void setRevision(final Date revision) {
-            this.revision = revision;
-        }
-
-        @Override
-        public String getPrefix() {
-            return prefix;
-        }
-
-        private void setPrefix(final String prefix) {
-            this.prefix = prefix;
-        }
-
-        @Override
-        public String getYangVersion() {
-            return yangVersion;
-        }
-
-        private void setYangVersion(final String yangVersion) {
-            this.yangVersion = yangVersion;
-        }
-
-        @Override
-        public String getDescription() {
-            return description;
-        }
-
-        private void setDescription(final String description) {
-            this.description = description;
-        }
-
-        @Override
-        public String getReference() {
-            return reference;
-        }
-
-        private void setReference(final String reference) {
-            this.reference = reference;
-        }
-
-        @Override
-        public String getOrganization() {
-            return organization;
-        }
-
-        private void setOrganization(final String organization) {
-            this.organization = organization;
-        }
-
-        @Override
-        public String getContact() {
-            return contact;
-        }
-
-        private void setContact(final String contact) {
-            this.contact = contact;
-        }
-
-        @Override
-        public Set<ModuleImport> getImports() {
-            return imports;
-        }
-
-        private void setImports(final Set<ModuleImport> imports) {
-            if (imports != null) {
-                this.imports.addAll(imports);
-            }
-        }
-
-        @Override
-        public Set<FeatureDefinition> getFeatures() {
-            return features;
-        }
-
-        private void setFeatures(final Set<FeatureDefinition> features) {
-            if (features != null) {
-                this.features.addAll(features);
-            }
-        }
-
-        @Override
-        public Set<TypeDefinition<?>> getTypeDefinitions() {
-            return typeDefinitions;
-        }
-
-        private void setTypeDefinitions(final Set<TypeDefinition<?>> typeDefinitions) {
-            if (typeDefinitions != null) {
-                this.typeDefinitions.addAll(typeDefinitions);
-            }
-        }
-
-        @Override
-        public Set<NotificationDefinition> getNotifications() {
-            return notifications;
-        }
-
-        private void setNotifications(final Set<NotificationDefinition> notifications) {
-            if (notifications != null) {
-                this.notifications.addAll(notifications);
-            }
-        }
-
-        @Override
-        public Set<AugmentationSchema> getAugmentations() {
-            return augmentations;
-        }
-
-        private void setAugmentations(final Set<AugmentationSchema> augmentations) {
-            if (augmentations != null) {
-                this.augmentations.addAll(augmentations);
-            }
-        }
-
-        @Override
-        public Set<RpcDefinition> getRpcs() {
-            return rpcs;
-        }
-
-        private void setRpcs(final Set<RpcDefinition> rpcs) {
-            if (rpcs != null) {
-                this.rpcs.addAll(rpcs);
-            }
-        }
-
-        @Override
-        public Set<Deviation> getDeviations() {
-            return deviations;
-        }
-
-        private void setDeviations(final Set<Deviation> deviations) {
-            if (deviations != null) {
-                this.deviations.addAll(deviations);
-            }
-        }
-
-        @Override
-        public Set<DataSchemaNode> getChildNodes() {
-            return Collections.unmodifiableSet(childNodes);
-        }
-
-        private void addChildNodes(final Collection<DataSchemaNode> childNodes) {
-            if (childNodes != null) {
-                this.childNodes.addAll(childNodes);
-            }
-        }
-
-        @Override
-        public Set<GroupingDefinition> getGroupings() {
-            return groupings;
-        }
-
-        private void setGroupings(final Set<GroupingDefinition> groupings) {
-            if (groupings != null) {
-                this.groupings.addAll(groupings);
-            }
-        }
-
-        @Override
-        public Set<UsesNode> getUses() {
-            return uses;
-        }
-
-        private void setUses(final Set<UsesNode> uses) {
-            if (uses != null) {
-                this.uses.addAll(uses);
-            }
-        }
-
-        @Override
-        public List<ExtensionDefinition> getExtensionSchemaNodes() {
-            Collections.sort(extensionNodes, Comparators.SCHEMA_NODE_COMP);
-            return extensionNodes;
-        }
-
-        private void setExtensionSchemaNodes(final List<ExtensionDefinition> extensionNodes) {
-            if (extensionNodes != null) {
-                this.extensionNodes.addAll(extensionNodes);
-            }
-        }
-
-        @Override
-        public Set<IdentitySchemaNode> getIdentities() {
-            return identities;
-        }
-
-        private void setIdentities(final Set<IdentitySchemaNode> identities) {
-            if (identities != null) {
-                this.identities.addAll(identities);
-            }
-        }
-
-        @Override
-        public List<UnknownSchemaNode> getUnknownSchemaNodes() {
-            return unknownNodes;
-        }
-
-        private void setUnknownSchemaNodes(final List<UnknownSchemaNode> unknownNodes) {
-            if (unknownNodes != null) {
-                this.unknownNodes.addAll(unknownNodes);
-            }
-        }
-
-        @Override
-        public DataSchemaNode getDataChildByName(final QName name) {
-            return getChildNode(childNodes, name);
-        }
-
-        @Override
-        public DataSchemaNode getDataChildByName(final String name) {
-            return getChildNode(childNodes, name);
-        }
-
-        void setSource(final String source) {
-            this.source = source;
-        }
-
-        public String getSource() {
-            return source;
-        }
-
-        @Override
-        public int hashCode() {
-            final int prime = 31;
-            int result = 1;
-            result = prime * result + ((namespace == null) ? 0 : namespace.hashCode());
-            result = prime * result + ((name == null) ? 0 : name.hashCode());
-            result = prime * result + ((revision == null) ? 0 : revision.hashCode());
-            result = prime * result + ((yangVersion == null) ? 0 : yangVersion.hashCode());
-            return result;
-        }
-
-        @Override
-        public boolean equals(final Object obj) {
-            if (this == obj) {
-                return true;
-            }
-            if (obj == null) {
-                return false;
-            }
-            if (getClass() != obj.getClass()) {
-                return false;
-            }
-            ModuleImpl other = (ModuleImpl) obj;
-            if (namespace == null) {
-                if (other.namespace != null) {
-                    return false;
-                }
-            } else if (!namespace.equals(other.namespace)) {
-                return false;
-            }
-            if (name == null) {
-                if (other.name != null) {
-                    return false;
-                }
-            } else if (!name.equals(other.name)) {
-                return false;
-            }
-            if (revision == null) {
-                if (other.revision != null) {
-                    return false;
-                }
-            } else if (!revision.equals(other.revision)) {
-                return false;
-            }
-            if (yangVersion == null) {
-                if (other.yangVersion != null) {
-                    return false;
-                }
-            } else if (!yangVersion.equals(other.yangVersion)) {
-                return false;
-            }
-            return true;
-        }
-
-        @Override
-        public String toString() {
-            StringBuilder sb = new StringBuilder(ModuleImpl.class.getSimpleName());
-            sb.append("[");
-            sb.append("name=" + name);
-            sb.append(", namespace=" + namespace);
-            sb.append(", revision=" + revision);
-            sb.append(", prefix=" + prefix);
-            sb.append(", yangVersion=" + yangVersion);
-            sb.append("]");
-            return sb.toString();
-        }
-    }
-
     /**
      * Add child to parent. Method checks for duplicates and add given child
      * node to parent. If node with same name is found, throws exception. If
@@ -1282,6 +894,18 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder {
         }
     }
 
+    public String getYangVersion() {
+        return yangVersion;
+    }
+
+    public String getContact() {
+        return contact;
+    }
+
+    public String getOrganization() {
+        return organization;
+    }
+
     /**
      * Adds child node <code>child</code> to the set of nodes child nodes.
      *
@@ -1303,7 +927,7 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder {
         // notifications, and anyxmls defined within a parent node or at the
         // top level of the module or its submodules share the same
         // identifier namespace.
-        for (DataSchemaNodeBuilder childNode : addedChildNodes) {
+        for (DataSchemaNodeBuilder childNode : getChildNodeBuilders()) {
             if (childNode.getQName().getLocalName().equals(childName)) {
                 raiseYangParserException("'" + child + "'", "node", childName, lineNum, childNode.getLine());
             }
@@ -1318,7 +942,7 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder {
                 raiseYangParserException("'" + child + "'", "notification", childName, lineNum, notification.getLine());
             }
         }
-        addedChildNodes.add(child);
+        addChildNode(child);
     }
 
     /**
@@ -1439,4 +1063,7 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder {
         return true;
     }
 
+    public List<UnknownSchemaNode> getExtensionInstances() {
+        return unknownNodes;
+    }
 }
diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/ModuleImpl.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/ModuleImpl.java
new file mode 100644 (file)
index 0000000..7adca41
--- /dev/null
@@ -0,0 +1,247 @@
+package org.opendaylight.yangtools.yang.parser.builder.impl;
+
+import com.google.common.base.Optional;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import java.net.URI;
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
+import org.opendaylight.yangtools.concepts.Immutable;
+import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
+import org.opendaylight.yangtools.yang.model.api.Deviation;
+import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition;
+import org.opendaylight.yangtools.yang.model.api.FeatureDefinition;
+import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
+import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.ModuleImport;
+import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
+import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
+import org.opendaylight.yangtools.yang.model.api.SchemaNode;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.parser.builder.util.AbstractDocumentedDataNodeContainer;
+import org.opendaylight.yangtools.yang.parser.builder.util.Comparators;
+
+public final class ModuleImpl extends AbstractDocumentedDataNodeContainer implements Module, Immutable {
+
+    private final URI namespace;
+    private final String name;
+    private final String sourcePath;
+    private final Optional<Date> revision;
+    private final String prefix;
+    private final String yangVersion;
+    private final String organization;
+    private final String contact;
+    private final Set<ModuleImport> imports;
+    private final Set<FeatureDefinition> features;
+    private final Set<NotificationDefinition> notifications;
+    private final Set<AugmentationSchema> augmentations;
+    private final Set<RpcDefinition> rpcs;
+    private final Set<Deviation> deviations;
+    private final List<ExtensionDefinition> extensionNodes;
+    private final Set<IdentitySchemaNode> identities;
+    private final List<UnknownSchemaNode> unknownNodes;
+    private final String source;
+
+    /**
+     *
+     *
+     * <b>Note</b>Constructor has intentionality limited visibility to package, since
+     * this class should be only instantied via builders.
+     *
+     * @param name
+     * @param sourcePath
+     * @param builder
+     */
+    ModuleImpl(final String name, final String sourcePath, final ModuleBuilder builder) {
+        super(builder);
+        this.name = name;
+        this.sourcePath = sourcePath;
+        this.imports = ImmutableSet.<ModuleImport> copyOf(builder.imports);
+        this.namespace = builder.getNamespace();
+        this.prefix = builder.getPrefix();
+        this.revision = builder.getRevision() == null ? Optional.<Date>absent():
+                Optional.of(new Date(builder.getRevision().getTime()));
+        this.yangVersion = builder.getYangVersion();
+        this.organization = builder.getOrganization();
+        this.contact = builder.getContact();
+        this.features = toImmutableSortedSet(builder.getFeatures());
+        this.notifications = toImmutableSortedSet(builder.getNotifications());
+        this.augmentations = ImmutableSet.copyOf(builder.getAugments());
+        this.rpcs = toImmutableSortedSet(builder.getRpcs());
+        this.deviations = ImmutableSet.copyOf(builder.getDeviations());
+        this.extensionNodes = ImmutableList.copyOf(builder.getExtensions());
+        this.identities = ImmutableSet.copyOf(builder.getIdentities());
+        this.unknownNodes = ImmutableList.copyOf(builder.getExtensionInstances());
+        this.source = builder.source;
+
+    }
+
+    @Override
+    public String getModuleSourcePath() {
+        return sourcePath;
+    }
+
+    @Override
+    public URI getNamespace() {
+        return namespace;
+    }
+
+    @Override
+    public String getName() {
+        return name;
+    }
+
+    @Override
+    public Date getRevision() {
+        if (revision.isPresent()) {
+            return new Date(revision.get().getTime());
+        } else {
+            return null;
+        }
+    }
+
+    @Override
+    public String getPrefix() {
+        return prefix;
+    }
+
+    @Override
+    public String getYangVersion() {
+        return yangVersion;
+    }
+
+    @Override
+    public String getOrganization() {
+        return organization;
+    }
+
+    @Override
+    public String getContact() {
+        return contact;
+    }
+
+    @Override
+    public Set<ModuleImport> getImports() {
+        return imports;
+    }
+
+    @Override
+    public Set<FeatureDefinition> getFeatures() {
+        return features;
+    }
+
+    @Override
+    public Set<NotificationDefinition> getNotifications() {
+        return notifications;
+    }
+
+    @Override
+    public Set<AugmentationSchema> getAugmentations() {
+        return augmentations;
+    }
+
+    @Override
+    public Set<RpcDefinition> getRpcs() {
+        return rpcs;
+    }
+
+    @Override
+    public Set<Deviation> getDeviations() {
+        return deviations;
+    }
+
+    @Override
+    public List<ExtensionDefinition> getExtensionSchemaNodes() {
+        return extensionNodes;
+    }
+
+    @Override
+    public Set<IdentitySchemaNode> getIdentities() {
+        return identities;
+    }
+
+    @Override
+    public List<UnknownSchemaNode> getUnknownSchemaNodes() {
+        return unknownNodes;
+    }
+
+    public String getSource() {
+        return source;
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((namespace == null) ? 0 : namespace.hashCode());
+        result = prime * result + ((name == null) ? 0 : name.hashCode());
+        result = prime * result + ((revision == null) ? 0 : revision.hashCode());
+        result = prime * result + ((yangVersion == null) ? 0 : yangVersion.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(final Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj == null) {
+            return false;
+        }
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+        ModuleImpl other = (ModuleImpl) obj;
+        if (namespace == null) {
+            if (other.namespace != null) {
+                return false;
+            }
+        } else if (!namespace.equals(other.namespace)) {
+            return false;
+        }
+        if (name == null) {
+            if (other.name != null) {
+                return false;
+            }
+        } else if (!name.equals(other.name)) {
+            return false;
+        }
+        if (revision == null) {
+            if (other.revision != null) {
+                return false;
+            }
+        } else if (!revision.equals(other.revision)) {
+            return false;
+        }
+        if (yangVersion == null) {
+            if (other.yangVersion != null) {
+                return false;
+            }
+        } else if (!yangVersion.equals(other.yangVersion)) {
+            return false;
+        }
+        return true;
+    }
+
+    private static <T extends SchemaNode> Set<T> toImmutableSortedSet(final Set<T> original) {
+        TreeSet<T> sorted = new TreeSet<>(Comparators.SCHEMA_NODE_COMP);
+        sorted.addAll(original);
+        return Collections.unmodifiableSet(sorted);
+    }
+
+    @Override
+    public String toString() {
+        StringBuilder sb = new StringBuilder(ModuleImpl.class.getSimpleName());
+        sb.append("[");
+        sb.append("name=" + name);
+        sb.append(", namespace=" + namespace);
+        sb.append(", revision=" + revision);
+        sb.append(", prefix=" + prefix);
+        sb.append(", yangVersion=" + yangVersion);
+        sb.append("]");
+        return sb.toString();
+    }
+}
\ No newline at end of file
index 938bc594ad0565df76e9eb22c9c02be5ffa488cc..59dd094fa5966e879fa44c69193e25d4ac7106ab 100644 (file)
@@ -15,37 +15,26 @@ import java.util.Set;
 
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
-import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
 import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-import org.opendaylight.yangtools.yang.model.api.Status;
-import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.UsesNode;
 import org.opendaylight.yangtools.yang.parser.builder.api.AugmentationSchemaBuilder;
 import org.opendaylight.yangtools.yang.parser.builder.api.AugmentationTargetBuilder;
-import org.opendaylight.yangtools.yang.parser.builder.api.DataSchemaNodeBuilder;
-import org.opendaylight.yangtools.yang.parser.builder.api.GroupingBuilder;
 import org.opendaylight.yangtools.yang.parser.builder.api.SchemaNodeBuilder;
-import org.opendaylight.yangtools.yang.parser.builder.api.TypeDefinitionBuilder;
 import org.opendaylight.yangtools.yang.parser.builder.api.UnknownSchemaNodeBuilder;
-import org.opendaylight.yangtools.yang.parser.builder.api.UsesNodeBuilder;
-import org.opendaylight.yangtools.yang.parser.builder.util.AbstractDataNodeContainerBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.util.AbstractDocumentedDataNodeContainer;
+import org.opendaylight.yangtools.yang.parser.builder.util.AbstractDocumentedDataNodeContainerBuilder;
 import org.opendaylight.yangtools.yang.parser.util.YangParseException;
 
 import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
 
-public final class NotificationBuilder extends AbstractDataNodeContainerBuilder implements SchemaNodeBuilder,
+public final class NotificationBuilder extends AbstractDocumentedDataNodeContainerBuilder implements SchemaNodeBuilder,
         AugmentationTargetBuilder {
     private NotificationDefinitionImpl instance;
     // SchemaNode args
     private SchemaPath schemaPath;
-    private String description;
-    private String reference;
-    private Status status = Status.CURRENT;
     // AugmentationTarget args
     private final List<AugmentationSchema> augmentations = new ArrayList<>();
     private final List<AugmentationSchemaBuilder> augmentationBuilders = new ArrayList<>();
@@ -55,65 +44,33 @@ public final class NotificationBuilder extends AbstractDataNodeContainerBuilder
         this.schemaPath = Preconditions.checkNotNull(path, "Schema Path must not be null");
     }
 
-    NotificationBuilder(final String moduleName, final int line, final QName qname, final SchemaPath path, final NotificationDefinition base) {
-        super(moduleName, line, qname);
+    NotificationBuilder(final String moduleName, final int line, final QName qname, final SchemaPath path,
+            final NotificationDefinition base) {
+        super(moduleName, line, qname, path, base);
         this.schemaPath = Preconditions.checkNotNull(path, "Schema Path must not be null");
 
-        description = base.getDescription();
-        reference = base.getReference();
-        status = base.getStatus();
-
         URI ns = qname.getNamespace();
         Date rev = qname.getRevision();
         String pref = qname.getPrefix();
-        addedChildNodes.addAll(BuilderUtils.wrapChildNodes(moduleName, line, base.getChildNodes(), path, ns, rev, pref));
-        addedGroupings.addAll(BuilderUtils.wrapGroupings(moduleName, line, base.getGroupings(), path, ns, rev, pref));
-        addedTypedefs.addAll(BuilderUtils.wrapTypedefs(moduleName, line, base, path, ns, rev, pref));
-        addedUnknownNodes.addAll(BuilderUtils.wrapUnknownNodes(moduleName, line, base.getUnknownSchemaNodes(), path, ns,
-                rev, pref));
+        addedUnknownNodes.addAll(BuilderUtils.wrapUnknownNodes(moduleName, line, base.getUnknownSchemaNodes(), path,
+                ns, rev, pref));
 
         augmentations.addAll(base.getAvailableAugmentations());
-        usesNodes.addAll(base.getUses());
+
     }
 
     @Override
     public NotificationDefinition build() {
         if (!(getParent() instanceof ModuleBuilder)) {
-            throw new YangParseException(getModuleName(), getLine(), "Notification can be defined only under module (was " + getParent() + ")");
+            throw new YangParseException(getModuleName(), getLine(),
+                    "Notification can be defined only under module (was " + getParent() + ")");
         }
         if (instance != null) {
             return instance;
         }
+        buildChildren();
 
-        instance = new NotificationDefinitionImpl(qname, schemaPath);
-
-        instance.description = description;
-        instance.reference = reference;
-        instance.status = status;
-
-        // CHILD NODES
-        for (DataSchemaNodeBuilder node : addedChildNodes) {
-            childNodes.put(node.getQName(), node.build());
-        }
-        instance.childNodes = ImmutableSet.copyOf(childNodes.values());
-
-        // GROUPINGS
-        for (GroupingBuilder builder : addedGroupings) {
-            groupings.add(builder.build());
-        }
-        instance.groupings = ImmutableSet.copyOf(groupings);
-
-        // TYPEDEFS
-        for (TypeDefinitionBuilder entry : addedTypedefs) {
-            typedefs.add(entry.build());
-        }
-        instance.typeDefinitions = ImmutableSet.copyOf(typedefs);
-
-        // USES
-        for (UsesNodeBuilder builder : addedUsesNodes) {
-            usesNodes.add(builder.build());
-        }
-        instance.uses = ImmutableSet.copyOf(usesNodes);
+        instance = new NotificationDefinitionImpl(qname, schemaPath, this);
 
         // AUGMENTATIONS
         for (AugmentationSchemaBuilder builder : augmentationBuilders) {
@@ -130,17 +87,6 @@ public final class NotificationBuilder extends AbstractDataNodeContainerBuilder
         return instance;
     }
 
-
-    @Override
-    public Set<TypeDefinitionBuilder> getTypeDefinitionBuilders() {
-        return addedTypedefs;
-    }
-
-    @Override
-    public void addTypedef(final TypeDefinitionBuilder type) {
-        addedTypedefs.add(type);
-    }
-
     @Override
     public SchemaPath getPath() {
         return schemaPath;
@@ -151,36 +97,6 @@ public final class NotificationBuilder extends AbstractDataNodeContainerBuilder
         this.schemaPath = path;
     }
 
-    @Override
-    public String getDescription() {
-        return description;
-    }
-
-    @Override
-    public void setDescription(final String description) {
-        this.description = description;
-    }
-
-    @Override
-    public String getReference() {
-        return reference;
-    }
-
-    @Override
-    public void setReference(final String reference) {
-        this.reference = reference;
-    }
-
-    @Override
-    public Status getStatus() {
-        return status;
-    }
-
-    @Override
-    public void setStatus(final Status status) {
-        this.status = Preconditions.checkNotNull(status, "status cannot be null");
-    }
-
     @Override
     public void addAugmentation(final AugmentationSchemaBuilder augment) {
         augmentationBuilders.add(augment);
@@ -191,20 +107,21 @@ public final class NotificationBuilder extends AbstractDataNodeContainerBuilder
         return "notification " + getQName().getLocalName();
     }
 
-    private static final class NotificationDefinitionImpl implements NotificationDefinition {
+    @Override
+    protected String getStatementName() {
+        return "notification";
+    }
+
+    private static final class NotificationDefinitionImpl extends AbstractDocumentedDataNodeContainer implements
+            NotificationDefinition {
         private final QName qname;
         private final SchemaPath path;
-        private String description;
-        private String reference;
-        private Status status;
         private ImmutableSet<AugmentationSchema> augmentations;
-        private ImmutableSet<DataSchemaNode> childNodes;
-        private ImmutableSet<GroupingDefinition> groupings;
-        private ImmutableSet<TypeDefinition<?>> typeDefinitions;
-        private ImmutableSet<UsesNode> uses;
         private ImmutableList<UnknownSchemaNode> unknownNodes;
 
-        private NotificationDefinitionImpl(final QName qname, final SchemaPath path) {
+        NotificationDefinitionImpl(final QName qname, final SchemaPath path, final NotificationBuilder builder) {
+            super(builder);
+            // TODO Auto-generated constructor stub
             this.qname = qname;
             this.path = path;
         }
@@ -219,41 +136,6 @@ public final class NotificationBuilder extends AbstractDataNodeContainerBuilder
             return path;
         }
 
-        @Override
-        public String getDescription() {
-            return description;
-        }
-
-        @Override
-        public String getReference() {
-            return reference;
-        }
-
-        @Override
-        public Status getStatus() {
-            return status;
-        }
-
-        @Override
-        public Set<DataSchemaNode> getChildNodes() {
-            return childNodes;
-        }
-
-        @Override
-        public Set<GroupingDefinition> getGroupings() {
-            return groupings;
-        }
-
-        @Override
-        public Set<UsesNode> getUses() {
-            return uses;
-        }
-
-        @Override
-        public Set<TypeDefinition<?>> getTypeDefinitions() {
-            return typeDefinitions;
-        }
-
         @Override
         public Set<AugmentationSchema> getAvailableAugmentations() {
             return augmentations;
@@ -264,16 +146,6 @@ public final class NotificationBuilder extends AbstractDataNodeContainerBuilder
             return unknownNodes;
         }
 
-        @Override
-        public DataSchemaNode getDataChildByName(final QName name) {
-            return getChildNode(childNodes, name);
-        }
-
-        @Override
-        public DataSchemaNode getDataChildByName(final String name) {
-            return getChildNode(childNodes, name);
-        }
-
         @Override
         public int hashCode() {
             final int prime = 31;
index bfc4928bf35c3f39820d87f62bbe8bdc000d4eef..c5071762f15dd81b9acc048c8825f83e224a7295 100644 (file)
@@ -7,11 +7,12 @@
  */
 package org.opendaylight.yangtools.yang.parser.builder.impl;
 
-import java.lang.reflect.Method;
 import java.util.List;
 
 import org.opendaylight.yangtools.yang.model.api.MustDefinition;
 import org.opendaylight.yangtools.yang.parser.builder.api.Builder;
+import org.opendaylight.yangtools.yang.parser.builder.api.DataSchemaNodeBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.api.DocumentedNodeBuilder;
 import org.opendaylight.yangtools.yang.parser.builder.api.GroupingBuilder;
 import org.opendaylight.yangtools.yang.parser.builder.api.RefineBuilder;
 import org.opendaylight.yangtools.yang.parser.builder.api.SchemaNodeBuilder;
@@ -260,33 +261,41 @@ public final class RefineUtils {
         final int line = refine.getLine();
         Class<? extends Builder> cls = node.getClass();
 
+
+        final DocumentedNodeBuilder documentedNode;
+        if(node instanceof DocumentedNodeBuilder) {
+            documentedNode = ((DocumentedNodeBuilder) node);
+        } else {
+            documentedNode = null;
+        }
+
         String description = refine.getDescription();
+
+
         if (description != null) {
-            try {
-                Method method = cls.getDeclaredMethod("setDescription", String.class);
-                method.invoke(node, description);
-            } catch (Exception e) {
-                throw new YangParseException(moduleName, line, "Cannot refine description in " + cls.getName(), e);
+            if(documentedNode != null) {
+                documentedNode.setDescription(description);
+            } else {
+                throw new YangParseException(moduleName, line, String.format("Cannot refine description in of target %s",refine.getTargetPathString()));
             }
+
         }
 
         String reference = refine.getReference();
         if (reference != null) {
-            try {
-                Method method = cls.getDeclaredMethod("setReference", String.class);
-                method.invoke(node, reference);
-            } catch (Exception e) {
-                throw new YangParseException(moduleName, line, "Cannot refine reference in " + cls.getName(), e);
+            if(documentedNode != null) {
+                documentedNode.setReference(reference);
+            } else {
+                throw new YangParseException(moduleName, line, String.format("Cannot refine reference in of target %s",refine.getTargetPathString()));
             }
         }
 
         Boolean config = refine.isConfiguration();
         if (config != null) {
-            try {
-                Method method = cls.getDeclaredMethod("setConfiguration", Boolean.TYPE);
-                method.invoke(node, config);
-            } catch (Exception e) {
-                throw new YangParseException(moduleName, line, "Cannot refine config in " + cls.getName(), e);
+            if(node instanceof DataSchemaNodeBuilder) {
+                ((DataSchemaNodeBuilder) node).setConfiguration(config);
+            } else {
+                throw new YangParseException(moduleName, line, String.format("Cannot refine config of target %s ",refine.getTargetPathString()));
             }
         }
     }
index 35b869be6bf9f9f13827a8db6b8e067f1a798a97..5063b7f49a1a05888df56c19a00a71d7941ddde8 100644 (file)
@@ -27,6 +27,7 @@ public abstract class AbstractBuilder implements Builder {
 
     protected final List<UnknownSchemaNode> unknownNodes = new ArrayList<>();
     protected final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
+    private boolean sealed;
 
     protected AbstractBuilder(final String moduleName, final int line) {
         this.moduleName = Preconditions.checkNotNull(moduleName,"moduleName must not be null");
@@ -56,6 +57,7 @@ public abstract class AbstractBuilder implements Builder {
 
     @Override
     public void setParent(final Builder parentBuilder) {
+        checkNotSealed();
         this.parentBuilder = parentBuilder;
     }
 
@@ -69,4 +71,17 @@ public abstract class AbstractBuilder implements Builder {
         addedUnknownNodes.add(unknownNode);
     }
 
+    protected void seal() {
+        checkNotSealed();
+        sealed  = true;
+    }
+
+    protected final void checkNotSealed() {
+        Preconditions.checkState(!sealed, "Builder is sealed. No further modifications allowed");
+    }
+
+    protected boolean isSealed() {
+        return sealed;
+    }
+
 }
diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/util/AbstractDataNodeContainerBuilder.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/util/AbstractDataNodeContainerBuilder.java
deleted file mode 100644 (file)
index 4c7b07f..0000000
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
- * 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.yangtools.yang.parser.builder.util;
-
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeMap;
-import java.util.TreeSet;
-
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
-import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.UsesNode;
-import org.opendaylight.yangtools.yang.parser.builder.api.DataNodeContainerBuilder;
-import org.opendaylight.yangtools.yang.parser.builder.api.DataSchemaNodeBuilder;
-import org.opendaylight.yangtools.yang.parser.builder.api.GroupingBuilder;
-import org.opendaylight.yangtools.yang.parser.builder.api.TypeDefinitionBuilder;
-import org.opendaylight.yangtools.yang.parser.builder.api.UsesNodeBuilder;
-import org.opendaylight.yangtools.yang.parser.util.YangParseException;
-
-/**
- * Basic implementation of DataNodeContainerBuilder.
- */
-public abstract class AbstractDataNodeContainerBuilder extends AbstractBuilder implements DataNodeContainerBuilder {
-    protected final QName qname;
-
-    protected final Map<QName, DataSchemaNode> childNodes = new TreeMap<>();
-    protected final Set<DataSchemaNodeBuilder> addedChildNodes = new HashSet<>();
-
-    protected final Set<GroupingDefinition> groupings = new TreeSet<>(Comparators.SCHEMA_NODE_COMP);
-    protected final Set<GroupingBuilder> addedGroupings = new HashSet<>();
-
-    protected final Set<TypeDefinition<?>> typedefs = new TreeSet<>(Comparators.SCHEMA_NODE_COMP);
-    protected final Set<TypeDefinitionBuilder> addedTypedefs = new HashSet<>();
-
-    protected final Set<UsesNode> usesNodes = new HashSet<>();
-    protected final Set<UsesNodeBuilder> addedUsesNodes = new HashSet<>();
-
-    protected AbstractDataNodeContainerBuilder(final String moduleName, final int line, final QName qname) {
-        super(moduleName, line);
-        this.qname = qname;
-    }
-
-    @Override
-    public QName getQName() {
-        return qname;
-    }
-
-    public Map<QName, DataSchemaNode> getChildNodes() {
-        return childNodes;
-    }
-
-    @Override
-    public Set<DataSchemaNodeBuilder> getChildNodeBuilders() {
-        return addedChildNodes;
-    }
-
-    @Override
-    public DataSchemaNodeBuilder getDataChildByName(final String name) {
-        for (DataSchemaNodeBuilder child : addedChildNodes) {
-            if (child.getQName().getLocalName().equals(name)) {
-                return child;
-            }
-        }
-        return null;
-    }
-
-    @Override
-    public void addChildNode(final DataSchemaNodeBuilder child) {
-        QName childName = child.getQName();
-        for (DataSchemaNodeBuilder addedChildNode : addedChildNodes) {
-            if (addedChildNode.getQName().equals(childName)) {
-                throw new YangParseException(child.getModuleName(), child.getLine(), String.format(
-                        "Can not add '%s' to '%s' in module '%s': node with same name already declared at line %d",
-                        child, this, getModuleName(), addedChildNode.getLine()));
-            }
-        }
-        addedChildNodes.add(child);
-    }
-
-    @Override
-    public void addChildNodeToContext(final DataSchemaNodeBuilder child) {
-        addedChildNodes.add(child);
-    }
-
-    @Override
-    public void addChildNode(final DataSchemaNode child) {
-        QName childName = child.getQName();
-        if (childNodes.containsKey(childName)) {
-            throw new YangParseException(getModuleName(), getLine(),
-                    String.format("Can not add '%s' to '%s' in module '%s': node with same name already declared",
-                            child, this, getModuleName()));
-        }
-        childNodes.put(childName, child);
-    }
-
-    @Override
-    public Set<GroupingDefinition> getGroupings() {
-        if (groupings == null) {
-            return Collections.emptySet();
-        }
-        return groupings;
-    }
-
-    @Override
-    public Set<GroupingBuilder> getGroupingBuilders() {
-        return addedGroupings;
-    }
-
-    @Override
-    public void addGrouping(final GroupingBuilder grouping) {
-        QName groupingName = grouping.getQName();
-        for (GroupingBuilder addedGrouping : addedGroupings) {
-            if (addedGrouping.getQName().equals(groupingName)) {
-                throw new YangParseException(grouping.getModuleName(), grouping.getLine(), String.format(
-                        "Can not add '%s': grouping with same name already declared in module '%s' at line %d",
-                        grouping, getModuleName(), addedGrouping.getLine()));
-            }
-        }
-        addedGroupings.add(grouping);
-    }
-
-    @Override
-    public Set<TypeDefinition<?>> getTypeDefinitions() {
-        return typedefs;
-    }
-
-    public Set<UsesNode> getUsesNodes() {
-        return usesNodes;
-    }
-
-    @Override
-    public Set<UsesNodeBuilder> getUsesNodeBuilders() {
-        return addedUsesNodes;
-    }
-
-    @Override
-    public void addUsesNode(final UsesNodeBuilder usesNode) {
-        addedUsesNodes.add(usesNode);
-    }
-
-    protected static DataSchemaNode getChildNode(final Set<DataSchemaNode> childNodes, final QName name) {
-        for (DataSchemaNode node : childNodes) {
-            if (node.getQName().equals(name)) {
-                return node;
-            }
-        }
-        return null;
-    }
-
-    protected static DataSchemaNode getChildNode(final Set<DataSchemaNode> childNodes, final String name) {
-        for (DataSchemaNode node : childNodes) {
-            if (node.getQName().getLocalName().equals(name)) {
-                return node;
-            }
-        }
-        return null;
-    }
-
-}
diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/util/AbstractDocumentedDataNodeContainer.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/util/AbstractDocumentedDataNodeContainer.java
new file mode 100644 (file)
index 0000000..f428e69
--- /dev/null
@@ -0,0 +1,72 @@
+package org.opendaylight.yangtools.yang.parser.builder.util;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+import java.util.Map;
+import java.util.Set;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.UsesNode;
+
+public abstract class AbstractDocumentedDataNodeContainer extends AbstractDocumentedNode implements DataNodeContainer {
+
+    protected final Map<QName, DataSchemaNode> childNodes;
+    private final Set<GroupingDefinition> groupings;
+    private final Set<UsesNode> uses;
+    private final Set<TypeDefinition<?>> typeDefinitions;
+
+    protected AbstractDocumentedDataNodeContainer(final AbstractDocumentedDataNodeContainerBuilder data) {
+        super(data);
+        // FIXME : Should be unmodifiable ordered set (ordered by QName... or appearance in YANG file).
+        // consider using new TreeSet<>(Comparators.SCHEMA_NODE_COMP);
+
+        childNodes = ImmutableMap.copyOf(data.getChildNodes());
+        groupings = ImmutableSet.copyOf(data.getGroupings());
+        uses = ImmutableSet.copyOf(data.getUsesNodes());
+        typeDefinitions = ImmutableSet.copyOf(data.getTypeDefinitions());
+    }
+
+    @Override
+    public final Set<TypeDefinition<?>> getTypeDefinitions() {
+        return typeDefinitions;
+    }
+
+    @Override
+    public final Set<DataSchemaNode> getChildNodes() {
+        return ImmutableSet.copyOf(childNodes.values());
+    }
+
+    @Override
+    public final Set<GroupingDefinition> getGroupings() {
+        return groupings;
+    }
+
+    @Override
+    public final DataSchemaNode getDataChildByName(final QName name) {
+        for (DataSchemaNode node : childNodes.values()) {
+            if (node.getQName().equals(name)) {
+                return node;
+            }
+        }
+        return null;
+    }
+
+    @Override
+    public final DataSchemaNode getDataChildByName(final String name) {
+        for (DataSchemaNode node : childNodes.values()) {
+            if (node.getQName().getLocalName().equals(name)) {
+                return node;
+            }
+        }
+        return null;
+    }
+
+    @Override
+    public Set<UsesNode> getUses() {
+        return uses;
+    }
+
+}
diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/util/AbstractDocumentedDataNodeContainerBuilder.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/util/AbstractDocumentedDataNodeContainerBuilder.java
new file mode 100644 (file)
index 0000000..1c50223
--- /dev/null
@@ -0,0 +1,238 @@
+/*
+ * 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.yangtools.yang.parser.builder.util;
+
+import java.net.URI;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.TreeSet;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.UsesNode;
+import org.opendaylight.yangtools.yang.parser.builder.api.DataNodeContainerBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.api.DataSchemaNodeBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.api.GroupingBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.api.TypeDefinitionBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.api.UsesNodeBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.impl.BuilderUtils;
+import org.opendaylight.yangtools.yang.parser.util.YangParseException;
+
+/**
+ * Basic implementation of DataNodeContainerBuilder.
+ */
+public abstract class AbstractDocumentedDataNodeContainerBuilder extends AbstractDocumentedNodeBuilder implements DataNodeContainerBuilder {
+    protected final QName qname;
+
+    protected final Map<QName, DataSchemaNode> childNodes = new TreeMap<>();
+    private final Set<DataSchemaNodeBuilder> addedChildNodes = new HashSet<>();
+
+    private final Set<GroupingDefinition> groupings = new TreeSet<>(Comparators.SCHEMA_NODE_COMP);
+    private final Set<GroupingBuilder> addedGroupings = new HashSet<>();
+
+    private final Set<TypeDefinition<?>> typedefs = new TreeSet<>(Comparators.SCHEMA_NODE_COMP);
+    private final Set<TypeDefinitionBuilder> addedTypedefs = new HashSet<>();
+
+    private final Set<UsesNode> usesNodes = new HashSet<>();
+    private final Set<UsesNodeBuilder> addedUsesNodes = new HashSet<>();
+
+    protected AbstractDocumentedDataNodeContainerBuilder(final String moduleName, final int line, final QName qname) {
+        super(moduleName, line);
+        this.qname = qname;
+    }
+
+    public AbstractDocumentedDataNodeContainerBuilder(final String moduleName, final int line, final QName qname, final SchemaPath path, final DataNodeContainer base) {
+        super(moduleName, line);
+        this.qname = qname;
+
+        URI ns = qname.getNamespace();
+        Date rev = qname.getRevision();
+        String pref = qname.getPrefix();
+
+        // We do copy of child nodes with namespace change
+        // FIXME: Copy should be part of builder API so impl we prevent
+        // cyclic dependencies and each builder carries its own semantic for copy.
+        addedChildNodes.addAll(BuilderUtils.wrapChildNodes(moduleName, line, base.getChildNodes(), path, ns, rev, pref));
+        addedGroupings.addAll(BuilderUtils.wrapGroupings(moduleName, line, base.getGroupings(), path, ns, rev, pref));
+        addedTypedefs.addAll(BuilderUtils.wrapTypedefs(moduleName, line, base, path, ns, rev, pref));
+        // FIXME: unkownSchemaNodes should be available in DataNodeContainer
+//        addedUnknownNodes.addAll(BuilderUtils.wrapUnknownNodes(moduleName, line, base.getUnknownSchemaNodes(), path, ns,
+//                rev, pref));
+        usesNodes.addAll(base.getUses());
+    }
+
+    @Override
+    public final QName getQName() {
+        return qname;
+    }
+
+    @Override
+    public final Map<QName, DataSchemaNode> getChildNodes() {
+        return childNodes;
+    }
+
+    @Override
+    public final Set<DataSchemaNodeBuilder> getChildNodeBuilders() {
+        return addedChildNodes;
+    }
+
+    @Override
+    public final DataSchemaNodeBuilder getDataChildByName(final String name) {
+        for (DataSchemaNodeBuilder child : addedChildNodes) {
+            if (child.getQName().getLocalName().equals(name)) {
+                return child;
+            }
+        }
+        return null;
+    }
+
+    @Override
+    public final void addChildNode(final DataSchemaNodeBuilder child) {
+        QName childName = child.getQName();
+        for (DataSchemaNodeBuilder addedChildNode : addedChildNodes) {
+            if (addedChildNode.getQName().equals(childName)) {
+                throw new YangParseException(child.getModuleName(), child.getLine(), String.format(
+                        "Can not add '%s' to '%s' in module '%s': node with same name already declared at line %d",
+                        child, this, getModuleName(), addedChildNode.getLine()));
+            }
+        }
+        addedChildNodes.add(child);
+    }
+
+    @Override
+    public final void addChildNodeToContext(final DataSchemaNodeBuilder child) {
+        addedChildNodes.add(child);
+    }
+
+    @Override
+    public final void addChildNode(final DataSchemaNode child) {
+        checkNotSealed();
+        QName childName = child.getQName();
+        for (DataSchemaNode childNode : childNodes.values()) {
+            if (childNode.getQName().equals(childName)) {
+                throw new YangParseException(getModuleName(), getLine(), String.format(
+                        "Can not add '%s' to '%s' in module '%s': node with same name already declared", child, this,
+                        getModuleName()));
+            }
+        }
+        childNodes.put(child.getQName(), child);
+    }
+
+    @Override
+    public final Set<GroupingDefinition> getGroupings() {
+        return groupings;
+    }
+
+    @Override
+    public final Set<GroupingBuilder> getGroupingBuilders() {
+        return addedGroupings;
+    }
+
+    @Override
+    public final void addGrouping(final GroupingBuilder grouping) {
+        checkNotSealed();
+        QName groupingName = grouping.getQName();
+        for (GroupingBuilder addedGrouping : addedGroupings) {
+            if (addedGrouping.getQName().equals(groupingName)) {
+                throw new YangParseException(grouping.getModuleName(), grouping.getLine(), String.format(
+                        "Can not add '%s': grouping with same name already declared in module '%s' at line %d",
+                        grouping, getModuleName(), addedGrouping.getLine()));
+            }
+        }
+        addedGroupings.add(grouping);
+    }
+
+    @Override
+    public final Set<TypeDefinition<?>> getTypeDefinitions() {
+        return typedefs;
+    }
+
+    public final Set<UsesNode> getUsesNodes() {
+        return usesNodes;
+    }
+
+    @Override
+    public final Set<UsesNodeBuilder> getUsesNodeBuilders() {
+        return addedUsesNodes;
+    }
+
+    @Override
+    public final void addUsesNode(final UsesNodeBuilder usesNode) {
+        checkNotSealed();
+        addedUsesNodes.add(usesNode);
+    }
+
+
+    @Override
+    public final Set<TypeDefinitionBuilder> getTypeDefinitionBuilders() {
+        return addedTypedefs;
+    }
+
+    @Override
+    public void addTypedef(final TypeDefinitionBuilder type) {
+        checkNotSealed();
+        String typeName = type.getQName().getLocalName();
+        for (TypeDefinitionBuilder addedTypedef : addedTypedefs) {
+            if (addedTypedef.getQName().getLocalName().equals(typeName)) {
+                throw new YangParseException(getModuleName(), type.getLine(), "Can not add typedef '" + typeName
+                        + "': typedef with same name already declared at line " + addedTypedef.getLine());
+            }
+        }
+        addedTypedefs.add(type);
+    }
+
+    protected abstract String getStatementName();
+
+    protected void buildChildren() {
+        checkNotSealed();
+        seal();
+
+        for (DataSchemaNodeBuilder node : addedChildNodes) {
+            childNodes.put(node.getQName(), node.build());
+        }
+
+        for (GroupingBuilder builder : addedGroupings) {
+            groupings.add(builder.build());
+        }
+
+        for (TypeDefinitionBuilder entry : addedTypedefs) {
+            typedefs.add(entry.build());
+        }
+
+        for (UsesNodeBuilder builder : addedUsesNodes) {
+            usesNodes.add(builder.build());
+        }
+    }
+
+    @Deprecated
+    protected static DataSchemaNode getChildNode(final Set<DataSchemaNode> childNodes, final QName name) {
+        for (DataSchemaNode node : childNodes) {
+            if (node.getQName().equals(name)) {
+                return node;
+            }
+        }
+        return null;
+    }
+
+    @Deprecated
+    protected static DataSchemaNode getChildNode(final Set<DataSchemaNode> childNodes, final String name) {
+        for (DataSchemaNode node : childNodes) {
+            if (node.getQName().getLocalName().equals(name)) {
+                return node;
+            }
+        }
+        return null;
+    }
+
+
+}
diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/util/AbstractDocumentedNode.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/util/AbstractDocumentedNode.java
new file mode 100644 (file)
index 0000000..807b700
--- /dev/null
@@ -0,0 +1,36 @@
+package org.opendaylight.yangtools.yang.parser.builder.util;
+
+import org.opendaylight.yangtools.yang.model.api.DocumentedNode;
+import org.opendaylight.yangtools.yang.model.api.Status;
+
+import com.google.common.base.Preconditions;
+
+public abstract class AbstractDocumentedNode implements DocumentedNode {
+
+    private final String description;
+    private final String reference;
+    private final Status status;
+
+    protected AbstractDocumentedNode(final AbstractDocumentedNodeBuilder builder) {
+        Preconditions.checkArgument(builder.isSealed(), "Builder must be sealed.");
+        this.description = builder.getDescription();
+        this.reference = builder.getReference();
+        this.status = builder.getStatus();
+    }
+
+    @Override
+    public final String getDescription() {
+        return description;
+    }
+
+    @Override
+    public final String getReference() {
+        return reference;
+    }
+
+    @Override
+    public final Status getStatus() {
+        return status;
+    }
+
+}
diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/util/AbstractDocumentedNodeBuilder.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/util/AbstractDocumentedNodeBuilder.java
new file mode 100644 (file)
index 0000000..285c040
--- /dev/null
@@ -0,0 +1,55 @@
+package org.opendaylight.yangtools.yang.parser.builder.util;
+
+import org.opendaylight.yangtools.yang.model.api.DocumentedNode;
+import org.opendaylight.yangtools.yang.model.api.Status;
+import org.opendaylight.yangtools.yang.parser.builder.api.DocumentedNodeBuilder;
+
+public abstract class AbstractDocumentedNodeBuilder extends AbstractBuilder implements DocumentedNodeBuilder{
+    private String description = null;
+    private String reference = null;
+    private Status status = Status.CURRENT;
+
+
+
+    public AbstractDocumentedNodeBuilder(final String moduleName, final int line) {
+        super(moduleName, line);
+    }
+
+    public AbstractDocumentedNodeBuilder(final String moduleName, final int line, final DocumentedNode node) {
+        super(moduleName, line);
+        description = node.getDescription();
+        reference = node.getReference();
+        status = node.getStatus();
+    }
+
+    @Override
+    public final void setDescription(final String description) {
+        this.description = description;
+    }
+
+    @Override
+    public final void setReference(final String reference) {
+        this.reference = reference;
+    }
+
+    @Override
+    public final void setStatus(final Status status) {
+        this.status  = status;
+    }
+
+    @Override
+    public final String getDescription() {
+        return description;
+    }
+
+    @Override
+    public final String getReference() {
+        return reference;
+    }
+
+    @Override
+    public final Status getStatus() {
+        return status;
+    }
+
+}
index a33c76cab2023e3db05ea7b6a66ae7f28a1fbbcd..77d390f8f7a9aeb0742590d1e71e3aaadc92299d 100644 (file)
@@ -86,7 +86,7 @@ import org.opendaylight.yangtools.yang.parser.builder.impl.GroupingUtils;
 import org.opendaylight.yangtools.yang.parser.builder.impl.IdentitySchemaNodeBuilder;
 import org.opendaylight.yangtools.yang.parser.builder.impl.IdentityrefTypeBuilder;
 import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleBuilder;
-import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleBuilder.ModuleImpl;
+import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleImpl;
 import org.opendaylight.yangtools.yang.parser.builder.impl.UnionTypeBuilder;
 import org.opendaylight.yangtools.yang.parser.builder.impl.UnknownSchemaNodeBuilderImpl;
 import org.opendaylight.yangtools.yang.parser.builder.util.Comparators;
index e0abd348d57b8ae3a973e50d71bf4246d1473988..a5c80b1e3e16b2064f3918a3515b5210effdcd19 100644 (file)
@@ -164,7 +164,7 @@ public class YangParserNegativeTest {
             }
         } catch (YangParseException e) {
             String expected = "Error in module 'typedef' at line 10: typedef with same name 'int-ext' already declared at line 6.";
-            assertEquals(expected, e.getMessage());
+            assertTrue(e.getMessage().contains("'typedef' at line 10: typedef with same name 'int-ext' already declared at line 6."));
         }
     }