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
--- /dev/null
+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();
+}
/**
* 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();
/**
* 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();
*/
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;
@Override
DataNodeContainer build();
+ Map<QName, DataSchemaNode> getChildNodes();
+
}
*/
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;
}
@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
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) {
}
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());
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;
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;
}
} 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;
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;
}
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;
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;
}
} 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;
return this.order - o.order;
}
}
-
}
import java.net.URI;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Set;
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
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());
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
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());
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;
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.");
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;
}
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;
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;
*/
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;
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;
// 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
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());
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;
}
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;
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
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;
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;
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;
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();
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
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());
@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);
@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);
}
@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()) {
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;
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;
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;
}
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;
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;
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;
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();
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
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();
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());
}
@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
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);
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;
}
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;
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;
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;
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;
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;
* 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;
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<>();
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);
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());
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;
}
}
@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) {
return revision;
}
+ protected Set<ModuleImport> getImports() {
+ return imports;
+ }
+
+ protected String getSource() {
+ return source;
+ }
+
public boolean isSubmodule() {
return submodule;
}
}
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);
}
}
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");
}
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();
}
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();
}
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();
}
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();
}
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();
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;
}
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();
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 + "'.");
}
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");
}
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");
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");
}
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");
}
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);
@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) {
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;
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
}
}
+ 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.
*
// 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());
}
raiseYangParserException("'" + child + "'", "notification", childName, lineNum, notification.getLine());
}
}
- addedChildNodes.add(child);
+ addChildNode(child);
}
/**
return true;
}
+ public List<UnknownSchemaNode> getExtensionInstances() {
+ return unknownNodes;
+ }
}
--- /dev/null
+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
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<>();
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) {
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;
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);
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;
}
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;
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;
*/
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;
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()));
}
}
}
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");
@Override
public void setParent(final Builder parentBuilder) {
+ checkNotSealed();
this.parentBuilder = parentBuilder;
}
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;
+ }
+
}
+++ /dev/null
-/*
- * 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;
- }
-
-}
--- /dev/null
+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;
+ }
+
+}
--- /dev/null
+/*
+ * 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;
+ }
+
+
+}
--- /dev/null
+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;
+ }
+
+}
--- /dev/null
+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;
+ }
+
+}
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;
}
} 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."));
}
}