2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
\r
4 * This program and the accompanying materials are made available under the
\r
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
\r
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
\r
8 package org.opendaylight.controller.yang.model.parser.builder.impl;
\r
10 import java.net.URI;
\r
11 import java.util.ArrayList;
\r
12 import java.util.Collections;
\r
13 import java.util.Date;
\r
14 import java.util.HashMap;
\r
15 import java.util.HashSet;
\r
16 import java.util.List;
\r
17 import java.util.Map;
\r
18 import java.util.Set;
\r
20 import org.opendaylight.controller.yang.common.QName;
\r
21 import org.opendaylight.controller.yang.model.api.AugmentationSchema;
\r
22 import org.opendaylight.controller.yang.model.api.DataSchemaNode;
\r
23 import org.opendaylight.controller.yang.model.api.Deviation;
\r
24 import org.opendaylight.controller.yang.model.api.ExtensionDefinition;
\r
25 import org.opendaylight.controller.yang.model.api.FeatureDefinition;
\r
26 import org.opendaylight.controller.yang.model.api.GroupingDefinition;
\r
27 import org.opendaylight.controller.yang.model.api.IdentitySchemaNode;
\r
28 import org.opendaylight.controller.yang.model.api.Module;
\r
29 import org.opendaylight.controller.yang.model.api.ModuleImport;
\r
30 import org.opendaylight.controller.yang.model.api.NotificationDefinition;
\r
31 import org.opendaylight.controller.yang.model.api.RpcDefinition;
\r
32 import org.opendaylight.controller.yang.model.api.TypeDefinition;
\r
33 import org.opendaylight.controller.yang.model.api.UsesNode;
\r
34 import org.opendaylight.controller.yang.model.parser.builder.api.AugmentationSchemaBuilder;
\r
35 import org.opendaylight.controller.yang.model.parser.builder.api.Builder;
\r
36 import org.opendaylight.controller.yang.model.parser.builder.api.ChildNodeBuilder;
\r
37 import org.opendaylight.controller.yang.model.parser.builder.api.DataSchemaNodeBuilder;
\r
38 import org.opendaylight.controller.yang.model.parser.builder.api.GroupingBuilder;
\r
39 import org.opendaylight.controller.yang.model.parser.builder.api.TypeAwareBuilder;
\r
40 import org.opendaylight.controller.yang.model.parser.builder.api.TypeDefinitionAwareBuilder;
\r
41 import org.opendaylight.controller.yang.model.parser.builder.api.TypeDefinitionBuilder;
\r
42 import org.opendaylight.controller.yang.model.parser.builder.api.UsesNodeBuilder;
\r
45 * This builder builds Module object. If this module is dependent on external
\r
46 * module/modules, these dependencies must be resolved before module is built,
\r
47 * otherwise result may not be valid.
\r
49 public class ModuleBuilder implements Builder {
\r
51 private final ModuleImpl instance;
\r
52 private final String name;
\r
53 private String prefix;
\r
54 private Date revision;
\r
56 private final Set<ModuleImport> imports = new HashSet<ModuleImport>();
\r
57 private Set<AugmentationSchema> augmentations;
\r
60 * All nodes, that can contain other nodes
\r
62 private final Map<List<String>, Builder> moduleNodes = new HashMap<List<String>, Builder>();
\r
65 * Holds all child (DataSchemaNode) nodes: anyxml, choice, case, container,
\r
66 * list, leaf, leaf-list.
\r
68 private final Map<List<String>, DataSchemaNodeBuilder> addedChilds = new HashMap<List<String>, DataSchemaNodeBuilder>();
\r
70 private final Map<List<String>, GroupingBuilder> addedGroupings = new HashMap<List<String>, GroupingBuilder>();
\r
71 private final Set<AugmentationSchemaBuilder> addedAugments = new HashSet<AugmentationSchemaBuilder>();
\r
72 private final Map<List<String>, UsesNodeBuilder> addedUsesNodes = new HashMap<List<String>, UsesNodeBuilder>();
\r
73 private final Map<List<String>, RpcDefinitionBuilder> addedRpcs = new HashMap<List<String>, RpcDefinitionBuilder>();
\r
74 private final Set<NotificationBuilder> addedNotifications = new HashSet<NotificationBuilder>();
\r
75 private final Set<IdentitySchemaNodeBuilder> addedIdentities = new HashSet<IdentitySchemaNodeBuilder>();
\r
76 private final Map<List<String>, FeatureBuilder> addedFeatures = new HashMap<List<String>, FeatureBuilder>();
\r
77 private final Map<String, DeviationBuilder> addedDeviations = new HashMap<String, DeviationBuilder>();
\r
78 private final Map<List<String>, TypeDefinitionBuilder> addedTypedefs = new HashMap<List<String>, TypeDefinitionBuilder>();
\r
79 private final List<ExtensionBuilder> addedExtensions = new ArrayList<ExtensionBuilder>();
\r
81 private final Map<List<String>, TypeAwareBuilder> dirtyNodes = new HashMap<List<String>, TypeAwareBuilder>();
\r
82 private final Map<List<String>, UnionTypeBuilder> unionTypes = new HashMap<List<String>, UnionTypeBuilder>();
\r
84 public ModuleBuilder(String name) {
\r
86 instance = new ModuleImpl(name);
\r
91 * Build new Module object based on this builder.
\r
94 public Module build() {
\r
95 instance.setImports(imports);
\r
98 final Set<TypeDefinition<?>> typedefs = buildModuleTypedefs(addedTypedefs);
\r
99 instance.setTypeDefinitions(typedefs);
\r
102 final Map<QName, DataSchemaNode> childNodes = buildModuleChildNodes(addedChilds);
\r
103 instance.setChildNodes(childNodes);
\r
106 final Set<GroupingDefinition> groupings = buildModuleGroupings(addedGroupings);
\r
107 instance.setGroupings(groupings);
\r
110 final Set<UsesNode> usesNodeDefinitions = buildUsesNodes(addedUsesNodes);
\r
111 instance.setUses(usesNodeDefinitions);
\r
114 final Set<FeatureDefinition> features = buildModuleFeatures(addedFeatures);
\r
115 instance.setFeatures(features);
\r
118 final Set<NotificationDefinition> notifications = new HashSet<NotificationDefinition>();
\r
119 for (NotificationBuilder entry : addedNotifications) {
\r
120 notifications.add((NotificationDefinition) entry.build());
\r
122 instance.setNotifications(notifications);
\r
125 instance.setAugmentations(augmentations);
\r
128 final Set<RpcDefinition> rpcs = buildModuleRpcs(addedRpcs);
\r
129 instance.setRpcs(rpcs);
\r
132 final Set<Deviation> deviations = new HashSet<Deviation>();
\r
133 for (Map.Entry<String, DeviationBuilder> entry : addedDeviations
\r
135 deviations.add(entry.getValue().build());
\r
137 instance.setDeviations(deviations);
\r
140 final List<ExtensionDefinition> extensions = new ArrayList<ExtensionDefinition>();
\r
141 for(ExtensionBuilder b : addedExtensions) {
\r
142 extensions.add(b.build());
\r
144 instance.setExtensionSchemaNodes(extensions);
\r
147 final Set<IdentitySchemaNode> identities = new HashSet<IdentitySchemaNode>();
\r
148 for(IdentitySchemaNodeBuilder idBuilder : addedIdentities) {
\r
149 identities.add(idBuilder.build());
\r
151 instance.setIdentities(identities);
\r
156 public Builder getNode(List<String> path) {
\r
157 return moduleNodes.get(path);
\r
160 public Map<List<String>, TypeAwareBuilder> getDirtyNodes() {
\r
164 public Set<AugmentationSchemaBuilder> getAddedAugments() {
\r
165 return addedAugments;
\r
168 public Set<IdentitySchemaNodeBuilder> getAddedIdentities() {
\r
169 return addedIdentities;
\r
172 public String getName() {
\r
176 public String getPrefix() {
\r
180 public Date getRevision() {
\r
184 public void addDirtyNode(List<String> path) {
\r
185 List<String> dirtyNodePath = new ArrayList<String>(path);
\r
186 TypeAwareBuilder nodeBuilder = (TypeAwareBuilder) moduleNodes
\r
187 .get(dirtyNodePath);
\r
188 dirtyNodes.put(dirtyNodePath, nodeBuilder);
\r
191 public void setNamespace(URI namespace) {
\r
192 instance.setNamespace(namespace);
\r
195 public void setRevision(Date revision) {
\r
196 this.revision = revision;
\r
197 instance.setRevision(revision);
\r
200 public void setPrefix(String prefix) {
\r
201 this.prefix = prefix;
\r
202 instance.setPrefix(prefix);
\r
205 public void setYangVersion(String yangVersion) {
\r
206 instance.setYangVersion(yangVersion);
\r
209 public void setDescription(String description) {
\r
210 instance.setDescription(description);
\r
213 public void setReference(String reference) {
\r
214 instance.setReference(reference);
\r
217 public void setOrganization(String organization) {
\r
218 instance.setOrganization(organization);
\r
221 public void setContact(String contact) {
\r
222 instance.setContact(contact);
\r
225 public void setAugmentations(Set<AugmentationSchema> augmentations) {
\r
226 this.augmentations = augmentations;
\r
229 public boolean addModuleImport(final String moduleName,
\r
230 final Date revision, final String prefix) {
\r
231 ModuleImport moduleImport = createModuleImport(moduleName, revision,
\r
233 return imports.add(moduleImport);
\r
236 public Set<ModuleImport> getModuleImports() {
\r
240 public ExtensionBuilder addExtension(QName qname) {
\r
241 ExtensionBuilder builder = new ExtensionBuilder(qname);
\r
245 public ContainerSchemaNodeBuilder addContainerNode(QName containerName,
\r
246 List<String> parentPath) {
\r
247 List<String> pathToNode = new ArrayList<String>(parentPath);
\r
249 ContainerSchemaNodeBuilder containerBuilder = new ContainerSchemaNodeBuilder(
\r
252 ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes
\r
254 if (parent != null) {
\r
255 if(parent instanceof AugmentationSchemaBuilder) {
\r
256 containerBuilder.setAugmenting(true);
\r
258 parent.addChildNode(containerBuilder);
\r
261 pathToNode.add(containerName.getLocalName());
\r
262 moduleNodes.put(pathToNode, containerBuilder);
\r
263 addedChilds.put(pathToNode, containerBuilder);
\r
265 return containerBuilder;
\r
268 public ListSchemaNodeBuilder addListNode(QName listName,
\r
269 List<String> parentPath) {
\r
270 List<String> pathToNode = new ArrayList<String>(parentPath);
\r
272 ListSchemaNodeBuilder listBuilder = new ListSchemaNodeBuilder(listName);
\r
274 ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes
\r
276 if (parent != null) {
\r
277 if(parent instanceof AugmentationSchemaBuilder) {
\r
278 listBuilder.setAugmenting(true);
\r
280 parent.addChildNode(listBuilder);
\r
283 pathToNode.add(listName.getLocalName());
\r
284 moduleNodes.put(pathToNode, listBuilder);
\r
285 addedChilds.put(pathToNode, listBuilder);
\r
287 return listBuilder;
\r
290 public LeafSchemaNodeBuilder addLeafNode(QName leafName,
\r
291 List<String> parentPath) {
\r
292 List<String> pathToNode = new ArrayList<String>(parentPath);
\r
294 LeafSchemaNodeBuilder leafBuilder = new LeafSchemaNodeBuilder(leafName);
\r
296 ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes.get(pathToNode);
\r
297 if (parent != null) {
\r
298 if(parent instanceof AugmentationSchemaBuilder) {
\r
299 leafBuilder.setAugmenting(true);
\r
301 parent.addChildNode(leafBuilder);
\r
304 pathToNode.add(leafName.getLocalName());
\r
305 addedChilds.put(pathToNode, leafBuilder);
\r
306 moduleNodes.put(pathToNode, leafBuilder);
\r
308 return leafBuilder;
\r
311 public LeafListSchemaNodeBuilder addLeafListNode(QName leafListName,
\r
312 List<String> parentPath) {
\r
313 List<String> pathToNode = new ArrayList<String>(parentPath);
\r
315 LeafListSchemaNodeBuilder leafListBuilder = new LeafListSchemaNodeBuilder(
\r
317 ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes.get(pathToNode);
\r
318 if (parent != null) {
\r
319 if(parent instanceof AugmentationSchemaBuilder) {
\r
320 leafListBuilder.setAugmenting(true);
\r
322 parent.addChildNode(leafListBuilder);
\r
325 pathToNode.add(leafListName.getLocalName());
\r
326 addedChilds.put(pathToNode, leafListBuilder);
\r
327 moduleNodes.put(pathToNode, leafListBuilder);
\r
329 return leafListBuilder;
\r
332 public GroupingBuilder addGrouping(QName qname, List<String> parentPath) {
\r
333 List<String> pathToGroup = new ArrayList<String>(parentPath);
\r
335 GroupingBuilder builder = new GroupingBuilderImpl(qname);
\r
336 ChildNodeBuilder parentNodeBuilder = (ChildNodeBuilder) moduleNodes.get(pathToGroup);
\r
337 if (parentNodeBuilder != null) {
\r
338 parentNodeBuilder.addGrouping(builder);
\r
341 pathToGroup.add(qname.getLocalName());
\r
342 moduleNodes.put(pathToGroup, builder);
\r
343 addedGroupings.put(pathToGroup, builder);
\r
348 public AugmentationSchemaBuilder addAugment(String name,
\r
349 List<String> parentPath) {
\r
350 List<String> pathToAugment = new ArrayList<String>(parentPath);
\r
352 AugmentationSchemaBuilder builder = new AugmentationSchemaBuilderImpl(name);
\r
354 // augment can only be in 'module' or 'uses' statement
\r
355 UsesNodeBuilder parent = addedUsesNodes.get(pathToAugment);
\r
356 if (parent != null) {
\r
357 parent.addAugment(builder);
\r
360 pathToAugment.add(name);
\r
361 moduleNodes.put(pathToAugment, builder);
\r
362 addedAugments.add(builder);
\r
367 public UsesNodeBuilder addUsesNode(String groupingPathStr,
\r
368 List<String> parentPath) {
\r
369 List<String> pathToUses = new ArrayList<String>(parentPath);
\r
371 UsesNodeBuilder usesBuilder = new UsesNodeBuilderImpl(groupingPathStr);
\r
373 ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes.get(pathToUses);
\r
374 if (parent != null) {
\r
375 if(parent instanceof AugmentationSchemaBuilder) {
\r
376 usesBuilder.setAugmenting(true);
\r
378 parent.addUsesNode(usesBuilder);
\r
381 pathToUses.add(groupingPathStr);
\r
382 addedUsesNodes.put(pathToUses, usesBuilder);
\r
384 return usesBuilder;
\r
387 public RpcDefinitionBuilder addRpc(QName qname, List<String> parentPath) {
\r
388 List<String> pathToRpc = new ArrayList<String>(parentPath);
\r
390 RpcDefinitionBuilder rpcBuilder = new RpcDefinitionBuilder(qname);
\r
392 pathToRpc.add(qname.getLocalName());
\r
393 addedRpcs.put(pathToRpc, rpcBuilder);
\r
395 QName inputQName = new QName(qname.getNamespace(), qname.getRevision(),
\r
396 qname.getPrefix(), "input");
\r
397 ContainerSchemaNodeBuilder inputBuilder = new ContainerSchemaNodeBuilder(inputQName);
\r
398 List<String> pathToInput = new ArrayList<String>(pathToRpc);
\r
399 pathToInput.add("input");
\r
400 moduleNodes.put(pathToInput, inputBuilder);
\r
401 rpcBuilder.setInput(inputBuilder);
\r
403 QName outputQName = new QName(qname.getNamespace(),
\r
404 qname.getRevision(), qname.getPrefix(), "output");
\r
405 ContainerSchemaNodeBuilder outputBuilder = new ContainerSchemaNodeBuilder(outputQName);
\r
406 List<String> pathToOutput = new ArrayList<String>(pathToRpc);
\r
407 pathToOutput.add("output");
\r
408 moduleNodes.put(pathToOutput, outputBuilder);
\r
409 rpcBuilder.setOutput(outputBuilder);
\r
414 public NotificationBuilder addNotification(QName notificationName,
\r
415 List<String> parentPath) {
\r
416 List<String> pathToNotification = new ArrayList<String>(parentPath);
\r
418 NotificationBuilder notificationBuilder = new NotificationBuilder(
\r
421 pathToNotification.add(notificationName.getLocalName());
\r
422 moduleNodes.put(pathToNotification, notificationBuilder);
\r
423 addedNotifications.add(notificationBuilder);
\r
425 return notificationBuilder;
\r
428 public FeatureBuilder addFeature(QName featureName, List<String> parentPath) {
\r
429 List<String> pathToFeature = new ArrayList<String>(parentPath);
\r
430 pathToFeature.add(featureName.getLocalName());
\r
432 FeatureBuilder builder = new FeatureBuilder(featureName);
\r
433 addedFeatures.put(pathToFeature, builder);
\r
437 public TypedefBuilder addTypedef(QName typeDefName, List<String> parentPath) {
\r
438 List<String> pathToType = new ArrayList<String>(parentPath);
\r
439 TypedefBuilder builder = new TypedefBuilder(typeDefName);
\r
440 TypeDefinitionAwareBuilder parent = (TypeDefinitionAwareBuilder) moduleNodes.get(pathToType);
\r
441 if (parent != null) {
\r
442 parent.addTypedef(builder);
\r
444 pathToType.add(typeDefName.getLocalName());
\r
445 addedTypedefs.put(pathToType, builder);
\r
446 moduleNodes.put(pathToType, builder);
\r
450 public Set<TypeDefinitionBuilder> getModuleTypedefs() {
\r
451 Set<TypeDefinitionBuilder> typedefs = new HashSet<TypeDefinitionBuilder>();
\r
452 for (Map.Entry<List<String>, TypeDefinitionBuilder> entry : addedTypedefs.entrySet()) {
\r
453 if (entry.getKey().size() == 2) {
\r
454 typedefs.add(entry.getValue());
\r
460 public void setType(TypeDefinition<?> type, List<String> parentPath) {
\r
461 TypeAwareBuilder parent = (TypeAwareBuilder) moduleNodes.get(parentPath);
\r
462 parent.setType(type);
\r
465 public void addUnionType(List<String> parentPath) {
\r
466 TypeAwareBuilder parent = (TypeAwareBuilder) moduleNodes.get(parentPath);
\r
467 UnionTypeBuilder union = new UnionTypeBuilder();
\r
468 parent.setType(union.build());
\r
470 List<String> path = new ArrayList<String>(parentPath);
\r
473 unionTypes.put(path, union);
\r
474 moduleNodes.put(path, union);
\r
477 public DeviationBuilder addDeviation(String targetPath) {
\r
478 DeviationBuilder builder = new DeviationBuilder(targetPath);
\r
479 addedDeviations.put(targetPath, builder);
\r
483 public IdentitySchemaNodeBuilder addIdentity(QName qname) {
\r
484 IdentitySchemaNodeBuilder builder = new IdentitySchemaNodeBuilder(qname);
\r
485 addedIdentities.add(builder);
\r
490 public void addConfiguration(boolean configuration, List<String> parentPath) {
\r
491 Builder builder = moduleNodes.get(parentPath);
\r
492 if (builder instanceof DeviationBuilder) {
\r
496 DataSchemaNodeBuilder configBuilder = (DataSchemaNodeBuilder) moduleNodes.get(parentPath);
\r
497 configBuilder.setConfiguration(configuration);
\r
501 public UnknownSchemaNodeBuilder addUnknownSchemaNode(QName qname, List<String> parentPath) {
\r
502 UnknownSchemaNodeBuilder builder = new UnknownSchemaNodeBuilder(qname);
\r
507 private class ModuleImpl implements Module {
\r
508 private URI namespace;
\r
509 private final String name;
\r
510 private Date revision;
\r
511 private String prefix;
\r
512 private String yangVersion;
\r
513 private String description;
\r
514 private String reference;
\r
515 private String organization;
\r
516 private String contact;
\r
517 private Set<ModuleImport> imports = Collections.emptySet();
\r
518 private Set<FeatureDefinition> features = Collections.emptySet();
\r
519 private Set<TypeDefinition<?>> typeDefinitions = Collections.emptySet();
\r
520 private Set<NotificationDefinition> notifications = Collections.emptySet();
\r
521 private Set<AugmentationSchema> augmentations = Collections.emptySet();
\r
522 private Set<RpcDefinition> rpcs = Collections.emptySet();
\r
523 private Set<Deviation> deviations = Collections.emptySet();
\r
524 private Map<QName, DataSchemaNode> childNodes = Collections.emptyMap();
\r
525 private Set<GroupingDefinition> groupings = Collections.emptySet();
\r
526 private Set<UsesNode> uses = Collections.emptySet();
\r
527 private List<ExtensionDefinition> extensionSchemaNodes = Collections.emptyList();
\r
528 private Set<IdentitySchemaNode> identities = Collections.emptySet();
\r
530 private ModuleImpl(String name) {
\r
535 public URI getNamespace() {
\r
539 private void setNamespace(URI namespace) {
\r
540 this.namespace = namespace;
\r
544 public String getName() {
\r
549 public Date getRevision() {
\r
553 private void setRevision(Date revision) {
\r
554 this.revision = revision;
\r
558 public String getPrefix() {
\r
562 private void setPrefix(String prefix) {
\r
563 this.prefix = prefix;
\r
567 public String getYangVersion() {
\r
568 return yangVersion;
\r
571 private void setYangVersion(String yangVersion) {
\r
572 this.yangVersion = yangVersion;
\r
576 public String getDescription() {
\r
577 return description;
\r
580 private void setDescription(String description) {
\r
581 this.description = description;
\r
585 public String getReference() {
\r
589 private void setReference(String reference) {
\r
590 this.reference = reference;
\r
594 public String getOrganization() {
\r
595 return organization;
\r
598 private void setOrganization(String organization) {
\r
599 this.organization = organization;
\r
603 public String getContact() {
\r
607 private void setContact(String contact) {
\r
608 this.contact = contact;
\r
612 public Set<ModuleImport> getImports() {
\r
616 private void setImports(Set<ModuleImport> imports) {
\r
617 if(imports != null) {
\r
618 this.imports = imports;
\r
623 public Set<FeatureDefinition> getFeatures() {
\r
627 private void setFeatures(Set<FeatureDefinition> features) {
\r
628 if(features != null) {
\r
629 this.features = features;
\r
634 public Set<TypeDefinition<?>> getTypeDefinitions() {
\r
635 return typeDefinitions;
\r
638 private void setTypeDefinitions(Set<TypeDefinition<?>> typeDefinitions) {
\r
639 if(typeDefinitions != null) {
\r
640 this.typeDefinitions = typeDefinitions;
\r
645 public Set<NotificationDefinition> getNotifications() {
\r
646 return notifications;
\r
649 private void setNotifications(Set<NotificationDefinition> notifications) {
\r
650 if(notifications != null) {
\r
651 this.notifications = notifications;
\r
656 public Set<AugmentationSchema> getAugmentations() {
\r
657 return augmentations;
\r
660 private void setAugmentations(Set<AugmentationSchema> augmentations) {
\r
661 if(augmentations != null) {
\r
662 this.augmentations = augmentations;
\r
667 public Set<RpcDefinition> getRpcs() {
\r
671 private void setRpcs(Set<RpcDefinition> rpcs) {
\r
678 public Set<Deviation> getDeviations() {
\r
682 private void setDeviations(Set<Deviation> deviations) {
\r
683 if(deviations != null) {
\r
684 this.deviations = deviations;
\r
689 public Set<DataSchemaNode> getChildNodes() {
\r
690 return new HashSet<DataSchemaNode>(childNodes.values());
\r
693 private void setChildNodes(Map<QName, DataSchemaNode> childNodes) {
\r
694 if(childNodes != null) {
\r
695 this.childNodes = childNodes;
\r
700 public Set<GroupingDefinition> getGroupings() {
\r
704 private void setGroupings(Set<GroupingDefinition> groupings) {
\r
705 if(groupings != null) {
\r
706 this.groupings = groupings;
\r
711 public Set<UsesNode> getUses() {
\r
715 private void setUses(Set<UsesNode> uses) {
\r
722 public List<ExtensionDefinition> getExtensionSchemaNodes() {
\r
723 return extensionSchemaNodes;
\r
726 private void setExtensionSchemaNodes(List<ExtensionDefinition> extensionSchemaNodes) {
\r
727 if(extensionSchemaNodes != null) {
\r
728 this.extensionSchemaNodes = extensionSchemaNodes;
\r
733 public Set<IdentitySchemaNode> getIdentities() {
\r
737 private void setIdentities(Set<IdentitySchemaNode> identities) {
\r
738 if(identities != null) {
\r
739 this.identities = identities;
\r
744 public DataSchemaNode getDataChildByName(QName name) {
\r
745 return childNodes.get(name);
\r
749 public DataSchemaNode getDataChildByName(String name) {
\r
750 DataSchemaNode result = null;
\r
751 for (Map.Entry<QName, DataSchemaNode> entry : childNodes.entrySet()) {
\r
752 if (entry.getKey().getLocalName().equals(name)) {
\r
753 result = entry.getValue();
\r
761 public int hashCode() {
\r
762 final int prime = 31;
\r
764 result = prime * result + ((namespace == null) ? 0 : namespace.hashCode());
\r
765 result = prime * result + ((name == null) ? 0 : name.hashCode());
\r
766 result = prime * result + ((revision == null) ? 0 : revision.hashCode());
\r
767 result = prime * result + ((prefix == null) ? 0 : prefix.hashCode());
\r
768 result = prime * result + ((yangVersion == null) ? 0 : yangVersion.hashCode());
\r
773 public boolean equals(Object obj) {
\r
780 if (getClass() != obj.getClass()) {
\r
783 ModuleImpl other = (ModuleImpl) obj;
\r
784 if (namespace == null) {
\r
785 if (other.namespace != null) {
\r
788 } else if (!namespace.equals(other.namespace)) {
\r
791 if (name == null) {
\r
792 if (other.name != null) {
\r
795 } else if (!name.equals(other.name)) {
\r
798 if (revision == null) {
\r
799 if (other.revision != null) {
\r
802 } else if (!revision.equals(other.revision)) {
\r
805 if (prefix == null) {
\r
806 if (other.prefix != null) {
\r
809 } else if (!prefix.equals(other.prefix)) {
\r
812 if (yangVersion == null) {
\r
813 if (other.yangVersion != null) {
\r
816 } else if (!yangVersion.equals(other.yangVersion)) {
\r
823 public String toString() {
\r
824 StringBuilder sb = new StringBuilder(
\r
825 ModuleImpl.class.getSimpleName());
\r
827 sb.append("name=" + name + ",\n");
\r
828 sb.append("namespace=" + namespace + ",\n");
\r
829 sb.append("revision=" + revision + ",\n");
\r
830 sb.append("prefix=" + prefix + ",\n");
\r
831 sb.append("yangVersion=" + yangVersion + ",\n");
\r
832 sb.append("description=" + description + ",\n");
\r
833 sb.append("reference=" + reference + ",\n");
\r
834 sb.append("organization=" + organization + ",\n");
\r
835 sb.append("contact=" + contact + ",\n");
\r
836 sb.append("childNodes=" + childNodes.values() + ",\n");
\r
837 sb.append("groupings=" + groupings + ",\n");
\r
838 sb.append("imports=" + imports + ",\n");
\r
839 sb.append("features=" + features + ",\n");
\r
840 sb.append("typeDefinitions=" + typeDefinitions + ",\n");
\r
841 sb.append("notifications=" + notifications + ",\n");
\r
842 sb.append("augmentations=" + augmentations + ",\n");
\r
843 sb.append("rpcs=" + rpcs + ",\n");
\r
844 sb.append("deviations=" + deviations + "\n");
\r
845 sb.append("uses=" + uses + "\n");
\r
847 return sb.toString();
\r
851 private ModuleImport createModuleImport(final String moduleName,
\r
852 final Date revision, final String prefix) {
\r
853 ModuleImport moduleImport = new ModuleImport() {
\r
855 public String getModuleName() {
\r
860 public Date getRevision() {
\r
865 public String getPrefix() {
\r
870 public int hashCode() {
\r
871 final int prime = 31;
\r
873 result = prime * result
\r
874 + ((moduleName == null) ? 0 : moduleName.hashCode());
\r
875 result = prime * result
\r
876 + ((revision == null) ? 0 : revision.hashCode());
\r
877 result = prime * result
\r
878 + ((prefix == null) ? 0 : prefix.hashCode());
\r
883 public boolean equals(Object obj) {
\r
890 if (getClass() != obj.getClass()) {
\r
893 ModuleImport other = (ModuleImport) obj;
\r
894 if (getModuleName() == null) {
\r
895 if (other.getModuleName() != null) {
\r
898 } else if (!getModuleName().equals(other.getModuleName())) {
\r
901 if (getRevision() == null) {
\r
902 if (other.getRevision() != null) {
\r
905 } else if (!getRevision().equals(other.getRevision())) {
\r
908 if (getPrefix() == null) {
\r
909 if (other.getPrefix() != null) {
\r
912 } else if (!getPrefix().equals(other.getPrefix())) {
\r
919 public String toString() {
\r
920 return "ModuleImport[moduleName=" + moduleName + ", revision="
\r
921 + revision + ", prefix=" + prefix + "]";
\r
924 return moduleImport;
\r
928 * Traverse through given addedChilds and add only direct module childs.
\r
929 * Direct module child path size is 2 (1. module name, 2. child name).
\r
931 * @param addedChilds
\r
932 * @return map of children, where key is child QName and value is child
\r
935 private Map<QName, DataSchemaNode> buildModuleChildNodes(
\r
936 Map<List<String>, DataSchemaNodeBuilder> addedChilds) {
\r
937 final Map<QName, DataSchemaNode> childNodes = new HashMap<QName, DataSchemaNode>();
\r
938 for (Map.Entry<List<String>, DataSchemaNodeBuilder> entry : addedChilds
\r
940 if (entry.getKey().size() == 2) {
\r
941 DataSchemaNode node = entry.getValue().build();
\r
942 QName qname = entry.getValue().getQName();
\r
943 childNodes.put(qname, node);
\r
950 * Traverse through given addedGroupings and add only direct module
\r
951 * groupings. Direct module grouping path size is 2 (1. module name, 2.
\r
954 * @param addedGroupings
\r
955 * @return set of built GroupingDefinition objects
\r
957 private Set<GroupingDefinition> buildModuleGroupings(
\r
958 Map<List<String>, GroupingBuilder> addedGroupings) {
\r
959 final Set<GroupingDefinition> groupings = new HashSet<GroupingDefinition>();
\r
960 for (Map.Entry<List<String>, GroupingBuilder> entry : addedGroupings
\r
962 if (entry.getKey().size() == 2) {
\r
963 groupings.add(entry.getValue().build());
\r
970 * Traverse through given addedRpcs and build RpcDefinition objects.
\r
973 * @return set of built RpcDefinition objects
\r
975 private Set<RpcDefinition> buildModuleRpcs(
\r
976 Map<List<String>, RpcDefinitionBuilder> addedRpcs) {
\r
977 final Set<RpcDefinition> rpcs = new HashSet<RpcDefinition>();
\r
978 RpcDefinitionBuilder builder;
\r
979 for (Map.Entry<List<String>, RpcDefinitionBuilder> entry : addedRpcs
\r
981 builder = entry.getValue();
\r
982 RpcDefinition rpc = builder.build();
\r
989 * Traverse through given addedTypedefs and add only direct module typedef
\r
990 * statements. Direct module typedef path size is 2 (1. module name, 2.
\r
993 * @param addedTypedefs
\r
994 * @return set of built module typedef statements
\r
996 private Set<TypeDefinition<?>> buildModuleTypedefs(
\r
997 Map<List<String>, TypeDefinitionBuilder> addedTypedefs) {
\r
998 Set<TypeDefinition<?>> typedefs = new HashSet<TypeDefinition<?>>();
\r
999 for (Map.Entry<List<String>, TypeDefinitionBuilder> entry : addedTypedefs
\r
1001 if (entry.getKey().size() == 2) {
\r
1002 TypeDefinition<? extends TypeDefinition<?>> node = entry
\r
1003 .getValue().build();
\r
1004 typedefs.add(node);
\r
1011 * Traverse through given addedUsesNodes and add only direct module uses
\r
1012 * nodes. Direct module uses node path size is 2 (1. module name, 2. uses
\r
1015 * @param addedUsesNodes
\r
1016 * @return set of built module uses nodes
\r
1018 private Set<UsesNode> buildUsesNodes(
\r
1019 Map<List<String>, UsesNodeBuilder> addedUsesNodes) {
\r
1020 final Set<UsesNode> usesNodeDefinitions = new HashSet<UsesNode>();
\r
1021 for (Map.Entry<List<String>, UsesNodeBuilder> entry : addedUsesNodes
\r
1023 if (entry.getKey().size() == 2) {
\r
1024 usesNodeDefinitions.add(entry.getValue().build());
\r
1027 return usesNodeDefinitions;
\r
1031 * Traverse through given addedFeatures and add only direct module features.
\r
1032 * Direct module feature path size is 2 (1. module name, 2. feature name).
\r
1034 * @param addedFeatures
\r
1035 * @return set of built module features
\r
1037 private Set<FeatureDefinition> buildModuleFeatures(
\r
1038 Map<List<String>, FeatureBuilder> addedFeatures) {
\r
1039 Set<FeatureDefinition> features = new HashSet<FeatureDefinition>();
\r
1040 for (Map.Entry<List<String>, FeatureBuilder> entry : addedFeatures
\r
1042 if (entry.getKey().size() == 2) {
\r
1043 features.add(entry.getValue().build());
\r