X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=yang%2Fyang-parser-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fyang%2Fparser%2Fbuilder%2Fimpl%2FModuleBuilder.java;h=79e992028dc52f7e2ee3f299393f9b9e7e9c7f19;hb=42abb28b99a02f9580f4676ce5c315628e5bcd24;hp=b7a25760c72374dfa4962d19d5602051d2309bd8;hpb=6e1f541302d06c8e20fa92eea87c6a7236d178e4;p=yangtools.git diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/ModuleBuilder.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/ModuleBuilder.java index b7a25760c7..79e992028d 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/ModuleBuilder.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/ModuleBuilder.java @@ -5,52 +5,92 @@ * 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.impl; +import com.google.common.base.Charsets; +import com.google.common.base.Preconditions; +import com.google.common.io.ByteSource; +import java.io.IOException; 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.HashMap; +import java.util.HashSet; +import java.util.LinkedHashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Objects; +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.parser.util.Comparators; -import org.opendaylight.yangtools.yang.parser.util.ModuleImportImpl; -import org.opendaylight.yangtools.yang.parser.util.RefineHolder; +import org.opendaylight.yangtools.yang.common.QNameModule; +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.SchemaPath; +import org.opendaylight.yangtools.yang.model.api.TypeDefinition; +import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode; +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.TypeAwareBuilder; +import org.opendaylight.yangtools.yang.parser.builder.api.TypeDefinitionBuilder; +import org.opendaylight.yangtools.yang.parser.builder.api.UnknownSchemaNodeBuilder; +import org.opendaylight.yangtools.yang.parser.builder.api.UsesNodeBuilder; +import org.opendaylight.yangtools.yang.parser.builder.util.AbstractDocumentedDataNodeContainerBuilder; +import org.opendaylight.yangtools.yang.parser.builder.util.Comparators; import org.opendaylight.yangtools.yang.parser.util.YangParseException; /** * Builder of Module object. If this module is dependent on external * module/modules, these dependencies must be resolved before module is built, * otherwise result may not be valid. + * + * @deprecated Pre-Beryllium implementation, scheduled for removal. */ -public class ModuleBuilder extends AbstractDataNodeContainerBuilder { - - private final ModuleImpl instance; +@Deprecated +public class ModuleBuilder extends AbstractDocumentedDataNodeContainerBuilder implements DocumentedNodeBuilder { + private static final QNameModule EMPTY_QNAME_MODULE = QNameModule.create(null, null).intern(); + private static final String GROUPING_STR = "Grouping"; + private static final String TYPEDEF_STR = "typedef"; + private ModuleImpl instance; private final String name; private final String sourcePath; - private final SchemaPath schemaPath; - private URI namespace; + private static final SchemaPath SCHEMA_PATH = SchemaPath.create(Collections. emptyList(), true); private String prefix; - private Date revision; + private QNameModule qnameModule = EMPTY_QNAME_MODULE; private final boolean submodule; private String belongsTo; private ModuleBuilder parent; - public ModuleBuilder getParent() { - return parent; - } - - public void setParent(ModuleBuilder parent) { - this.parent = parent; - } - private final Deque actualPath = new LinkedList<>(); private final Set dirtyNodes = new HashSet<>(); - private final Set imports = new HashSet(); + final Map imports = new HashMap<>(); + final Map importedModules = new HashMap<>(); + + final Set addedSubmodules = new HashSet<>(); + final Set submodules = new HashSet<>(); + final Map includedModules = new HashMap<>(); - private final Set augments = new HashSet<>(); + private final Set augments = new LinkedHashSet<>(); private final List augmentBuilders = new ArrayList<>(); private final List allAugments = new ArrayList<>(); @@ -76,9 +116,14 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder { private final List extensions = new ArrayList<>(); private final List addedExtensions = new ArrayList<>(); - private final List allUnknownNodes = new ArrayList(); + private final List allUnknownNodes = new ArrayList<>(); - private final List allLists = new ArrayList(); + private final List allLists = new ArrayList<>(); + + private String source; + private String yangVersion; + private String organization; + private String contact; public ModuleBuilder(final String name, final String sourcePath) { this(name, false, sourcePath); @@ -88,39 +133,40 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder { super(name, 0, null); this.name = name; this.sourcePath = sourcePath; - schemaPath = new SchemaPath(Collections. emptyList(), true); this.submodule = submodule; - instance = new ModuleImpl(name, sourcePath); - actualPath.push(this); + actualPath.push(this);//FIXME: this escapes constructor } - public ModuleBuilder(Module base) { - super(base.getName(), 0, null); + public ModuleBuilder(final Module base) { + super(base.getName(), 0, QName.create(base.getQNameModule(), base.getName()), + SCHEMA_PATH, base); this.name = base.getName(); this.sourcePath = base.getModuleSourcePath(); - schemaPath = new SchemaPath(Collections. emptyList(), true); + submodule = false; - instance = new ModuleImpl(base.getName(), base.getModuleSourcePath()); - actualPath.push(this); - namespace = base.getNamespace(); + yangVersion = base.getYangVersion(); + actualPath.push(this);//FIXME: this escapes constructor prefix = base.getPrefix(); - revision = base.getRevision(); - - for (DataSchemaNode childNode : base.getChildNodes()) { - childNodes.add(childNode); - } + qnameModule = base.getQNameModule(); - typedefs.addAll(base.getTypeDefinitions()); - groupings.addAll(base.getGroupings()); - usesNodes.addAll(base.getUses()); 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()); unknownNodes.addAll(base.getUnknownSchemaNodes()); + source = base.getSource(); + } + + @Override + protected String getStatementName() { + return "module"; } /** @@ -128,85 +174,61 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder { */ @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.add(child.build()); + if(instance != null) { + return instance; } - instance.addChildNodes(childNodes); - // GROUPINGS - for (GroupingBuilder gb : addedGroupings) { - groupings.add(gb.build()); - } - instance.setGroupings(groupings); + buildChildren(); - // USES - for (UsesNodeBuilder unb : addedUsesNodes) { - usesNodes.add(unb.build()); + // SUBMODULES + for (ModuleBuilder submodule : addedSubmodules) { + submodules.add(submodule.build()); } - instance.setUses(usesNodes); // 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 = new ModuleImpl(name, sourcePath, this); return instance; } @@ -215,18 +237,22 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder { } @Override - public void setParent(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 getTypeDefinitionBuilders() { - return addedTypedefs; + public SchemaPath getPath() { + return SCHEMA_PATH; } public void enterNode(final Builder node) { @@ -245,17 +271,6 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder { } } - 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 getDirtyNodes() { return dirtyNodes; } @@ -325,11 +340,19 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder { } public URI getNamespace() { - return namespace; + return qnameModule.getNamespace(); + } + + public QNameModule getQNameModule() { + return qnameModule; + } + + public void setQNameModule(final QNameModule qnameModule) { + this.qnameModule = Preconditions.checkNotNull(qnameModule); } public void setNamespace(final URI namespace) { - this.namespace = namespace; + this.qnameModule = QNameModule.create(namespace, qnameModule.getRevision()).intern(); } public String getPrefix() { @@ -337,7 +360,40 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder { } public Date getRevision() { - return revision; + return qnameModule.getRevision(); + } + + public ModuleImport getImport(final String prefix) { + return imports.get(prefix); + } + + public Map getImports() { + return imports; + } + + public ModuleBuilder getImportedModule(final String prefix) { + return importedModules.get(prefix); + } + + public void addImportedModule(final String prefix, final ModuleBuilder module) { + checkPrefix(prefix); + importedModules.put(prefix, module); + } + + public Map getIncludedModules() { + return includedModules; + } + + public void addInclude(final String name, final Date revision) { + includedModules.put(name, revision); + } + + public void addSubmodule(final ModuleBuilder submodule) { + addedSubmodules.add(submodule); + } + + protected String getSource() { + return source; } public boolean isSubmodule() { @@ -348,7 +404,7 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder { return belongsTo; } - public void setBelongsTo(String belongsTo) { + public void setBelongsTo(final String belongsTo) { this.belongsTo = belongsTo; } @@ -358,7 +414,7 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder { } public void setRevision(final Date revision) { - this.revision = revision; + this.qnameModule = QNameModule.create(qnameModule.getNamespace(), revision).intern(); } public void setPrefix(final String prefix) { @@ -366,37 +422,37 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder { } public void setYangVersion(final String yangVersion) { - instance.setYangVersion(yangVersion); - } - - public void setDescription(final String description) { - instance.setDescription(description); - } - - public void setReference(final String reference) { - instance.setReference(reference); + this.yangVersion = yangVersion; } public void setOrganization(final String organization) { - instance.setOrganization(organization); + this.organization = organization; } public void setContact(final String contact) { - instance.setContact(contact); + this.contact = contact; } - public boolean addModuleImport(final String moduleName, final Date revision, final String prefix) { - final ModuleImport moduleImport = createModuleImport(moduleName, revision, prefix); - return imports.add(moduleImport); + public void addModuleImport(final String moduleName, final Date revision, final String prefix) { + checkPrefix(prefix); + checkNotSealed(); + final ModuleImport moduleImport = new ModuleImportImpl(moduleName, revision, prefix); + imports.put(prefix, moduleImport); } - public Set getModuleImports() { - return imports; + private void checkPrefix(final String prefix) { + if (prefix == null || prefix.isEmpty()) { + throw new IllegalArgumentException("Cannot add imported module with undefined prefix"); + } + if (prefix.equals(this.prefix)) { + throw new IllegalArgumentException("Cannot add imported module with prefix equals to module prefix"); + } } public ExtensionBuilder addExtension(final QName qname, final int line, final SchemaPath path) { - Builder parent = getActualNode(); - if (!(parent.equals(this))) { + checkNotSealed(); + Builder parentBuilder = getActualNode(); + if (!(parentBuilder.equals(this))) { throw new YangParseException(name, line, "extension can be defined only in module or submodule"); } @@ -406,81 +462,86 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder { raiseYangParserException("extension", "node", extName, line, addedExtension.getLine()); } } - final ExtensionBuilder builder = new ExtensionBuilder(name, line, qname, path); - builder.setParent(parent); + final ExtensionBuilder builder = new ExtensionBuilderImpl(name, line, qname, path); + builder.setParent(parentBuilder); addedExtensions.add(builder); return builder; } 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(); - builder.setParent(parent); - addChildToParent(parent, builder, qname.getLocalName()); + Builder parentBuilder = getActualNode(); + builder.setParent(parentBuilder); + addChildToParent(parentBuilder, builder, qname.getLocalName()); return builder; } 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(); - builder.setParent(parent); - addChildToParent(parent, builder, qname.getLocalName()); + Builder parentBuilder = getActualNode(); + builder.setParent(parentBuilder); + addChildToParent(parentBuilder, builder, qname.getLocalName()); allLists.add(builder); return builder; } 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(); - builder.setParent(parent); - addChildToParent(parent, builder, qname.getLocalName()); + Builder parentBuilder = getActualNode(); + builder.setParent(parentBuilder); + addChildToParent(parentBuilder, builder, qname.getLocalName()); return builder; } 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(); - builder.setParent(parent); - addChildToParent(parent, builder, qname.getLocalName()); + Builder parentBuilder = getActualNode(); + builder.setParent(parentBuilder); + addChildToParent(parentBuilder, builder, qname.getLocalName()); return builder; } 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(); - builder.setParent(parent); + Builder parentBuilder = getActualNode(); + builder.setParent(parentBuilder); String groupingName = qname.getLocalName(); - if (parent.equals(this)) { - for (GroupingBuilder addedGrouping : addedGroupings) { + if (parentBuilder.equals(this)) { + for (GroupingBuilder addedGrouping : getGroupingBuilders()) { if (addedGrouping.getQName().getLocalName().equals(groupingName)) { - raiseYangParserException("", "Grouping", groupingName, line, addedGrouping.getLine()); + raiseYangParserException("", GROUPING_STR, groupingName, line, addedGrouping.getLine()); } } - addedGroupings.add(builder); + addGrouping(builder); } else { - if (parent instanceof DataNodeContainerBuilder) { - DataNodeContainerBuilder parentNode = (DataNodeContainerBuilder) parent; + if (parentBuilder instanceof DataNodeContainerBuilder) { + DataNodeContainerBuilder parentNode = (DataNodeContainerBuilder) parentBuilder; for (GroupingBuilder addedGrouping : parentNode.getGroupingBuilders()) { if (addedGrouping.getQName().getLocalName().equals(groupingName)) { - raiseYangParserException("", "Grouping", groupingName, line, addedGrouping.getLine()); + raiseYangParserException("", GROUPING_STR, groupingName, line, addedGrouping.getLine()); } } parentNode.addGrouping(builder); - } else if (parent instanceof RpcDefinitionBuilder) { - RpcDefinitionBuilder parentNode = (RpcDefinitionBuilder) parent; + } else if (parentBuilder instanceof RpcDefinitionBuilder) { + RpcDefinitionBuilder parentNode = (RpcDefinitionBuilder) parentBuilder; for (GroupingBuilder child : parentNode.getGroupings()) { if (child.getQName().getLocalName().equals(groupingName)) { - raiseYangParserException("", "Grouping", groupingName, line, child.getLine()); + raiseYangParserException("", GROUPING_STR, groupingName, line, child.getLine()); } } parentNode.addGrouping(builder); @@ -493,13 +554,16 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder { 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 SchemaPath targetPath, final int order) { + checkNotSealed(); + final AugmentationSchemaBuilder builder = new AugmentationSchemaBuilderImpl(name, line, augmentTargetStr, + targetPath, order); - Builder parent = getActualNode(); - builder.setParent(parent); + Builder parentBuilder = getActualNode(); + builder.setParent(parentBuilder); - if (parent.equals(this)) { + if (parentBuilder.equals(this)) { // augment can be declared only under 'module' ... if (!(augmentTargetStr.startsWith("/"))) { throw new YangParseException( @@ -510,13 +574,13 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder { augmentBuilders.add(builder); } else { // ... or 'uses' statement - if (parent instanceof UsesNodeBuilder) { + if (parentBuilder instanceof UsesNodeBuilder) { if (augmentTargetStr.startsWith("/")) { throw new YangParseException(name, line, "If 'augment' statement is a substatement to the 'uses' statement, it cannot contain absolute path (" + augmentTargetStr + ")"); } - ((UsesNodeBuilder) parent).addAugment(builder); + ((UsesNodeBuilder) parentBuilder).addAugment(builder); } else { throw new YangParseException(name, line, "Augment can be declared only under module or uses statement."); } @@ -526,27 +590,22 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder { return builder; } - @Override - public void addUsesNode(UsesNodeBuilder usesBuilder) { - addedUsesNodes.add(usesBuilder); - allUsesNodes.add(usesBuilder); - } - - public UsesNodeBuilder addUsesNode(final int line, final String groupingPathStr) { - final UsesNodeBuilder usesBuilder = new UsesNodeBuilderImpl(name, line, groupingPathStr); + public UsesNodeBuilder addUsesNode(final int line, final SchemaPath grouping) { + checkNotSealed(); + final UsesNodeBuilder usesBuilder = new UsesNodeBuilderImpl(name, line, grouping); - Builder parent = getActualNode(); - usesBuilder.setParent(parent); + Builder parentBuilder = getActualNode(); + usesBuilder.setParent(parentBuilder); - if (parent.equals(this)) { - addedUsesNodes.add(usesBuilder); + if (parentBuilder.equals(this)) { + addUsesNode(usesBuilder); } else { - if (!(parent instanceof DataNodeContainerBuilder)) { - throw new YangParseException(name, line, "Unresolved parent of uses '" + groupingPathStr + "'."); + if (!(parentBuilder instanceof DataNodeContainerBuilder)) { + throw new YangParseException(name, line, "Unresolved parent of uses '" + grouping + "'."); } - ((DataNodeContainerBuilder) parent).addUsesNode(usesBuilder); + ((DataNodeContainerBuilder) parentBuilder).addUsesNode(usesBuilder); } - if (parent instanceof AugmentationSchemaBuilder) { + if (parentBuilder instanceof AugmentationSchemaBuilder) { usesBuilder.setAugmenting(true); } @@ -554,50 +613,57 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder { return usesBuilder; } - public void addRefine(final RefineHolder refine) { - final Builder parent = getActualNode(); - if (!(parent instanceof UsesNodeBuilder)) { + public void addRefine(final RefineHolderImpl refine) { + checkNotSealed(); + final Builder parentBuilder = getActualNode(); + if (!(parentBuilder instanceof UsesNodeBuilder)) { throw new YangParseException(name, refine.getLine(), "refine can be defined only in uses statement"); } - ((UsesNodeBuilder) parent).addRefine(refine); - refine.setParent(parent); + ((UsesNodeBuilder) parentBuilder).addRefine(refine); + refine.setParent(parentBuilder); } public RpcDefinitionBuilder addRpc(final int line, final QName qname, final SchemaPath path) { - Builder parent = getActualNode(); - if (!(parent.equals(this))) { + checkNotSealed(); + Builder parentBuilder = getActualNode(); + if (!(parentBuilder.equals(this))) { throw new YangParseException(name, line, "rpc can be defined only in module or submodule"); } final RpcDefinitionBuilder rpcBuilder = new RpcDefinitionBuilder(name, line, qname, path); - rpcBuilder.setParent(parent); + rpcBuilder.setParent(parentBuilder); 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) { - final Builder parent = getActualNode(); - if (!(parent instanceof RpcDefinitionBuilder)) { + checkNotSealed(); + final Builder parentBuilder = getActualNode(); + if (!(parentBuilder instanceof RpcDefinitionBuilder)) { throw new YangParseException(name, line, "input can be defined only in rpc statement"); } - final RpcDefinitionBuilder rpc = (RpcDefinitionBuilder) parent; + final RpcDefinitionBuilder rpc = (RpcDefinitionBuilder) parentBuilder; final ContainerSchemaNodeBuilder inputBuilder = new ContainerSchemaNodeBuilder(name, line, qname, schemaPath); inputBuilder.setParent(rpc); @@ -607,11 +673,12 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder { } public ContainerSchemaNodeBuilder addRpcOutput(final SchemaPath schemaPath, final QName qname, final int line) { - final Builder parent = getActualNode(); - if (!(parent instanceof RpcDefinitionBuilder)) { + checkNotSealed(); + final Builder parentBuilder = getActualNode(); + if (!(parentBuilder instanceof RpcDefinitionBuilder)) { throw new YangParseException(name, line, "output can be defined only in rpc statement"); } - final RpcDefinitionBuilder rpc = (RpcDefinitionBuilder) parent; + final RpcDefinitionBuilder rpc = (RpcDefinitionBuilder) parentBuilder; final ContainerSchemaNodeBuilder outputBuilder = new ContainerSchemaNodeBuilder(name, line, qname, schemaPath); outputBuilder.setParent(rpc); @@ -620,48 +687,36 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder { return outputBuilder; } - public void addNotification(NotificationDefinition notification) { + public void addNotification(final NotificationDefinition notification) { + checkNotSealed(); notifications.add(notification); } public NotificationBuilder addNotification(final int line, final QName qname, final SchemaPath path) { - final Builder parent = getActualNode(); - if (!(parent.equals(this))) { + checkNotSealed(); + final Builder parentBuilder = getActualNode(); + if (!(parentBuilder.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); + builder.setParent(parentBuilder); addedNotifications.add(builder); return builder; } public FeatureBuilder addFeature(final int line, final QName qname, final SchemaPath path) { - Builder parent = getActualNode(); - if (!(parent.equals(this))) { + Builder parentBuilder = getActualNode(); + if (!(parentBuilder.equals(this))) { throw new YangParseException(name, line, "feature can be defined only in module or submodule"); } final FeatureBuilder builder = new FeatureBuilder(name, line, qname, path); - builder.setParent(parent); + builder.setParent(parentBuilder); String featureName = qname.getLocalName(); for (FeatureBuilder addedFeature : addedFeatures) { @@ -676,26 +731,26 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder { public ChoiceBuilder addChoice(final int line, final QName qname, final SchemaPath path) { final ChoiceBuilder builder = new ChoiceBuilder(name, line, qname, path); - Builder parent = getActualNode(); - builder.setParent(parent); - addChildToParent(parent, builder, qname.getLocalName()); + Builder parentBuilder = getActualNode(); + builder.setParent(parentBuilder); + addChildToParent(parentBuilder, builder, qname.getLocalName()); return builder; } public ChoiceCaseBuilder addCase(final int line, final QName qname, final SchemaPath path) { - Builder parent = getActualNode(); - if (parent == null || parent.equals(this)) { + Builder parentBuilder = getActualNode(); + if (parentBuilder == null || parentBuilder.equals(this)) { throw new YangParseException(name, line, "'case' parent not found"); } final ChoiceCaseBuilder builder = new ChoiceCaseBuilder(name, line, qname, path); - builder.setParent(parent); + builder.setParent(parentBuilder); - if (parent instanceof ChoiceBuilder) { - ((ChoiceBuilder) parent).addCase(builder); - } else if (parent instanceof AugmentationSchemaBuilder) { - ((AugmentationSchemaBuilder) parent).addChildNode(builder); + if (parentBuilder instanceof ChoiceBuilder) { + ((ChoiceBuilder) parentBuilder).addCase(builder); + } else if (parentBuilder instanceof AugmentationSchemaBuilder) { + ((AugmentationSchemaBuilder) parentBuilder).addChildNode(builder); } else { throw new YangParseException(name, line, "Unresolved parent of 'case' " + qname.getLocalName()); } @@ -706,52 +761,47 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder { public AnyXmlBuilder addAnyXml(final int line, final QName qname, final SchemaPath schemaPath) { final AnyXmlBuilder builder = new AnyXmlBuilder(name, line, qname, schemaPath); - Builder parent = getActualNode(); - builder.setParent(parent); - addChildToParent(parent, builder, qname.getLocalName()); + Builder parentBuilder = getActualNode(); + builder.setParent(parentBuilder); + addChildToParent(parentBuilder, builder, qname.getLocalName()); return builder; } @Override - public void addTypedef(TypeDefinitionBuilder typedefBuilder) { + 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()); + raiseYangParserException("", TYPEDEF_STR, nodeName, typedefBuilder.getLine(), tdb.getLine()); } } - addedTypedefs.add(typedefBuilder); + super.addTypedef(typedefBuilder); } public TypeDefinitionBuilderImpl addTypedef(final int line, final QName qname, final SchemaPath path) { final TypeDefinitionBuilderImpl builder = new TypeDefinitionBuilderImpl(name, line, qname, path); - Builder parent = getActualNode(); - builder.setParent(parent); + Builder parentBuilder = getActualNode(); + builder.setParent(parentBuilder); 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); + if (parentBuilder.equals(this)) { + addTypedef(builder); } else { - if (parent instanceof DataNodeContainerBuilder) { - DataNodeContainerBuilder parentNode = (DataNodeContainerBuilder) parent; + if (parentBuilder instanceof DataNodeContainerBuilder) { + DataNodeContainerBuilder parentNode = (DataNodeContainerBuilder) parentBuilder; for (TypeDefinitionBuilder child : parentNode.getTypeDefinitionBuilders()) { if (child.getQName().getLocalName().equals(typedefName)) { - raiseYangParserException("", "typedef", typedefName, line, child.getLine()); + raiseYangParserException("", TYPEDEF_STR, typedefName, line, child.getLine()); } } parentNode.addTypedef(builder); - } else if (parent instanceof RpcDefinitionBuilder) { - RpcDefinitionBuilder rpcParent = (RpcDefinitionBuilder) parent; + } else if (parentBuilder instanceof RpcDefinitionBuilder) { + RpcDefinitionBuilder rpcParent = (RpcDefinitionBuilder) parentBuilder; for (TypeDefinitionBuilder tdb : rpcParent.getTypeDefinitions()) { if (tdb.getQName().getLocalName().equals(builder.getQName().getLocalName())) { - raiseYangParserException("", "typedef", typedefName, line, tdb.getLine()); + raiseYangParserException("", TYPEDEF_STR, typedefName, line, tdb.getLine()); } } rpcParent.addTypedef(builder); @@ -764,22 +814,22 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder { } public void setType(final TypeDefinition type) { - Builder parent = getActualNode(); - if (!(parent instanceof TypeAwareBuilder)) { + Builder parentBuilder = getActualNode(); + if (!(parentBuilder instanceof TypeAwareBuilder)) { throw new YangParseException("Failed to set type '" + type.getQName().getLocalName() - + "'. Invalid parent node: " + parent); + + "'. Invalid parent node: " + parentBuilder); } - ((TypeAwareBuilder) parent).setType(type); + ((TypeAwareBuilder) parentBuilder).setType(type); } - public UnionTypeBuilder addUnionType(final int line, final URI namespace, final Date revision) { - final Builder parent = getActualNode(); - if (parent == null) { + public UnionTypeBuilder addUnionType(final int line, final QNameModule module) { + final Builder parentBuilder = getActualNode(); + if (parentBuilder == null) { throw new YangParseException(name, line, "Unresolved parent of union type"); } else { final UnionTypeBuilder union = new UnionTypeBuilder(name, line); - if (parent instanceof TypeAwareBuilder) { - ((TypeAwareBuilder) parent).setTypedef(union); + if (parentBuilder instanceof TypeAwareBuilder) { + ((TypeAwareBuilder) parentBuilder).setTypedef(union); return union; } else { throw new YangParseException(name, line, "Invalid parent of union type."); @@ -790,12 +840,12 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder { public void addIdentityrefType(final int line, final SchemaPath schemaPath, final String baseString) { final IdentityrefTypeBuilder identityref = new IdentityrefTypeBuilder(name, line, baseString, schemaPath); - final Builder parent = getActualNode(); - if (parent == null) { + final Builder parentBuilder = getActualNode(); + if (parentBuilder == null) { throw new YangParseException(name, line, "Unresolved parent of identityref type."); } else { - if (parent instanceof TypeAwareBuilder) { - final TypeAwareBuilder typeParent = (TypeAwareBuilder) parent; + if (parentBuilder instanceof TypeAwareBuilder) { + final TypeAwareBuilder typeParent = (TypeAwareBuilder) parentBuilder; typeParent.setTypedef(identityref); dirtyNodes.add(typeParent); } else { @@ -804,21 +854,21 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder { } } - public DeviationBuilder addDeviation(final int line, final String targetPath) { - Builder parent = getActualNode(); - if (!(parent.equals(this))) { + public DeviationBuilder addDeviation(final int line, final SchemaPath targetPath) { + Builder parentBuilder = getActualNode(); + if (!(parentBuilder.equals(this))) { throw new YangParseException(name, line, "deviation can be defined only in module or submodule"); } final DeviationBuilder builder = new DeviationBuilder(name, line, targetPath); - builder.setParent(parent); + builder.setParent(parentBuilder); deviationBuilders.add(builder); return builder; } public IdentitySchemaNodeBuilder addIdentity(final QName qname, final int line, final SchemaPath path) { - Builder parent = getActualNode(); - if (!(parent.equals(this))) { + Builder parentBuilder = getActualNode(); + if (!(parentBuilder.equals(this))) { throw new YangParseException(name, line, "identity can be defined only in module or submodule"); } String identityName = qname.getLocalName(); @@ -829,7 +879,7 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder { } final IdentitySchemaNodeBuilder builder = new IdentitySchemaNodeBuilder(name, line, qname, path); - builder.setParent(parent); + builder.setParent(parentBuilder); addedIdentities.add(builder); return builder; } @@ -840,21 +890,21 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder { allUnknownNodes.add(builder); } - public UnknownSchemaNodeBuilder addUnknownSchemaNode(final int line, final QName qname, final SchemaPath path) { - final Builder parent = getActualNode(); - final UnknownSchemaNodeBuilder builder = new UnknownSchemaNodeBuilder(name, line, qname, path); - builder.setParent(parent); + public UnknownSchemaNodeBuilderImpl addUnknownSchemaNode(final int line, final QName qname, final SchemaPath path) { + final Builder parentBuilder = getActualNode(); + final UnknownSchemaNodeBuilderImpl builder = new UnknownSchemaNodeBuilderImpl(name, line, qname, path); + builder.setParent(parentBuilder); allUnknownNodes.add(builder); - if (parent.equals(this)) { + if (parentBuilder.equals(this)) { addedUnknownNodes.add(builder); } else { - if (parent instanceof SchemaNodeBuilder) { - ((SchemaNodeBuilder) parent).addUnknownNodeBuilder(builder); - } else if (parent instanceof DataNodeContainerBuilder) { - ((DataNodeContainerBuilder) parent).addUnknownNodeBuilder(builder); - } else if (parent instanceof RefineHolder) { - ((RefineHolder) parent).addUnknownNodeBuilder(builder); + if (parentBuilder instanceof SchemaNodeBuilder) { + parentBuilder.addUnknownNodeBuilder(builder); + } else if (parentBuilder instanceof DataNodeContainerBuilder) { + parentBuilder.addUnknownNodeBuilder(builder); + } else if (parentBuilder instanceof RefineHolderImpl) { + parentBuilder.addUnknownNodeBuilder(builder); } else { throw new YangParseException(name, line, "Unresolved parent of unknown node '" + qname.getLocalName() + "'"); @@ -885,346 +935,12 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder { return "module " + name; } - private 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 imports = new HashSet<>(); - private final Set features = new TreeSet<>(Comparators.SCHEMA_NODE_COMP); - private final Set> typeDefinitions = new TreeSet<>(Comparators.SCHEMA_NODE_COMP); - private final Set notifications = new TreeSet<>(Comparators.SCHEMA_NODE_COMP); - private final Set augmentations = new HashSet<>(); - private final Set rpcs = new TreeSet<>(Comparators.SCHEMA_NODE_COMP); - private final Set deviations = new HashSet<>(); - private final Set childNodes = new TreeSet<>(Comparators.SCHEMA_NODE_COMP); - private final Set groupings = new TreeSet<>(Comparators.SCHEMA_NODE_COMP); - private final Set uses = new HashSet<>(); - private final List extensionNodes = new ArrayList<>(); - private final Set identities = new TreeSet<>(Comparators.SCHEMA_NODE_COMP); - private final List unknownNodes = new ArrayList<>(); - - private ModuleImpl(String name, String sourcePath) { - this.name = name; - this.sourcePath = sourcePath; - } - - @Override - public String getModuleSourcePath() { - return sourcePath; - } - - @Override - public URI getNamespace() { - return namespace; - } - - private void setNamespace(URI namespace) { - this.namespace = namespace; - } - - @Override - public String getName() { - return name; - } - - @Override - public Date getRevision() { - return revision; - } - - private void setRevision(Date revision) { - this.revision = revision; - } - - @Override - public String getPrefix() { - return prefix; - } - - private void setPrefix(String prefix) { - this.prefix = prefix; - } - - @Override - public String getYangVersion() { - return yangVersion; - } - - private void setYangVersion(String yangVersion) { - this.yangVersion = yangVersion; - } - - @Override - public String getDescription() { - return description; - } - - private void setDescription(String description) { - this.description = description; - } - - @Override - public String getReference() { - return reference; - } - - private void setReference(String reference) { - this.reference = reference; - } - - @Override - public String getOrganization() { - return organization; - } - - private void setOrganization(String organization) { - this.organization = organization; - } - - @Override - public String getContact() { - return contact; - } - - private void setContact(String contact) { - this.contact = contact; - } - - @Override - public Set getImports() { - return imports; - } - - private void setImports(Set imports) { - if (imports != null) { - this.imports.addAll(imports); - } - } - - @Override - public Set getFeatures() { - return features; - } - - private void setFeatures(Set features) { - if (features != null) { - this.features.addAll(features); - } - } - - @Override - public Set> getTypeDefinitions() { - return typeDefinitions; - } - - private void setTypeDefinitions(Set> typeDefinitions) { - if (typeDefinitions != null) { - this.typeDefinitions.addAll(typeDefinitions); - } - } - - @Override - public Set getNotifications() { - return notifications; - } - - private void setNotifications(Set notifications) { - if (notifications != null) { - this.notifications.addAll(notifications); - } - } - - @Override - public Set getAugmentations() { - return augmentations; - } - - private void setAugmentations(Set augmentations) { - if (augmentations != null) { - this.augmentations.addAll(augmentations); - } - } - - @Override - public Set getRpcs() { - return rpcs; - } - - private void setRpcs(Set rpcs) { - if (rpcs != null) { - this.rpcs.addAll(rpcs); - } - } - - @Override - public Set getDeviations() { - return deviations; - } - - private void setDeviations(Set deviations) { - if (deviations != null) { - this.deviations.addAll(deviations); - } - } - - @Override - public Set getChildNodes() { - return Collections.unmodifiableSet(childNodes); - } - - private void addChildNodes(Set childNodes) { - if (childNodes != null) { - this.childNodes.addAll(childNodes); - } - } - - @Override - public Set getGroupings() { - return groupings; - } - - private void setGroupings(Set groupings) { - if (groupings != null) { - this.groupings.addAll(groupings); - } - } - - @Override - public Set getUses() { - return uses; - } - - private void setUses(Set uses) { - if (uses != null) { - this.uses.addAll(uses); - } - } - - @Override - public List getExtensionSchemaNodes() { - Collections.sort(extensionNodes, Comparators.SCHEMA_NODE_COMP); - return extensionNodes; - } - - private void setExtensionSchemaNodes(final List extensionNodes) { - if (extensionNodes != null) { - this.extensionNodes.addAll(extensionNodes); - } - } - - @Override - public Set getIdentities() { - return identities; - } - - private void setIdentities(final Set identities) { - if (identities != null) { - this.identities.addAll(identities); - } - } - - @Override - public List getUnknownSchemaNodes() { - return unknownNodes; - } - - private void setUnknownSchemaNodes(final List unknownNodes) { - if (unknownNodes != null) { - this.unknownNodes.addAll(unknownNodes); - } - } - - @Override - public DataSchemaNode getDataChildByName(QName name) { - return getChildNode(childNodes, name); - } - - @Override - public DataSchemaNode getDataChildByName(String name) { - return getChildNode(childNodes, name); - } - - @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 + ((prefix == null) ? 0 : prefix.hashCode()); - result = prime * result + ((yangVersion == null) ? 0 : yangVersion.hashCode()); - return result; - } - - @Override - public boolean equals(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 (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; - } - } else if (!yangVersion.equals(other.yangVersion)) { - return false; - } - return true; - } + public void setSource(final ByteSource byteSource) throws IOException { + setSource(byteSource.asCharSource(Charsets.UTF_8).read()); + } - @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(); - } + public void setSource(final String source) { + this.source = source; } /** @@ -1245,6 +961,18 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder { } } + public String getYangVersion() { + return yangVersion; + } + + public String getContact() { + return contact; + } + + public String getOrganization() { + return organization; + } + /** * Adds child node child to the set of nodes child nodes. * @@ -1266,7 +994,7 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder { // notifications, and anyxmls defined within a parent node or at the // top level of the module or its submodules share the same // identifier namespace. - for (DataSchemaNodeBuilder childNode : addedChildNodes) { + for (DataSchemaNodeBuilder childNode : getChildNodeBuilders()) { if (childNode.getQName().getLocalName().equals(childName)) { raiseYangParserException("'" + child + "'", "node", childName, lineNum, childNode.getLine()); } @@ -1281,7 +1009,7 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder { raiseYangParserException("'" + child + "'", "notification", childName, lineNum, notification.getLine()); } } - addedChildNodes.add(child); + addChildNode(child); } /** @@ -1327,11 +1055,6 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder { } } - private ModuleImport createModuleImport(final String moduleName, final Date revision, final String prefix) { - final ModuleImport moduleImport = new ModuleImportImpl(moduleName, revision, prefix); - return moduleImport; - } - private void raiseYangParserException(final String cantAddType, final String type, final String name, final int currentLine, final int duplicateLine) { @@ -1344,23 +1067,22 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder { String msg = String.format("%s%s with same name '%s' already declared at line %d.", msgPrefix, type, name, duplicateLine); - throw new YangParseException(moduleName, currentLine, msg); + throw new YangParseException(getModuleName(), currentLine, msg); } @Override public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((name == null) ? 0 : name.hashCode()); - result = prime * result + ((namespace == null) ? 0 : namespace.hashCode()); - result = prime * result + ((revision == null) ? 0 : revision.hashCode()); - result = prime * result + ((prefix == null) ? 0 : prefix.hashCode()); + result = prime * result + Objects.hashCode(name); + result = prime * result + qnameModule.hashCode(); + result = prime * result + Objects.hashCode(prefix); return result; } @Override - public boolean equals(Object obj) { + public boolean equals(final Object obj) { if (this == obj) { return true; } @@ -1378,11 +1100,7 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder { } else if (!name.equals(other.name)) { return false; } - if (namespace == null) { - if (other.namespace != null) { - return false; - } - } else if (!namespace.equals(other.namespace)) { + if (!qnameModule.equals(other.qnameModule)) { return false; } if (prefix == null) { @@ -1392,14 +1110,10 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder { } else if (!prefix.equals(other.prefix)) { return false; } - if (revision == null) { - if (other.revision != null) { - return false; - } - } else if (!revision.equals(other.revision)) { - return false; - } return true; } + public List getExtensionInstances() { + return unknownNodes; + } }