2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.yang.model.parser.builder.impl;
11 import java.util.ArrayList;
12 import java.util.Collections;
13 import java.util.Date;
14 import java.util.HashMap;
15 import java.util.HashSet;
16 import java.util.List;
20 import org.opendaylight.controller.yang.common.QName;
21 import org.opendaylight.controller.yang.model.api.AugmentationSchema;
22 import org.opendaylight.controller.yang.model.api.DataSchemaNode;
23 import org.opendaylight.controller.yang.model.api.Deviation;
24 import org.opendaylight.controller.yang.model.api.ExtensionDefinition;
25 import org.opendaylight.controller.yang.model.api.FeatureDefinition;
26 import org.opendaylight.controller.yang.model.api.GroupingDefinition;
27 import org.opendaylight.controller.yang.model.api.IdentitySchemaNode;
28 import org.opendaylight.controller.yang.model.api.Module;
29 import org.opendaylight.controller.yang.model.api.ModuleImport;
30 import org.opendaylight.controller.yang.model.api.NotificationDefinition;
31 import org.opendaylight.controller.yang.model.api.RpcDefinition;
32 import org.opendaylight.controller.yang.model.api.TypeDefinition;
33 import org.opendaylight.controller.yang.model.api.UsesNode;
34 import org.opendaylight.controller.yang.model.parser.builder.api.AugmentationSchemaBuilder;
35 import org.opendaylight.controller.yang.model.parser.builder.api.Builder;
36 import org.opendaylight.controller.yang.model.parser.builder.api.ChildNodeBuilder;
37 import org.opendaylight.controller.yang.model.parser.builder.api.DataSchemaNodeBuilder;
38 import org.opendaylight.controller.yang.model.parser.builder.api.GroupingBuilder;
39 import org.opendaylight.controller.yang.model.parser.builder.api.SchemaNodeBuilder;
40 import org.opendaylight.controller.yang.model.parser.builder.api.TypeAwareBuilder;
41 import org.opendaylight.controller.yang.model.parser.builder.api.TypeDefinitionAwareBuilder;
42 import org.opendaylight.controller.yang.model.parser.builder.api.TypeDefinitionBuilder;
43 import org.opendaylight.controller.yang.model.parser.builder.api.UsesNodeBuilder;
44 import org.opendaylight.controller.yang.model.parser.util.YangParseException;
47 * This builder builds Module object. If this module is dependent on external
48 * module/modules, these dependencies must be resolved before module is built,
49 * otherwise result may not be valid.
51 public class ModuleBuilder implements Builder {
52 private final ModuleImpl instance;
53 private final String name;
54 private URI namespace;
55 private String prefix;
56 private Date revision;
58 private int augmentsResolved;
60 private final Set<ModuleImport> imports = new HashSet<ModuleImport>();
63 * All nodes, that can contain other nodes
65 private final Map<List<String>, Builder> moduleNodes = new HashMap<List<String>, Builder>();
68 * Holds all child (DataSchemaNode) nodes: anyxml, choice, case, container,
69 * list, leaf, leaf-list.
71 private final Map<List<String>, DataSchemaNodeBuilder> addedChilds = new HashMap<List<String>, DataSchemaNodeBuilder>();
73 private final Map<List<String>, GroupingBuilder> addedGroupings = new HashMap<List<String>, GroupingBuilder>();
74 private final Set<AugmentationSchemaBuilder> addedAugments = new HashSet<AugmentationSchemaBuilder>();
75 private final Map<List<String>, UsesNodeBuilder> addedUsesNodes = new HashMap<List<String>, UsesNodeBuilder>();
76 private final Map<List<String>, RpcDefinitionBuilder> addedRpcs = new HashMap<List<String>, RpcDefinitionBuilder>();
77 private final Set<NotificationBuilder> addedNotifications = new HashSet<NotificationBuilder>();
78 private final Set<IdentitySchemaNodeBuilder> addedIdentities = new HashSet<IdentitySchemaNodeBuilder>();
79 private final Map<List<String>, FeatureBuilder> addedFeatures = new HashMap<List<String>, FeatureBuilder>();
80 private final Map<String, DeviationBuilder> addedDeviations = new HashMap<String, DeviationBuilder>();
81 private final Map<List<String>, TypeDefinitionBuilder> addedTypedefs = new HashMap<List<String>, TypeDefinitionBuilder>();
82 private final List<ExtensionBuilder> addedExtensions = new ArrayList<ExtensionBuilder>();
84 private final Map<List<String>, TypeAwareBuilder> dirtyNodes = new HashMap<List<String>, TypeAwareBuilder>();
86 public ModuleBuilder(final String name) {
88 instance = new ModuleImpl(name);
92 * Build new Module object based on this builder.
95 public Module build() {
96 instance.setImports(imports);
97 instance.setNamespace(namespace);
100 final Set<TypeDefinition<?>> typedefs = buildModuleTypedefs(addedTypedefs);
101 instance.setTypeDefinitions(typedefs);
104 final Map<QName, DataSchemaNode> childNodes = buildModuleChildNodes(addedChilds);
105 instance.setChildNodes(childNodes);
108 final Set<GroupingDefinition> groupings = buildModuleGroupings(addedGroupings);
109 instance.setGroupings(groupings);
112 final Set<UsesNode> usesDefinitions = buildUsesNodes(addedUsesNodes);
113 instance.setUses(usesDefinitions);
116 final Set<FeatureDefinition> features = buildModuleFeatures(addedFeatures);
117 instance.setFeatures(features);
120 final Set<NotificationDefinition> notifications = new HashSet<NotificationDefinition>();
121 for (NotificationBuilder entry : addedNotifications) {
122 notifications.add((NotificationDefinition) entry.build());
124 instance.setNotifications(notifications);
127 // instance.setAugmentations(augmentations);
128 final Set<AugmentationSchema> augmentations = new HashSet<AugmentationSchema>();
129 for (AugmentationSchemaBuilder builder : addedAugments) {
130 augmentations.add(builder.build());
132 instance.setAugmentations(augmentations);
135 final Set<RpcDefinition> rpcs = buildModuleRpcs(addedRpcs);
136 instance.setRpcs(rpcs);
139 final Set<Deviation> deviations = new HashSet<Deviation>();
140 for (Map.Entry<String, DeviationBuilder> entry : addedDeviations
142 deviations.add(entry.getValue().build());
144 instance.setDeviations(deviations);
147 final List<ExtensionDefinition> extensions = new ArrayList<ExtensionDefinition>();
148 for (ExtensionBuilder b : addedExtensions) {
149 extensions.add(b.build());
151 instance.setExtensionSchemaNodes(extensions);
154 final Set<IdentitySchemaNode> identities = new HashSet<IdentitySchemaNode>();
155 for (IdentitySchemaNodeBuilder idBuilder : addedIdentities) {
156 identities.add(idBuilder.build());
158 instance.setIdentities(identities);
163 public Builder getNode(final List<String> path) {
164 return moduleNodes.get(path);
167 public Set<DataSchemaNodeBuilder> getChildNodes() {
168 final Set<DataSchemaNodeBuilder> childNodes = new HashSet<DataSchemaNodeBuilder>();
169 for (Map.Entry<List<String>, DataSchemaNodeBuilder> entry : addedChilds
171 List<String> path = entry.getKey();
172 DataSchemaNodeBuilder child = entry.getValue();
173 if (path.size() == 2) {
174 childNodes.add(child);
180 public Map<List<String>, TypeAwareBuilder> getDirtyNodes() {
184 public Set<AugmentationSchemaBuilder> getAddedAugments() {
185 return addedAugments;
188 public Set<IdentitySchemaNodeBuilder> getAddedIdentities() {
189 return addedIdentities;
192 public Map<List<String>, UsesNodeBuilder> getAddedUsesNodes() {
193 return addedUsesNodes;
196 public Set<TypeDefinitionBuilder> getModuleTypedefs() {
197 Set<TypeDefinitionBuilder> typedefs = new HashSet<TypeDefinitionBuilder>();
198 for (Map.Entry<List<String>, TypeDefinitionBuilder> entry : addedTypedefs
200 if (entry.getKey().size() == 2) {
201 typedefs.add(entry.getValue());
207 public String getName() {
211 public URI getNamespace() {
215 public void setNamespace(final URI namespace) {
216 this.namespace = namespace;
219 public String getPrefix() {
223 public Date getRevision() {
227 public int getAugmentsResolved() {
228 return augmentsResolved;
231 public void augmentResolved() {
235 public void addDirtyNode(final List<String> path) {
236 final List<String> dirtyNodePath = new ArrayList<String>(path);
237 final TypeAwareBuilder nodeBuilder = (TypeAwareBuilder) moduleNodes
239 dirtyNodes.put(dirtyNodePath, nodeBuilder);
242 public void setRevision(final Date revision) {
243 this.revision = revision;
244 instance.setRevision(revision);
247 public void setPrefix(final String prefix) {
248 this.prefix = prefix;
249 instance.setPrefix(prefix);
252 public void setYangVersion(final String yangVersion) {
253 instance.setYangVersion(yangVersion);
256 public void setDescription(final String description) {
257 instance.setDescription(description);
260 public void setReference(final String reference) {
261 instance.setReference(reference);
264 public void setOrganization(final String organization) {
265 instance.setOrganization(organization);
268 public void setContact(final String contact) {
269 instance.setContact(contact);
272 public boolean addModuleImport(final String moduleName,
273 final Date revision, final String prefix) {
274 final ModuleImport moduleImport = createModuleImport(moduleName,
276 return imports.add(moduleImport);
279 public Set<ModuleImport> getModuleImports() {
283 public ExtensionBuilder addExtension(final QName qname) {
284 final ExtensionBuilder builder = new ExtensionBuilder(qname);
285 addedExtensions.add(builder);
289 public ContainerSchemaNodeBuilder addContainerNode(
290 final QName containerName, final List<String> parentPath) {
291 final List<String> pathToNode = new ArrayList<String>(parentPath);
293 final ContainerSchemaNodeBuilder containerBuilder = new ContainerSchemaNodeBuilder(
296 final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes
298 if (parent != null) {
299 if (parent instanceof AugmentationSchemaBuilder) {
300 containerBuilder.setAugmenting(true);
302 parent.addChildNode(containerBuilder);
305 pathToNode.add(containerName.getLocalName());
306 moduleNodes.put(pathToNode, containerBuilder);
307 addedChilds.put(pathToNode, containerBuilder);
309 return containerBuilder;
312 public ListSchemaNodeBuilder addListNode(final QName listName,
313 final List<String> parentPath) {
314 final List<String> pathToNode = new ArrayList<String>(parentPath);
316 final ListSchemaNodeBuilder listBuilder = new ListSchemaNodeBuilder(
319 final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes
321 if (parent != null) {
322 if (parent instanceof AugmentationSchemaBuilder) {
323 listBuilder.setAugmenting(true);
325 parent.addChildNode(listBuilder);
328 pathToNode.add(listName.getLocalName());
329 moduleNodes.put(pathToNode, listBuilder);
330 addedChilds.put(pathToNode, listBuilder);
335 public LeafSchemaNodeBuilder addLeafNode(final QName leafName,
336 final List<String> parentPath) {
337 final List<String> pathToNode = new ArrayList<String>(parentPath);
339 final LeafSchemaNodeBuilder leafBuilder = new LeafSchemaNodeBuilder(
342 final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes
344 if (parent != null) {
345 if (parent instanceof AugmentationSchemaBuilder) {
346 leafBuilder.setAugmenting(true);
348 parent.addChildNode(leafBuilder);
351 pathToNode.add(leafName.getLocalName());
352 addedChilds.put(pathToNode, leafBuilder);
353 moduleNodes.put(pathToNode, leafBuilder);
358 public LeafListSchemaNodeBuilder addLeafListNode(final QName leafListName,
359 final List<String> parentPath) {
360 final List<String> pathToNode = new ArrayList<String>(parentPath);
362 final LeafListSchemaNodeBuilder leafListBuilder = new LeafListSchemaNodeBuilder(
364 final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes
366 if (parent != null) {
367 if (parent instanceof AugmentationSchemaBuilder) {
368 leafListBuilder.setAugmenting(true);
370 parent.addChildNode(leafListBuilder);
373 pathToNode.add(leafListName.getLocalName());
374 addedChilds.put(pathToNode, leafListBuilder);
375 moduleNodes.put(pathToNode, leafListBuilder);
377 return leafListBuilder;
380 public GroupingBuilder addGrouping(final QName qname,
381 final List<String> parentPath) {
382 final List<String> pathToGroup = new ArrayList<String>(parentPath);
384 final GroupingBuilder builder = new GroupingBuilderImpl(qname);
385 final ChildNodeBuilder parentNodeBuilder = (ChildNodeBuilder) moduleNodes
387 if (parentNodeBuilder != null) {
388 parentNodeBuilder.addGrouping(builder);
391 pathToGroup.add("grouping");
392 pathToGroup.add(qname.getLocalName());
393 moduleNodes.put(pathToGroup, builder);
394 addedGroupings.put(pathToGroup, builder);
399 public AugmentationSchemaBuilder addAugment(final String name,
400 final List<String> parentPath) {
401 final List<String> pathToAugment = new ArrayList<String>(parentPath);
403 final AugmentationSchemaBuilder builder = new AugmentationSchemaBuilderImpl(
406 // augment can only be in 'module' or 'uses' statement
407 final UsesNodeBuilder parent = addedUsesNodes.get(pathToAugment);
408 if (parent != null) {
409 parent.addAugment(builder);
412 pathToAugment.add(name);
413 moduleNodes.put(pathToAugment, builder);
414 addedAugments.add(builder);
419 public UsesNodeBuilder addUsesNode(final String groupingPathStr,
420 final List<String> parentPath) {
421 final List<String> pathToUses = new ArrayList<String>(parentPath);
423 UsesNodeBuilder usesBuilder = new UsesNodeBuilderImpl(groupingPathStr);
425 ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes
427 if (parent != null) {
428 parent.addUsesNode(usesBuilder);
431 pathToUses.add(groupingPathStr);
432 addedUsesNodes.put(pathToUses, usesBuilder);
437 public RpcDefinitionBuilder addRpc(final QName qname,
438 final List<String> parentPath) {
439 List<String> pathToRpc = new ArrayList<String>(parentPath);
441 RpcDefinitionBuilder rpcBuilder = new RpcDefinitionBuilder(qname);
443 pathToRpc.add(qname.getLocalName());
444 addedRpcs.put(pathToRpc, rpcBuilder);
446 QName inputQName = new QName(qname.getNamespace(), qname.getRevision(),
447 qname.getPrefix(), "input");
448 ContainerSchemaNodeBuilder inputBuilder = new ContainerSchemaNodeBuilder(
450 List<String> pathToInput = new ArrayList<String>(pathToRpc);
451 pathToInput.add("input");
452 moduleNodes.put(pathToInput, inputBuilder);
453 rpcBuilder.setInput(inputBuilder);
455 QName outputQName = new QName(qname.getNamespace(),
456 qname.getRevision(), qname.getPrefix(), "output");
457 ContainerSchemaNodeBuilder outputBuilder = new ContainerSchemaNodeBuilder(
459 List<String> pathToOutput = new ArrayList<String>(pathToRpc);
460 pathToOutput.add("output");
461 moduleNodes.put(pathToOutput, outputBuilder);
462 rpcBuilder.setOutput(outputBuilder);
467 public NotificationBuilder addNotification(final QName notificationName,
468 final List<String> parentPath) {
469 final List<String> pathToNotification = new ArrayList<String>(
472 NotificationBuilder builder = new NotificationBuilder(notificationName);
474 pathToNotification.add(notificationName.getLocalName());
475 moduleNodes.put(pathToNotification, builder);
476 addedNotifications.add(builder);
481 public FeatureBuilder addFeature(final QName featureName,
482 final List<String> parentPath) {
483 List<String> pathToFeature = new ArrayList<String>(parentPath);
484 pathToFeature.add(featureName.getLocalName());
486 FeatureBuilder builder = new FeatureBuilder(featureName);
487 addedFeatures.put(pathToFeature, builder);
491 public ChoiceBuilder addChoice(final QName choiceName,
492 final List<String> parentPath) {
493 List<String> pathToChoice = new ArrayList<String>(parentPath);
494 ChoiceBuilder builder = new ChoiceBuilder(choiceName);
496 final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes
498 if (parent != null) {
499 if (parent instanceof AugmentationSchemaBuilder) {
500 builder.setAugmenting(true);
502 parent.addChildNode(builder);
505 pathToChoice.add(choiceName.getLocalName());
506 addedChilds.put(pathToChoice, builder);
507 moduleNodes.put(pathToChoice, builder);
512 public ChoiceCaseBuilder addCase(final QName caseName,
513 final List<String> parentPath) {
514 List<String> pathToCase = new ArrayList<String>(parentPath);
515 ChoiceCaseBuilder builder = new ChoiceCaseBuilder(caseName);
517 final ChoiceBuilder parent = (ChoiceBuilder) moduleNodes
519 if (parent != null) {
520 if (parent instanceof AugmentationSchemaBuilder) {
521 builder.setAugmenting(true);
523 parent.addChildNode(builder);
526 pathToCase.add(caseName.getLocalName());
527 addedChilds.put(pathToCase, builder);
528 moduleNodes.put(pathToCase, builder);
533 public AnyXmlBuilder addAnyXml(final QName anyXmlName,
534 final List<String> parentPath) {
535 List<String> pathToAnyXml = new ArrayList<String>(parentPath);
536 AnyXmlBuilder builder = new AnyXmlBuilder(anyXmlName);
538 final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes
540 if (parent != null) {
541 if (parent instanceof AugmentationSchemaBuilder) {
542 throw new UnsupportedOperationException(
543 "An anyxml node cannot be augmented.");
545 parent.addChildNode(builder);
548 pathToAnyXml.add(anyXmlName.getLocalName());
549 addedChilds.put(pathToAnyXml, builder);
550 moduleNodes.put(pathToAnyXml, builder);
555 public TypedefBuilder addTypedef(final QName typeDefName,
556 final List<String> parentPath) {
557 List<String> pathToType = new ArrayList<String>(parentPath);
558 TypedefBuilder builder = new TypedefBuilder(typeDefName);
559 TypeDefinitionAwareBuilder parent = (TypeDefinitionAwareBuilder) moduleNodes
561 if (parent != null) {
562 parent.addTypedef(builder);
564 pathToType.add(typeDefName.getLocalName());
565 addedTypedefs.put(pathToType, builder);
566 moduleNodes.put(pathToType, builder);
570 public void setType(TypeDefinition<?> type, List<String> parentPath) {
571 TypeAwareBuilder parent = (TypeAwareBuilder) moduleNodes
573 if (parent == null) {
574 throw new YangParseException("Failed to set type '"
575 + type.getQName().getLocalName()
576 + "'. Parent node not found.");
578 parent.setType(type);
581 public void addUnionType(List<String> parentPath) {
582 TypeAwareBuilder parent = (TypeAwareBuilder) moduleNodes
584 UnionTypeBuilder union = new UnionTypeBuilder();
585 parent.setType(union);
587 List<String> path = new ArrayList<String>(parentPath);
590 moduleNodes.put(path, union);
593 public void addIdentityrefType(String baseString, List<String> parentPath) {
594 TypeAwareBuilder parent = (TypeAwareBuilder) moduleNodes
596 IdentityrefTypeBuilder identityref = new IdentityrefTypeBuilder(baseString);
597 parent.setType(identityref);
598 dirtyNodes.put(parentPath, parent);
601 public DeviationBuilder addDeviation(String targetPath,
602 List<String> parentPath) {
603 final List<String> pathToDeviation = new ArrayList<String>(parentPath);
604 pathToDeviation.add(targetPath);
605 DeviationBuilder builder = new DeviationBuilder(targetPath);
606 addedDeviations.put(targetPath, builder);
607 moduleNodes.put(pathToDeviation, builder);
611 public IdentitySchemaNodeBuilder addIdentity(QName qname) {
612 IdentitySchemaNodeBuilder builder = new IdentitySchemaNodeBuilder(qname);
613 addedIdentities.add(builder);
617 public void addConfiguration(boolean configuration, List<String> parentPath) {
618 Builder builder = moduleNodes.get(parentPath);
619 // current api did not support adding config to deviate
620 if (!(builder instanceof DeviationBuilder)) {
621 DataSchemaNodeBuilder configBuilder = (DataSchemaNodeBuilder) moduleNodes
623 configBuilder.setConfiguration(configuration);
627 public UnknownSchemaNodeBuilder addUnknownSchemaNode(QName qname,
628 List<String> parentPath) {
629 final List<String> pathToUnknown = new ArrayList<String>(parentPath);
630 final UnknownSchemaNodeBuilder builder = new UnknownSchemaNodeBuilder(
633 final SchemaNodeBuilder parent = (SchemaNodeBuilder) moduleNodes
635 if (parent != null) {
636 parent.addUnknownSchemaNode(builder);
639 return new UnknownSchemaNodeBuilder(qname);
642 private class ModuleImpl implements Module {
643 private URI namespace;
644 private final String name;
645 private Date revision;
646 private String prefix;
647 private String yangVersion;
648 private String description;
649 private String reference;
650 private String organization;
651 private String contact;
652 private Set<ModuleImport> imports = Collections.emptySet();
653 private Set<FeatureDefinition> features = Collections.emptySet();
654 private Set<TypeDefinition<?>> typeDefinitions = Collections.emptySet();
655 private Set<NotificationDefinition> notifications = Collections
657 private Set<AugmentationSchema> augmentations = Collections.emptySet();
658 private Set<RpcDefinition> rpcs = Collections.emptySet();
659 private Set<Deviation> deviations = Collections.emptySet();
660 private Map<QName, DataSchemaNode> childNodes = Collections.emptyMap();
661 private Set<GroupingDefinition> groupings = Collections.emptySet();
662 private Set<UsesNode> uses = Collections.emptySet();
663 private List<ExtensionDefinition> extensionNodes = Collections
665 private Set<IdentitySchemaNode> identities = Collections.emptySet();
667 private ModuleImpl(String name) {
672 public URI getNamespace() {
676 private void setNamespace(URI namespace) {
677 this.namespace = namespace;
681 public String getName() {
686 public Date getRevision() {
690 private void setRevision(Date revision) {
691 this.revision = revision;
695 public String getPrefix() {
699 private void setPrefix(String prefix) {
700 this.prefix = prefix;
704 public String getYangVersion() {
708 private void setYangVersion(String yangVersion) {
709 this.yangVersion = yangVersion;
713 public String getDescription() {
717 private void setDescription(String description) {
718 this.description = description;
722 public String getReference() {
726 private void setReference(String reference) {
727 this.reference = reference;
731 public String getOrganization() {
735 private void setOrganization(String organization) {
736 this.organization = organization;
740 public String getContact() {
744 private void setContact(String contact) {
745 this.contact = contact;
749 public Set<ModuleImport> getImports() {
753 private void setImports(Set<ModuleImport> imports) {
754 if (imports != null) {
755 this.imports = imports;
760 public Set<FeatureDefinition> getFeatures() {
764 private void setFeatures(Set<FeatureDefinition> features) {
765 if (features != null) {
766 this.features = features;
771 public Set<TypeDefinition<?>> getTypeDefinitions() {
772 return typeDefinitions;
775 private void setTypeDefinitions(Set<TypeDefinition<?>> typeDefinitions) {
776 if (typeDefinitions != null) {
777 this.typeDefinitions = typeDefinitions;
782 public Set<NotificationDefinition> getNotifications() {
783 return notifications;
786 private void setNotifications(Set<NotificationDefinition> notifications) {
787 if (notifications != null) {
788 this.notifications = notifications;
793 public Set<AugmentationSchema> getAugmentations() {
794 return augmentations;
797 private void setAugmentations(Set<AugmentationSchema> augmentations) {
798 if (augmentations != null) {
799 this.augmentations = augmentations;
804 public Set<RpcDefinition> getRpcs() {
808 private void setRpcs(Set<RpcDefinition> rpcs) {
815 public Set<Deviation> getDeviations() {
819 private void setDeviations(Set<Deviation> deviations) {
820 if (deviations != null) {
821 this.deviations = deviations;
826 public Set<DataSchemaNode> getChildNodes() {
827 return new HashSet<DataSchemaNode>(childNodes.values());
830 private void setChildNodes(Map<QName, DataSchemaNode> childNodes) {
831 if (childNodes != null) {
832 this.childNodes = childNodes;
837 public Set<GroupingDefinition> getGroupings() {
841 private void setGroupings(Set<GroupingDefinition> groupings) {
842 if (groupings != null) {
843 this.groupings = groupings;
848 public Set<UsesNode> getUses() {
852 private void setUses(Set<UsesNode> uses) {
859 public List<ExtensionDefinition> getExtensionSchemaNodes() {
860 return extensionNodes;
863 private void setExtensionSchemaNodes(
864 List<ExtensionDefinition> extensionNodes) {
865 if (extensionNodes != null) {
866 this.extensionNodes = extensionNodes;
871 public Set<IdentitySchemaNode> getIdentities() {
875 private void setIdentities(Set<IdentitySchemaNode> identities) {
876 if (identities != null) {
877 this.identities = identities;
882 public DataSchemaNode getDataChildByName(QName name) {
883 return childNodes.get(name);
887 public DataSchemaNode getDataChildByName(String name) {
888 DataSchemaNode result = null;
889 for (Map.Entry<QName, DataSchemaNode> entry : childNodes.entrySet()) {
890 if (entry.getKey().getLocalName().equals(name)) {
891 result = entry.getValue();
899 public int hashCode() {
900 final int prime = 31;
902 result = prime * result
903 + ((namespace == null) ? 0 : namespace.hashCode());
904 result = prime * result + ((name == null) ? 0 : name.hashCode());
905 result = prime * result
906 + ((revision == null) ? 0 : revision.hashCode());
907 result = prime * result
908 + ((prefix == null) ? 0 : prefix.hashCode());
909 result = prime * result
910 + ((yangVersion == null) ? 0 : yangVersion.hashCode());
915 public boolean equals(Object obj) {
922 if (getClass() != obj.getClass()) {
925 ModuleImpl other = (ModuleImpl) obj;
926 if (namespace == null) {
927 if (other.namespace != null) {
930 } else if (!namespace.equals(other.namespace)) {
934 if (other.name != null) {
937 } else if (!name.equals(other.name)) {
940 if (revision == null) {
941 if (other.revision != null) {
944 } else if (!revision.equals(other.revision)) {
947 if (prefix == null) {
948 if (other.prefix != null) {
951 } else if (!prefix.equals(other.prefix)) {
954 if (yangVersion == null) {
955 if (other.yangVersion != null) {
958 } else if (!yangVersion.equals(other.yangVersion)) {
965 public String toString() {
966 StringBuilder sb = new StringBuilder(
967 ModuleImpl.class.getSimpleName());
969 sb.append("name=" + name + ",\n");
970 sb.append("namespace=" + namespace + ",\n");
971 sb.append("revision=" + revision + ",\n");
972 sb.append("prefix=" + prefix + ",\n");
973 sb.append("yangVersion=" + yangVersion + ",\n");
974 sb.append("description=" + description + ",\n");
975 sb.append("reference=" + reference + ",\n");
976 sb.append("organization=" + organization + ",\n");
977 sb.append("contact=" + contact + ",\n");
978 sb.append("childNodes=" + childNodes.values() + ",\n");
979 sb.append("groupings=" + groupings + ",\n");
980 sb.append("imports=" + imports + ",\n");
981 sb.append("features=" + features + ",\n");
982 sb.append("typeDefinitions=" + typeDefinitions + ",\n");
983 sb.append("notifications=" + notifications + ",\n");
984 sb.append("augmentations=" + augmentations + ",\n");
985 sb.append("rpcs=" + rpcs + ",\n");
986 sb.append("deviations=" + deviations + "\n");
987 sb.append("uses=" + uses + "\n");
989 return sb.toString();
993 private ModuleImport createModuleImport(final String moduleName,
994 final Date revision, final String prefix) {
995 ModuleImport moduleImport = new ModuleImport() {
997 public String getModuleName() {
1002 public Date getRevision() {
1007 public String getPrefix() {
1012 public int hashCode() {
1013 final int prime = 31;
1015 result = prime * result
1016 + ((moduleName == null) ? 0 : moduleName.hashCode());
1017 result = prime * result
1018 + ((revision == null) ? 0 : revision.hashCode());
1019 result = prime * result
1020 + ((prefix == null) ? 0 : prefix.hashCode());
1025 public boolean equals(Object obj) {
1032 if (getClass() != obj.getClass()) {
1035 ModuleImport other = (ModuleImport) obj;
1036 if (getModuleName() == null) {
1037 if (other.getModuleName() != null) {
1040 } else if (!getModuleName().equals(other.getModuleName())) {
1043 if (getRevision() == null) {
1044 if (other.getRevision() != null) {
1047 } else if (!getRevision().equals(other.getRevision())) {
1050 if (getPrefix() == null) {
1051 if (other.getPrefix() != null) {
1054 } else if (!getPrefix().equals(other.getPrefix())) {
1061 public String toString() {
1062 return "ModuleImport[moduleName=" + moduleName + ", revision="
1063 + revision + ", prefix=" + prefix + "]";
1066 return moduleImport;
1070 * Traverse through given addedChilds and add only direct module childs.
1071 * Direct module child path size is 2 (1. module name, 2. child name).
1073 * @param addedChilds
1074 * @return map of children, where key is child QName and value is child
1077 private Map<QName, DataSchemaNode> buildModuleChildNodes(
1078 Map<List<String>, DataSchemaNodeBuilder> addedChilds) {
1079 final Map<QName, DataSchemaNode> childNodes = new HashMap<QName, DataSchemaNode>();
1080 for (Map.Entry<List<String>, DataSchemaNodeBuilder> entry : addedChilds
1082 List<String> path = entry.getKey();
1083 DataSchemaNodeBuilder child = entry.getValue();
1084 if (path.size() == 2) {
1085 DataSchemaNode node = child.build();
1086 QName qname = node.getQName();
1087 childNodes.put(qname, node);
1094 * Traverse through given addedGroupings and add only direct module
1095 * groupings. Direct module grouping path size is 2 (1. module name, 2.
1098 * @param addedGroupings
1099 * @return set of built GroupingDefinition objects
1101 private Set<GroupingDefinition> buildModuleGroupings(
1102 Map<List<String>, GroupingBuilder> addedGroupings) {
1103 final Set<GroupingDefinition> groupings = new HashSet<GroupingDefinition>();
1104 for (Map.Entry<List<String>, GroupingBuilder> entry : addedGroupings
1106 if (entry.getKey().size() == 2) {
1107 groupings.add(entry.getValue().build());
1114 * Traverse through given addedRpcs and build RpcDefinition objects.
1117 * @return set of built RpcDefinition objects
1119 private Set<RpcDefinition> buildModuleRpcs(
1120 Map<List<String>, RpcDefinitionBuilder> addedRpcs) {
1121 final Set<RpcDefinition> rpcs = new HashSet<RpcDefinition>();
1122 RpcDefinitionBuilder builder;
1123 for (Map.Entry<List<String>, RpcDefinitionBuilder> entry : addedRpcs
1125 builder = entry.getValue();
1126 RpcDefinition rpc = builder.build();
1133 * Traverse through given addedTypedefs and add only direct module typedef
1134 * statements. Direct module typedef path size is 2 (1. module name, 2.
1137 * @param addedTypedefs
1138 * @return set of built module typedef statements
1140 private Set<TypeDefinition<?>> buildModuleTypedefs(
1141 Map<List<String>, TypeDefinitionBuilder> addedTypedefs) {
1142 Set<TypeDefinition<?>> typedefs = new HashSet<TypeDefinition<?>>();
1143 for (Map.Entry<List<String>, TypeDefinitionBuilder> entry : addedTypedefs
1145 List<String> key = entry.getKey();
1146 TypeDefinitionBuilder typedefBuilder = entry.getValue();
1147 if (key.size() == 2) {
1148 TypeDefinition<? extends TypeDefinition<?>> node = typedefBuilder
1157 * Traverse through given addedUsesNodes and add only direct module uses
1158 * nodes. Direct module uses node path size is 2 (1. module name, 2. uses
1161 * @param addedUsesNodes
1162 * @return set of built module uses nodes
1164 private Set<UsesNode> buildUsesNodes(
1165 Map<List<String>, UsesNodeBuilder> addedUsesNodes) {
1166 final Set<UsesNode> usesNodeDefs = new HashSet<UsesNode>();
1167 for (Map.Entry<List<String>, UsesNodeBuilder> entry : addedUsesNodes
1169 if (entry.getKey().size() == 2) {
1170 usesNodeDefs.add(entry.getValue().build());
1173 return usesNodeDefs;
1177 * Traverse through given addedFeatures and add only direct module features.
1178 * Direct module feature path size is 2 (1. module name, 2. feature name).
1180 * @param addedFeatures
1181 * @return set of built module features
1183 private Set<FeatureDefinition> buildModuleFeatures(
1184 Map<List<String>, FeatureBuilder> addedFeatures) {
1185 Set<FeatureDefinition> features = new HashSet<FeatureDefinition>();
1186 for (Map.Entry<List<String>, FeatureBuilder> entry : addedFeatures
1188 if (entry.getKey().size() == 2) {
1189 features.add(entry.getValue().build());