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.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.parser.builder.api.AugmentationSchemaBuilder;
36 import org.opendaylight.controller.yang.parser.builder.api.Builder;
37 import org.opendaylight.controller.yang.parser.builder.api.ChildNodeBuilder;
38 import org.opendaylight.controller.yang.parser.builder.api.DataSchemaNodeBuilder;
39 import org.opendaylight.controller.yang.parser.builder.api.GroupingBuilder;
40 import org.opendaylight.controller.yang.parser.builder.api.SchemaNodeBuilder;
41 import org.opendaylight.controller.yang.parser.builder.api.TypeAwareBuilder;
42 import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionAwareBuilder;
43 import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionBuilder;
44 import org.opendaylight.controller.yang.parser.builder.api.UsesNodeBuilder;
45 import org.opendaylight.controller.yang.parser.util.RefineHolder;
46 import org.opendaylight.controller.yang.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 List<AugmentationSchemaBuilder> addedAugments = new ArrayList<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.setPrefix(prefix);
100 instance.setRevision(revision);
101 instance.setImports(imports);
102 instance.setNamespace(namespace);
105 final Set<TypeDefinition<?>> typedefs = buildModuleTypedefs(addedTypedefs);
106 instance.setTypeDefinitions(typedefs);
109 final Map<QName, DataSchemaNode> childNodes = buildModuleChildNodes(addedChilds);
110 instance.setChildNodes(childNodes);
113 final Set<GroupingDefinition> groupings = buildModuleGroupings(addedGroupings);
114 instance.setGroupings(groupings);
117 final Set<UsesNode> usesDefinitions = buildUsesNodes(addedUsesNodes);
118 instance.setUses(usesDefinitions);
121 final Set<FeatureDefinition> features = buildModuleFeatures(addedFeatures);
122 instance.setFeatures(features);
125 final Set<NotificationDefinition> notifications = new HashSet<NotificationDefinition>();
126 for (NotificationBuilder entry : addedNotifications) {
127 notifications.add((NotificationDefinition) entry.build());
129 instance.setNotifications(notifications);
132 final Set<AugmentationSchema> augmentations = new HashSet<AugmentationSchema>();
133 for (AugmentationSchemaBuilder builder : addedAugments) {
134 augmentations.add(builder.build());
136 instance.setAugmentations(augmentations);
139 final Set<RpcDefinition> rpcs = buildModuleRpcs(addedRpcs);
140 instance.setRpcs(rpcs);
143 final Set<Deviation> deviations = new HashSet<Deviation>();
144 for (Map.Entry<String, DeviationBuilder> entry : addedDeviations
146 deviations.add(entry.getValue().build());
148 instance.setDeviations(deviations);
151 final List<ExtensionDefinition> extensions = new ArrayList<ExtensionDefinition>();
152 for (ExtensionBuilder b : addedExtensions) {
153 extensions.add(b.build());
155 instance.setExtensionSchemaNodes(extensions);
158 final Set<IdentitySchemaNode> identities = new HashSet<IdentitySchemaNode>();
159 for (IdentitySchemaNodeBuilder idBuilder : addedIdentities) {
160 identities.add(idBuilder.build());
162 instance.setIdentities(identities);
168 public int getLine() {
172 public Builder getNode(final List<String> path) {
173 return moduleNodes.get(path);
176 public Set<DataSchemaNodeBuilder> getChildNodes() {
177 final Set<DataSchemaNodeBuilder> childNodes = new HashSet<DataSchemaNodeBuilder>();
178 for (Map.Entry<List<String>, DataSchemaNodeBuilder> entry : addedChilds
180 List<String> path = entry.getKey();
181 DataSchemaNodeBuilder child = entry.getValue();
182 if (path.size() == 2) {
183 childNodes.add(child);
189 public Map<List<String>, TypeAwareBuilder> getDirtyNodes() {
193 public List<AugmentationSchemaBuilder> getAddedAugments() {
194 return addedAugments;
197 public Set<IdentitySchemaNodeBuilder> getAddedIdentities() {
198 return addedIdentities;
201 public Map<List<String>, UsesNodeBuilder> getAddedUsesNodes() {
202 return addedUsesNodes;
205 public Set<UnknownSchemaNodeBuilder> getAddedUnknownNodes() {
206 return addedUnknownNodes;
209 public Set<TypeDefinitionBuilder> getModuleTypedefs() {
210 Set<TypeDefinitionBuilder> typedefs = new HashSet<TypeDefinitionBuilder>();
211 for (Map.Entry<List<String>, TypeDefinitionBuilder> entry : addedTypedefs
213 if (entry.getKey().size() == 2) {
214 typedefs.add(entry.getValue());
220 public String getName() {
224 public URI getNamespace() {
228 public void setNamespace(final URI namespace) {
229 this.namespace = namespace;
232 public String getPrefix() {
236 public Date getRevision() {
240 public int getAugmentsResolved() {
241 return augmentsResolved;
244 public void augmentResolved() {
248 public void addDirtyNode(final List<String> path) {
249 final List<String> dirtyNodePath = new ArrayList<String>(path);
250 final TypeAwareBuilder nodeBuilder = (TypeAwareBuilder) moduleNodes
252 dirtyNodes.put(dirtyNodePath, nodeBuilder);
255 public void setRevision(final Date revision) {
256 this.revision = revision;
259 public void setPrefix(final String prefix) {
260 this.prefix = prefix;
263 public void setYangVersion(final String yangVersion) {
264 instance.setYangVersion(yangVersion);
267 public void setDescription(final String description) {
268 instance.setDescription(description);
271 public void setReference(final String reference) {
272 instance.setReference(reference);
275 public void setOrganization(final String organization) {
276 instance.setOrganization(organization);
279 public void setContact(final String contact) {
280 instance.setContact(contact);
283 public boolean addModuleImport(final String moduleName,
284 final Date revision, final String prefix) {
285 final ModuleImport moduleImport = createModuleImport(moduleName,
287 return imports.add(moduleImport);
290 public Set<ModuleImport> getModuleImports() {
294 public ExtensionBuilder addExtension(final QName qname, final int line) {
295 final ExtensionBuilder builder = new ExtensionBuilder(qname, line);
296 addedExtensions.add(builder);
300 public ContainerSchemaNodeBuilder addContainerNode(
301 final QName containerName, final List<String> parentPath,
303 final List<String> pathToNode = new ArrayList<String>(parentPath);
304 final ContainerSchemaNodeBuilder containerBuilder = new ContainerSchemaNodeBuilder(
305 containerName, line);
306 final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes
308 if (parent != null) {
309 if (parent instanceof AugmentationSchemaBuilder) {
310 containerBuilder.setAugmenting(true);
312 parent.addChildNode(containerBuilder);
315 pathToNode.add(containerName.getLocalName());
316 moduleNodes.put(pathToNode, containerBuilder);
317 addedChilds.put(pathToNode, containerBuilder);
319 return containerBuilder;
322 public ListSchemaNodeBuilder addListNode(final QName listName,
323 final List<String> parentPath, final int line) {
324 final List<String> pathToNode = new ArrayList<String>(parentPath);
325 final ListSchemaNodeBuilder listBuilder = new ListSchemaNodeBuilder(
327 final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes
329 if (parent != null) {
330 if (parent instanceof AugmentationSchemaBuilder) {
331 listBuilder.setAugmenting(true);
333 parent.addChildNode(listBuilder);
336 pathToNode.add(listName.getLocalName());
337 moduleNodes.put(pathToNode, listBuilder);
338 addedChilds.put(pathToNode, listBuilder);
343 public LeafSchemaNodeBuilder addLeafNode(final QName leafName,
344 final List<String> parentPath, final int line) {
345 final List<String> pathToNode = new ArrayList<String>(parentPath);
346 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, final int line) {
366 final List<String> pathToNode = new ArrayList<String>(parentPath);
367 final LeafListSchemaNodeBuilder leafListBuilder = new LeafListSchemaNodeBuilder(
369 final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes
371 if (parent != null) {
372 if (parent instanceof AugmentationSchemaBuilder) {
373 leafListBuilder.setAugmenting(true);
375 parent.addChildNode(leafListBuilder);
378 pathToNode.add(leafListName.getLocalName());
379 addedChilds.put(pathToNode, leafListBuilder);
380 moduleNodes.put(pathToNode, leafListBuilder);
382 return leafListBuilder;
385 public GroupingBuilder addGrouping(final QName qname,
386 final List<String> parentPath, final int line) {
387 final List<String> pathToGroup = new ArrayList<String>(parentPath);
388 final GroupingBuilder builder = new GroupingBuilderImpl(qname, line);
389 final ChildNodeBuilder parentNodeBuilder = (ChildNodeBuilder) moduleNodes
391 if (parentNodeBuilder != null) {
392 parentNodeBuilder.addGrouping(builder);
395 pathToGroup.add("grouping");
396 pathToGroup.add(qname.getLocalName());
397 moduleNodes.put(pathToGroup, builder);
398 addedGroupings.put(pathToGroup, builder);
403 public AugmentationSchemaBuilder addAugment(final String name,
404 final List<String> parentPath, final int line) {
405 final List<String> pathToAugment = new ArrayList<String>(parentPath);
406 final AugmentationSchemaBuilder builder = new AugmentationSchemaBuilderImpl(
409 // augment can only be in 'module' or 'uses' statement
410 final UsesNodeBuilder parent = addedUsesNodes.get(pathToAugment);
411 if (parent != null) {
412 parent.addAugment(builder);
415 pathToAugment.add(name);
416 moduleNodes.put(pathToAugment, builder);
417 addedAugments.add(builder);
422 public UsesNodeBuilder addUsesNode(final String groupingPathStr,
423 final List<String> parentPath, final int line) {
424 final List<String> pathToUses = new ArrayList<String>(parentPath);
425 final UsesNodeBuilder usesBuilder = new UsesNodeBuilderImpl(
426 groupingPathStr, line);
427 final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes
429 if (parent != null) {
430 parent.addUsesNode(usesBuilder);
433 pathToUses.add(groupingPathStr);
434 addedUsesNodes.put(pathToUses, usesBuilder);
435 moduleNodes.put(pathToUses, usesBuilder);
439 public void addRefine(final RefineHolder refine,
440 final List<String> parentPath) {
441 final List<String> path = new ArrayList<String>(parentPath);
442 final Builder parent = moduleNodes.get(path);
443 if (!(parent instanceof UsesNodeBuilder)) {
444 throw new YangParseException("Failed to parse refine "
447 UsesNodeBuilder usesBuilder = (UsesNodeBuilder) parent;
448 usesBuilder.addRefine(refine);
449 path.add(refine.getName());
450 moduleNodes.put(path, refine);
453 public RpcDefinitionBuilder addRpc(final QName qname,
454 final List<String> parentPath, final int line) {
455 final List<String> pathToRpc = new ArrayList<String>(parentPath);
456 final RpcDefinitionBuilder rpcBuilder = new RpcDefinitionBuilder(qname,
459 pathToRpc.add(qname.getLocalName());
460 addedRpcs.put(pathToRpc, rpcBuilder);
462 final QName inputQName = new QName(qname.getNamespace(),
463 qname.getRevision(), qname.getPrefix(), "input");
464 final ContainerSchemaNodeBuilder inputBuilder = new ContainerSchemaNodeBuilder(
466 final List<String> pathToInput = new ArrayList<String>(pathToRpc);
467 pathToInput.add("input");
468 moduleNodes.put(pathToInput, inputBuilder);
469 rpcBuilder.setInput(inputBuilder);
471 final QName outputQName = new QName(qname.getNamespace(),
472 qname.getRevision(), qname.getPrefix(), "output");
473 final ContainerSchemaNodeBuilder outputBuilder = new ContainerSchemaNodeBuilder(
475 final List<String> pathToOutput = new ArrayList<String>(pathToRpc);
476 pathToOutput.add("output");
477 moduleNodes.put(pathToOutput, outputBuilder);
478 rpcBuilder.setOutput(outputBuilder);
483 public NotificationBuilder addNotification(final QName notificationName,
484 final List<String> parentPath, final int line) {
485 final List<String> pathToNotification = new ArrayList<String>(
488 NotificationBuilder builder = new NotificationBuilder(notificationName,
491 pathToNotification.add(notificationName.getLocalName());
492 moduleNodes.put(pathToNotification, builder);
493 addedNotifications.add(builder);
498 public FeatureBuilder addFeature(final QName featureName,
499 final List<String> parentPath, final int line) {
500 List<String> pathToFeature = new ArrayList<String>(parentPath);
501 pathToFeature.add(featureName.getLocalName());
503 FeatureBuilder builder = new FeatureBuilder(featureName, line);
504 addedFeatures.put(pathToFeature, builder);
508 public ChoiceBuilder addChoice(final QName choiceName,
509 final List<String> parentPath, final int line) {
510 List<String> pathToChoice = new ArrayList<String>(parentPath);
511 ChoiceBuilder builder = new ChoiceBuilder(choiceName, line);
513 final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes
515 if (parent != null) {
516 if (parent instanceof AugmentationSchemaBuilder) {
517 builder.setAugmenting(true);
519 parent.addChildNode(builder);
522 pathToChoice.add(choiceName.getLocalName());
523 addedChilds.put(pathToChoice, builder);
524 moduleNodes.put(pathToChoice, builder);
529 public ChoiceCaseBuilder addCase(final QName caseName,
530 final List<String> parentPath, final int line) {
531 List<String> pathToCase = new ArrayList<String>(parentPath);
532 ChoiceCaseBuilder builder = new ChoiceCaseBuilder(caseName, line);
534 final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes
536 if (parent != null) {
537 if (parent instanceof AugmentationSchemaBuilder) {
538 builder.setAugmenting(true);
540 parent.addChildNode(builder);
543 pathToCase.add(caseName.getLocalName());
544 moduleNodes.put(pathToCase, builder);
549 public AnyXmlBuilder addAnyXml(final QName anyXmlName,
550 final List<String> parentPath, final int line) {
551 List<String> pathToAnyXml = new ArrayList<String>(parentPath);
552 AnyXmlBuilder builder = new AnyXmlBuilder(anyXmlName, line);
554 final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes
556 if (parent != null) {
557 if (parent instanceof AugmentationSchemaBuilder) {
558 throw new YangParseException(
559 "An anyxml node cannot be augmented.");
561 parent.addChildNode(builder);
564 pathToAnyXml.add(anyXmlName.getLocalName());
565 addedChilds.put(pathToAnyXml, builder);
566 moduleNodes.put(pathToAnyXml, builder);
571 public TypedefBuilder addTypedef(final QName typeDefName,
572 final List<String> parentPath, final int line) {
573 List<String> pathToType = new ArrayList<String>(parentPath);
574 TypedefBuilder builder = new TypedefBuilder(typeDefName, line);
575 TypeDefinitionAwareBuilder parent = (TypeDefinitionAwareBuilder) moduleNodes
577 if (parent != null) {
578 parent.addTypedef(builder);
580 pathToType.add(typeDefName.getLocalName());
581 addedTypedefs.put(pathToType, builder);
582 moduleNodes.put(pathToType, builder);
586 public void setType(TypeDefinition<?> type, List<String> parentPath) {
587 TypeAwareBuilder parent = (TypeAwareBuilder) moduleNodes
589 if (parent == null) {
590 throw new YangParseException("Failed to set type '"
591 + type.getQName().getLocalName()
592 + "'. Parent node not found.");
594 parent.setType(type);
597 public void addUnionType(final List<String> actualPath,
598 final URI namespace, final Date revision, final int line) {
599 List<String> pathToUnion = new ArrayList<String>(actualPath);
600 TypeAwareBuilder parent = (TypeAwareBuilder) moduleNodes
602 UnionTypeBuilder union = new UnionTypeBuilder(pathToUnion, namespace,
604 parent.setType(union);
606 List<String> path = new ArrayList<String>(pathToUnion);
609 moduleNodes.put(path, union);
612 public void addIdentityrefType(final String baseString,
613 final List<String> parentPath, final 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, line);
620 parent.setType(identityref);
621 dirtyNodes.put(pathToIdentityref, parent);
624 public DeviationBuilder addDeviation(final String targetPath,
625 final List<String> parentPath, final int line) {
626 final List<String> pathToDeviation = new ArrayList<String>(parentPath);
627 pathToDeviation.add(targetPath);
628 DeviationBuilder builder = new DeviationBuilder(targetPath, line);
629 addedDeviations.put(targetPath, builder);
630 moduleNodes.put(pathToDeviation, builder);
634 public IdentitySchemaNodeBuilder addIdentity(final QName qname,
635 final List<String> parentPath, final int line) {
636 final List<String> pathToIdentity = new ArrayList<String>(parentPath);
637 final IdentitySchemaNodeBuilder builder = new IdentitySchemaNodeBuilder(
639 pathToIdentity.add(qname.getLocalName());
640 moduleNodes.put(pathToIdentity, builder);
641 addedIdentities.add(builder);
645 public void addConfiguration(boolean configuration, List<String> parentPath) {
646 Builder builder = moduleNodes.get(parentPath);
647 // current api did not support adding config to deviate
648 if (!(builder instanceof DeviationBuilder)) {
649 if(builder instanceof RefineHolder) {
650 ((RefineHolder)builder).setConfig(configuration);
652 ((DataSchemaNodeBuilder)builder).setConfiguration(configuration);
657 public UnknownSchemaNodeBuilder addUnknownSchemaNode(final QName qname,
658 final List<String> parentPath, final int line) {
659 final List<String> pathToUnknown = new ArrayList<String>(parentPath);
660 final UnknownSchemaNodeBuilder builder = new UnknownSchemaNodeBuilder(
662 final Builder parent = moduleNodes.get(pathToUnknown);
663 if (parent instanceof RefineHolder) {
664 ((RefineHolder) parent).addUnknownSchemaNode(builder);
665 } else if (parent instanceof SchemaNodeBuilder) {
666 ((SchemaNodeBuilder) parent).addUnknownSchemaNode(builder);
668 addedUnknownNodes.add(builder);
672 private class ModuleImpl implements Module {
673 private URI namespace;
674 private final String name;
675 private Date revision;
676 private String prefix;
677 private String yangVersion;
678 private String description;
679 private String reference;
680 private String organization;
681 private String contact;
682 private Set<ModuleImport> imports = Collections.emptySet();
683 private Set<FeatureDefinition> features = Collections.emptySet();
684 private Set<TypeDefinition<?>> typeDefinitions = Collections.emptySet();
685 private Set<NotificationDefinition> notifications = Collections
687 private Set<AugmentationSchema> augmentations = Collections.emptySet();
688 private Set<RpcDefinition> rpcs = Collections.emptySet();
689 private Set<Deviation> deviations = Collections.emptySet();
690 private Map<QName, DataSchemaNode> childNodes = Collections.emptyMap();
691 private Set<GroupingDefinition> groupings = Collections.emptySet();
692 private Set<UsesNode> uses = Collections.emptySet();
693 private List<ExtensionDefinition> extensionNodes = Collections
695 private Set<IdentitySchemaNode> identities = Collections.emptySet();
697 private ModuleImpl(String name) {
702 public URI getNamespace() {
706 private void setNamespace(URI namespace) {
707 this.namespace = namespace;
711 public String getName() {
716 public Date getRevision() {
720 private void setRevision(Date revision) {
721 this.revision = revision;
725 public String getPrefix() {
729 private void setPrefix(String prefix) {
730 this.prefix = prefix;
734 public String getYangVersion() {
738 private void setYangVersion(String yangVersion) {
739 this.yangVersion = yangVersion;
743 public String getDescription() {
747 private void setDescription(String description) {
748 this.description = description;
752 public String getReference() {
756 private void setReference(String reference) {
757 this.reference = reference;
761 public String getOrganization() {
765 private void setOrganization(String organization) {
766 this.organization = organization;
770 public String getContact() {
774 private void setContact(String contact) {
775 this.contact = contact;
779 public Set<ModuleImport> getImports() {
783 private void setImports(Set<ModuleImport> imports) {
784 if (imports != null) {
785 this.imports = imports;
790 public Set<FeatureDefinition> getFeatures() {
794 private void setFeatures(Set<FeatureDefinition> features) {
795 if (features != null) {
796 this.features = features;
801 public Set<TypeDefinition<?>> getTypeDefinitions() {
802 return typeDefinitions;
805 private void setTypeDefinitions(Set<TypeDefinition<?>> typeDefinitions) {
806 if (typeDefinitions != null) {
807 this.typeDefinitions = typeDefinitions;
812 public Set<NotificationDefinition> getNotifications() {
813 return notifications;
816 private void setNotifications(Set<NotificationDefinition> notifications) {
817 if (notifications != null) {
818 this.notifications = notifications;
823 public Set<AugmentationSchema> getAugmentations() {
824 return augmentations;
827 private void setAugmentations(Set<AugmentationSchema> augmentations) {
828 if (augmentations != null) {
829 this.augmentations = augmentations;
834 public Set<RpcDefinition> getRpcs() {
838 private void setRpcs(Set<RpcDefinition> rpcs) {
845 public Set<Deviation> getDeviations() {
849 private void setDeviations(Set<Deviation> deviations) {
850 if (deviations != null) {
851 this.deviations = deviations;
856 public Set<DataSchemaNode> getChildNodes() {
857 return new HashSet<DataSchemaNode>(childNodes.values());
860 private void setChildNodes(Map<QName, DataSchemaNode> childNodes) {
861 if (childNodes != null) {
862 this.childNodes = childNodes;
867 public Set<GroupingDefinition> getGroupings() {
871 private void setGroupings(Set<GroupingDefinition> groupings) {
872 if (groupings != null) {
873 this.groupings = groupings;
878 public Set<UsesNode> getUses() {
882 private void setUses(Set<UsesNode> uses) {
889 public List<ExtensionDefinition> getExtensionSchemaNodes() {
890 return extensionNodes;
893 private void setExtensionSchemaNodes(
894 List<ExtensionDefinition> extensionNodes) {
895 if (extensionNodes != null) {
896 this.extensionNodes = extensionNodes;
901 public Set<IdentitySchemaNode> getIdentities() {
905 private void setIdentities(Set<IdentitySchemaNode> identities) {
906 if (identities != null) {
907 this.identities = identities;
912 public DataSchemaNode getDataChildByName(QName name) {
913 return childNodes.get(name);
917 public DataSchemaNode getDataChildByName(String name) {
918 DataSchemaNode result = null;
919 for (Map.Entry<QName, DataSchemaNode> entry : childNodes.entrySet()) {
920 if (entry.getKey().getLocalName().equals(name)) {
921 result = entry.getValue();
929 public int hashCode() {
930 final int prime = 31;
932 result = prime * result
933 + ((namespace == null) ? 0 : namespace.hashCode());
934 result = prime * result + ((name == null) ? 0 : name.hashCode());
935 result = prime * result
936 + ((revision == null) ? 0 : revision.hashCode());
937 result = prime * result
938 + ((prefix == null) ? 0 : prefix.hashCode());
939 result = prime * result
940 + ((yangVersion == null) ? 0 : yangVersion.hashCode());
945 public boolean equals(Object obj) {
952 if (getClass() != obj.getClass()) {
955 ModuleImpl other = (ModuleImpl) obj;
956 if (namespace == null) {
957 if (other.namespace != null) {
960 } else if (!namespace.equals(other.namespace)) {
964 if (other.name != null) {
967 } else if (!name.equals(other.name)) {
970 if (revision == null) {
971 if (other.revision != null) {
974 } else if (!revision.equals(other.revision)) {
977 if (prefix == null) {
978 if (other.prefix != null) {
981 } else if (!prefix.equals(other.prefix)) {
984 if (yangVersion == null) {
985 if (other.yangVersion != null) {
988 } else if (!yangVersion.equals(other.yangVersion)) {
995 public String toString() {
996 StringBuilder sb = new StringBuilder(
997 ModuleImpl.class.getSimpleName());
999 sb.append("name=" + name);
1000 sb.append(", namespace=" + namespace);
1001 sb.append(", revision=" + revision);
1002 sb.append(", prefix=" + prefix);
1003 sb.append(", yangVersion=" + yangVersion);
1005 return sb.toString();
1009 private ModuleImport createModuleImport(final String moduleName,
1010 final Date revision, final String prefix) {
1011 ModuleImport moduleImport = new ModuleImport() {
1013 public String getModuleName() {
1018 public Date getRevision() {
1023 public String getPrefix() {
1028 public int hashCode() {
1029 final int prime = 31;
1031 result = prime * result
1032 + ((moduleName == null) ? 0 : moduleName.hashCode());
1033 result = prime * result
1034 + ((revision == null) ? 0 : revision.hashCode());
1035 result = prime * result
1036 + ((prefix == null) ? 0 : prefix.hashCode());
1041 public boolean equals(Object obj) {
1048 if (getClass() != obj.getClass()) {
1051 ModuleImport other = (ModuleImport) obj;
1052 if (getModuleName() == null) {
1053 if (other.getModuleName() != null) {
1056 } else if (!getModuleName().equals(other.getModuleName())) {
1059 if (getRevision() == null) {
1060 if (other.getRevision() != null) {
1063 } else if (!getRevision().equals(other.getRevision())) {
1066 if (getPrefix() == null) {
1067 if (other.getPrefix() != null) {
1070 } else if (!getPrefix().equals(other.getPrefix())) {
1077 public String toString() {
1078 return "ModuleImport[moduleName=" + moduleName + ", revision="
1079 + revision + ", prefix=" + prefix + "]";
1082 return moduleImport;
1086 * Traverse through given addedChilds and add only direct module childs.
1087 * Direct module child path size is 2 (1. module name, 2. child name).
1089 * @param addedChilds
1090 * @return map of children, where key is child QName and value is child
1093 private Map<QName, DataSchemaNode> buildModuleChildNodes(
1094 Map<List<String>, DataSchemaNodeBuilder> addedChilds) {
1095 final Map<QName, DataSchemaNode> childNodes = new HashMap<QName, DataSchemaNode>();
1096 for (Map.Entry<List<String>, DataSchemaNodeBuilder> entry : addedChilds
1098 List<String> path = entry.getKey();
1099 DataSchemaNodeBuilder child = entry.getValue();
1100 if (path.size() == 2) {
1101 DataSchemaNode node = child.build();
1102 QName qname = node.getQName();
1103 childNodes.put(qname, node);
1110 * Traverse through given addedGroupings and add only direct module
1111 * groupings. Direct module grouping path size is 2 (1. module name, 2.
1114 * @param addedGroupings
1115 * @return set of built GroupingDefinition objects
1117 private Set<GroupingDefinition> buildModuleGroupings(
1118 Map<List<String>, GroupingBuilder> addedGroupings) {
1119 final Set<GroupingDefinition> groupings = new HashSet<GroupingDefinition>();
1120 for (Map.Entry<List<String>, GroupingBuilder> entry : addedGroupings
1122 if (entry.getKey().size() == 2) {
1123 groupings.add(entry.getValue().build());
1130 * Traverse through given addedRpcs and build RpcDefinition objects.
1133 * @return set of built RpcDefinition objects
1135 private Set<RpcDefinition> buildModuleRpcs(
1136 Map<List<String>, RpcDefinitionBuilder> addedRpcs) {
1137 final Set<RpcDefinition> rpcs = new HashSet<RpcDefinition>();
1138 RpcDefinitionBuilder builder;
1139 for (Map.Entry<List<String>, RpcDefinitionBuilder> entry : addedRpcs
1141 builder = entry.getValue();
1142 RpcDefinition rpc = builder.build();
1149 * Traverse through given addedTypedefs and add only direct module typedef
1150 * statements. Direct module typedef path size is 2 (1. module name, 2.
1153 * @param addedTypedefs
1154 * @return set of built module typedef statements
1156 private Set<TypeDefinition<?>> buildModuleTypedefs(
1157 Map<List<String>, TypeDefinitionBuilder> addedTypedefs) {
1158 Set<TypeDefinition<?>> typedefs = new HashSet<TypeDefinition<?>>();
1159 for (Map.Entry<List<String>, TypeDefinitionBuilder> entry : addedTypedefs
1161 List<String> key = entry.getKey();
1162 TypeDefinitionBuilder typedefBuilder = entry.getValue();
1163 if (key.size() == 2) {
1164 TypeDefinition<? extends TypeDefinition<?>> node = typedefBuilder
1173 * Traverse through given addedUsesNodes and add only direct module uses
1174 * nodes. Direct module uses node path size is 2 (1. module name, 2. uses
1177 * @param addedUsesNodes
1178 * @return set of built module uses nodes
1180 private Set<UsesNode> buildUsesNodes(
1181 Map<List<String>, UsesNodeBuilder> addedUsesNodes) {
1182 final Set<UsesNode> usesNodeDefs = new HashSet<UsesNode>();
1183 for (Map.Entry<List<String>, UsesNodeBuilder> entry : addedUsesNodes
1185 if (entry.getKey().size() == 2) {
1186 usesNodeDefs.add(entry.getValue().build());
1189 return usesNodeDefs;
1193 * Traverse through given addedFeatures and add only direct module features.
1194 * Direct module feature path size is 2 (1. module name, 2. feature name).
1196 * @param addedFeatures
1197 * @return set of built module features
1199 private Set<FeatureDefinition> buildModuleFeatures(
1200 Map<List<String>, FeatureBuilder> addedFeatures) {
1201 Set<FeatureDefinition> features = new HashSet<FeatureDefinition>();
1202 for (Map.Entry<List<String>, FeatureBuilder> entry : addedFeatures
1204 if (entry.getKey().size() == 2) {
1205 features.add(entry.getValue().build());