X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fsal%2Fyang-prototype%2Fcode-generator%2Fyang-model-parser-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fyang%2Fparser%2Fbuilder%2Fimpl%2FModuleBuilder.java;h=57e87b33ad855bb345bcd0cf5d1459ac8304ca62;hp=fa307972d49c7be12e57a12f7d9a9901881075b5;hb=154b5dde1af41aff2ae0cc6e08400153162a4a3c;hpb=8f13b5e59fc066808cc73879f8defcb9cf3dc82a diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/impl/ModuleBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/impl/ModuleBuilder.java index fa307972d4..57e87b33ad 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/impl/ModuleBuilder.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/impl/ModuleBuilder.java @@ -13,10 +13,13 @@ import java.util.Collections; import java.util.Date; 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.Set; +import java.util.TreeMap; +import java.util.TreeSet; import org.opendaylight.controller.yang.common.QName; import org.opendaylight.controller.yang.model.api.AugmentationSchema; @@ -32,6 +35,7 @@ import org.opendaylight.controller.yang.model.api.NotificationDefinition; import org.opendaylight.controller.yang.model.api.RpcDefinition; import org.opendaylight.controller.yang.model.api.SchemaPath; import org.opendaylight.controller.yang.model.api.TypeDefinition; +import org.opendaylight.controller.yang.model.api.UnknownSchemaNode; import org.opendaylight.controller.yang.model.api.UsesNode; import org.opendaylight.controller.yang.parser.builder.api.AugmentationSchemaBuilder; import org.opendaylight.controller.yang.parser.builder.api.Builder; @@ -40,9 +44,9 @@ import org.opendaylight.controller.yang.parser.builder.api.DataSchemaNodeBuilder import org.opendaylight.controller.yang.parser.builder.api.GroupingBuilder; import org.opendaylight.controller.yang.parser.builder.api.SchemaNodeBuilder; import org.opendaylight.controller.yang.parser.builder.api.TypeAwareBuilder; -import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionAwareBuilder; import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionBuilder; import org.opendaylight.controller.yang.parser.builder.api.UsesNodeBuilder; +import org.opendaylight.controller.yang.parser.util.Comparators; import org.opendaylight.controller.yang.parser.util.RefineHolder; import org.opendaylight.controller.yang.parser.util.YangParseException; @@ -51,7 +55,7 @@ import org.opendaylight.controller.yang.parser.util.YangParseException; * module/modules, these dependencies must be resolved before module is built, * otherwise result may not be valid. */ -public class ModuleBuilder implements Builder { +public class ModuleBuilder implements DataNodeContainerBuilder { private final ModuleImpl instance; private final String name; private URI namespace; @@ -66,20 +70,22 @@ public class ModuleBuilder implements Builder { * Holds all child (DataSchemaNode) nodes: anyxml, choice, case, container, * list, leaf, leaf-list. */ - private final Map, DataSchemaNodeBuilder> childNodes = new HashMap, DataSchemaNodeBuilder>(); + private final Set childNodes = new HashSet(); - private final Map, GroupingBuilder> addedGroupings = new HashMap, GroupingBuilder>(); + private final Set addedGroupings = new HashSet(); private final List addedAugments = new ArrayList(); - private final Map, UsesNodeBuilder> addedUsesNodes = new HashMap, UsesNodeBuilder>(); - private final Map, RpcDefinitionBuilder> addedRpcs = new HashMap, RpcDefinitionBuilder>(); + private final List allAugments = new ArrayList(); + private final Set addedUsesNodes = new HashSet(); + private final List allUsesNodes = new ArrayList(); + private final Set addedRpcs = new HashSet(); private final Set addedNotifications = new HashSet(); private final Set addedIdentities = new HashSet(); - private final Map, FeatureBuilder> addedFeatures = new HashMap, FeatureBuilder>(); + private final Set addedFeatures = new HashSet(); private final Map, DeviationBuilder> addedDeviations = new HashMap, DeviationBuilder>(); - private final Map, TypeDefinitionBuilder> addedTypedefs = new HashMap, TypeDefinitionBuilder>(); + private final Set addedTypedefs = new HashSet(); private final Map, UnionTypeBuilder> addedUnionTypes = new HashMap, UnionTypeBuilder>(); private final List addedExtensions = new ArrayList(); - private final Set addedUnknownNodes = new HashSet(); + private final Map, List> addedUnknownNodes = new HashMap, List>(); private final Map, TypeAwareBuilder> dirtyNodes = new HashMap, TypeAwareBuilder>(); @@ -101,29 +107,45 @@ public class ModuleBuilder implements Builder { instance.setNamespace(namespace); // TYPEDEFS - final Set> typedefs = buildModuleTypedefs(addedTypedefs); + final Set> typedefs = new TreeSet>(Comparators.SCHEMA_NODE_COMP); + for (TypeDefinitionBuilder tdb : addedTypedefs) { + typedefs.add(tdb.build()); + } instance.setTypeDefinitions(typedefs); // CHILD NODES - final Map children = buildModuleChildNodes(childNodes); + final Map children = new TreeMap(Comparators.QNAME_COMP); + for (DataSchemaNodeBuilder child : childNodes) { + children.put(child.getQName(), child.build()); + } instance.setChildNodes(children); // GROUPINGS - final Set groupings = buildModuleGroupings(addedGroupings); + final Set groupings = new TreeSet(Comparators.SCHEMA_NODE_COMP); + for (GroupingBuilder gb : addedGroupings) { + groupings.add(gb.build()); + } instance.setGroupings(groupings); // USES - final Set usesDefinitions = buildUsesNodes(addedUsesNodes); + final Set usesDefinitions = new HashSet(); + for (UsesNodeBuilder unb : addedUsesNodes) { + usesDefinitions.add(unb.build()); + } instance.setUses(usesDefinitions); // FEATURES - final Set features = buildModuleFeatures(addedFeatures); + final Set features = new TreeSet(Comparators.SCHEMA_NODE_COMP); + for (FeatureBuilder fb : addedFeatures) { + features.add(fb.build()); + } instance.setFeatures(features); // NOTIFICATIONS - final Set notifications = new HashSet(); + final Set notifications = new TreeSet( + Comparators.SCHEMA_NODE_COMP); for (NotificationBuilder entry : addedNotifications) { - notifications.add((NotificationDefinition) entry.build()); + notifications.add(entry.build()); } instance.setNotifications(notifications); @@ -135,31 +157,38 @@ public class ModuleBuilder implements Builder { instance.setAugmentations(augmentations); // RPCs - final Set rpcs = buildModuleRpcs(addedRpcs); + final Set rpcs = new TreeSet(Comparators.SCHEMA_NODE_COMP); + for (RpcDefinitionBuilder rpc : addedRpcs) { + rpcs.add(rpc.build()); + } instance.setRpcs(rpcs); // DEVIATIONS final Set deviations = new HashSet(); - for (Map.Entry, DeviationBuilder> entry : addedDeviations - .entrySet()) { + for (Map.Entry, DeviationBuilder> entry : addedDeviations.entrySet()) { deviations.add(entry.getValue().build()); } instance.setDeviations(deviations); // EXTENSIONS final List extensions = new ArrayList(); - for (ExtensionBuilder b : addedExtensions) { - extensions.add(b.build()); + for (ExtensionBuilder eb : addedExtensions) { + extensions.add(eb.build()); } + Collections.sort(extensions, Comparators.SCHEMA_NODE_COMP); instance.setExtensionSchemaNodes(extensions); // IDENTITIES - final Set identities = new HashSet(); - for (IdentitySchemaNodeBuilder idBuilder : addedIdentities) { - identities.add(idBuilder.build()); + final Set identities = new TreeSet(Comparators.SCHEMA_NODE_COMP); + for (IdentitySchemaNodeBuilder id : addedIdentities) { + identities.add(id.build()); } instance.setIdentities(identities); + // UNKNOWN NODES + final List unknownNodes = buildModuleUnknownNodes(addedUnknownNodes); + instance.setUnknownSchemaNodes(unknownNodes); + return instance; } @@ -168,6 +197,31 @@ public class ModuleBuilder implements Builder { return 0; } + @Override + public Builder getParent() { + return null; + } + + @Override + public void setParent(Builder parent) { + throw new YangParseException(name, 0, "Can not set parent to module"); + } + + @Override + public QName getQName() { + return new QName(namespace, revision, prefix, name); + } + + @Override + public SchemaPath getPath() { + return null; + } + + @Override + public Set getTypeDefinitionBuilders() { + return addedTypedefs; + } + public void enterNode(final Builder node) { actualPath.push(node); } @@ -184,71 +238,55 @@ public class ModuleBuilder implements Builder { } } - public Builder getModuleNode(final List path) { - return childNodes.get(path); + public Builder getActualParent() { + if (actualPath.size() < 2) { + return null; + } else { + return actualPath.get(1); + } } - public GroupingBuilder getGrouping(final List path) { - return addedGroupings.get(path); + @Override + public Set getGroupings() { + return Collections.emptySet(); } - public Builder getModuleTypedef(final List path) { - return addedTypedefs.get(path); + @Override + public Set getGroupingBuilders() { + return addedGroupings; } - public Set getChildNodes() { - final Set children = new HashSet(); - for (Map.Entry, DataSchemaNodeBuilder> entry : childNodes - .entrySet()) { - final List path = entry.getKey(); - final DataSchemaNodeBuilder child = entry.getValue(); - if (path.size() == 2) { - children.add(child); - } - } - return children; + @Override + public Set getChildNodes() { + return Collections.emptySet(); + } + + public Set getChildNodeBuilders() { + return childNodes; } public Map, TypeAwareBuilder> getDirtyNodes() { return dirtyNodes; } - public List getAugments() { - return addedAugments; + public List getAllAugments() { + return allAugments; } public Set getIdentities() { return addedIdentities; } - public Map, UsesNodeBuilder> getUsesNodes() { - return addedUsesNodes; - } - - public Set getUnknownNodes() { - return addedUnknownNodes; + public List getAllUsesNodes() { + return allUsesNodes; } - public Set getModuleTypedefs() { - final Set typedefs = new HashSet(); - for (Map.Entry, TypeDefinitionBuilder> entry : addedTypedefs - .entrySet()) { - if (entry.getKey().size() == 2) { - typedefs.add(entry.getValue()); - } + public List getUnknownNodes() { + List result = new ArrayList(); + for (List entry : addedUnknownNodes.values()) { + result.addAll(entry); } - return typedefs; - } - - public Set getModuleGroupings() { - final Set groupings = new HashSet(); - for (Map.Entry, GroupingBuilder> entry : addedGroupings - .entrySet()) { - if (entry.getKey().size() == 2) { - groupings.add(entry.getValue()); - } - } - return groupings; + return result; } public String getName() { @@ -281,8 +319,7 @@ public class ModuleBuilder implements Builder { public void addDirtyNode(final List path) { final List dirtyNodePath = new ArrayList(path); - final TypeAwareBuilder nodeBuilder = (TypeAwareBuilder) actualPath - .getFirst(); + final TypeAwareBuilder nodeBuilder = (TypeAwareBuilder) actualPath.getFirst(); dirtyNodes.put(dirtyNodePath, nodeBuilder); } @@ -314,10 +351,8 @@ public class ModuleBuilder implements Builder { instance.setContact(contact); } - public boolean addModuleImport(final String moduleName, - final Date revision, final String prefix) { - final ModuleImport moduleImport = createModuleImport(moduleName, - revision, prefix); + public boolean addModuleImport(final String moduleName, final Date revision, final String prefix) { + final ModuleImport moduleImport = createModuleImport(moduleName, revision, prefix); return imports.add(moduleImport); } @@ -326,335 +361,358 @@ public class ModuleBuilder implements Builder { } public ExtensionBuilder addExtension(final QName qname, final int line) { - final ExtensionBuilder builder = new ExtensionBuilder(qname, line); + final ExtensionBuilder builder = new ExtensionBuilder(line, qname); addedExtensions.add(builder); return builder; } - public ContainerSchemaNodeBuilder addContainerNode( - final QName containerName, final List parentPath, - final int line) { - final List pathToNode = new ArrayList(parentPath); - final ContainerSchemaNodeBuilder containerBuilder = new ContainerSchemaNodeBuilder( - containerName, line); - updateParent(containerBuilder, line, "container"); + @Override + public void addChildNode(DataSchemaNodeBuilder child) { + for (DataSchemaNodeBuilder childNode : childNodes) { + if (childNode.getQName().getLocalName().equals(child.getQName().getLocalName())) { + throw new YangParseException(name, child.getLine(), "Duplicate node found at line " + + childNode.getLine()); + } + } + childNodes.add(child); + } + + public ContainerSchemaNodeBuilder addContainerNode(final int line, final QName containerName, + final SchemaPath schemaPath) { + final ContainerSchemaNodeBuilder builder = new ContainerSchemaNodeBuilder(line, containerName, schemaPath); - pathToNode.add(containerName.getLocalName()); - childNodes.put(pathToNode, containerBuilder); + Builder parent = getActualNode(); + builder.setParent(parent); + addChildToParent(parent, builder, containerName.getLocalName()); - return containerBuilder; + return builder; } - public ListSchemaNodeBuilder addListNode(final QName listName, - final List parentPath, final int line) { - final List pathToNode = new ArrayList(parentPath); - final ListSchemaNodeBuilder listBuilder = new ListSchemaNodeBuilder( - listName, line); - updateParent(listBuilder, line, "list"); + public ListSchemaNodeBuilder addListNode(final int line, final QName listName, final SchemaPath schemaPath) { + final ListSchemaNodeBuilder builder = new ListSchemaNodeBuilder(line, listName, schemaPath); - pathToNode.add(listName.getLocalName()); - childNodes.put(pathToNode, listBuilder); + Builder parent = getActualNode(); + builder.setParent(parent); + addChildToParent(parent, builder, listName.getLocalName()); - return listBuilder; + return builder; } - public LeafSchemaNodeBuilder addLeafNode(final QName leafName, - final List parentPath, final int line) { - final List pathToNode = new ArrayList(parentPath); - final LeafSchemaNodeBuilder leafBuilder = new LeafSchemaNodeBuilder( - leafName, line); - updateParent(leafBuilder, line, "leaf"); + public LeafSchemaNodeBuilder addLeafNode(final int line, final QName leafName, final SchemaPath schemaPath) { + final LeafSchemaNodeBuilder builder = new LeafSchemaNodeBuilder(leafName, schemaPath, line); - pathToNode.add(leafName.getLocalName()); - childNodes.put(pathToNode, leafBuilder); + Builder parent = getActualNode(); + builder.setParent(parent); + addChildToParent(parent, builder, leafName.getLocalName()); - return leafBuilder; + return builder; } - public LeafListSchemaNodeBuilder addLeafListNode(final QName qname, - final List parentPath, final int line) { - final List pathToNode = new ArrayList(parentPath); - final LeafListSchemaNodeBuilder leafListBuilder = new LeafListSchemaNodeBuilder( - qname, line); - updateParent(leafListBuilder, line, "leaf-list"); + public LeafListSchemaNodeBuilder addLeafListNode(final int line, final QName leafListName, + final SchemaPath schemaPath) { + final LeafListSchemaNodeBuilder builder = new LeafListSchemaNodeBuilder(line, leafListName, schemaPath); - pathToNode.add(qname.getLocalName()); - childNodes.put(pathToNode, leafListBuilder); + Builder parent = getActualNode(); + builder.setParent(parent); + addChildToParent(parent, builder, leafListName.getLocalName()); - return leafListBuilder; + return builder; } - public GroupingBuilder addGrouping(final QName qname, - final List parentPath, final int line) { - final List pathToGroup = new ArrayList(parentPath); + @Override + public void addGrouping(GroupingBuilder groupingBuilder) { + for (GroupingBuilder gb : addedGroupings) { + if (gb.getQName().getLocalName().equals(groupingBuilder.getQName().getLocalName())) { + throw new YangParseException(name, groupingBuilder.getLine(), "Duplicate node found at line " + + gb.getLine()); + } + } + addedGroupings.add(groupingBuilder); + } + + public GroupingBuilder addGrouping(final int line, final QName qname) { final GroupingBuilder builder = new GroupingBuilderImpl(qname, line); - if (!(actualPath.isEmpty())) { - final Builder parent = actualPath.getFirst(); + Builder parent = getActualNode(); + builder.setParent(parent); + + if (parent == null) { + for (GroupingBuilder child : addedGroupings) { + if (child.getQName().getLocalName().equals(qname.getLocalName())) { + throw new YangParseException(name, line, "Duplicate node found at line " + child.getLine()); + } + } + addedGroupings.add(builder); + } else { if (parent instanceof DataNodeContainerBuilder) { - ((DataNodeContainerBuilder) parent).addGrouping(builder); + DataNodeContainerBuilder parentNode = (DataNodeContainerBuilder) parent; + for (DataSchemaNodeBuilder child : parentNode.getChildNodeBuilders()) { + if (child.getQName().getLocalName().equals(qname.getLocalName())) { + throw new YangParseException(name, line, "Duplicate node found at line " + child.getLine()); + } + } + parentNode.addGrouping(builder); + } else if (parent instanceof RpcDefinitionBuilder) { + RpcDefinitionBuilder parentNode = (RpcDefinitionBuilder) parent; + for (GroupingBuilder child : parentNode.getGroupings()) { + if (child.getQName().getLocalName().equals(qname.getLocalName())) { + throw new YangParseException(name, line, "Duplicate node found at line " + child.getLine()); + } + } + parentNode.addGrouping(builder); } else { - throw new YangParseException(name, line, - "Unresolved parent of grouping " + qname.getLocalName()); + throw new YangParseException(name, line, "Unresolved parent of grouping " + qname.getLocalName()); } } - pathToGroup.add(qname.getLocalName()); - addedGroupings.put(pathToGroup, builder); - return builder; } - public AugmentationSchemaBuilder addAugment(final String name, - final List parentPath, final int line) { - final List pathToAugment = new ArrayList(parentPath); - final AugmentationSchemaBuilder builder = new AugmentationSchemaBuilderImpl( - name, line); + public AugmentationSchemaBuilder addAugment(final int line, final String augmentTargetStr) { + final AugmentationSchemaBuilder builder = new AugmentationSchemaBuilderImpl(line, augmentTargetStr); - // augment can only be in 'module' or 'uses' statement - if (!(actualPath.isEmpty())) { - final Builder parent = actualPath.getFirst(); + Builder parent = getActualNode(); + builder.setParent(parent); + + if (parent == null) { + addedAugments.add(builder); + } else { + // augment can only be in 'module' or 'uses' statement if (parent instanceof UsesNodeBuilder) { ((UsesNodeBuilder) parent).addAugment(builder); } else { - throw new YangParseException(this.name, line, - "Unresolved parent of augment " + name); + throw new YangParseException(name, line, "Augment can be declared only under module or uses."); } } - - pathToAugment.add(name); - addedAugments.add(builder); + allAugments.add(builder); return builder; } - public UsesNodeBuilder addUsesNode(final String groupingPathStr, - final List parentPath, final int line) { - final List pathToUses = new ArrayList(parentPath); - final UsesNodeBuilder usesBuilder = new UsesNodeBuilderImpl( - groupingPathStr, line); + @Override + public void addUsesNode(UsesNodeBuilder usesBuilder) { + addedUsesNodes.add(usesBuilder); + allUsesNodes.add(usesBuilder); + } - if (!(actualPath.isEmpty())) { - final Builder parent = actualPath.getFirst(); - if (parent instanceof DataNodeContainerBuilder) { - if (parent instanceof AugmentationSchemaBuilder) { - usesBuilder.setAugmenting(true); - } - ((DataNodeContainerBuilder) parent).addUsesNode(usesBuilder); - } else { - throw new YangParseException(name, line, - "Unresolved parent of uses " + groupingPathStr); + public UsesNodeBuilder addUsesNode(final int line, final String groupingPathStr) { + final UsesNodeBuilder usesBuilder = new UsesNodeBuilderImpl(line, groupingPathStr); + + Builder parent = getActualNode(); + usesBuilder.setParent(parent); + + if (parent == null) { + addedUsesNodes.add(usesBuilder); + } else { + if (!(parent instanceof DataNodeContainerBuilder)) { + throw new YangParseException(name, line, "Unresolved parent of uses '" + groupingPathStr + "'."); } + if (parent instanceof AugmentationSchemaBuilder) { + usesBuilder.setAugmenting(true); + } + ((DataNodeContainerBuilder) parent).addUsesNode(usesBuilder); } - - pathToUses.add(groupingPathStr); - addedUsesNodes.put(pathToUses, usesBuilder); + allUsesNodes.add(usesBuilder); return usesBuilder; } - public void addRefine(final RefineHolder refine, - final List parentPath) { + public void addRefine(final RefineHolder refine, final List parentPath) { final List path = new ArrayList(parentPath); if (actualPath.isEmpty()) { - throw new YangParseException(name, refine.getLine(), - "refine can be defined only in uses statement"); + throw new YangParseException(name, refine.getLine(), "refine can be defined only in uses statement"); } else { - final Builder parent = actualPath.getFirst(); + final Builder parent = getActualNode(); if (parent instanceof UsesNodeBuilder) { ((UsesNodeBuilder) parent).addRefine(refine); } else { - throw new YangParseException(name, refine.getLine(), - "refine can be defined only in uses statement"); + throw new YangParseException(name, refine.getLine(), "refine can be defined only in uses statement"); } + refine.setParent(parent); } path.add(refine.getName()); } - public RpcDefinitionBuilder addRpc(final QName qname, - final List parentPath, final int line) { - - if (!(actualPath.isEmpty())) { - throw new YangParseException(name, line, - "rpc can be defined only in module or submodule"); + public RpcDefinitionBuilder addRpc(final int line, final QName qname) { + Builder parent = getActualNode(); + if (parent != null) { + throw new YangParseException(name, line, "rpc can be defined only in module or submodule"); } - final List pathToRpc = new ArrayList(parentPath); - final RpcDefinitionBuilder rpcBuilder = new RpcDefinitionBuilder(qname, - line); - - pathToRpc.add(qname.getLocalName()); - addedRpcs.put(pathToRpc, rpcBuilder); - + final RpcDefinitionBuilder rpcBuilder = new RpcDefinitionBuilder(line, qname); + for (RpcDefinitionBuilder rpc : addedRpcs) { + if (rpc.getQName().getLocalName().equals(qname.getLocalName())) { + throw new YangParseException(name, line, "Duplicate node found at line " + rpc.getLine()); + } + } + addedRpcs.add(rpcBuilder); return rpcBuilder; } - public ContainerSchemaNodeBuilder addRpcInput(final QName inputQName, - final int line) { - final Builder parent = actualPath.getFirst(); + public ContainerSchemaNodeBuilder addRpcInput(final SchemaPath schemaPath, final QName inputQName, final int line) { + final Builder parent = getActualNode(); if (!(parent instanceof RpcDefinitionBuilder)) { - throw new YangParseException(name, line, - "input can be defined only in rpc statement"); + throw new YangParseException(name, line, "input can be defined only in rpc statement"); } final RpcDefinitionBuilder rpc = (RpcDefinitionBuilder) parent; - final ContainerSchemaNodeBuilder inputBuilder = new ContainerSchemaNodeBuilder( - inputQName, line); + final ContainerSchemaNodeBuilder inputBuilder = new ContainerSchemaNodeBuilder(line, inputQName, schemaPath); + inputBuilder.setParent(rpc); + rpc.setInput(inputBuilder); return inputBuilder; } - public ContainerSchemaNodeBuilder addRpcOutput(final QName outputQName, - final int line) { + public ContainerSchemaNodeBuilder addRpcOutput(final SchemaPath schemaPath, final QName outputQName, final int line) { final Builder parent = actualPath.getFirst(); if (!(parent instanceof RpcDefinitionBuilder)) { - throw new YangParseException(name, line, - "output can be defined only in rpc statement"); + throw new YangParseException(name, line, "output can be defined only in rpc statement"); } final RpcDefinitionBuilder rpc = (RpcDefinitionBuilder) parent; - final ContainerSchemaNodeBuilder outputBuilder = new ContainerSchemaNodeBuilder( - outputQName, line); + final ContainerSchemaNodeBuilder outputBuilder = new ContainerSchemaNodeBuilder(line, outputQName, schemaPath); + outputBuilder.setParent(rpc); + rpc.setOutput(outputBuilder); return outputBuilder; } - public NotificationBuilder addNotification(final QName notificationName, - final List parentPath, final int line) { + public NotificationBuilder addNotification(final QName notificationName, final List parentPath, + final int line) { if (!(actualPath.isEmpty())) { - throw new YangParseException(name, line, - "notification can be defined only in module or submodule"); + throw new YangParseException(name, line, "notification can be defined only in module or submodule"); + } + for (NotificationBuilder nb : addedNotifications) { + if (nb.getQName().equals(notificationName)) { + throw new YangParseException(name, line, "Duplicate node found at line " + nb.getLine()); + } } - final NotificationBuilder builder = new NotificationBuilder( - notificationName, line); - - final List notificationPath = new ArrayList(parentPath); - notificationPath.add(notificationName.getLocalName()); + final NotificationBuilder builder = new NotificationBuilder(line, notificationName); addedNotifications.add(builder); return builder; } - public FeatureBuilder addFeature(final QName featureName, - final List parentPath, final int line) { - if (!(actualPath.isEmpty())) { - throw new YangParseException(name, line, - "feature can be defined only in module or submodule"); + public FeatureBuilder addFeature(final int line, final QName featureName) { + Builder parent = getActualNode(); + if (parent != null) { + throw new YangParseException(name, line, "feature can be defined only in module or submodule"); } - final List pathToFeature = new ArrayList(parentPath); - pathToFeature.add(featureName.getLocalName()); - - final FeatureBuilder builder = new FeatureBuilder(featureName, line); - addedFeatures.put(pathToFeature, builder); + final FeatureBuilder builder = new FeatureBuilder(line, featureName); + for (FeatureBuilder fb : addedFeatures) { + if (fb.getQName().getLocalName().equals(featureName.getLocalName())) { + throw new YangParseException(name, line, "Duplicate node found at line " + fb.getLine()); + } + } + addedFeatures.add(builder); return builder; } - public ChoiceBuilder addChoice(final QName choiceName, - final List parentPath, final int line) { - final List pathToChoice = new ArrayList(parentPath); - final ChoiceBuilder builder = new ChoiceBuilder(choiceName, line); - - if (!(actualPath.isEmpty())) { - Builder parent = actualPath.getFirst(); - if (parent instanceof DataNodeContainerBuilder) { - if (parent instanceof AugmentationSchemaBuilder) { - builder.setAugmenting(true); - } - ((DataNodeContainerBuilder) parent).addChildNode(builder); - } else { - throw new YangParseException(name, line, - "Unresolved parent of choice " - + choiceName.getLocalName()); - } - } + public ChoiceBuilder addChoice(final int line, final QName choiceName) { + final ChoiceBuilder builder = new ChoiceBuilder(line, choiceName); - pathToChoice.add(choiceName.getLocalName()); - childNodes.put(pathToChoice, builder); + Builder parent = getActualNode(); + builder.setParent(parent); + addChildToParent(parent, builder, choiceName.getLocalName()); return builder; } - public ChoiceCaseBuilder addCase(final QName caseName, - final List parentPath, final int line) { - final List pathToCase = new ArrayList(parentPath); - final ChoiceCaseBuilder builder = new ChoiceCaseBuilder(caseName, line); - - if (actualPath.isEmpty()) { + public ChoiceCaseBuilder addCase(final int line, final QName caseName) { + Builder parent = getActualNode(); + if (parent == null) { throw new YangParseException(name, line, "'case' parent not found"); - } else { - final Builder parent = actualPath.getFirst(); - if (parent instanceof ChoiceBuilder) { - ((ChoiceBuilder) parent).addChildNode(builder); - } else if (parent instanceof AugmentationSchemaBuilder) { - builder.setAugmenting(true); - ((AugmentationSchemaBuilder) parent).addChildNode(builder); - } else { - throw new YangParseException(name, line, - "Unresolved parent of 'case' " - + caseName.getLocalName()); - } } - pathToCase.add(caseName.getLocalName()); - childNodes.put(pathToCase, builder); + final ChoiceCaseBuilder builder = new ChoiceCaseBuilder(line, caseName); + builder.setParent(parent); + + if (parent instanceof ChoiceBuilder) { + ((ChoiceBuilder) parent).addChildNode(builder); + } else if (parent instanceof AugmentationSchemaBuilder) { + ((AugmentationSchemaBuilder) parent).addChildNode(builder); + } else { + throw new YangParseException(name, line, "Unresolved parent of 'case' " + caseName.getLocalName()); + } return builder; } - public AnyXmlBuilder addAnyXml(final QName anyXmlName, - final List parentPath, final int line) { - final List pathToAnyXml = new ArrayList(parentPath); - final AnyXmlBuilder builder = new AnyXmlBuilder(anyXmlName, line); - updateParent(builder, line, "anyxml"); + public AnyXmlBuilder addAnyXml(final int line, final QName anyXmlName, final SchemaPath schemaPath) { + final AnyXmlBuilder builder = new AnyXmlBuilder(line, anyXmlName, schemaPath); - pathToAnyXml.add(anyXmlName.getLocalName()); - childNodes.put(pathToAnyXml, builder); + Builder parent = getActualNode(); + builder.setParent(parent); + addChildToParent(parent, builder, anyXmlName.getLocalName()); return builder; } - public TypeDefinitionBuilderImpl addTypedef(final QName typeDefName, - final List parentPath, final int line) { - final List pathToType = new ArrayList(parentPath); - final TypeDefinitionBuilderImpl builder = new TypeDefinitionBuilderImpl( - typeDefName, line); + @Override + public void addTypedef(TypeDefinitionBuilder typedefBuilder) { + for (TypeDefinitionBuilder tdb : addedTypedefs) { + if (tdb.getQName().getLocalName().equals(typedefBuilder.getQName().getLocalName())) { + throw new YangParseException(name, typedefBuilder.getLine(), "Duplicate node found at line " + + tdb.getLine()); + } + } + addedTypedefs.add(typedefBuilder); + } + + public TypeDefinitionBuilderImpl addTypedef(final int line, final QName typeDefName) { + final TypeDefinitionBuilderImpl builder = new TypeDefinitionBuilderImpl(typeDefName, line); - if (!(actualPath.isEmpty())) { - final Builder parent = actualPath.getFirst(); - if (parent instanceof TypeDefinitionAwareBuilder) { - ((TypeDefinitionAwareBuilder) parent).addTypedef(builder); + Builder parent = getActualNode(); + builder.setParent(parent); + + if (parent == null) { + for (TypeDefinitionBuilder tdb : addedTypedefs) { + if (tdb.getQName().getLocalName().equals(builder.getQName().getLocalName())) { + throw new YangParseException(name, builder.getLine(), "Duplicate node found at line " + + tdb.getLine()); + } + } + addedTypedefs.add(builder); + } else { + if (parent instanceof DataNodeContainerBuilder) { + DataNodeContainerBuilder parentNode = (DataNodeContainerBuilder) parent; + for (DataSchemaNodeBuilder child : parentNode.getChildNodeBuilders()) { + if (child.getQName().getLocalName().equals(typeDefName.getLocalName())) { + throw new YangParseException(name, line, "Duplicate node found at line " + child.getLine()); + } + } + parentNode.addTypedef(builder); + } else if (parent instanceof RpcDefinitionBuilder) { + RpcDefinitionBuilder rpcParent = (RpcDefinitionBuilder) parent; + for (TypeDefinitionBuilder tdb : rpcParent.getTypeDefinitions()) { + if (tdb.getQName().getLocalName().equals(builder.getQName().getLocalName())) { + throw new YangParseException(name, builder.getLine(), "Duplicate node found at line " + + tdb.getLine()); + } + } + rpcParent.addTypedef(builder); } else { - throw new YangParseException(name, line, - "Unresolved parent of typedef " - + typeDefName.getLocalName()); + throw new YangParseException(name, line, "Unresolved parent of typedef " + typeDefName.getLocalName()); } } - pathToType.add(typeDefName.getLocalName()); - addedTypedefs.put(pathToType, builder); return builder; } - public void setType(final TypeDefinition type, - final List parentPath) { - - if (!(actualPath.isEmpty())) { - final Builder parent = actualPath.getFirst(); - if (parent instanceof TypeAwareBuilder) { - ((TypeAwareBuilder) parent).setType(type); - } else { - throw new YangParseException("Failed to set type '" - + type.getQName().getLocalName() - + "'. Unknown parent node: " + parent); - } + public void setType(final TypeDefinition type) { + Builder parent = getActualNode(); + if (parent == null || !(parent instanceof TypeAwareBuilder)) { + throw new YangParseException("Failed to set type '" + type.getQName().getLocalName() + + "'. Unknown parent node: " + parent); } + ((TypeAwareBuilder) parent).setType(type); } - public UnionTypeBuilder addUnionType(final List currentPath, - final URI namespace, final Date revision, final int line) { + public UnionTypeBuilder addUnionType(final List currentPath, final URI namespace, final Date revision, + final int line) { final List pathToUnion = new ArrayList(currentPath); final UnionTypeBuilder union = new UnionTypeBuilder(line); @@ -672,18 +730,15 @@ public class ModuleBuilder implements Builder { addedUnionTypes.put(path, union); return union; } else { - throw new YangParseException(name, line, - "Unresolved parent of union type."); + throw new YangParseException(name, line, "Unresolved parent of union type."); } } } - public void addIdentityrefType(final String baseString, - final List parentPath, final SchemaPath schemaPath, + public void addIdentityrefType(final String baseString, final List parentPath, final SchemaPath schemaPath, final int line) { final List pathToIdentityref = new ArrayList(parentPath); - final IdentityrefTypeBuilder identityref = new IdentityrefTypeBuilder( - baseString, schemaPath, line); + final IdentityrefTypeBuilder identityref = new IdentityrefTypeBuilder(baseString, schemaPath, line); if (actualPath.isEmpty()) { throw new YangParseException(line, "identityref error"); @@ -694,17 +749,15 @@ public class ModuleBuilder implements Builder { typeParent.setTypedef(identityref); dirtyNodes.put(pathToIdentityref, typeParent); } else { - throw new YangParseException(name, line, - "Unresolved parent of identityref type."); + throw new YangParseException(name, line, "Unresolved parent of identityref type."); } } } - public DeviationBuilder addDeviation(final String targetPath, - final List parentPath, final int line) { - if (!(actualPath.isEmpty())) { - throw new YangParseException(name, line, - "deviation can be defined only in module or submodule"); + public DeviationBuilder addDeviation(final String targetPath, final List parentPath, final int line) { + Builder parent = getActualNode(); + if (parent != null) { + throw new YangParseException(name, line, "deviation can be defined only in module or submodule"); } final List pathToDeviation = new ArrayList(parentPath); @@ -714,63 +767,63 @@ public class ModuleBuilder implements Builder { return builder; } - public IdentitySchemaNodeBuilder addIdentity(final QName qname, - final List parentPath, final int line) { - if (!(actualPath.isEmpty())) { - throw new YangParseException(name, line, - "identity can be defined only in module or submodule"); + public IdentitySchemaNodeBuilder addIdentity(final QName qname, final List parentPath, final int line) { + Builder parent = getActualNode(); + if (parent != null) { + throw new YangParseException(name, line, "identity can be defined only in module or submodule"); + } + for (IdentitySchemaNodeBuilder idBuilder : addedIdentities) { + if (idBuilder.getQName().equals(qname)) { + throw new YangParseException(name, line, "Duplicate node found at line " + idBuilder.getLine()); + } } - final List pathToIdentity = new ArrayList(parentPath); - final IdentitySchemaNodeBuilder builder = new IdentitySchemaNodeBuilder( - qname, line); - pathToIdentity.add(qname.getLocalName()); + final IdentitySchemaNodeBuilder builder = new IdentitySchemaNodeBuilder(line, qname); addedIdentities.add(builder); return builder; } - public void addConfiguration(final boolean configuration, - final List parentPath, final int line) { - if (actualPath.isEmpty()) { - throw new YangParseException(name, line, - "Parent node of config statement not found."); + @Override + public void addUnknownSchemaNode(UnknownSchemaNodeBuilder builder) { + final List unPath = new ArrayList(); + for (QName name : builder.getPath().getPath()) { + unPath.add(name.getLocalName()); + } + if (addedUnknownNodes.containsKey(unPath)) { + addedUnknownNodes.get(unPath).add(builder); } else { - final Builder parent = actualPath.getFirst(); - if (parent instanceof DataSchemaNodeBuilder) { - ((DataSchemaNodeBuilder) parent) - .setConfiguration(configuration); - } else if (parent instanceof RefineHolder) { - ((RefineHolder) parent).setConfig(configuration); - } else if (parent instanceof DeviationBuilder) { - // skip: set config to deviation (deviate stmt) not supported by - // current api - return; - } else { - throw new YangParseException(name, line, - "Unresolved parent of config statement."); - } + List nodes = new ArrayList(); + nodes.add(builder); + addedUnknownNodes.put(unPath, nodes); } } - public UnknownSchemaNodeBuilder addUnknownSchemaNode(final QName qname, - final List parentPath, final int line) { - final UnknownSchemaNodeBuilder builder = new UnknownSchemaNodeBuilder( - qname, line); + public UnknownSchemaNodeBuilder addUnknownSchemaNode(final QName qname, final List parentPath, + final int line) { + final Builder parent = getActualNode(); + final UnknownSchemaNodeBuilder builder = new UnknownSchemaNodeBuilder(line, qname); + builder.setParent(parent); - if (!(actualPath.isEmpty())) { - final Builder parent = actualPath.getFirst(); + if (parent != null) { if (parent instanceof SchemaNodeBuilder) { ((SchemaNodeBuilder) parent).addUnknownSchemaNode(builder); } else if (parent instanceof RefineHolder) { ((RefineHolder) parent).addUnknownSchemaNode(builder); } else { - throw new YangParseException(name, line, - "Unresolved parent of unknown node '" - + qname.getLocalName() + "'"); + throw new YangParseException(name, line, "Unresolved parent of unknown node '" + qname.getLocalName() + + "'"); } } + final List unPath = new ArrayList(parentPath); + unPath.add(qname.getLocalName()); - addedUnknownNodes.add(builder); + if (addedUnknownNodes.containsKey(unPath)) { + addedUnknownNodes.get(unPath).add(builder); + } else { + List nodes = new ArrayList(); + nodes.add(builder); + addedUnknownNodes.put(unPath, nodes); + } return builder; } @@ -792,17 +845,16 @@ public class ModuleBuilder implements Builder { private Set imports = Collections.emptySet(); private Set features = Collections.emptySet(); private Set> typeDefinitions = Collections.emptySet(); - private Set notifications = Collections - .emptySet(); + private Set notifications = Collections.emptySet(); private Set augmentations = Collections.emptySet(); private Set rpcs = Collections.emptySet(); private Set deviations = Collections.emptySet(); private Map childNodes = Collections.emptyMap(); private Set groupings = Collections.emptySet(); private Set uses = Collections.emptySet(); - private List extensionNodes = Collections - .emptyList(); + private List extensionNodes = Collections.emptyList(); private Set identities = Collections.emptySet(); + private List unknownNodes = Collections.emptyList(); private ModuleImpl(String name) { this.name = name; @@ -964,7 +1016,7 @@ public class ModuleBuilder implements Builder { @Override public Set getChildNodes() { - return new HashSet(childNodes.values()); + return new LinkedHashSet(childNodes.values()); } private void setChildNodes(Map childNodes) { @@ -1000,8 +1052,7 @@ public class ModuleBuilder implements Builder { return extensionNodes; } - private void setExtensionSchemaNodes( - List extensionNodes) { + private void setExtensionSchemaNodes(final List extensionNodes) { if (extensionNodes != null) { this.extensionNodes = extensionNodes; } @@ -1012,12 +1063,23 @@ public class ModuleBuilder implements Builder { return identities; } - private void setIdentities(Set identities) { + private void setIdentities(final Set identities) { if (identities != null) { this.identities = identities; } } + @Override + public List getUnknownSchemaNodes() { + return unknownNodes; + } + + private void setUnknownSchemaNodes(final List unknownNodes) { + if (unknownNodes != null) { + this.unknownNodes = unknownNodes; + } + } + @Override public DataSchemaNode getDataChildByName(QName name) { return childNodes.get(name); @@ -1039,15 +1101,11 @@ public class ModuleBuilder implements Builder { public int hashCode() { final int prime = 31; int result = 1; - result = prime * result - + ((namespace == null) ? 0 : namespace.hashCode()); + 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()); + 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; } @@ -1103,8 +1161,7 @@ public class ModuleBuilder implements Builder { @Override public String toString() { - StringBuilder sb = new StringBuilder( - ModuleImpl.class.getSimpleName()); + StringBuilder sb = new StringBuilder(ModuleImpl.class.getSimpleName()); sb.append("["); sb.append("name=" + name); sb.append(", namespace=" + namespace); @@ -1116,28 +1173,58 @@ public class ModuleBuilder implements Builder { } } - private void updateParent(DataSchemaNodeBuilder nodeBuilder, int line, - String nodeTypeName) { - if (!(actualPath.isEmpty())) { - final Builder parent = actualPath.getFirst(); + private void addChildToParent(final Builder parent, final DataSchemaNodeBuilder child, final String childLocalName) { + final int line = child.getLine(); + if (parent == null) { + // if parent == null => node is defined under module + // All leafs, leaf-lists, lists, containers, choices, rpcs, + // 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 : childNodes) { + if (childNode.getQName().getLocalName().equals(childLocalName)) { + throw new YangParseException(name, line, "Duplicate node found at line " + childNode.getLine()); + } + } + for (RpcDefinitionBuilder rpc : addedRpcs) { + if (rpc.getQName().getLocalName().equals(childLocalName)) { + throw new YangParseException(name, line, "Duplicate node found at line " + rpc.getLine()); + } + } + for (NotificationBuilder notification : addedNotifications) { + if (notification.getQName().getLocalName().equals(childLocalName)) { + throw new YangParseException(name, line, "Duplicate node found at line " + notification.getLine()); + } + } + childNodes.add(child); + } else { + // no need for checking rpc and notification because they can be + // defined only under module or submodule if (parent instanceof DataNodeContainerBuilder) { - if (parent instanceof AugmentationSchemaBuilder) { - nodeBuilder.setAugmenting(true); + DataNodeContainerBuilder parentNode = (DataNodeContainerBuilder) parent; + for (DataSchemaNodeBuilder childNode : parentNode.getChildNodeBuilders()) { + if (childNode.getQName().getLocalName().equals(childLocalName)) { + throw new YangParseException(name, line, "Duplicate node found at line " + childNode.getLine()); + } } - ((DataNodeContainerBuilder) parent).addChildNode(nodeBuilder); + parentNode.addChildNode(child); } else if (parent instanceof ChoiceBuilder) { - ((ChoiceBuilder) parent).addChildNode(nodeBuilder); + ChoiceBuilder parentNode = (ChoiceBuilder) parent; + for (ChoiceCaseBuilder caseBuilder : parentNode.getCases()) { + if (caseBuilder.getQName().getLocalName().equals(childLocalName)) { + throw new YangParseException(name, line, "Duplicate node found at line " + + caseBuilder.getLine()); + } + } + parentNode.addChildNode(child); } else { - throw new YangParseException(name, line, - "Unresolved parent of " + nodeTypeName + " " - + nodeBuilder.getQName().getLocalName()); + throw new YangParseException(name, line, "Unresolved parent of node '" + childLocalName + "'."); } } } - private ModuleImport createModuleImport(final String moduleName, - final Date revision, final String prefix) { - ModuleImport moduleImport = new ModuleImport() { + private ModuleImport createModuleImport(final String moduleName, final Date revision, final String prefix) { + final ModuleImport moduleImport = new ModuleImport() { @Override public String getModuleName() { return moduleName; @@ -1157,12 +1244,9 @@ public class ModuleBuilder implements Builder { public int hashCode() { final int prime = 31; int result = 1; - result = prime * result - + ((moduleName == null) ? 0 : moduleName.hashCode()); - result = prime * result - + ((revision == null) ? 0 : revision.hashCode()); - result = prime * result - + ((prefix == null) ? 0 : prefix.hashCode()); + result = prime * result + ((moduleName == null) ? 0 : moduleName.hashCode()); + result = prime * result + ((revision == null) ? 0 : revision.hashCode()); + result = prime * result + ((prefix == null) ? 0 : prefix.hashCode()); return result; } @@ -1204,137 +1288,36 @@ public class ModuleBuilder implements Builder { @Override public String toString() { - return "ModuleImport[moduleName=" + moduleName + ", revision=" - + revision + ", prefix=" + prefix + "]"; + return "ModuleImport[moduleName=" + moduleName + ", revision=" + revision + ", prefix=" + prefix + "]"; } }; return moduleImport; } /** - * Traverse through given addedChilds and add only direct module childs. - * Direct module child path size is 2 (1. module name, 2. child name). - * - * @param addedChilds - * @return map of children, where key is child QName and value is child - * itself - */ - private Map buildModuleChildNodes( - Map, DataSchemaNodeBuilder> addedChilds) { - final Map childNodes = new HashMap(); - for (Map.Entry, DataSchemaNodeBuilder> entry : addedChilds - .entrySet()) { - List path = entry.getKey(); - DataSchemaNodeBuilder child = entry.getValue(); - if (path.size() == 2) { - DataSchemaNode node = child.build(); - QName qname = node.getQName(); - childNodes.put(qname, node); - } - } - return childNodes; - } - - /** - * Traverse through given addedGroupings and add only direct module - * groupings. Direct module grouping path size is 2 (1. module name, 2. - * grouping name). - * - * @param addedGroupings - * @return set of built GroupingDefinition objects - */ - private Set buildModuleGroupings( - Map, GroupingBuilder> addedGroupings) { - final Set groupings = new HashSet(); - for (Map.Entry, GroupingBuilder> entry : addedGroupings - .entrySet()) { - if (entry.getKey().size() == 2) { - groupings.add(entry.getValue().build()); - } - } - return groupings; - } - - /** - * Traverse through given addedRpcs and build RpcDefinition objects. - * - * @param addedRpcs - * @return set of built RpcDefinition objects - */ - private Set buildModuleRpcs( - Map, RpcDefinitionBuilder> addedRpcs) { - final Set rpcs = new HashSet(); - RpcDefinitionBuilder builder; - for (Map.Entry, RpcDefinitionBuilder> entry : addedRpcs - .entrySet()) { - builder = entry.getValue(); - RpcDefinition rpc = builder.build(); - rpcs.add(rpc); - } - return rpcs; - } - - /** - * Traverse through given addedTypedefs and add only direct module typedef - * statements. Direct module typedef path size is 2 (1. module name, 2. - * typedef name). + * Traverse through given addedUnknownNodes and add only unknown nodes + * defined under module statement. * - * @param addedTypedefs - * @return set of built module typedef statements + * @param addedUnknownNodes + * unknown node builders + * @return list of all unknown nodes defined in module in lexicographical + * order */ - private Set> buildModuleTypedefs( - Map, TypeDefinitionBuilder> addedTypedefs) { - Set> typedefs = new HashSet>(); - for (Map.Entry, TypeDefinitionBuilder> entry : addedTypedefs - .entrySet()) { - List key = entry.getKey(); - TypeDefinitionBuilder typedefBuilder = entry.getValue(); - if (key.size() == 2) { - TypeDefinition> node = typedefBuilder - .build(); - typedefs.add(node); - } - } - return typedefs; - } - - /** - * Traverse through given addedUsesNodes and add only direct module uses - * nodes. Direct module uses node path size is 2 (1. module name, 2. uses - * name). - * - * @param addedUsesNodes - * @return set of built module uses nodes - */ - private Set buildUsesNodes( - Map, UsesNodeBuilder> addedUsesNodes) { - final Set usesNodeDefs = new HashSet(); - for (Map.Entry, UsesNodeBuilder> entry : addedUsesNodes - .entrySet()) { - if (entry.getKey().size() == 2) { - usesNodeDefs.add(entry.getValue().build()); - } - } - return usesNodeDefs; - } + private List buildModuleUnknownNodes( + final Map, List> addedUnknownNodes) { + final List result = new ArrayList(); + for (Map.Entry, List> entry : addedUnknownNodes.entrySet()) { + final List path = entry.getKey(); + final List child = entry.getValue(); - /** - * Traverse through given addedFeatures and add only direct module features. - * Direct module feature path size is 2 (1. module name, 2. feature name). - * - * @param addedFeatures - * @return set of built module features - */ - private Set buildModuleFeatures( - Map, FeatureBuilder> addedFeatures) { - Set features = new HashSet(); - for (Map.Entry, FeatureBuilder> entry : addedFeatures - .entrySet()) { - if (entry.getKey().size() == 2) { - features.add(entry.getValue().build()); + if (path.size() == 2) { + for (UnknownSchemaNodeBuilder node : child) { + result.add(node.build()); + } } } - return features; + Collections.sort(result, Comparators.SCHEMA_NODE_COMP); + return result; } }