package org.opendaylight.yangtools.yang.parser.builder.impl;
import java.net.URI;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Date;
+import java.util.Deque;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.*;
-import org.opendaylight.yangtools.yang.parser.builder.api.*;
+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.NotificationDefinition;
+import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.UsesNode;
+import org.opendaylight.yangtools.yang.parser.builder.api.AbstractDataNodeContainerBuilder;
+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.GroupingBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.api.SchemaNodeBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.api.TypeAwareBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.api.TypeDefinitionBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.api.UsesNodeBuilder;
import org.opendaylight.yangtools.yang.parser.util.Comparators;
import org.opendaylight.yangtools.yang.parser.util.ModuleImportImpl;
import org.opendaylight.yangtools.yang.parser.util.RefineHolder;
private final ModuleImpl instance;
private final String name;
+ private final String sourcePath;
private final SchemaPath schemaPath;
private URI namespace;
private String prefix;
private Date revision;
+ private final boolean submodule;
+ 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>();
- private final Set<AugmentationSchema> augments = new HashSet<>();
+ private final Set<AugmentationSchema> augments = new LinkedHashSet<>();
private final List<AugmentationSchemaBuilder> augmentBuilders = new ArrayList<>();
private final List<AugmentationSchemaBuilder> allAugments = new ArrayList<>();
private final List<UnknownSchemaNodeBuilder> allUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
- public ModuleBuilder(final String name) {
+ private final List<ListSchemaNodeBuilder> allLists = new ArrayList<ListSchemaNodeBuilder>();
+
+ private String source;
+
+ public ModuleBuilder(final String name, final String sourcePath) {
+ this(name, false, sourcePath);
+ }
+
+ public ModuleBuilder(final String name, final boolean submodule, final String sourcePath) {
super(name, 0, null);
this.name = name;
- schemaPath = new SchemaPath(Collections.<QName> emptyList(), true);
- instance = new ModuleImpl(name);
+ this.sourcePath = sourcePath;
+ schemaPath = SchemaPath.create(Collections.<QName> emptyList(), true);
+ this.submodule = submodule;
+ instance = new ModuleImpl(name, sourcePath);
actualPath.push(this);
}
- public ModuleBuilder(Module base) {
+ public ModuleBuilder(final Module base) {
super(base.getName(), 0, null);
this.name = base.getName();
- schemaPath = new SchemaPath(Collections.<QName> emptyList(), true);
- instance = new ModuleImpl(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());
actualPath.push(this);
-
namespace = base.getNamespace();
prefix = base.getPrefix();
revision = base.getRevision();
for (DataSchemaNode childNode : base.getChildNodes()) {
- childNodes.put(childNode.getQName(), childNode);
+ childNodes.add(childNode);
}
typedefs.addAll(base.getTypeDefinitions());
augments.addAll(base.getAugmentations());
rpcs.addAll(base.getRpcs());
notifications.addAll(base.getNotifications());
- identities.addAll(base.getIdentities());
+
+ for (IdentitySchemaNode identityNode : base.getIdentities()) {
+ addedIdentities.add(new IdentitySchemaNodeBuilder(name, identityNode));
+ }
+
features.addAll(base.getFeatures());
deviations.addAll(base.getDeviations());
extensions.addAll(base.getExtensionSchemaNodes());
// CHILD NODES
for (DataSchemaNodeBuilder child : addedChildNodes) {
- DataSchemaNode childNode = child.build();
- childNodes.put(childNode.getQName(), childNode);
+ childNodes.add(child.build());
}
instance.addChildNodes(childNodes);
Collections.sort(unknownNodes, Comparators.SCHEMA_NODE_COMP);
instance.setUnknownSchemaNodes(unknownNodes);
+ instance.setSource(source);
+
return instance;
}
+ public String getModuleSourcePath() {
+ return sourcePath;
+ }
+
@Override
- public void setParent(Builder parent) {
+ public void setParent(final Builder parent) {
throw new YangParseException(name, 0, "Can not set parent to module");
}
}
}
- public Builder getActualParent() {
- if (actualPath.size() < 2) {
- return null;
- } else {
- Builder builderChild = actualPath.removeFirst();
- Builder builderParent = actualPath.peekFirst();
- actualPath.addFirst(builderChild);
- return builderParent;
- }
- }
-
public Set<TypeAwareBuilder> getDirtyNodes() {
return dirtyNodes;
}
+ public Set<AugmentationSchema> getAugments() {
+ return augments;
+ }
+
+ public List<AugmentationSchemaBuilder> getAugmentBuilders() {
+ return augmentBuilders;
+ }
+
public List<AugmentationSchemaBuilder> getAllAugments() {
return allAugments;
}
- public Set<IdentitySchemaNodeBuilder> getIdentities() {
+ public Set<IdentitySchemaNode> getIdentities() {
+ return identities;
+ }
+
+ public Set<IdentitySchemaNodeBuilder> getAddedIdentities() {
return addedIdentities;
}
+ public Set<FeatureDefinition> getFeatures() {
+ return features;
+ }
+
+ public Set<FeatureBuilder> getAddedFeatures() {
+ return addedFeatures;
+ }
+
public List<GroupingBuilder> getAllGroupings() {
return allGroupings;
}
return allUsesNodes;
}
- public Set<DeviationBuilder> getDeviations() {
+ public Set<Deviation> getDeviations() {
+ return deviations;
+ }
+
+ public Set<DeviationBuilder> getDeviationBuilders() {
return deviationBuilders;
}
- public List<ExtensionBuilder> getExtensions() {
+ public List<ExtensionDefinition> getExtensions() {
+ return extensions;
+ }
+
+ public List<ExtensionBuilder> getAddedExtensions() {
return addedExtensions;
}
return allUnknownNodes;
}
+ public List<ListSchemaNodeBuilder> getAllLists() {
+ return allLists;
+ }
+
public String getName() {
return name;
}
return revision;
}
+ public boolean isSubmodule() {
+ return submodule;
+ }
+
+ public String getBelongsTo() {
+ return belongsTo;
+ }
+
+ public void setBelongsTo(final String belongsTo) {
+ this.belongsTo = belongsTo;
+ }
+
public void markActualNodeDirty() {
final TypeAwareBuilder nodeBuilder = (TypeAwareBuilder) getActualNode();
dirtyNodes.add(nodeBuilder);
Builder parent = getActualNode();
builder.setParent(parent);
addChildToParent(parent, builder, qname.getLocalName());
+ allLists.add(builder);
return builder;
}
return builder;
}
- public AugmentationSchemaBuilder addAugment(final int line, final String augmentTargetStr) {
- final AugmentationSchemaBuilder builder = new AugmentationSchemaBuilderImpl(name, line, augmentTargetStr);
+ public AugmentationSchemaBuilder addAugment(final int line, final String augmentTargetStr, final int order) {
+ final AugmentationSchemaBuilder builder = new AugmentationSchemaBuilderImpl(name, line, augmentTargetStr, order);
Builder parent = getActualNode();
builder.setParent(parent);
}
@Override
- public void addUsesNode(UsesNodeBuilder usesBuilder) {
+ public void addUsesNode(final UsesNodeBuilder usesBuilder) {
addedUsesNodes.add(usesBuilder);
allUsesNodes.add(usesBuilder);
}
return outputBuilder;
}
- public void addNotification(NotificationDefinition notification) {
+ public void addNotification(final NotificationDefinition notification) {
notifications.add(notification);
}
}
@Override
- public void addTypedef(TypeDefinitionBuilder typedefBuilder) {
+ public void addTypedef(final TypeDefinitionBuilder typedefBuilder) {
String nodeName = typedefBuilder.getQName().getLocalName();
for (TypeDefinitionBuilder tdb : addedTypedefs) {
if (tdb.getQName().getLocalName().equals(nodeName)) {
return builder;
}
- public Set<RpcDefinitionBuilder> getRpcs() {
+ public Set<RpcDefinition> getRpcs() {
+ return rpcs;
+ }
+
+ public Set<RpcDefinitionBuilder> getAddedRpcs() {
return addedRpcs;
}
- public Set<NotificationBuilder> getNotifications() {
+ public Set<NotificationDefinition> getNotifications() {
+ return notifications;
+ }
+
+ public Set<NotificationBuilder> getAddedNotifications() {
return addedNotifications;
}
return "module " + name;
}
- private final class ModuleImpl implements Module {
+ public void setSource(final String source) {
+ 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 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 Map<QName, DataSchemaNode> childNodes = new TreeMap<>(Comparators.QNAME_COMP);
+ 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(String name) {
+ private ModuleImpl(final String name, final String sourcePath) {
this.name = name;
+ this.sourcePath = sourcePath;
+ }
+
+ @Override
+ public String getModuleSourcePath() {
+ return sourcePath;
}
@Override
return namespace;
}
- private void setNamespace(URI namespace) {
+ private void setNamespace(final URI namespace) {
this.namespace = namespace;
}
return revision;
}
- private void setRevision(Date revision) {
+ private void setRevision(final Date revision) {
this.revision = revision;
}
return prefix;
}
- private void setPrefix(String prefix) {
+ private void setPrefix(final String prefix) {
this.prefix = prefix;
}
return yangVersion;
}
- private void setYangVersion(String yangVersion) {
+ private void setYangVersion(final String yangVersion) {
this.yangVersion = yangVersion;
}
return description;
}
- private void setDescription(String description) {
+ private void setDescription(final String description) {
this.description = description;
}
return reference;
}
- private void setReference(String reference) {
+ private void setReference(final String reference) {
this.reference = reference;
}
return organization;
}
- private void setOrganization(String organization) {
+ private void setOrganization(final String organization) {
this.organization = organization;
}
return contact;
}
- private void setContact(String contact) {
+ private void setContact(final String contact) {
this.contact = contact;
}
return imports;
}
- private void setImports(Set<ModuleImport> imports) {
+ private void setImports(final Set<ModuleImport> imports) {
if (imports != null) {
this.imports.addAll(imports);
}
return features;
}
- private void setFeatures(Set<FeatureDefinition> features) {
+ private void setFeatures(final Set<FeatureDefinition> features) {
if (features != null) {
this.features.addAll(features);
}
return typeDefinitions;
}
- private void setTypeDefinitions(Set<TypeDefinition<?>> typeDefinitions) {
+ private void setTypeDefinitions(final Set<TypeDefinition<?>> typeDefinitions) {
if (typeDefinitions != null) {
this.typeDefinitions.addAll(typeDefinitions);
}
return notifications;
}
- private void setNotifications(Set<NotificationDefinition> notifications) {
+ private void setNotifications(final Set<NotificationDefinition> notifications) {
if (notifications != null) {
this.notifications.addAll(notifications);
}
return augmentations;
}
- private void setAugmentations(Set<AugmentationSchema> augmentations) {
+ private void setAugmentations(final Set<AugmentationSchema> augmentations) {
if (augmentations != null) {
this.augmentations.addAll(augmentations);
}
return rpcs;
}
- private void setRpcs(Set<RpcDefinition> rpcs) {
+ private void setRpcs(final Set<RpcDefinition> rpcs) {
if (rpcs != null) {
this.rpcs.addAll(rpcs);
}
return deviations;
}
- private void setDeviations(Set<Deviation> deviations) {
+ private void setDeviations(final Set<Deviation> deviations) {
if (deviations != null) {
this.deviations.addAll(deviations);
}
@Override
public Set<DataSchemaNode> getChildNodes() {
- final Set<DataSchemaNode> result = new TreeSet<>(Comparators.SCHEMA_NODE_COMP);
- result.addAll(childNodes.values());
- return Collections.unmodifiableSet(result);
+ return Collections.unmodifiableSet(childNodes);
}
- private void addChildNodes(Map<QName, DataSchemaNode> childNodes) {
+ private void addChildNodes(final Set<DataSchemaNode> childNodes) {
if (childNodes != null) {
- this.childNodes.putAll(childNodes);
+ this.childNodes.addAll(childNodes);
}
}
return groupings;
}
- private void setGroupings(Set<GroupingDefinition> groupings) {
+ private void setGroupings(final Set<GroupingDefinition> groupings) {
if (groupings != null) {
this.groupings.addAll(groupings);
}
return uses;
}
- private void setUses(Set<UsesNode> uses) {
+ private void setUses(final Set<UsesNode> uses) {
if (uses != null) {
this.uses.addAll(uses);
}
}
@Override
- public DataSchemaNode getDataChildByName(QName name) {
- return childNodes.get(name);
+ public DataSchemaNode getDataChildByName(final QName name) {
+ return getChildNode(childNodes, name);
}
@Override
- public DataSchemaNode getDataChildByName(String name) {
- DataSchemaNode result = null;
- for (Map.Entry<QName, DataSchemaNode> entry : childNodes.entrySet()) {
- if (entry.getKey().getLocalName().equals(name)) {
- result = entry.getValue();
- break;
- }
- }
- return result;
+ public DataSchemaNode getDataChildByName(final String name) {
+ return getChildNode(childNodes, name);
+ }
+
+ void setSource(final String source){
+ this.source = source;
+ }
+
+ public String getSource() {
+ return source;
}
@Override
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 + ((prefix == null) ? 0 : prefix.hashCode());
result = prime * result + ((yangVersion == null) ? 0 : yangVersion.hashCode());
return result;
}
@Override
- public boolean equals(Object obj) {
+ public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
} else if (!revision.equals(other.revision)) {
return false;
}
- if (prefix == null) {
- if (other.prefix != null) {
- return false;
- }
- } else if (!prefix.equals(other.prefix)) {
- return false;
- }
if (yangVersion == null) {
if (other.yangVersion != null) {
return false;
// defined only under module or submodule
if (parent instanceof DataNodeContainerBuilder) {
DataNodeContainerBuilder parentNode = (DataNodeContainerBuilder) parent;
- for (DataSchemaNodeBuilder childNode : parentNode.getChildNodes()) {
+ for (DataSchemaNodeBuilder childNode : parentNode.getChildNodeBuilders()) {
if (childNode.getQName().getLocalName().equals(childName)) {
raiseYangParserException("'" + child + "'", "node", childName, lineNum, childNode.getLine());
}
}
@Override
- public boolean equals(Object obj) {
+ public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
return true;
}
+
}