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=47f1fbc2f16dee262e7117b7f0d6f7da1dbf77b8;hp=0d47d7a5fc5dbd391be57e032dd387b490c8da93;hb=271b40037939f2020378be14ca13caef16276b6e;hpb=0f846fcbc207a4213ac133e1d08a305fc72168ba 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 0d47d7a5fc..47f1fbc2f1 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 @@ -11,11 +11,14 @@ import java.net.URI; import java.util.ArrayList; 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; @@ -31,26 +34,28 @@ 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.AbstractDataNodeContainerBuilder; import org.opendaylight.controller.yang.parser.builder.api.AugmentationSchemaBuilder; import org.opendaylight.controller.yang.parser.builder.api.Builder; -import org.opendaylight.controller.yang.parser.builder.api.ChildNodeBuilder; +import org.opendaylight.controller.yang.parser.builder.api.DataNodeContainerBuilder; 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; /** - * This builder builds Module object. If this module is dependent on external + * 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. */ -public class ModuleBuilder implements Builder { +public class ModuleBuilder extends AbstractDataNodeContainerBuilder { private final ModuleImpl instance; private final String name; private URI namespace; @@ -59,34 +64,26 @@ public class ModuleBuilder implements Builder { private int augmentsResolved; - private final Set imports = new HashSet(); - - /** - * All nodes, that can contain other nodes - */ - private final Map, Builder> moduleNodes = new HashMap, Builder>(); - - /** - * Holds all child (DataSchemaNode) nodes: anyxml, choice, case, container, - * list, leaf, leaf-list. - */ - private final Map, DataSchemaNodeBuilder> addedChilds = new HashMap, DataSchemaNodeBuilder>(); + private final LinkedList actualPath = new LinkedList(); + private final Set dirtyNodes = new HashSet(); - private final Map, GroupingBuilder> addedGroupings = new HashMap, GroupingBuilder>(); + private final Set imports = 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 Map addedDeviations = new HashMap(); - private final Map, TypeDefinitionBuilder> addedTypedefs = new HashMap, TypeDefinitionBuilder>(); + private final Set addedFeatures = new HashSet(); + private final Set addedDeviations = new HashSet(); + private final Set addedTypedefs = new HashSet(); private final List addedExtensions = new ArrayList(); - private final Set addedUnknownNodes = new HashSet(); - - private final Map, TypeAwareBuilder> dirtyNodes = new HashMap, TypeAwareBuilder>(); + private final List addedUnknownNodes = new ArrayList(); + private final List allUnknownNodes = new ArrayList(); public ModuleBuilder(final String name) { + super(0, null); this.name = name; instance = new ModuleImpl(name); } @@ -102,29 +99,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 childNodes = buildModuleChildNodes(addedChilds); - instance.setChildNodes(childNodes); + final Map children = new TreeMap(Comparators.QNAME_COMP); + for (DataSchemaNodeBuilder child : addedChildNodes) { + 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); @@ -136,85 +149,105 @@ 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 entry : addedDeviations - .entrySet()) { - deviations.add(entry.getValue().build()); + for (DeviationBuilder entry : addedDeviations) { + deviations.add(entry.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 = new ArrayList(); + for (UnknownSchemaNodeBuilder unb : addedUnknownNodes) { + unknownNodes.add(unb.build()); + } + instance.setUnknownSchemaNodes(unknownNodes); + return instance; } @Override - public int getLine() { - return 0; + public void setParent(Builder parent) { + throw new YangParseException(name, 0, "Can not set parent to module"); } - public Builder getNode(final List path) { - return moduleNodes.get(path); + @Override + public SchemaPath getPath() { + return null; } - public Set getChildNodes() { - final Set childNodes = new HashSet(); - for (Map.Entry, DataSchemaNodeBuilder> entry : addedChilds - .entrySet()) { - List path = entry.getKey(); - DataSchemaNodeBuilder child = entry.getValue(); - if (path.size() == 2) { - childNodes.add(child); - } + @Override + public Set getTypeDefinitionBuilders() { + return addedTypedefs; + } + + public void enterNode(final Builder node) { + actualPath.push(node); + } + + public void exitNode() { + actualPath.pop(); + } + + public Builder getActualNode() { + if (actualPath.isEmpty()) { + return null; + } else { + return actualPath.get(0); + } + } + + public Builder getActualParent() { + if (actualPath.size() < 2) { + return null; + } else { + return actualPath.get(1); } - return childNodes; } - public Map, TypeAwareBuilder> getDirtyNodes() { + public Set getDirtyNodes() { return dirtyNodes; } - public List getAddedAugments() { - return addedAugments; + public List getAllAugments() { + return allAugments; } - public Set getAddedIdentities() { + public Set getIdentities() { return addedIdentities; } - public Map, UsesNodeBuilder> getAddedUsesNodes() { - return addedUsesNodes; + public List getAllUsesNodes() { + return allUsesNodes; } - public Set getAddedUnknownNodes() { - return addedUnknownNodes; + public Set getDeviations() { + return addedDeviations; } - public Set getModuleTypedefs() { - Set typedefs = new HashSet(); - for (Map.Entry, TypeDefinitionBuilder> entry : addedTypedefs - .entrySet()) { - if (entry.getKey().size() == 2) { - typedefs.add(entry.getValue()); - } - } - return typedefs; + public List getAllUnknownNodes() { + return allUnknownNodes; } public String getName() { @@ -245,11 +278,9 @@ public class ModuleBuilder implements Builder { augmentsResolved++; } - public void addDirtyNode(final List path) { - final List dirtyNodePath = new ArrayList(path); - final TypeAwareBuilder nodeBuilder = (TypeAwareBuilder) moduleNodes - .get(dirtyNodePath); - dirtyNodes.put(dirtyNodePath, nodeBuilder); + public void markActualNodeDirty() { + final TypeAwareBuilder nodeBuilder = (TypeAwareBuilder) getActualNode(); + dirtyNodes.add(nodeBuilder); } public void setRevision(final Date revision) { @@ -280,10 +311,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); } @@ -292,383 +321,428 @@ 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); - final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes - .get(pathToNode); - if (parent != null) { - if (parent instanceof AugmentationSchemaBuilder) { - containerBuilder.setAugmenting(true); - } - parent.addChildNode(containerBuilder); - } + public ContainerSchemaNodeBuilder addContainerNode(final int line, final QName containerName, + final SchemaPath schemaPath) { + final ContainerSchemaNodeBuilder builder = new ContainerSchemaNodeBuilder(line, containerName, schemaPath); - pathToNode.add(containerName.getLocalName()); - moduleNodes.put(pathToNode, containerBuilder); - addedChilds.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); - final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes - .get(pathToNode); - if (parent != null) { - if (parent instanceof AugmentationSchemaBuilder) { - listBuilder.setAugmenting(true); - } - parent.addChildNode(listBuilder); - } + public ListSchemaNodeBuilder addListNode(final int line, final QName listName, final SchemaPath schemaPath) { + final ListSchemaNodeBuilder builder = new ListSchemaNodeBuilder(line, listName, schemaPath); - pathToNode.add(listName.getLocalName()); - moduleNodes.put(pathToNode, listBuilder); - addedChilds.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); - final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes - .get(pathToNode); - if (parent != null) { - if (parent instanceof AugmentationSchemaBuilder) { - leafBuilder.setAugmenting(true); - } - parent.addChildNode(leafBuilder); - } + public LeafSchemaNodeBuilder addLeafNode(final int line, final QName leafName, final SchemaPath schemaPath) { + final LeafSchemaNodeBuilder builder = new LeafSchemaNodeBuilder(leafName, schemaPath, line); - pathToNode.add(leafName.getLocalName()); - addedChilds.put(pathToNode, leafBuilder); - moduleNodes.put(pathToNode, leafBuilder); + Builder parent = getActualNode(); + builder.setParent(parent); + addChildToParent(parent, builder, leafName.getLocalName()); - return leafBuilder; + return builder; } - public LeafListSchemaNodeBuilder addLeafListNode(final QName leafListName, - final List parentPath, final int line) { - final List pathToNode = new ArrayList(parentPath); - final LeafListSchemaNodeBuilder leafListBuilder = new LeafListSchemaNodeBuilder( - leafListName, line); - final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes - .get(pathToNode); - if (parent != null) { - if (parent instanceof AugmentationSchemaBuilder) { - leafListBuilder.setAugmenting(true); - } - parent.addChildNode(leafListBuilder); - } + public LeafListSchemaNodeBuilder addLeafListNode(final int line, final QName leafListName, + final SchemaPath schemaPath) { + final LeafListSchemaNodeBuilder builder = new LeafListSchemaNodeBuilder(line, leafListName, schemaPath); - pathToNode.add(leafListName.getLocalName()); - addedChilds.put(pathToNode, leafListBuilder); - moduleNodes.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); + public GroupingBuilder addGrouping(final int line, final QName qname) { final GroupingBuilder builder = new GroupingBuilderImpl(qname, line); - final ChildNodeBuilder parentNodeBuilder = (ChildNodeBuilder) moduleNodes - .get(pathToGroup); - if (parentNodeBuilder != null) { - parentNodeBuilder.addGrouping(builder); - } - pathToGroup.add("grouping"); - pathToGroup.add(qname.getLocalName()); - moduleNodes.put(pathToGroup, builder); - addedGroupings.put(pathToGroup, builder); + 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 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()); + } + } 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 - final UsesNodeBuilder parent = addedUsesNodes.get(pathToAugment); - if (parent != null) { - parent.addAugment(builder); - } + Builder parent = getActualNode(); + builder.setParent(parent); - pathToAugment.add(name); - moduleNodes.put(pathToAugment, builder); - addedAugments.add(builder); + 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(name, line, "Augment can be declared only under module or uses."); + } + } + 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); - final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes - .get(pathToUses); - if (parent != null) { - parent.addUsesNode(usesBuilder); - } + @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(line, groupingPathStr); + + Builder parent = getActualNode(); + usesBuilder.setParent(parent); - pathToUses.add(groupingPathStr); - addedUsesNodes.put(pathToUses, usesBuilder); - moduleNodes.put(pathToUses, usesBuilder); + 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); + } + 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); - final Builder parent = moduleNodes.get(path); - if (!(parent instanceof UsesNodeBuilder)) { - throw new YangParseException("Failed to parse refine " - + refine.getName()); + + if (actualPath.isEmpty()) { + throw new YangParseException(name, refine.getLine(), "refine can be defined only in uses statement"); + } else { + 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"); + } + refine.setParent(parent); } - UsesNodeBuilder usesBuilder = (UsesNodeBuilder) parent; - usesBuilder.addRefine(refine); + path.add(refine.getName()); - moduleNodes.put(path, refine); } - public RpcDefinitionBuilder addRpc(final QName qname, - final List parentPath, final int line) { - final List pathToRpc = new ArrayList(parentPath); - final RpcDefinitionBuilder rpcBuilder = new RpcDefinitionBuilder(qname, - line); - - pathToRpc.add(qname.getLocalName()); - addedRpcs.put(pathToRpc, rpcBuilder); - - final QName inputQName = new QName(qname.getNamespace(), - qname.getRevision(), qname.getPrefix(), "input"); - final ContainerSchemaNodeBuilder inputBuilder = new ContainerSchemaNodeBuilder( - inputQName, line); - final List pathToInput = new ArrayList(pathToRpc); - pathToInput.add("input"); - moduleNodes.put(pathToInput, inputBuilder); - rpcBuilder.setInput(inputBuilder); - - final QName outputQName = new QName(qname.getNamespace(), - qname.getRevision(), qname.getPrefix(), "output"); - final ContainerSchemaNodeBuilder outputBuilder = new ContainerSchemaNodeBuilder( - outputQName, line); - final List pathToOutput = new ArrayList(pathToRpc); - pathToOutput.add("output"); - moduleNodes.put(pathToOutput, outputBuilder); - rpcBuilder.setOutput(outputBuilder); + 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 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 NotificationBuilder addNotification(final QName notificationName, - final List parentPath, final int line) { - final List pathToNotification = new ArrayList( - parentPath); + 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"); + } + final RpcDefinitionBuilder rpc = (RpcDefinitionBuilder) parent; + + final ContainerSchemaNodeBuilder inputBuilder = new ContainerSchemaNodeBuilder(line, inputQName, schemaPath); + inputBuilder.setParent(rpc); - NotificationBuilder builder = new NotificationBuilder(notificationName, - line); + rpc.setInput(inputBuilder); + return inputBuilder; + } - pathToNotification.add(notificationName.getLocalName()); - moduleNodes.put(pathToNotification, builder); - addedNotifications.add(builder); + 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"); + } + final RpcDefinitionBuilder rpc = (RpcDefinitionBuilder) parent; - return builder; + final ContainerSchemaNodeBuilder outputBuilder = new ContainerSchemaNodeBuilder(line, outputQName, schemaPath); + outputBuilder.setParent(rpc); + + rpc.setOutput(outputBuilder); + return outputBuilder; } - public FeatureBuilder addFeature(final QName featureName, - final List parentPath, final int line) { - List pathToFeature = new ArrayList(parentPath); - pathToFeature.add(featureName.getLocalName()); + 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"); + } + 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(line, notificationName); + addedNotifications.add(builder); - FeatureBuilder builder = new FeatureBuilder(featureName, line); - addedFeatures.put(pathToFeature, builder); return builder; } - public ChoiceBuilder addChoice(final QName choiceName, - final List parentPath, final int line) { - List pathToChoice = new ArrayList(parentPath); - ChoiceBuilder builder = new ChoiceBuilder(choiceName, line); - - final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes - .get(pathToChoice); + public FeatureBuilder addFeature(final int line, final QName featureName) { + Builder parent = getActualNode(); if (parent != null) { - if (parent instanceof AugmentationSchemaBuilder) { - builder.setAugmenting(true); + throw new YangParseException(name, line, "feature can be defined only in module or submodule"); + } + + 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()); } - parent.addChildNode(builder); } + addedFeatures.add(builder); + return builder; + } - pathToChoice.add(choiceName.getLocalName()); - addedChilds.put(pathToChoice, builder); - moduleNodes.put(pathToChoice, builder); + public ChoiceBuilder addChoice(final int line, final QName choiceName) { + final ChoiceBuilder builder = new ChoiceBuilder(line, choiceName); + + 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) { - List pathToCase = new ArrayList(parentPath); - ChoiceCaseBuilder builder = new ChoiceCaseBuilder(caseName, line); - - final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes - .get(pathToCase); - if (parent != null) { - if (parent instanceof AugmentationSchemaBuilder) { - builder.setAugmenting(true); - } - parent.addChildNode(builder); + public ChoiceCaseBuilder addCase(final int line, final QName caseName) { + Builder parent = getActualNode(); + if (parent == null) { + throw new YangParseException(name, line, "'case' parent not found"); } - pathToCase.add(caseName.getLocalName()); - moduleNodes.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) { - List pathToAnyXml = new ArrayList(parentPath); - AnyXmlBuilder builder = new AnyXmlBuilder(anyXmlName, line); + public AnyXmlBuilder addAnyXml(final int line, final QName anyXmlName, final SchemaPath schemaPath) { + final AnyXmlBuilder builder = new AnyXmlBuilder(line, anyXmlName, schemaPath); - final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes - .get(pathToAnyXml); - if (parent != null) { - if (parent instanceof AugmentationSchemaBuilder) { - throw new YangParseException( - "An anyxml node cannot be augmented."); + Builder parent = getActualNode(); + builder.setParent(parent); + addChildToParent(parent, builder, anyXmlName.getLocalName()); + + return builder; + } + + @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()); } - parent.addChildNode(builder); } + addedTypedefs.add(typedefBuilder); + } + + public TypeDefinitionBuilderImpl addTypedef(final int line, final QName typeDefName) { + final TypeDefinitionBuilderImpl builder = new TypeDefinitionBuilderImpl(typeDefName, line); - pathToAnyXml.add(anyXmlName.getLocalName()); - addedChilds.put(pathToAnyXml, builder); - moduleNodes.put(pathToAnyXml, 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()); + } + } return builder; } - public TypedefBuilder addTypedef(final QName typeDefName, - final List parentPath, final int line) { - List pathToType = new ArrayList(parentPath); - TypedefBuilder builder = new TypedefBuilder(typeDefName, line); - TypeDefinitionAwareBuilder parent = (TypeDefinitionAwareBuilder) moduleNodes - .get(pathToType); - if (parent != null) { - parent.addTypedef(builder); + 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() + + "'. Invalid parent node: " + parent); } - pathToType.add(typeDefName.getLocalName()); - addedTypedefs.put(pathToType, builder); - moduleNodes.put(pathToType, builder); - return builder; + ((TypeAwareBuilder) parent).setType(type); } - public void setType(TypeDefinition type, List parentPath) { - TypeAwareBuilder parent = (TypeAwareBuilder) moduleNodes - .get(parentPath); + public UnionTypeBuilder addUnionType(final int line, final URI namespace, final Date revision) { + final Builder parent = getActualNode(); if (parent == null) { - throw new YangParseException("Failed to set type '" - + type.getQName().getLocalName() - + "'. Parent node not found."); + throw new YangParseException(line, "Error while parsing union type"); + } else { + final UnionTypeBuilder union = new UnionTypeBuilder(line); + if (parent instanceof TypeAwareBuilder) { + ((TypeAwareBuilder) parent).setTypedef(union); + return union; + } else { + throw new YangParseException(name, line, "Invalid parent of union type."); + } } - parent.setType(type); } - public UnionTypeBuilder addUnionType(final List actualPath, - final URI namespace, final Date revision, final int line) { - List pathToUnion = new ArrayList(actualPath); - TypeAwareBuilder parent = (TypeAwareBuilder) moduleNodes - .get(pathToUnion); - UnionTypeBuilder union = new UnionTypeBuilder(line); - parent.setType(union); - - List path = new ArrayList(pathToUnion); - path.add("union"); + public void addIdentityrefType(final int line, final SchemaPath schemaPath, final String baseString) { + final IdentityrefTypeBuilder identityref = new IdentityrefTypeBuilder(baseString, schemaPath, line); - moduleNodes.put(path, union); - return union; + final Builder parent = getActualNode(); + if (parent == null) { + throw new YangParseException(line, "Error while parsing identityref type."); + } else { + if (parent instanceof TypeAwareBuilder) { + final TypeAwareBuilder typeParent = (TypeAwareBuilder) parent; + typeParent.setTypedef(identityref); + dirtyNodes.add(typeParent); + } else { + throw new YangParseException(name, line, "Invalid parent of identityref type."); + } + } } - public void addIdentityrefType(final String baseString, - final List parentPath, final SchemaPath schemaPath, - final int line) { - List pathToIdentityref = new ArrayList(parentPath); - TypeAwareBuilder parent = (TypeAwareBuilder) moduleNodes - .get(pathToIdentityref); - IdentityrefTypeBuilder identityref = new IdentityrefTypeBuilder( - baseString, schemaPath, line); - parent.setType(identityref); - dirtyNodes.put(pathToIdentityref, parent); - } + public DeviationBuilder addDeviation(final int line, final String targetPath) { + Builder parent = getActualNode(); + if (parent != null) { + 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) { - final List pathToDeviation = new ArrayList(parentPath); - pathToDeviation.add(targetPath); - DeviationBuilder builder = new DeviationBuilder(targetPath, line); - addedDeviations.put(targetPath, builder); - moduleNodes.put(pathToDeviation, builder); + final DeviationBuilder builder = new DeviationBuilder(line, targetPath); + addedDeviations.add(builder); return builder; } - public IdentitySchemaNodeBuilder addIdentity(final QName qname, - final List parentPath, final int line) { - final List pathToIdentity = new ArrayList(parentPath); - final IdentitySchemaNodeBuilder builder = new IdentitySchemaNodeBuilder( - qname, line); - pathToIdentity.add(qname.getLocalName()); - moduleNodes.put(pathToIdentity, builder); + 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 IdentitySchemaNodeBuilder builder = new IdentitySchemaNodeBuilder(line, qname); addedIdentities.add(builder); return builder; } - public void addConfiguration(boolean configuration, List parentPath) { - Builder builder = moduleNodes.get(parentPath); - // current api did not support adding config to deviate - if (!(builder instanceof DeviationBuilder)) { - if(builder instanceof RefineHolder) { - ((RefineHolder)builder).setConfig(configuration); + @Override + public void addUnknownSchemaNode(final UnknownSchemaNodeBuilder builder) { + addedUnknownNodes.add(builder); + allUnknownNodes.add(builder); + } + + public UnknownSchemaNodeBuilder addUnknownSchemaNode(final int line, final QName qname) { + final Builder parent = getActualNode(); + final UnknownSchemaNodeBuilder builder = new UnknownSchemaNodeBuilder(line, qname); + builder.setParent(parent); + allUnknownNodes.add(builder); + + if (parent == null) { + addedUnknownNodes.add(builder); + } else { + if (parent instanceof SchemaNodeBuilder) { + ((SchemaNodeBuilder) parent).addUnknownSchemaNode(builder); + } else if (parent instanceof DataNodeContainerBuilder) { + ((DataNodeContainerBuilder) parent).addUnknownSchemaNode(builder); + } else if (parent instanceof RefineHolder) { + ((RefineHolder) parent).addUnknownSchemaNode(builder); } else { - ((DataSchemaNodeBuilder)builder).setConfiguration(configuration); + throw new YangParseException(name, line, "Unresolved parent of unknown node '" + qname.getLocalName() + + "'"); } } - } - public UnknownSchemaNodeBuilder addUnknownSchemaNode(final QName qname, - final List parentPath, final int line) { - final List pathToUnknown = new ArrayList(parentPath); - final UnknownSchemaNodeBuilder builder = new UnknownSchemaNodeBuilder( - qname, line); - final Builder parent = moduleNodes.get(pathToUnknown); - if (parent instanceof RefineHolder) { - ((RefineHolder) parent).addUnknownSchemaNode(builder); - } else if (parent instanceof SchemaNodeBuilder) { - ((SchemaNodeBuilder) parent).addUnknownSchemaNode(builder); - } - addedUnknownNodes.add(builder); return builder; } + @Override + public String toString() { + return "module " + name; + } + private final class ModuleImpl implements Module { private URI namespace; private final String name; @@ -682,17 +756,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; @@ -854,7 +927,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) { @@ -890,8 +963,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; } @@ -902,12 +974,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); @@ -929,15 +1012,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; } @@ -993,8 +1072,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); @@ -1006,9 +1084,58 @@ public class ModuleBuilder implements Builder { } } - private ModuleImport createModuleImport(final String moduleName, - final Date revision, final String prefix) { - ModuleImport moduleImport = new ModuleImport() { + 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 : addedChildNodes) { + 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()); + } + } + addedChildNodes.add(child); + } else { + // no need for checking rpc and notification because they can be + // defined only under module or submodule + if (parent instanceof DataNodeContainerBuilder) { + 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()); + } + } + parentNode.addChildNode(child); + } else if (parent instanceof ChoiceBuilder) { + 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 node '" + childLocalName + "'."); + } + } + } + + private ModuleImport createModuleImport(final String moduleName, final Date revision, final String prefix) { + final ModuleImport moduleImport = new ModuleImport() { @Override public String getModuleName() { return moduleName; @@ -1028,12 +1155,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; } @@ -1075,137 +1199,10 @@ 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() == 3) { - 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). - * - * @param addedTypedefs - * @return set of built module typedef statements - */ - 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; - } - - /** - * 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()); - } - } - return features; - } - }