X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fsal%2Fyang-prototype%2Fcode-generator%2Fyang-model-parser-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fyang%2Fmodel%2Fparser%2Fbuilder%2Fimpl%2FModuleBuilder.java;h=e0ba03adfb0013f4eb69873ee96973b9f1c2733f;hb=be6d2cfbf462fc44301309b872ca8eeae6e2eb97;hp=5f89e864559fd9f8d74dadc691150b367b16168f;hpb=ca85a6f3a39b406ab122fe985ee010a41489f658;p=controller.git diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/ModuleBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/ModuleBuilder.java index 5f89e86455..e0ba03adfb 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/ModuleBuilder.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/ModuleBuilder.java @@ -24,10 +24,12 @@ import org.opendaylight.controller.yang.model.api.Deviation; import org.opendaylight.controller.yang.model.api.ExtensionDefinition; import org.opendaylight.controller.yang.model.api.FeatureDefinition; import org.opendaylight.controller.yang.model.api.GroupingDefinition; +import org.opendaylight.controller.yang.model.api.IdentitySchemaNode; import org.opendaylight.controller.yang.model.api.Module; import org.opendaylight.controller.yang.model.api.ModuleImport; 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.UsesNode; import org.opendaylight.controller.yang.model.parser.builder.api.AugmentationSchemaBuilder; @@ -35,10 +37,13 @@ import org.opendaylight.controller.yang.model.parser.builder.api.Builder; import org.opendaylight.controller.yang.model.parser.builder.api.ChildNodeBuilder; import org.opendaylight.controller.yang.model.parser.builder.api.DataSchemaNodeBuilder; import org.opendaylight.controller.yang.model.parser.builder.api.GroupingBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.SchemaNodeBuilder; import org.opendaylight.controller.yang.model.parser.builder.api.TypeAwareBuilder; import org.opendaylight.controller.yang.model.parser.builder.api.TypeDefinitionAwareBuilder; import org.opendaylight.controller.yang.model.parser.builder.api.TypeDefinitionBuilder; import org.opendaylight.controller.yang.model.parser.builder.api.UsesNodeBuilder; +import org.opendaylight.controller.yang.model.parser.util.RefineHolder; +import org.opendaylight.controller.yang.model.parser.util.YangParseException; /** * This builder builds Module object. If this module is dependent on external @@ -46,14 +51,15 @@ import org.opendaylight.controller.yang.model.parser.builder.api.UsesNodeBuilder * otherwise result may not be valid. */ public class ModuleBuilder implements Builder { - private final ModuleImpl instance; private final String name; + private URI namespace; private String prefix; private Date revision; + private int augmentsResolved; + private final Set imports = new HashSet(); - private Set augmentations; /** * All nodes, that can contain other nodes @@ -71,26 +77,27 @@ public class ModuleBuilder implements Builder { private final Map, UsesNodeBuilder> addedUsesNodes = new HashMap, UsesNodeBuilder>(); private final Map, RpcDefinitionBuilder> addedRpcs = new HashMap, RpcDefinitionBuilder>(); 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 List addedExtensions = new ArrayList(); + private final Set addedUnknownNodes = new HashSet(); private final Map, TypeAwareBuilder> dirtyNodes = new HashMap, TypeAwareBuilder>(); - public ModuleBuilder(String name) { + public ModuleBuilder(final String name) { this.name = name; instance = new ModuleImpl(name); } - - /** * Build new Module object based on this builder. */ @Override public Module build() { instance.setImports(imports); + instance.setNamespace(namespace); // TYPEDEFS final Set> typedefs = buildModuleTypedefs(addedTypedefs); @@ -105,8 +112,8 @@ public class ModuleBuilder implements Builder { instance.setGroupings(groupings); // USES - final Set usesNodeDefinitions = buildUsesNodes(addedUsesNodes); - instance.setUses(usesNodeDefinitions); + final Set usesDefinitions = buildUsesNodes(addedUsesNodes); + instance.setUses(usesDefinitions); // FEATURES final Set features = buildModuleFeatures(addedFeatures); @@ -120,6 +127,10 @@ public class ModuleBuilder implements Builder { instance.setNotifications(notifications); // AUGMENTATIONS + final Set augmentations = new HashSet(); + for (AugmentationSchemaBuilder builder : addedAugments) { + augmentations.add(builder.build()); + } instance.setAugmentations(augmentations); // RPCs @@ -136,26 +147,81 @@ public class ModuleBuilder implements Builder { // EXTENSIONS final List extensions = new ArrayList(); - for(ExtensionBuilder b : addedExtensions) { + for (ExtensionBuilder b : addedExtensions) { extensions.add(b.build()); } instance.setExtensionSchemaNodes(extensions); + // IDENTITIES + final Set identities = new HashSet(); + for (IdentitySchemaNodeBuilder idBuilder : addedIdentities) { + identities.add(idBuilder.build()); + } + instance.setIdentities(identities); + return instance; } - public Builder getNode(List path) { + public Builder getNode(final List path) { return moduleNodes.get(path); } + 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); + } + } + return childNodes; + } + public Map, TypeAwareBuilder> getDirtyNodes() { return dirtyNodes; } + public Set getAddedAugments() { + return addedAugments; + } + + public Set getAddedIdentities() { + return addedIdentities; + } + + public Map, UsesNodeBuilder> getAddedUsesNodes() { + return addedUsesNodes; + } + + public Set getAddedUnknownNodes() { + return addedUnknownNodes; + } + + 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 String getName() { return name; } + public URI getNamespace() { + return namespace; + } + + public void setNamespace(final URI namespace) { + this.namespace = namespace; + } + public String getPrefix() { return prefix; } @@ -164,59 +230,55 @@ public class ModuleBuilder implements Builder { return revision; } - public Set getAddedAugments() { - return addedAugments; + public int getAugmentsResolved() { + return augmentsResolved; } - public void addDirtyNode(List path) { - List dirtyNodePath = new ArrayList(path); - TypeAwareBuilder nodeBuilder = (TypeAwareBuilder) moduleNodes - .get(dirtyNodePath); - dirtyNodes.put(dirtyNodePath, nodeBuilder); + public void augmentResolved() { + augmentsResolved++; } - public void setNamespace(URI namespace) { - instance.setNamespace(namespace); + 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 setRevision(Date revision) { + public void setRevision(final Date revision) { this.revision = revision; instance.setRevision(revision); } - public void setPrefix(String prefix) { + public void setPrefix(final String prefix) { this.prefix = prefix; instance.setPrefix(prefix); } - public void setYangVersion(String yangVersion) { + public void setYangVersion(final String yangVersion) { instance.setYangVersion(yangVersion); } - public void setDescription(String description) { + public void setDescription(final String description) { instance.setDescription(description); } - public void setReference(String reference) { + public void setReference(final String reference) { instance.setReference(reference); } - public void setOrganization(String organization) { + public void setOrganization(final String organization) { instance.setOrganization(organization); } - public void setContact(String contact) { + public void setContact(final String contact) { instance.setContact(contact); } - public void setAugmentations(Set augmentations) { - this.augmentations = augmentations; - } - public boolean addModuleImport(final String moduleName, final Date revision, final String prefix) { - ModuleImport moduleImport = createModuleImport(moduleName, revision, - prefix); + final ModuleImport moduleImport = createModuleImport(moduleName, + revision, prefix); return imports.add(moduleImport); } @@ -224,22 +286,23 @@ public class ModuleBuilder implements Builder { return imports; } - public ExtensionBuilder addExtension(QName qname) { - ExtensionBuilder builder = new ExtensionBuilder(qname); + public ExtensionBuilder addExtension(final QName qname) { + final ExtensionBuilder builder = new ExtensionBuilder(qname); + addedExtensions.add(builder); return builder; } - public ContainerSchemaNodeBuilder addContainerNode(QName containerName, - List parentPath) { - List pathToNode = new ArrayList(parentPath); + public ContainerSchemaNodeBuilder addContainerNode( + final QName containerName, final List parentPath) { + final List pathToNode = new ArrayList(parentPath); - ContainerSchemaNodeBuilder containerBuilder = new ContainerSchemaNodeBuilder( + final ContainerSchemaNodeBuilder containerBuilder = new ContainerSchemaNodeBuilder( containerName); - ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes + final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes .get(pathToNode); if (parent != null) { - if(parent instanceof AugmentationSchemaBuilder) { + if (parent instanceof AugmentationSchemaBuilder) { containerBuilder.setAugmenting(true); } parent.addChildNode(containerBuilder); @@ -252,16 +315,17 @@ public class ModuleBuilder implements Builder { return containerBuilder; } - public ListSchemaNodeBuilder addListNode(QName listName, - List parentPath) { - List pathToNode = new ArrayList(parentPath); + public ListSchemaNodeBuilder addListNode(final QName listName, + final List parentPath) { + final List pathToNode = new ArrayList(parentPath); - ListSchemaNodeBuilder listBuilder = new ListSchemaNodeBuilder(listName); + final ListSchemaNodeBuilder listBuilder = new ListSchemaNodeBuilder( + listName); - ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes + final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes .get(pathToNode); if (parent != null) { - if(parent instanceof AugmentationSchemaBuilder) { + if (parent instanceof AugmentationSchemaBuilder) { listBuilder.setAugmenting(true); } parent.addChildNode(listBuilder); @@ -274,15 +338,17 @@ public class ModuleBuilder implements Builder { return listBuilder; } - public LeafSchemaNodeBuilder addLeafNode(QName leafName, - List parentPath) { - List pathToNode = new ArrayList(parentPath); + public LeafSchemaNodeBuilder addLeafNode(final QName leafName, + final List parentPath) { + final List pathToNode = new ArrayList(parentPath); - LeafSchemaNodeBuilder leafBuilder = new LeafSchemaNodeBuilder(leafName); + final LeafSchemaNodeBuilder leafBuilder = new LeafSchemaNodeBuilder( + leafName); - ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes.get(pathToNode); + final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes + .get(pathToNode); if (parent != null) { - if(parent instanceof AugmentationSchemaBuilder) { + if (parent instanceof AugmentationSchemaBuilder) { leafBuilder.setAugmenting(true); } parent.addChildNode(leafBuilder); @@ -295,15 +361,16 @@ public class ModuleBuilder implements Builder { return leafBuilder; } - public LeafListSchemaNodeBuilder addLeafListNode(QName leafListName, - List parentPath) { - List pathToNode = new ArrayList(parentPath); + public LeafListSchemaNodeBuilder addLeafListNode(final QName leafListName, + final List parentPath) { + final List pathToNode = new ArrayList(parentPath); - LeafListSchemaNodeBuilder leafListBuilder = new LeafListSchemaNodeBuilder( + final LeafListSchemaNodeBuilder leafListBuilder = new LeafListSchemaNodeBuilder( leafListName); - ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes.get(pathToNode); + final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes + .get(pathToNode); if (parent != null) { - if(parent instanceof AugmentationSchemaBuilder) { + if (parent instanceof AugmentationSchemaBuilder) { leafListBuilder.setAugmenting(true); } parent.addChildNode(leafListBuilder); @@ -316,15 +383,18 @@ public class ModuleBuilder implements Builder { return leafListBuilder; } - public GroupingBuilder addGrouping(QName qname, List parentPath) { - List pathToGroup = new ArrayList(parentPath); + public GroupingBuilder addGrouping(final QName qname, + final List parentPath) { + final List pathToGroup = new ArrayList(parentPath); - GroupingBuilder builder = new GroupingBuilderImpl(qname); - ChildNodeBuilder parentNodeBuilder = (ChildNodeBuilder) moduleNodes.get(pathToGroup); + final GroupingBuilder builder = new GroupingBuilderImpl(qname); + 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); @@ -332,14 +402,15 @@ public class ModuleBuilder implements Builder { return builder; } - public AugmentationSchemaBuilder addAugment(String name, - List parentPath) { - List pathToAugment = new ArrayList(parentPath); + public AugmentationSchemaBuilder addAugment(final String name, + final List parentPath) { + final List pathToAugment = new ArrayList(parentPath); - AugmentationSchemaBuilder builder = new AugmentationSchemaBuilderImpl(name); + final AugmentationSchemaBuilder builder = new AugmentationSchemaBuilderImpl( + name); // augment can only be in 'module' or 'uses' statement - UsesNodeBuilder parent = addedUsesNodes.get(pathToAugment); + final UsesNodeBuilder parent = addedUsesNodes.get(pathToAugment); if (parent != null) { parent.addAugment(builder); } @@ -351,46 +422,59 @@ public class ModuleBuilder implements Builder { return builder; } - public UsesNodeBuilder addUsesNode(String groupingPathStr, - List parentPath) { - List pathToUses = new ArrayList(parentPath); - - UsesNodeBuilder usesBuilder = new UsesNodeBuilderImpl(groupingPathStr); - - ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes.get(pathToUses); + public UsesNodeBuilder addUsesNode(final String groupingPathStr, + final List parentPath) { + final List pathToUses = new ArrayList(parentPath); + final UsesNodeBuilder usesBuilder = new UsesNodeBuilderImpl( + groupingPathStr); + final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes + .get(pathToUses); if (parent != null) { - if(parent instanceof AugmentationSchemaBuilder) { - usesBuilder.setAugmenting(true); - } parent.addUsesNode(usesBuilder); } pathToUses.add(groupingPathStr); addedUsesNodes.put(pathToUses, usesBuilder); - + moduleNodes.put(pathToUses, usesBuilder); return usesBuilder; } - public RpcDefinitionBuilder addRpc(QName qname, List parentPath) { - List pathToRpc = new ArrayList(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()); + } + UsesNodeBuilder usesBuilder = (UsesNodeBuilder) parent; + usesBuilder.addRefine(refine); + path.add(refine.getName()); + moduleNodes.put(path, refine); + } - RpcDefinitionBuilder rpcBuilder = new RpcDefinitionBuilder(qname); + public RpcDefinitionBuilder addRpc(final QName qname, + final List parentPath) { + final List pathToRpc = new ArrayList(parentPath); + final RpcDefinitionBuilder rpcBuilder = new RpcDefinitionBuilder(qname); pathToRpc.add(qname.getLocalName()); addedRpcs.put(pathToRpc, rpcBuilder); - QName inputQName = new QName(qname.getNamespace(), qname.getRevision(), - qname.getPrefix(), "input"); - ContainerSchemaNodeBuilder inputBuilder = new ContainerSchemaNodeBuilder(inputQName); - List pathToInput = new ArrayList(pathToRpc); + final QName inputQName = new QName(qname.getNamespace(), + qname.getRevision(), qname.getPrefix(), "input"); + final ContainerSchemaNodeBuilder inputBuilder = new ContainerSchemaNodeBuilder( + inputQName); + final List pathToInput = new ArrayList(pathToRpc); pathToInput.add("input"); moduleNodes.put(pathToInput, inputBuilder); rpcBuilder.setInput(inputBuilder); - QName outputQName = new QName(qname.getNamespace(), + final QName outputQName = new QName(qname.getNamespace(), qname.getRevision(), qname.getPrefix(), "output"); - ContainerSchemaNodeBuilder outputBuilder = new ContainerSchemaNodeBuilder(outputQName); - List pathToOutput = new ArrayList(pathToRpc); + final ContainerSchemaNodeBuilder outputBuilder = new ContainerSchemaNodeBuilder( + outputQName); + final List pathToOutput = new ArrayList(pathToRpc); pathToOutput.add("output"); moduleNodes.put(pathToOutput, outputBuilder); rpcBuilder.setOutput(outputBuilder); @@ -398,21 +482,22 @@ public class ModuleBuilder implements Builder { return rpcBuilder; } - public NotificationBuilder addNotification(QName notificationName, - List parentPath) { - List pathToNotification = new ArrayList(parentPath); + public NotificationBuilder addNotification(final QName notificationName, + final List parentPath) { + final List pathToNotification = new ArrayList( + parentPath); - NotificationBuilder notificationBuilder = new NotificationBuilder( - notificationName); + NotificationBuilder builder = new NotificationBuilder(notificationName); pathToNotification.add(notificationName.getLocalName()); - moduleNodes.put(pathToNotification, notificationBuilder); - addedNotifications.add(notificationBuilder); + moduleNodes.put(pathToNotification, builder); + addedNotifications.add(builder); - return notificationBuilder; + return builder; } - public FeatureBuilder addFeature(QName featureName, List parentPath) { + public FeatureBuilder addFeature(final QName featureName, + final List parentPath) { List pathToFeature = new ArrayList(parentPath); pathToFeature.add(featureName.getLocalName()); @@ -421,10 +506,75 @@ public class ModuleBuilder implements Builder { return builder; } - public TypedefBuilder addTypedef(QName typeDefName, List parentPath) { + public ChoiceBuilder addChoice(final QName choiceName, + final List parentPath) { + List pathToChoice = new ArrayList(parentPath); + ChoiceBuilder builder = new ChoiceBuilder(choiceName); + + final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes + .get(pathToChoice); + if (parent != null) { + if (parent instanceof AugmentationSchemaBuilder) { + builder.setAugmenting(true); + } + parent.addChildNode(builder); + } + + pathToChoice.add(choiceName.getLocalName()); + addedChilds.put(pathToChoice, builder); + moduleNodes.put(pathToChoice, builder); + + return builder; + } + + public ChoiceCaseBuilder addCase(final QName caseName, + final List parentPath) { + List pathToCase = new ArrayList(parentPath); + ChoiceCaseBuilder builder = new ChoiceCaseBuilder(caseName); + + final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes + .get(pathToCase); + if (parent != null) { + if (parent instanceof AugmentationSchemaBuilder) { + builder.setAugmenting(true); + } + parent.addChildNode(builder); + } + + pathToCase.add(caseName.getLocalName()); + moduleNodes.put(pathToCase, builder); + + return builder; + } + + public AnyXmlBuilder addAnyXml(final QName anyXmlName, + final List parentPath) { + List pathToAnyXml = new ArrayList(parentPath); + AnyXmlBuilder builder = new AnyXmlBuilder(anyXmlName); + + final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes + .get(pathToAnyXml); + if (parent != null) { + if (parent instanceof AugmentationSchemaBuilder) { + throw new UnsupportedOperationException( + "An anyxml node cannot be augmented."); + } + parent.addChildNode(builder); + } + + pathToAnyXml.add(anyXmlName.getLocalName()); + addedChilds.put(pathToAnyXml, builder); + moduleNodes.put(pathToAnyXml, builder); + + return builder; + } + + public TypedefBuilder addTypedef(final QName typeDefName, + final List parentPath) { List pathToType = new ArrayList(parentPath); TypedefBuilder builder = new TypedefBuilder(typeDefName); - TypeDefinitionAwareBuilder parent = (TypeDefinitionAwareBuilder) moduleNodes.get(pathToType); + TypeDefinitionAwareBuilder parent = (TypeDefinitionAwareBuilder) moduleNodes + .get(pathToType); if (parent != null) { parent.addTypedef(builder); } @@ -434,44 +584,88 @@ public class ModuleBuilder implements Builder { return builder; } - public Set getModuleTypedefs() { - Set typedefs = new HashSet(); - for (Map.Entry, TypeDefinitionBuilder> entry : addedTypedefs.entrySet()) { - if (entry.getKey().size() == 2) { - typedefs.add(entry.getValue()); - } + public void setType(TypeDefinition type, List parentPath) { + TypeAwareBuilder parent = (TypeAwareBuilder) moduleNodes + .get(parentPath); + if (parent == null) { + throw new YangParseException("Failed to set type '" + + type.getQName().getLocalName() + + "'. Parent node not found."); } - return typedefs; + parent.setType(type); } - public void setType(TypeDefinition type, List parentPath) { - TypeAwareBuilder parent = (TypeAwareBuilder) moduleNodes.get(parentPath); - parent.setType(type); + public void addUnionType(final List actualPath, + final URI namespace, final Date revision) { + List pathToUnion = new ArrayList(actualPath); + TypeAwareBuilder parent = (TypeAwareBuilder) moduleNodes + .get(pathToUnion); + UnionTypeBuilder union = new UnionTypeBuilder(pathToUnion, namespace, + revision); + parent.setType(union); + + List path = new ArrayList(pathToUnion); + path.add("union"); + + moduleNodes.put(path, union); + } + + public void addIdentityrefType(String baseString, List parentPath, + SchemaPath schemaPath) { + List pathToIdentityref = new ArrayList(parentPath); + TypeAwareBuilder parent = (TypeAwareBuilder) moduleNodes + .get(pathToIdentityref); + IdentityrefTypeBuilder identityref = new IdentityrefTypeBuilder( + baseString, schemaPath); + parent.setType(identityref); + dirtyNodes.put(pathToIdentityref, parent); } - public DeviationBuilder addDeviation(String targetPath) { + public DeviationBuilder addDeviation(String targetPath, + List parentPath) { + final List pathToDeviation = new ArrayList(parentPath); + pathToDeviation.add(targetPath); DeviationBuilder builder = new DeviationBuilder(targetPath); addedDeviations.put(targetPath, builder); + moduleNodes.put(pathToDeviation, builder); + return builder; + } + + public IdentitySchemaNodeBuilder addIdentity(QName qname, + List parentPath) { + List pathToIdentity = new ArrayList(parentPath); + IdentitySchemaNodeBuilder builder = new IdentitySchemaNodeBuilder(qname); + pathToIdentity.add(qname.getLocalName()); + moduleNodes.put(pathToIdentity, builder); + addedIdentities.add(builder); return builder; } public void addConfiguration(boolean configuration, List parentPath) { Builder builder = moduleNodes.get(parentPath); - if (builder instanceof DeviationBuilder) { - // skip - // TODO - } else { - DataSchemaNodeBuilder configBuilder = (DataSchemaNodeBuilder) moduleNodes.get(parentPath); + // current api did not support adding config to deviate + if (!(builder instanceof DeviationBuilder)) { + DataSchemaNodeBuilder configBuilder = (DataSchemaNodeBuilder) moduleNodes + .get(parentPath); configBuilder.setConfiguration(configuration); } } - public UnknownSchemaNodeBuilder addUnknownSchemaNode(QName qname, List parentPath) { - UnknownSchemaNodeBuilder builder = new UnknownSchemaNodeBuilder(qname); + public UnknownSchemaNodeBuilder addUnknownSchemaNode(QName qname, + List parentPath) { + final List pathToUnknown = new ArrayList(parentPath); + final UnknownSchemaNodeBuilder builder = new UnknownSchemaNodeBuilder( + qname); + 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; } - private class ModuleImpl implements Module { private URI namespace; private final String name; @@ -485,14 +679,17 @@ 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 extensionSchemaNodes = Collections.emptyList(); + private List extensionNodes = Collections + .emptyList(); + private Set identities = Collections.emptySet(); private ModuleImpl(String name) { this.name = name; @@ -581,7 +778,9 @@ public class ModuleBuilder implements Builder { } private void setImports(Set imports) { - this.imports = imports; + if (imports != null) { + this.imports = imports; + } } @Override @@ -590,7 +789,9 @@ public class ModuleBuilder implements Builder { } private void setFeatures(Set features) { - this.features = features; + if (features != null) { + this.features = features; + } } @Override @@ -599,7 +800,9 @@ public class ModuleBuilder implements Builder { } private void setTypeDefinitions(Set> typeDefinitions) { - this.typeDefinitions = typeDefinitions; + if (typeDefinitions != null) { + this.typeDefinitions = typeDefinitions; + } } @Override @@ -608,7 +811,9 @@ public class ModuleBuilder implements Builder { } private void setNotifications(Set notifications) { - this.notifications = notifications; + if (notifications != null) { + this.notifications = notifications; + } } @Override @@ -617,7 +822,9 @@ public class ModuleBuilder implements Builder { } private void setAugmentations(Set augmentations) { - this.augmentations = augmentations; + if (augmentations != null) { + this.augmentations = augmentations; + } } @Override @@ -626,7 +833,9 @@ public class ModuleBuilder implements Builder { } private void setRpcs(Set rpcs) { - this.rpcs = rpcs; + if (rpcs != null) { + this.rpcs = rpcs; + } } @Override @@ -635,7 +844,9 @@ public class ModuleBuilder implements Builder { } private void setDeviations(Set deviations) { - this.deviations = deviations; + if (deviations != null) { + this.deviations = deviations; + } } @Override @@ -644,7 +855,9 @@ public class ModuleBuilder implements Builder { } private void setChildNodes(Map childNodes) { - this.childNodes = childNodes; + if (childNodes != null) { + this.childNodes = childNodes; + } } @Override @@ -653,7 +866,9 @@ public class ModuleBuilder implements Builder { } private void setGroupings(Set groupings) { - this.groupings = groupings; + if (groupings != null) { + this.groupings = groupings; + } } @Override @@ -662,17 +877,31 @@ public class ModuleBuilder implements Builder { } private void setUses(Set uses) { - this.uses = uses; + if (uses != null) { + this.uses = uses; + } } @Override public List getExtensionSchemaNodes() { - return extensionSchemaNodes; + return extensionNodes; + } + + private void setExtensionSchemaNodes( + List extensionNodes) { + if (extensionNodes != null) { + this.extensionNodes = extensionNodes; + } + } + + @Override + public Set getIdentities() { + return identities; } - private void setExtensionSchemaNodes(List extensionSchemaNodes) { - if(extensionSchemaNodes != null) { - this.extensionSchemaNodes = extensionSchemaNodes; + private void setIdentities(Set identities) { + if (identities != null) { + this.identities = identities; } } @@ -697,26 +926,15 @@ 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 + ((description == null) ? 0 : description.hashCode()); - result = prime * result + ((reference == null) ? 0 : reference.hashCode()); - - result = prime * result + ((organization == null) ? 0 : organization.hashCode()); - result = prime * result + ((contact == null) ? 0 : contact.hashCode()); - result = prime * result + ((imports == null) ? 0 : imports.hashCode()); - result = prime * result + ((features == null) ? 0 : features.hashCode()); - result = prime * result + ((typeDefinitions == null) ? 0 : typeDefinitions.hashCode()); - result = prime * result + ((notifications == null) ? 0 : notifications.hashCode()); - result = prime * result + ((augmentations == null) ? 0 : augmentations.hashCode()); - result = prime * result + ((rpcs == null) ? 0 : rpcs.hashCode()); - result = prime * result + ((deviations == null) ? 0 : deviations.hashCode()); - result = prime * result + ((childNodes == null) ? 0 : childNodes.hashCode()); - result = prime * result + ((groupings == null) ? 0 : groupings.hashCode()); - result = prime * result + ((uses == null) ? 0 : uses.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; } @@ -767,104 +985,6 @@ public class ModuleBuilder implements Builder { } else if (!yangVersion.equals(other.yangVersion)) { return false; } - if (description == null) { - if (other.description != null) { - return false; - } - } else if (!description.equals(other.description)) { - return false; - } - if (reference == null) { - if (other.reference != null) { - return false; - } - } else if (!reference.equals(other.reference)) { - return false; - } - if (organization == null) { - if (other.organization != null) { - return false; - } - } else if (!organization.equals(other.organization)) { - return false; - } - if (contact == null) { - if (other.contact != null) { - return false; - } - } else if (!contact.equals(other.contact)) { - return false; - } - if (imports == null) { - if (other.imports != null) { - return false; - } - } else if (!imports.equals(other.imports)) { - return false; - } - if (features == null) { - if (other.features != null) { - return false; - } - } else if (!features.equals(other.features)) { - return false; - } - if (typeDefinitions == null) { - if (other.typeDefinitions != null) { - return false; - } - } else if (!typeDefinitions.equals(other.typeDefinitions)) { - return false; - } - if (notifications == null) { - if (other.notifications != null) { - return false; - } - } else if (!notifications.equals(other.notifications)) { - return false; - } - if (augmentations == null) { - if (other.augmentations != null) { - return false; - } - } else if (!augmentations.equals(other.augmentations)) { - return false; - } - if (rpcs == null) { - if (other.rpcs != null) { - return false; - } - } else if (!rpcs.equals(other.rpcs)) { - return false; - } - if (deviations == null) { - if (other.deviations != null) { - return false; - } - } else if (!deviations.equals(other.deviations)) { - return false; - } - if (childNodes == null) { - if (other.childNodes != null) { - return false; - } - } else if (!childNodes.equals(other.childNodes)) { - return false; - } - if (groupings == null) { - if (other.groupings != null) { - return false; - } - } else if (!groupings.equals(other.groupings)) { - return false; - } - if (uses == null) { - if (other.uses != null) { - return false; - } - } else if (!uses.equals(other.uses)) { - return false; - } return true; } @@ -986,9 +1106,11 @@ public class ModuleBuilder implements Builder { final Map childNodes = new HashMap(); for (Map.Entry, DataSchemaNodeBuilder> entry : addedChilds .entrySet()) { - if (entry.getKey().size() == 2) { - DataSchemaNode node = entry.getValue().build(); - QName qname = entry.getValue().getQName(); + List path = entry.getKey(); + DataSchemaNodeBuilder child = entry.getValue(); + if (path.size() == 2) { + DataSchemaNode node = child.build(); + QName qname = node.getQName(); childNodes.put(qname, node); } } @@ -1047,9 +1169,11 @@ public class ModuleBuilder implements Builder { Set> typedefs = new HashSet>(); for (Map.Entry, TypeDefinitionBuilder> entry : addedTypedefs .entrySet()) { - if (entry.getKey().size() == 2) { - TypeDefinition> node = entry - .getValue().build(); + List key = entry.getKey(); + TypeDefinitionBuilder typedefBuilder = entry.getValue(); + if (key.size() == 2) { + TypeDefinition> node = typedefBuilder + .build(); typedefs.add(node); } } @@ -1066,14 +1190,14 @@ public class ModuleBuilder implements Builder { */ private Set buildUsesNodes( Map, UsesNodeBuilder> addedUsesNodes) { - final Set usesNodeDefinitions = new HashSet(); + final Set usesNodeDefs = new HashSet(); for (Map.Entry, UsesNodeBuilder> entry : addedUsesNodes .entrySet()) { if (entry.getKey().size() == 2) { - usesNodeDefinitions.add(entry.getValue().build()); + usesNodeDefs.add(entry.getValue().build()); } } - return usesNodeDefinitions; + return usesNodeDefs; } /**