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.SchemaPath;
33 import org.opendaylight.controller.yang.model.api.TypeDefinition;
34 import org.opendaylight.controller.yang.model.api.UsesNode;
35 import org.opendaylight.controller.yang.model.parser.builder.api.AugmentationSchemaBuilder;
36 import org.opendaylight.controller.yang.model.parser.builder.api.Builder;
37 import org.opendaylight.controller.yang.model.parser.builder.api.ChildNodeBuilder;
38 import org.opendaylight.controller.yang.model.parser.builder.api.DataSchemaNodeBuilder;
39 import org.opendaylight.controller.yang.model.parser.builder.api.GroupingBuilder;
40 import org.opendaylight.controller.yang.model.parser.builder.api.SchemaNodeBuilder;
41 import org.opendaylight.controller.yang.model.parser.builder.api.TypeAwareBuilder;
42 import org.opendaylight.controller.yang.model.parser.builder.api.TypeDefinitionAwareBuilder;
43 import org.opendaylight.controller.yang.model.parser.builder.api.TypeDefinitionBuilder;
44 import org.opendaylight.controller.yang.model.parser.builder.api.UsesNodeBuilder;
45 import org.opendaylight.controller.yang.model.parser.util.RefineHolder;
46 import org.opendaylight.controller.yang.model.parser.util.YangParseException;
49 * This builder builds Module object. If this module is dependent on external
50 * module/modules, these dependencies must be resolved before module is built,
51 * otherwise result may not be valid.
53 public class ModuleBuilder implements Builder {
54 private final ModuleImpl instance;
55 private final String name;
56 private URI namespace;
57 private String prefix;
58 private Date revision;
60 private int augmentsResolved;
62 private final Set<ModuleImport> imports = new HashSet<ModuleImport>();
65 * All nodes, that can contain other nodes
67 private final Map<List<String>, Builder> moduleNodes = new HashMap<List<String>, Builder>();
70 * Holds all child (DataSchemaNode) nodes: anyxml, choice, case, container,
71 * list, leaf, leaf-list.
73 private final Map<List<String>, DataSchemaNodeBuilder> addedChilds = new HashMap<List<String>, DataSchemaNodeBuilder>();
75 private final Map<List<String>, GroupingBuilder> addedGroupings = new HashMap<List<String>, GroupingBuilder>();
76 private final Set<AugmentationSchemaBuilder> addedAugments = new HashSet<AugmentationSchemaBuilder>();
77 private final Map<List<String>, UsesNodeBuilder> addedUsesNodes = new HashMap<List<String>, UsesNodeBuilder>();
78 private final Map<List<String>, RpcDefinitionBuilder> addedRpcs = new HashMap<List<String>, RpcDefinitionBuilder>();
79 private final Set<NotificationBuilder> addedNotifications = new HashSet<NotificationBuilder>();
80 private final Set<IdentitySchemaNodeBuilder> addedIdentities = new HashSet<IdentitySchemaNodeBuilder>();
81 private final Map<List<String>, FeatureBuilder> addedFeatures = new HashMap<List<String>, FeatureBuilder>();
82 private final Map<String, DeviationBuilder> addedDeviations = new HashMap<String, DeviationBuilder>();
83 private final Map<List<String>, TypeDefinitionBuilder> addedTypedefs = new HashMap<List<String>, TypeDefinitionBuilder>();
84 private final List<ExtensionBuilder> addedExtensions = new ArrayList<ExtensionBuilder>();
85 private final Set<UnknownSchemaNodeBuilder> addedUnknownNodes = new HashSet<UnknownSchemaNodeBuilder>();
87 private final Map<List<String>, TypeAwareBuilder> dirtyNodes = new HashMap<List<String>, TypeAwareBuilder>();
89 public ModuleBuilder(final String name) {
91 instance = new ModuleImpl(name);
95 * Build new Module object based on this builder.
98 public Module build() {
99 instance.setImports(imports);
100 instance.setNamespace(namespace);
103 final Set<TypeDefinition<?>> typedefs = buildModuleTypedefs(addedTypedefs);
104 instance.setTypeDefinitions(typedefs);
107 final Map<QName, DataSchemaNode> childNodes = buildModuleChildNodes(addedChilds);
108 instance.setChildNodes(childNodes);
111 final Set<GroupingDefinition> groupings = buildModuleGroupings(addedGroupings);
112 instance.setGroupings(groupings);
115 final Set<UsesNode> usesDefinitions = buildUsesNodes(addedUsesNodes);
116 instance.setUses(usesDefinitions);
119 final Set<FeatureDefinition> features = buildModuleFeatures(addedFeatures);
120 instance.setFeatures(features);
123 final Set<NotificationDefinition> notifications = new HashSet<NotificationDefinition>();
124 for (NotificationBuilder entry : addedNotifications) {
125 notifications.add((NotificationDefinition) entry.build());
127 instance.setNotifications(notifications);
130 final Set<AugmentationSchema> augmentations = new HashSet<AugmentationSchema>();
131 for (AugmentationSchemaBuilder builder : addedAugments) {
132 augmentations.add(builder.build());
134 instance.setAugmentations(augmentations);
137 final Set<RpcDefinition> rpcs = buildModuleRpcs(addedRpcs);
138 instance.setRpcs(rpcs);
141 final Set<Deviation> deviations = new HashSet<Deviation>();
142 for (Map.Entry<String, DeviationBuilder> entry : addedDeviations
144 deviations.add(entry.getValue().build());
146 instance.setDeviations(deviations);
149 final List<ExtensionDefinition> extensions = new ArrayList<ExtensionDefinition>();
150 for (ExtensionBuilder b : addedExtensions) {
151 extensions.add(b.build());
153 instance.setExtensionSchemaNodes(extensions);
156 final Set<IdentitySchemaNode> identities = new HashSet<IdentitySchemaNode>();
157 for (IdentitySchemaNodeBuilder idBuilder : addedIdentities) {
158 identities.add(idBuilder.build());
160 instance.setIdentities(identities);
165 public Builder getNode(final List<String> path) {
166 return moduleNodes.get(path);
169 public Set<DataSchemaNodeBuilder> getChildNodes() {
170 final Set<DataSchemaNodeBuilder> childNodes = new HashSet<DataSchemaNodeBuilder>();
171 for (Map.Entry<List<String>, DataSchemaNodeBuilder> entry : addedChilds
173 List<String> path = entry.getKey();
174 DataSchemaNodeBuilder child = entry.getValue();
175 if (path.size() == 2) {
176 childNodes.add(child);
182 public Map<List<String>, TypeAwareBuilder> getDirtyNodes() {
186 public Set<AugmentationSchemaBuilder> getAddedAugments() {
187 return addedAugments;
190 public Set<IdentitySchemaNodeBuilder> getAddedIdentities() {
191 return addedIdentities;
194 public Map<List<String>, UsesNodeBuilder> getAddedUsesNodes() {
195 return addedUsesNodes;
198 public Set<UnknownSchemaNodeBuilder> getAddedUnknownNodes() {
199 return addedUnknownNodes;
202 public Set<TypeDefinitionBuilder> getModuleTypedefs() {
203 Set<TypeDefinitionBuilder> typedefs = new HashSet<TypeDefinitionBuilder>();
204 for (Map.Entry<List<String>, TypeDefinitionBuilder> entry : addedTypedefs
206 if (entry.getKey().size() == 2) {
207 typedefs.add(entry.getValue());
213 public String getName() {
217 public URI getNamespace() {
221 public void setNamespace(final URI namespace) {
222 this.namespace = namespace;
225 public String getPrefix() {
229 public Date getRevision() {
233 public int getAugmentsResolved() {
234 return augmentsResolved;
237 public void augmentResolved() {
241 public void addDirtyNode(final List<String> path) {
242 final List<String> dirtyNodePath = new ArrayList<String>(path);
243 final TypeAwareBuilder nodeBuilder = (TypeAwareBuilder) moduleNodes
245 dirtyNodes.put(dirtyNodePath, nodeBuilder);
248 public void setRevision(final Date revision) {
249 this.revision = revision;
250 instance.setRevision(revision);
253 public void setPrefix(final String prefix) {
254 this.prefix = prefix;
255 instance.setPrefix(prefix);
258 public void setYangVersion(final String yangVersion) {
259 instance.setYangVersion(yangVersion);
262 public void setDescription(final String description) {
263 instance.setDescription(description);
266 public void setReference(final String reference) {
267 instance.setReference(reference);
270 public void setOrganization(final String organization) {
271 instance.setOrganization(organization);
274 public void setContact(final String contact) {
275 instance.setContact(contact);
278 public boolean addModuleImport(final String moduleName,
279 final Date revision, final String prefix) {
280 final ModuleImport moduleImport = createModuleImport(moduleName,
282 return imports.add(moduleImport);
285 public Set<ModuleImport> getModuleImports() {
289 public ExtensionBuilder addExtension(final QName qname) {
290 final ExtensionBuilder builder = new ExtensionBuilder(qname);
291 addedExtensions.add(builder);
295 public ContainerSchemaNodeBuilder addContainerNode(
296 final QName containerName, final List<String> parentPath) {
297 final List<String> pathToNode = new ArrayList<String>(parentPath);
299 final ContainerSchemaNodeBuilder containerBuilder = new ContainerSchemaNodeBuilder(
302 final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes
304 if (parent != null) {
305 if (parent instanceof AugmentationSchemaBuilder) {
306 containerBuilder.setAugmenting(true);
308 parent.addChildNode(containerBuilder);
311 pathToNode.add(containerName.getLocalName());
312 moduleNodes.put(pathToNode, containerBuilder);
313 addedChilds.put(pathToNode, containerBuilder);
315 return containerBuilder;
318 public ListSchemaNodeBuilder addListNode(final QName listName,
319 final List<String> parentPath) {
320 final List<String> pathToNode = new ArrayList<String>(parentPath);
322 final ListSchemaNodeBuilder listBuilder = new ListSchemaNodeBuilder(
325 final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes
327 if (parent != null) {
328 if (parent instanceof AugmentationSchemaBuilder) {
329 listBuilder.setAugmenting(true);
331 parent.addChildNode(listBuilder);
334 pathToNode.add(listName.getLocalName());
335 moduleNodes.put(pathToNode, listBuilder);
336 addedChilds.put(pathToNode, listBuilder);
341 public LeafSchemaNodeBuilder addLeafNode(final QName leafName,
342 final List<String> parentPath) {
343 final List<String> pathToNode = new ArrayList<String>(parentPath);
345 final LeafSchemaNodeBuilder leafBuilder = new LeafSchemaNodeBuilder(
348 final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes
350 if (parent != null) {
351 if (parent instanceof AugmentationSchemaBuilder) {
352 leafBuilder.setAugmenting(true);
354 parent.addChildNode(leafBuilder);
357 pathToNode.add(leafName.getLocalName());
358 addedChilds.put(pathToNode, leafBuilder);
359 moduleNodes.put(pathToNode, leafBuilder);
364 public LeafListSchemaNodeBuilder addLeafListNode(final QName leafListName,
365 final List<String> parentPath) {
366 final List<String> pathToNode = new ArrayList<String>(parentPath);
368 final LeafListSchemaNodeBuilder leafListBuilder = new LeafListSchemaNodeBuilder(
370 final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes
372 if (parent != null) {
373 if (parent instanceof AugmentationSchemaBuilder) {
374 leafListBuilder.setAugmenting(true);
376 parent.addChildNode(leafListBuilder);
379 pathToNode.add(leafListName.getLocalName());
380 addedChilds.put(pathToNode, leafListBuilder);
381 moduleNodes.put(pathToNode, leafListBuilder);
383 return leafListBuilder;
386 public GroupingBuilder addGrouping(final QName qname,
387 final List<String> parentPath) {
388 final List<String> pathToGroup = new ArrayList<String>(parentPath);
390 final GroupingBuilder builder = new GroupingBuilderImpl(qname);
391 final ChildNodeBuilder parentNodeBuilder = (ChildNodeBuilder) moduleNodes
393 if (parentNodeBuilder != null) {
394 parentNodeBuilder.addGrouping(builder);
397 pathToGroup.add("grouping");
398 pathToGroup.add(qname.getLocalName());
399 moduleNodes.put(pathToGroup, builder);
400 addedGroupings.put(pathToGroup, builder);
405 public AugmentationSchemaBuilder addAugment(final String name,
406 final List<String> parentPath) {
407 final List<String> pathToAugment = new ArrayList<String>(parentPath);
409 final AugmentationSchemaBuilder builder = new AugmentationSchemaBuilderImpl(
412 // augment can only be in 'module' or 'uses' statement
413 final UsesNodeBuilder parent = addedUsesNodes.get(pathToAugment);
414 if (parent != null) {
415 parent.addAugment(builder);
418 pathToAugment.add(name);
419 moduleNodes.put(pathToAugment, builder);
420 addedAugments.add(builder);
425 public UsesNodeBuilder addUsesNode(final String groupingPathStr,
426 final List<String> parentPath) {
427 final List<String> pathToUses = new ArrayList<String>(parentPath);
428 final UsesNodeBuilder usesBuilder = new UsesNodeBuilderImpl(
430 final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes
432 if (parent != null) {
433 parent.addUsesNode(usesBuilder);
436 pathToUses.add(groupingPathStr);
437 addedUsesNodes.put(pathToUses, usesBuilder);
438 moduleNodes.put(pathToUses, usesBuilder);
442 public void addRefine(final RefineHolder refine,
443 final List<String> parentPath) {
444 final List<String> path = new ArrayList<String>(parentPath);
445 final Builder parent = moduleNodes.get(path);
446 if (!(parent instanceof UsesNodeBuilder)) {
447 throw new YangParseException("Failed to parse refine "
450 UsesNodeBuilder usesBuilder = (UsesNodeBuilder) parent;
451 usesBuilder.addRefine(refine);
452 path.add(refine.getName());
453 moduleNodes.put(path, refine);
456 public RpcDefinitionBuilder addRpc(final QName qname,
457 final List<String> parentPath) {
458 final List<String> pathToRpc = new ArrayList<String>(parentPath);
459 final RpcDefinitionBuilder rpcBuilder = new RpcDefinitionBuilder(qname);
461 pathToRpc.add(qname.getLocalName());
462 addedRpcs.put(pathToRpc, rpcBuilder);
464 final QName inputQName = new QName(qname.getNamespace(),
465 qname.getRevision(), qname.getPrefix(), "input");
466 final ContainerSchemaNodeBuilder inputBuilder = new ContainerSchemaNodeBuilder(
468 final List<String> pathToInput = new ArrayList<String>(pathToRpc);
469 pathToInput.add("input");
470 moduleNodes.put(pathToInput, inputBuilder);
471 rpcBuilder.setInput(inputBuilder);
473 final QName outputQName = new QName(qname.getNamespace(),
474 qname.getRevision(), qname.getPrefix(), "output");
475 final ContainerSchemaNodeBuilder outputBuilder = new ContainerSchemaNodeBuilder(
477 final List<String> pathToOutput = new ArrayList<String>(pathToRpc);
478 pathToOutput.add("output");
479 moduleNodes.put(pathToOutput, outputBuilder);
480 rpcBuilder.setOutput(outputBuilder);
485 public NotificationBuilder addNotification(final QName notificationName,
486 final List<String> parentPath) {
487 final List<String> pathToNotification = new ArrayList<String>(
490 NotificationBuilder builder = new NotificationBuilder(notificationName);
492 pathToNotification.add(notificationName.getLocalName());
493 moduleNodes.put(pathToNotification, builder);
494 addedNotifications.add(builder);
499 public FeatureBuilder addFeature(final QName featureName,
500 final List<String> parentPath) {
501 List<String> pathToFeature = new ArrayList<String>(parentPath);
502 pathToFeature.add(featureName.getLocalName());
504 FeatureBuilder builder = new FeatureBuilder(featureName);
505 addedFeatures.put(pathToFeature, builder);
509 public ChoiceBuilder addChoice(final QName choiceName,
510 final List<String> parentPath) {
511 List<String> pathToChoice = new ArrayList<String>(parentPath);
512 ChoiceBuilder builder = new ChoiceBuilder(choiceName);
514 final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes
516 if (parent != null) {
517 if (parent instanceof AugmentationSchemaBuilder) {
518 builder.setAugmenting(true);
520 parent.addChildNode(builder);
523 pathToChoice.add(choiceName.getLocalName());
524 addedChilds.put(pathToChoice, builder);
525 moduleNodes.put(pathToChoice, builder);
530 public ChoiceCaseBuilder addCase(final QName caseName,
531 final List<String> parentPath) {
532 List<String> pathToCase = new ArrayList<String>(parentPath);
533 ChoiceCaseBuilder builder = new ChoiceCaseBuilder(caseName);
535 final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes
537 if (parent != null) {
538 if (parent instanceof AugmentationSchemaBuilder) {
539 builder.setAugmenting(true);
541 parent.addChildNode(builder);
544 pathToCase.add(caseName.getLocalName());
545 moduleNodes.put(pathToCase, builder);
550 public AnyXmlBuilder addAnyXml(final QName anyXmlName,
551 final List<String> parentPath) {
552 List<String> pathToAnyXml = new ArrayList<String>(parentPath);
553 AnyXmlBuilder builder = new AnyXmlBuilder(anyXmlName);
555 final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes
557 if (parent != null) {
558 if (parent instanceof AugmentationSchemaBuilder) {
559 throw new UnsupportedOperationException(
560 "An anyxml node cannot be augmented.");
562 parent.addChildNode(builder);
565 pathToAnyXml.add(anyXmlName.getLocalName());
566 addedChilds.put(pathToAnyXml, builder);
567 moduleNodes.put(pathToAnyXml, builder);
572 public TypedefBuilder addTypedef(final QName typeDefName,
573 final List<String> parentPath) {
574 List<String> pathToType = new ArrayList<String>(parentPath);
575 TypedefBuilder builder = new TypedefBuilder(typeDefName);
576 TypeDefinitionAwareBuilder parent = (TypeDefinitionAwareBuilder) moduleNodes
578 if (parent != null) {
579 parent.addTypedef(builder);
581 pathToType.add(typeDefName.getLocalName());
582 addedTypedefs.put(pathToType, builder);
583 moduleNodes.put(pathToType, builder);
587 public void setType(TypeDefinition<?> type, List<String> parentPath) {
588 TypeAwareBuilder parent = (TypeAwareBuilder) moduleNodes
590 if (parent == null) {
591 throw new YangParseException("Failed to set type '"
592 + type.getQName().getLocalName()
593 + "'. Parent node not found.");
595 parent.setType(type);
598 public void addUnionType(final List<String> actualPath,
599 final URI namespace, final Date revision) {
600 List<String> pathToUnion = new ArrayList<String>(actualPath);
601 TypeAwareBuilder parent = (TypeAwareBuilder) moduleNodes
603 UnionTypeBuilder union = new UnionTypeBuilder(pathToUnion, namespace,
605 parent.setType(union);
607 List<String> path = new ArrayList<String>(pathToUnion);
610 moduleNodes.put(path, union);
613 public void addIdentityrefType(String baseString, List<String> parentPath,
614 SchemaPath schemaPath) {
615 List<String> pathToIdentityref = new ArrayList<String>(parentPath);
616 TypeAwareBuilder parent = (TypeAwareBuilder) moduleNodes
617 .get(pathToIdentityref);
618 IdentityrefTypeBuilder identityref = new IdentityrefTypeBuilder(
619 baseString, schemaPath);
620 parent.setType(identityref);
621 dirtyNodes.put(pathToIdentityref, parent);
624 public DeviationBuilder addDeviation(String targetPath,
625 List<String> parentPath) {
626 final List<String> pathToDeviation = new ArrayList<String>(parentPath);
627 pathToDeviation.add(targetPath);
628 DeviationBuilder builder = new DeviationBuilder(targetPath);
629 addedDeviations.put(targetPath, builder);
630 moduleNodes.put(pathToDeviation, builder);
634 public IdentitySchemaNodeBuilder addIdentity(QName qname,
635 List<String> parentPath) {
636 List<String> pathToIdentity = new ArrayList<String>(parentPath);
637 IdentitySchemaNodeBuilder builder = new IdentitySchemaNodeBuilder(qname);
638 pathToIdentity.add(qname.getLocalName());
639 moduleNodes.put(pathToIdentity, builder);
640 addedIdentities.add(builder);
644 public void addConfiguration(boolean configuration, List<String> parentPath) {
645 Builder builder = moduleNodes.get(parentPath);
646 // current api did not support adding config to deviate
647 if (!(builder instanceof DeviationBuilder)) {
648 DataSchemaNodeBuilder configBuilder = (DataSchemaNodeBuilder) moduleNodes
650 configBuilder.setConfiguration(configuration);
654 public UnknownSchemaNodeBuilder addUnknownSchemaNode(QName qname,
655 List<String> parentPath) {
656 final List<String> pathToUnknown = new ArrayList<String>(parentPath);
657 final UnknownSchemaNodeBuilder builder = new UnknownSchemaNodeBuilder(
659 final Builder parent = moduleNodes.get(pathToUnknown);
660 if (parent instanceof RefineHolder) {
661 ((RefineHolder) parent).addUnknownSchemaNode(builder);
662 } else if (parent instanceof SchemaNodeBuilder) {
663 ((SchemaNodeBuilder) parent).addUnknownSchemaNode(builder);
665 addedUnknownNodes.add(builder);
669 private class ModuleImpl implements Module {
670 private URI namespace;
671 private final String name;
672 private Date revision;
673 private String prefix;
674 private String yangVersion;
675 private String description;
676 private String reference;
677 private String organization;
678 private String contact;
679 private Set<ModuleImport> imports = Collections.emptySet();
680 private Set<FeatureDefinition> features = Collections.emptySet();
681 private Set<TypeDefinition<?>> typeDefinitions = Collections.emptySet();
682 private Set<NotificationDefinition> notifications = Collections
684 private Set<AugmentationSchema> augmentations = Collections.emptySet();
685 private Set<RpcDefinition> rpcs = Collections.emptySet();
686 private Set<Deviation> deviations = Collections.emptySet();
687 private Map<QName, DataSchemaNode> childNodes = Collections.emptyMap();
688 private Set<GroupingDefinition> groupings = Collections.emptySet();
689 private Set<UsesNode> uses = Collections.emptySet();
690 private List<ExtensionDefinition> extensionNodes = Collections
692 private Set<IdentitySchemaNode> identities = Collections.emptySet();
694 private ModuleImpl(String name) {
699 public URI getNamespace() {
703 private void setNamespace(URI namespace) {
704 this.namespace = namespace;
708 public String getName() {
713 public Date getRevision() {
717 private void setRevision(Date revision) {
718 this.revision = revision;
722 public String getPrefix() {
726 private void setPrefix(String prefix) {
727 this.prefix = prefix;
731 public String getYangVersion() {
735 private void setYangVersion(String yangVersion) {
736 this.yangVersion = yangVersion;
740 public String getDescription() {
744 private void setDescription(String description) {
745 this.description = description;
749 public String getReference() {
753 private void setReference(String reference) {
754 this.reference = reference;
758 public String getOrganization() {
762 private void setOrganization(String organization) {
763 this.organization = organization;
767 public String getContact() {
771 private void setContact(String contact) {
772 this.contact = contact;
776 public Set<ModuleImport> getImports() {
780 private void setImports(Set<ModuleImport> imports) {
781 if (imports != null) {
782 this.imports = imports;
787 public Set<FeatureDefinition> getFeatures() {
791 private void setFeatures(Set<FeatureDefinition> features) {
792 if (features != null) {
793 this.features = features;
798 public Set<TypeDefinition<?>> getTypeDefinitions() {
799 return typeDefinitions;
802 private void setTypeDefinitions(Set<TypeDefinition<?>> typeDefinitions) {
803 if (typeDefinitions != null) {
804 this.typeDefinitions = typeDefinitions;
809 public Set<NotificationDefinition> getNotifications() {
810 return notifications;
813 private void setNotifications(Set<NotificationDefinition> notifications) {
814 if (notifications != null) {
815 this.notifications = notifications;
820 public Set<AugmentationSchema> getAugmentations() {
821 return augmentations;
824 private void setAugmentations(Set<AugmentationSchema> augmentations) {
825 if (augmentations != null) {
826 this.augmentations = augmentations;
831 public Set<RpcDefinition> getRpcs() {
835 private void setRpcs(Set<RpcDefinition> rpcs) {
842 public Set<Deviation> getDeviations() {
846 private void setDeviations(Set<Deviation> deviations) {
847 if (deviations != null) {
848 this.deviations = deviations;
853 public Set<DataSchemaNode> getChildNodes() {
854 return new HashSet<DataSchemaNode>(childNodes.values());
857 private void setChildNodes(Map<QName, DataSchemaNode> childNodes) {
858 if (childNodes != null) {
859 this.childNodes = childNodes;
864 public Set<GroupingDefinition> getGroupings() {
868 private void setGroupings(Set<GroupingDefinition> groupings) {
869 if (groupings != null) {
870 this.groupings = groupings;
875 public Set<UsesNode> getUses() {
879 private void setUses(Set<UsesNode> uses) {
886 public List<ExtensionDefinition> getExtensionSchemaNodes() {
887 return extensionNodes;
890 private void setExtensionSchemaNodes(
891 List<ExtensionDefinition> extensionNodes) {
892 if (extensionNodes != null) {
893 this.extensionNodes = extensionNodes;
898 public Set<IdentitySchemaNode> getIdentities() {
902 private void setIdentities(Set<IdentitySchemaNode> identities) {
903 if (identities != null) {
904 this.identities = identities;
909 public DataSchemaNode getDataChildByName(QName name) {
910 return childNodes.get(name);
914 public DataSchemaNode getDataChildByName(String name) {
915 DataSchemaNode result = null;
916 for (Map.Entry<QName, DataSchemaNode> entry : childNodes.entrySet()) {
917 if (entry.getKey().getLocalName().equals(name)) {
918 result = entry.getValue();
926 public int hashCode() {
927 final int prime = 31;
929 result = prime * result
930 + ((namespace == null) ? 0 : namespace.hashCode());
931 result = prime * result + ((name == null) ? 0 : name.hashCode());
932 result = prime * result
933 + ((revision == null) ? 0 : revision.hashCode());
934 result = prime * result
935 + ((prefix == null) ? 0 : prefix.hashCode());
936 result = prime * result
937 + ((yangVersion == null) ? 0 : yangVersion.hashCode());
942 public boolean equals(Object obj) {
949 if (getClass() != obj.getClass()) {
952 ModuleImpl other = (ModuleImpl) obj;
953 if (namespace == null) {
954 if (other.namespace != null) {
957 } else if (!namespace.equals(other.namespace)) {
961 if (other.name != null) {
964 } else if (!name.equals(other.name)) {
967 if (revision == null) {
968 if (other.revision != null) {
971 } else if (!revision.equals(other.revision)) {
974 if (prefix == null) {
975 if (other.prefix != null) {
978 } else if (!prefix.equals(other.prefix)) {
981 if (yangVersion == null) {
982 if (other.yangVersion != null) {
985 } else if (!yangVersion.equals(other.yangVersion)) {
992 public String toString() {
993 StringBuilder sb = new StringBuilder(
994 ModuleImpl.class.getSimpleName());
996 sb.append("name=" + name + ",\n");
997 sb.append("namespace=" + namespace + ",\n");
998 sb.append("revision=" + revision + ",\n");
999 sb.append("prefix=" + prefix + ",\n");
1000 sb.append("yangVersion=" + yangVersion + ",\n");
1001 sb.append("description=" + description + ",\n");
1002 sb.append("reference=" + reference + ",\n");
1003 sb.append("organization=" + organization + ",\n");
1004 sb.append("contact=" + contact + ",\n");
1005 sb.append("childNodes=" + childNodes.values() + ",\n");
1006 sb.append("groupings=" + groupings + ",\n");
1007 sb.append("imports=" + imports + ",\n");
1008 sb.append("features=" + features + ",\n");
1009 sb.append("typeDefinitions=" + typeDefinitions + ",\n");
1010 sb.append("notifications=" + notifications + ",\n");
1011 sb.append("augmentations=" + augmentations + ",\n");
1012 sb.append("rpcs=" + rpcs + ",\n");
1013 sb.append("deviations=" + deviations + "\n");
1014 sb.append("uses=" + uses + "\n");
1016 return sb.toString();
1020 private ModuleImport createModuleImport(final String moduleName,
1021 final Date revision, final String prefix) {
1022 ModuleImport moduleImport = new ModuleImport() {
1024 public String getModuleName() {
1029 public Date getRevision() {
1034 public String getPrefix() {
1039 public int hashCode() {
1040 final int prime = 31;
1042 result = prime * result
1043 + ((moduleName == null) ? 0 : moduleName.hashCode());
1044 result = prime * result
1045 + ((revision == null) ? 0 : revision.hashCode());
1046 result = prime * result
1047 + ((prefix == null) ? 0 : prefix.hashCode());
1052 public boolean equals(Object obj) {
1059 if (getClass() != obj.getClass()) {
1062 ModuleImport other = (ModuleImport) obj;
1063 if (getModuleName() == null) {
1064 if (other.getModuleName() != null) {
1067 } else if (!getModuleName().equals(other.getModuleName())) {
1070 if (getRevision() == null) {
1071 if (other.getRevision() != null) {
1074 } else if (!getRevision().equals(other.getRevision())) {
1077 if (getPrefix() == null) {
1078 if (other.getPrefix() != null) {
1081 } else if (!getPrefix().equals(other.getPrefix())) {
1088 public String toString() {
1089 return "ModuleImport[moduleName=" + moduleName + ", revision="
1090 + revision + ", prefix=" + prefix + "]";
1093 return moduleImport;
1097 * Traverse through given addedChilds and add only direct module childs.
1098 * Direct module child path size is 2 (1. module name, 2. child name).
1100 * @param addedChilds
1101 * @return map of children, where key is child QName and value is child
1104 private Map<QName, DataSchemaNode> buildModuleChildNodes(
1105 Map<List<String>, DataSchemaNodeBuilder> addedChilds) {
1106 final Map<QName, DataSchemaNode> childNodes = new HashMap<QName, DataSchemaNode>();
1107 for (Map.Entry<List<String>, DataSchemaNodeBuilder> entry : addedChilds
1109 List<String> path = entry.getKey();
1110 DataSchemaNodeBuilder child = entry.getValue();
1111 if (path.size() == 2) {
1112 DataSchemaNode node = child.build();
1113 QName qname = node.getQName();
1114 childNodes.put(qname, node);
1121 * Traverse through given addedGroupings and add only direct module
1122 * groupings. Direct module grouping path size is 2 (1. module name, 2.
1125 * @param addedGroupings
1126 * @return set of built GroupingDefinition objects
1128 private Set<GroupingDefinition> buildModuleGroupings(
1129 Map<List<String>, GroupingBuilder> addedGroupings) {
1130 final Set<GroupingDefinition> groupings = new HashSet<GroupingDefinition>();
1131 for (Map.Entry<List<String>, GroupingBuilder> entry : addedGroupings
1133 if (entry.getKey().size() == 2) {
1134 groupings.add(entry.getValue().build());
1141 * Traverse through given addedRpcs and build RpcDefinition objects.
1144 * @return set of built RpcDefinition objects
1146 private Set<RpcDefinition> buildModuleRpcs(
1147 Map<List<String>, RpcDefinitionBuilder> addedRpcs) {
1148 final Set<RpcDefinition> rpcs = new HashSet<RpcDefinition>();
1149 RpcDefinitionBuilder builder;
1150 for (Map.Entry<List<String>, RpcDefinitionBuilder> entry : addedRpcs
1152 builder = entry.getValue();
1153 RpcDefinition rpc = builder.build();
1160 * Traverse through given addedTypedefs and add only direct module typedef
1161 * statements. Direct module typedef path size is 2 (1. module name, 2.
1164 * @param addedTypedefs
1165 * @return set of built module typedef statements
1167 private Set<TypeDefinition<?>> buildModuleTypedefs(
1168 Map<List<String>, TypeDefinitionBuilder> addedTypedefs) {
1169 Set<TypeDefinition<?>> typedefs = new HashSet<TypeDefinition<?>>();
1170 for (Map.Entry<List<String>, TypeDefinitionBuilder> entry : addedTypedefs
1172 List<String> key = entry.getKey();
1173 TypeDefinitionBuilder typedefBuilder = entry.getValue();
1174 if (key.size() == 2) {
1175 TypeDefinition<? extends TypeDefinition<?>> node = typedefBuilder
1184 * Traverse through given addedUsesNodes and add only direct module uses
1185 * nodes. Direct module uses node path size is 2 (1. module name, 2. uses
1188 * @param addedUsesNodes
1189 * @return set of built module uses nodes
1191 private Set<UsesNode> buildUsesNodes(
1192 Map<List<String>, UsesNodeBuilder> addedUsesNodes) {
1193 final Set<UsesNode> usesNodeDefs = new HashSet<UsesNode>();
1194 for (Map.Entry<List<String>, UsesNodeBuilder> entry : addedUsesNodes
1196 if (entry.getKey().size() == 2) {
1197 usesNodeDefs.add(entry.getValue().build());
1200 return usesNodeDefs;
1204 * Traverse through given addedFeatures and add only direct module features.
1205 * Direct module feature path size is 2 (1. module name, 2. feature name).
1207 * @param addedFeatures
1208 * @return set of built module features
1210 private Set<FeatureDefinition> buildModuleFeatures(
1211 Map<List<String>, FeatureBuilder> addedFeatures) {
1212 Set<FeatureDefinition> features = new HashSet<FeatureDefinition>();
1213 for (Map.Entry<List<String>, FeatureBuilder> entry : addedFeatures
1215 if (entry.getKey().size() == 2) {
1216 features.add(entry.getValue().build());