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.Module;
\r
28 import org.opendaylight.controller.yang.model.api.ModuleImport;
\r
29 import org.opendaylight.controller.yang.model.api.NotificationDefinition;
\r
30 import org.opendaylight.controller.yang.model.api.RpcDefinition;
\r
31 import org.opendaylight.controller.yang.model.api.TypeDefinition;
\r
32 import org.opendaylight.controller.yang.model.api.UsesNode;
\r
33 import org.opendaylight.controller.yang.model.parser.builder.api.AugmentationSchemaBuilder;
\r
34 import org.opendaylight.controller.yang.model.parser.builder.api.Builder;
\r
35 import org.opendaylight.controller.yang.model.parser.builder.api.ChildNodeBuilder;
\r
36 import org.opendaylight.controller.yang.model.parser.builder.api.DataSchemaNodeBuilder;
\r
37 import org.opendaylight.controller.yang.model.parser.builder.api.GroupingBuilder;
\r
38 import org.opendaylight.controller.yang.model.parser.builder.api.TypeAwareBuilder;
\r
39 import org.opendaylight.controller.yang.model.parser.builder.api.TypeDefinitionAwareBuilder;
\r
40 import org.opendaylight.controller.yang.model.parser.builder.api.TypeDefinitionBuilder;
\r
41 import org.opendaylight.controller.yang.model.parser.builder.api.UsesNodeBuilder;
\r
44 * This builder builds Module object. If this module is dependent on external
\r
45 * module/modules, these dependencies must be resolved before module is built,
\r
46 * otherwise result may not be valid.
\r
48 public class ModuleBuilder implements Builder {
\r
50 private final ModuleImpl instance;
\r
51 private final String name;
\r
52 private String prefix;
\r
53 private Date revision;
\r
55 private final Set<ModuleImport> imports = new HashSet<ModuleImport>();
\r
56 private Set<AugmentationSchema> augmentations;
\r
59 * All nodes, that can contain other nodes
\r
61 private final Map<List<String>, Builder> moduleNodes = new HashMap<List<String>, Builder>();
\r
64 * Holds all child (DataSchemaNode) nodes: anyxml, choice, case, container,
\r
65 * list, leaf, leaf-list.
\r
67 private final Map<List<String>, DataSchemaNodeBuilder> addedChilds = new HashMap<List<String>, DataSchemaNodeBuilder>();
\r
69 private final Map<List<String>, GroupingBuilder> addedGroupings = new HashMap<List<String>, GroupingBuilder>();
\r
70 private final Set<AugmentationSchemaBuilder> addedAugments = new HashSet<AugmentationSchemaBuilder>();
\r
71 private final Map<List<String>, UsesNodeBuilder> addedUsesNodes = new HashMap<List<String>, UsesNodeBuilder>();
\r
72 private final Map<List<String>, RpcDefinitionBuilder> addedRpcs = new HashMap<List<String>, RpcDefinitionBuilder>();
\r
73 private final Set<NotificationBuilder> addedNotifications = new HashSet<NotificationBuilder>();
\r
74 private final Map<List<String>, FeatureBuilder> addedFeatures = new HashMap<List<String>, FeatureBuilder>();
\r
75 private final Map<String, DeviationBuilder> addedDeviations = new HashMap<String, DeviationBuilder>();
\r
76 private final Map<List<String>, TypeDefinitionBuilder> addedTypedefs = new HashMap<List<String>, TypeDefinitionBuilder>();
\r
77 private final List<ExtensionBuilder> addedExtensions = new ArrayList<ExtensionBuilder>();
\r
79 private final Map<List<String>, TypeAwareBuilder> dirtyNodes = new HashMap<List<String>, TypeAwareBuilder>();
\r
80 private final Map<List<String>, UnionTypeBuilder> unionTypes = new HashMap<List<String>, UnionTypeBuilder>();
\r
82 public ModuleBuilder(String name) {
\r
84 instance = new ModuleImpl(name);
\r
90 * Build new Module object based on this builder.
\r
93 public Module build() {
\r
94 instance.setImports(imports);
\r
97 final Set<TypeDefinition<?>> typedefs = buildModuleTypedefs(addedTypedefs);
\r
98 instance.setTypeDefinitions(typedefs);
\r
101 final Map<QName, DataSchemaNode> childNodes = buildModuleChildNodes(addedChilds);
\r
102 instance.setChildNodes(childNodes);
\r
105 final Set<GroupingDefinition> groupings = buildModuleGroupings(addedGroupings);
\r
106 instance.setGroupings(groupings);
\r
109 final Set<UsesNode> usesNodeDefinitions = buildUsesNodes(addedUsesNodes);
\r
110 instance.setUses(usesNodeDefinitions);
\r
113 final Set<FeatureDefinition> features = buildModuleFeatures(addedFeatures);
\r
114 instance.setFeatures(features);
\r
117 final Set<NotificationDefinition> notifications = new HashSet<NotificationDefinition>();
\r
118 for (NotificationBuilder entry : addedNotifications) {
\r
119 notifications.add((NotificationDefinition) entry.build());
\r
121 instance.setNotifications(notifications);
\r
124 instance.setAugmentations(augmentations);
\r
127 final Set<RpcDefinition> rpcs = buildModuleRpcs(addedRpcs);
\r
128 instance.setRpcs(rpcs);
\r
131 final Set<Deviation> deviations = new HashSet<Deviation>();
\r
132 for (Map.Entry<String, DeviationBuilder> entry : addedDeviations
\r
134 deviations.add(entry.getValue().build());
\r
136 instance.setDeviations(deviations);
\r
139 final List<ExtensionDefinition> extensions = new ArrayList<ExtensionDefinition>();
\r
140 for(ExtensionBuilder b : addedExtensions) {
\r
141 extensions.add(b.build());
\r
143 instance.setExtensionSchemaNodes(extensions);
\r
148 public Builder getNode(List<String> path) {
\r
149 return moduleNodes.get(path);
\r
152 public Map<List<String>, TypeAwareBuilder> getDirtyNodes() {
\r
156 public String getName() {
\r
160 public String getPrefix() {
\r
164 public Date getRevision() {
\r
168 public Set<AugmentationSchemaBuilder> getAddedAugments() {
\r
169 return addedAugments;
\r
172 public void addDirtyNode(List<String> path) {
\r
173 List<String> dirtyNodePath = new ArrayList<String>(path);
\r
174 TypeAwareBuilder nodeBuilder = (TypeAwareBuilder) moduleNodes
\r
175 .get(dirtyNodePath);
\r
176 dirtyNodes.put(dirtyNodePath, nodeBuilder);
\r
179 public void setNamespace(URI namespace) {
\r
180 instance.setNamespace(namespace);
\r
183 public void setRevision(Date revision) {
\r
184 this.revision = revision;
\r
185 instance.setRevision(revision);
\r
188 public void setPrefix(String prefix) {
\r
189 this.prefix = prefix;
\r
190 instance.setPrefix(prefix);
\r
193 public void setYangVersion(String yangVersion) {
\r
194 instance.setYangVersion(yangVersion);
\r
197 public void setDescription(String description) {
\r
198 instance.setDescription(description);
\r
201 public void setReference(String reference) {
\r
202 instance.setReference(reference);
\r
205 public void setOrganization(String organization) {
\r
206 instance.setOrganization(organization);
\r
209 public void setContact(String contact) {
\r
210 instance.setContact(contact);
\r
213 public void setAugmentations(Set<AugmentationSchema> augmentations) {
\r
214 this.augmentations = augmentations;
\r
217 public boolean addModuleImport(final String moduleName,
\r
218 final Date revision, final String prefix) {
\r
219 ModuleImport moduleImport = createModuleImport(moduleName, revision,
\r
221 return imports.add(moduleImport);
\r
224 public Set<ModuleImport> getModuleImports() {
\r
228 public ExtensionBuilder addExtension(QName qname) {
\r
229 ExtensionBuilder builder = new ExtensionBuilder(qname);
\r
233 public ContainerSchemaNodeBuilder addContainerNode(QName containerName,
\r
234 List<String> parentPath) {
\r
235 List<String> pathToNode = new ArrayList<String>(parentPath);
\r
237 ContainerSchemaNodeBuilder containerBuilder = new ContainerSchemaNodeBuilder(
\r
240 ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes
\r
242 if (parent != null) {
\r
243 if(parent instanceof AugmentationSchemaBuilder) {
\r
244 containerBuilder.setAugmenting(true);
\r
246 parent.addChildNode(containerBuilder);
\r
249 pathToNode.add(containerName.getLocalName());
\r
250 moduleNodes.put(pathToNode, containerBuilder);
\r
251 addedChilds.put(pathToNode, containerBuilder);
\r
253 return containerBuilder;
\r
256 public ListSchemaNodeBuilder addListNode(QName listName,
\r
257 List<String> parentPath) {
\r
258 List<String> pathToNode = new ArrayList<String>(parentPath);
\r
260 ListSchemaNodeBuilder listBuilder = new ListSchemaNodeBuilder(listName);
\r
262 ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes
\r
264 if (parent != null) {
\r
265 if(parent instanceof AugmentationSchemaBuilder) {
\r
266 listBuilder.setAugmenting(true);
\r
268 parent.addChildNode(listBuilder);
\r
271 pathToNode.add(listName.getLocalName());
\r
272 moduleNodes.put(pathToNode, listBuilder);
\r
273 addedChilds.put(pathToNode, listBuilder);
\r
275 return listBuilder;
\r
278 public LeafSchemaNodeBuilder addLeafNode(QName leafName,
\r
279 List<String> parentPath) {
\r
280 List<String> pathToNode = new ArrayList<String>(parentPath);
\r
282 LeafSchemaNodeBuilder leafBuilder = new LeafSchemaNodeBuilder(leafName);
\r
284 ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes.get(pathToNode);
\r
285 if (parent != null) {
\r
286 if(parent instanceof AugmentationSchemaBuilder) {
\r
287 leafBuilder.setAugmenting(true);
\r
289 parent.addChildNode(leafBuilder);
\r
292 pathToNode.add(leafName.getLocalName());
\r
293 addedChilds.put(pathToNode, leafBuilder);
\r
294 moduleNodes.put(pathToNode, leafBuilder);
\r
296 return leafBuilder;
\r
299 public LeafListSchemaNodeBuilder addLeafListNode(QName leafListName,
\r
300 List<String> parentPath) {
\r
301 List<String> pathToNode = new ArrayList<String>(parentPath);
\r
303 LeafListSchemaNodeBuilder leafListBuilder = new LeafListSchemaNodeBuilder(
\r
305 ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes.get(pathToNode);
\r
306 if (parent != null) {
\r
307 if(parent instanceof AugmentationSchemaBuilder) {
\r
308 leafListBuilder.setAugmenting(true);
\r
310 parent.addChildNode(leafListBuilder);
\r
313 pathToNode.add(leafListName.getLocalName());
\r
314 addedChilds.put(pathToNode, leafListBuilder);
\r
315 moduleNodes.put(pathToNode, leafListBuilder);
\r
317 return leafListBuilder;
\r
320 public GroupingBuilder addGrouping(QName qname, List<String> parentPath) {
\r
321 List<String> pathToGroup = new ArrayList<String>(parentPath);
\r
323 GroupingBuilder builder = new GroupingBuilderImpl(qname);
\r
324 ChildNodeBuilder parentNodeBuilder = (ChildNodeBuilder) moduleNodes.get(pathToGroup);
\r
325 if (parentNodeBuilder != null) {
\r
326 parentNodeBuilder.addGrouping(builder);
\r
329 pathToGroup.add(qname.getLocalName());
\r
330 moduleNodes.put(pathToGroup, builder);
\r
331 addedGroupings.put(pathToGroup, builder);
\r
336 public AugmentationSchemaBuilder addAugment(String name,
\r
337 List<String> parentPath) {
\r
338 List<String> pathToAugment = new ArrayList<String>(parentPath);
\r
340 AugmentationSchemaBuilder builder = new AugmentationSchemaBuilderImpl(name);
\r
342 // augment can only be in 'module' or 'uses' statement
\r
343 UsesNodeBuilder parent = addedUsesNodes.get(pathToAugment);
\r
344 if (parent != null) {
\r
345 parent.addAugment(builder);
\r
348 pathToAugment.add(name);
\r
349 moduleNodes.put(pathToAugment, builder);
\r
350 addedAugments.add(builder);
\r
355 public UsesNodeBuilder addUsesNode(String groupingPathStr,
\r
356 List<String> parentPath) {
\r
357 List<String> pathToUses = new ArrayList<String>(parentPath);
\r
359 UsesNodeBuilder usesBuilder = new UsesNodeBuilderImpl(groupingPathStr);
\r
361 ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes.get(pathToUses);
\r
362 if (parent != null) {
\r
363 if(parent instanceof AugmentationSchemaBuilder) {
\r
364 usesBuilder.setAugmenting(true);
\r
366 parent.addUsesNode(usesBuilder);
\r
369 pathToUses.add(groupingPathStr);
\r
370 addedUsesNodes.put(pathToUses, usesBuilder);
\r
372 return usesBuilder;
\r
375 public RpcDefinitionBuilder addRpc(QName qname, List<String> parentPath) {
\r
376 List<String> pathToRpc = new ArrayList<String>(parentPath);
\r
378 RpcDefinitionBuilder rpcBuilder = new RpcDefinitionBuilder(qname);
\r
380 pathToRpc.add(qname.getLocalName());
\r
381 addedRpcs.put(pathToRpc, rpcBuilder);
\r
383 QName inputQName = new QName(qname.getNamespace(), qname.getRevision(),
\r
384 qname.getPrefix(), "input");
\r
385 ContainerSchemaNodeBuilder inputBuilder = new ContainerSchemaNodeBuilder(inputQName);
\r
386 List<String> pathToInput = new ArrayList<String>(pathToRpc);
\r
387 pathToInput.add("input");
\r
388 moduleNodes.put(pathToInput, inputBuilder);
\r
389 rpcBuilder.setInput(inputBuilder);
\r
391 QName outputQName = new QName(qname.getNamespace(),
\r
392 qname.getRevision(), qname.getPrefix(), "output");
\r
393 ContainerSchemaNodeBuilder outputBuilder = new ContainerSchemaNodeBuilder(outputQName);
\r
394 List<String> pathToOutput = new ArrayList<String>(pathToRpc);
\r
395 pathToOutput.add("output");
\r
396 moduleNodes.put(pathToOutput, outputBuilder);
\r
397 rpcBuilder.setOutput(outputBuilder);
\r
402 public NotificationBuilder addNotification(QName notificationName,
\r
403 List<String> parentPath) {
\r
404 List<String> pathToNotification = new ArrayList<String>(parentPath);
\r
406 NotificationBuilder notificationBuilder = new NotificationBuilder(
\r
409 pathToNotification.add(notificationName.getLocalName());
\r
410 moduleNodes.put(pathToNotification, notificationBuilder);
\r
411 addedNotifications.add(notificationBuilder);
\r
413 return notificationBuilder;
\r
416 public FeatureBuilder addFeature(QName featureName, List<String> parentPath) {
\r
417 List<String> pathToFeature = new ArrayList<String>(parentPath);
\r
418 pathToFeature.add(featureName.getLocalName());
\r
420 FeatureBuilder builder = new FeatureBuilder(featureName);
\r
421 addedFeatures.put(pathToFeature, builder);
\r
425 public TypedefBuilder addTypedef(QName typeDefName, List<String> parentPath) {
\r
426 List<String> pathToType = new ArrayList<String>(parentPath);
\r
427 TypedefBuilder builder = new TypedefBuilder(typeDefName);
\r
428 TypeDefinitionAwareBuilder parent = (TypeDefinitionAwareBuilder) moduleNodes.get(pathToType);
\r
429 if (parent != null) {
\r
430 parent.addTypedef(builder);
\r
432 pathToType.add(typeDefName.getLocalName());
\r
433 addedTypedefs.put(pathToType, builder);
\r
434 moduleNodes.put(pathToType, builder);
\r
438 public Set<TypeDefinitionBuilder> getModuleTypedefs() {
\r
439 Set<TypeDefinitionBuilder> typedefs = new HashSet<TypeDefinitionBuilder>();
\r
440 for (Map.Entry<List<String>, TypeDefinitionBuilder> entry : addedTypedefs.entrySet()) {
\r
441 if (entry.getKey().size() == 2) {
\r
442 typedefs.add(entry.getValue());
\r
448 public void setType(TypeDefinition<?> type, List<String> parentPath) {
\r
449 TypeAwareBuilder parent = (TypeAwareBuilder) moduleNodes.get(parentPath);
\r
450 parent.setType(type);
\r
453 public void addUnionType(List<String> parentPath) {
\r
454 TypeAwareBuilder parent = (TypeAwareBuilder) moduleNodes.get(parentPath);
\r
455 UnionTypeBuilder union = new UnionTypeBuilder();
\r
456 parent.setType(union.build());
\r
458 List<String> path = new ArrayList<String>(parentPath);
\r
461 unionTypes.put(path, union);
\r
462 moduleNodes.put(path, union);
\r
465 public DeviationBuilder addDeviation(String targetPath) {
\r
466 DeviationBuilder builder = new DeviationBuilder(targetPath);
\r
467 addedDeviations.put(targetPath, builder);
\r
471 public void addConfiguration(boolean configuration, List<String> parentPath) {
\r
472 Builder builder = moduleNodes.get(parentPath);
\r
473 if (builder instanceof DeviationBuilder) {
\r
477 DataSchemaNodeBuilder configBuilder = (DataSchemaNodeBuilder) moduleNodes.get(parentPath);
\r
478 configBuilder.setConfiguration(configuration);
\r
482 public UnknownSchemaNodeBuilder addUnknownSchemaNode(QName qname, List<String> parentPath) {
\r
483 UnknownSchemaNodeBuilder builder = new UnknownSchemaNodeBuilder(qname);
\r
488 private class ModuleImpl implements Module {
\r
489 private URI namespace;
\r
490 private final String name;
\r
491 private Date revision;
\r
492 private String prefix;
\r
493 private String yangVersion;
\r
494 private String description;
\r
495 private String reference;
\r
496 private String organization;
\r
497 private String contact;
\r
498 private Set<ModuleImport> imports = Collections.emptySet();
\r
499 private Set<FeatureDefinition> features = Collections.emptySet();
\r
500 private Set<TypeDefinition<?>> typeDefinitions = Collections.emptySet();
\r
501 private Set<NotificationDefinition> notifications = Collections.emptySet();
\r
502 private Set<AugmentationSchema> augmentations = Collections.emptySet();
\r
503 private Set<RpcDefinition> rpcs = Collections.emptySet();
\r
504 private Set<Deviation> deviations = Collections.emptySet();
\r
505 private Map<QName, DataSchemaNode> childNodes = Collections.emptyMap();
\r
506 private Set<GroupingDefinition> groupings = Collections.emptySet();
\r
507 private Set<UsesNode> uses = Collections.emptySet();
\r
508 private List<ExtensionDefinition> extensionSchemaNodes = Collections.emptyList();
\r
510 private ModuleImpl(String name) {
\r
515 public URI getNamespace() {
\r
519 private void setNamespace(URI namespace) {
\r
520 this.namespace = namespace;
\r
524 public String getName() {
\r
529 public Date getRevision() {
\r
533 private void setRevision(Date revision) {
\r
534 this.revision = revision;
\r
538 public String getPrefix() {
\r
542 private void setPrefix(String prefix) {
\r
543 this.prefix = prefix;
\r
547 public String getYangVersion() {
\r
548 return yangVersion;
\r
551 private void setYangVersion(String yangVersion) {
\r
552 this.yangVersion = yangVersion;
\r
556 public String getDescription() {
\r
557 return description;
\r
560 private void setDescription(String description) {
\r
561 this.description = description;
\r
565 public String getReference() {
\r
569 private void setReference(String reference) {
\r
570 this.reference = reference;
\r
574 public String getOrganization() {
\r
575 return organization;
\r
578 private void setOrganization(String organization) {
\r
579 this.organization = organization;
\r
583 public String getContact() {
\r
587 private void setContact(String contact) {
\r
588 this.contact = contact;
\r
592 public Set<ModuleImport> getImports() {
\r
596 private void setImports(Set<ModuleImport> imports) {
\r
597 if(imports != null) {
\r
598 this.imports = imports;
\r
603 public Set<FeatureDefinition> getFeatures() {
\r
607 private void setFeatures(Set<FeatureDefinition> features) {
\r
608 if(features != null) {
\r
609 this.features = features;
\r
614 public Set<TypeDefinition<?>> getTypeDefinitions() {
\r
615 return typeDefinitions;
\r
618 private void setTypeDefinitions(Set<TypeDefinition<?>> typeDefinitions) {
\r
619 if(typeDefinitions != null) {
\r
620 this.typeDefinitions = typeDefinitions;
\r
625 public Set<NotificationDefinition> getNotifications() {
\r
626 return notifications;
\r
629 private void setNotifications(Set<NotificationDefinition> notifications) {
\r
630 if(notifications != null) {
\r
631 this.notifications = notifications;
\r
636 public Set<AugmentationSchema> getAugmentations() {
\r
637 return augmentations;
\r
640 private void setAugmentations(Set<AugmentationSchema> augmentations) {
\r
641 if(augmentations != null) {
\r
642 this.augmentations = augmentations;
\r
647 public Set<RpcDefinition> getRpcs() {
\r
651 private void setRpcs(Set<RpcDefinition> rpcs) {
\r
658 public Set<Deviation> getDeviations() {
\r
662 private void setDeviations(Set<Deviation> deviations) {
\r
663 if(deviations != null) {
\r
664 this.deviations = deviations;
\r
669 public Set<DataSchemaNode> getChildNodes() {
\r
670 return new HashSet<DataSchemaNode>(childNodes.values());
\r
673 private void setChildNodes(Map<QName, DataSchemaNode> childNodes) {
\r
674 if(childNodes != null) {
\r
675 this.childNodes = childNodes;
\r
680 public Set<GroupingDefinition> getGroupings() {
\r
684 private void setGroupings(Set<GroupingDefinition> groupings) {
\r
685 if(groupings != null) {
\r
686 this.groupings = groupings;
\r
691 public Set<UsesNode> getUses() {
\r
695 private void setUses(Set<UsesNode> uses) {
\r
702 public List<ExtensionDefinition> getExtensionSchemaNodes() {
\r
703 return extensionSchemaNodes;
\r
706 private void setExtensionSchemaNodes(List<ExtensionDefinition> extensionSchemaNodes) {
\r
707 if(extensionSchemaNodes != null) {
\r
708 this.extensionSchemaNodes = extensionSchemaNodes;
\r
713 public DataSchemaNode getDataChildByName(QName name) {
\r
714 return childNodes.get(name);
\r
718 public DataSchemaNode getDataChildByName(String name) {
\r
719 DataSchemaNode result = null;
\r
720 for (Map.Entry<QName, DataSchemaNode> entry : childNodes.entrySet()) {
\r
721 if (entry.getKey().getLocalName().equals(name)) {
\r
722 result = entry.getValue();
\r
730 public int hashCode() {
\r
731 final int prime = 31;
\r
733 result = prime * result + ((namespace == null) ? 0 : namespace.hashCode());
\r
734 result = prime * result + ((name == null) ? 0 : name.hashCode());
\r
735 result = prime * result + ((revision == null) ? 0 : revision.hashCode());
\r
736 result = prime * result + ((prefix == null) ? 0 : prefix.hashCode());
\r
737 result = prime * result + ((yangVersion == null) ? 0 : yangVersion.hashCode());
\r
742 public boolean equals(Object obj) {
\r
749 if (getClass() != obj.getClass()) {
\r
752 ModuleImpl other = (ModuleImpl) obj;
\r
753 if (namespace == null) {
\r
754 if (other.namespace != null) {
\r
757 } else if (!namespace.equals(other.namespace)) {
\r
760 if (name == null) {
\r
761 if (other.name != null) {
\r
764 } else if (!name.equals(other.name)) {
\r
767 if (revision == null) {
\r
768 if (other.revision != null) {
\r
771 } else if (!revision.equals(other.revision)) {
\r
774 if (prefix == null) {
\r
775 if (other.prefix != null) {
\r
778 } else if (!prefix.equals(other.prefix)) {
\r
781 if (yangVersion == null) {
\r
782 if (other.yangVersion != null) {
\r
785 } else if (!yangVersion.equals(other.yangVersion)) {
\r
792 public String toString() {
\r
793 StringBuilder sb = new StringBuilder(
\r
794 ModuleImpl.class.getSimpleName());
\r
796 sb.append("name=" + name + ",\n");
\r
797 sb.append("namespace=" + namespace + ",\n");
\r
798 sb.append("revision=" + revision + ",\n");
\r
799 sb.append("prefix=" + prefix + ",\n");
\r
800 sb.append("yangVersion=" + yangVersion + ",\n");
\r
801 sb.append("description=" + description + ",\n");
\r
802 sb.append("reference=" + reference + ",\n");
\r
803 sb.append("organization=" + organization + ",\n");
\r
804 sb.append("contact=" + contact + ",\n");
\r
805 sb.append("childNodes=" + childNodes.values() + ",\n");
\r
806 sb.append("groupings=" + groupings + ",\n");
\r
807 sb.append("imports=" + imports + ",\n");
\r
808 sb.append("features=" + features + ",\n");
\r
809 sb.append("typeDefinitions=" + typeDefinitions + ",\n");
\r
810 sb.append("notifications=" + notifications + ",\n");
\r
811 sb.append("augmentations=" + augmentations + ",\n");
\r
812 sb.append("rpcs=" + rpcs + ",\n");
\r
813 sb.append("deviations=" + deviations + "\n");
\r
814 sb.append("uses=" + uses + "\n");
\r
816 return sb.toString();
\r
820 private ModuleImport createModuleImport(final String moduleName,
\r
821 final Date revision, final String prefix) {
\r
822 ModuleImport moduleImport = new ModuleImport() {
\r
824 public String getModuleName() {
\r
829 public Date getRevision() {
\r
834 public String getPrefix() {
\r
839 public int hashCode() {
\r
840 final int prime = 31;
\r
842 result = prime * result
\r
843 + ((moduleName == null) ? 0 : moduleName.hashCode());
\r
844 result = prime * result
\r
845 + ((revision == null) ? 0 : revision.hashCode());
\r
846 result = prime * result
\r
847 + ((prefix == null) ? 0 : prefix.hashCode());
\r
852 public boolean equals(Object obj) {
\r
859 if (getClass() != obj.getClass()) {
\r
862 ModuleImport other = (ModuleImport) obj;
\r
863 if (getModuleName() == null) {
\r
864 if (other.getModuleName() != null) {
\r
867 } else if (!getModuleName().equals(other.getModuleName())) {
\r
870 if (getRevision() == null) {
\r
871 if (other.getRevision() != null) {
\r
874 } else if (!getRevision().equals(other.getRevision())) {
\r
877 if (getPrefix() == null) {
\r
878 if (other.getPrefix() != null) {
\r
881 } else if (!getPrefix().equals(other.getPrefix())) {
\r
888 public String toString() {
\r
889 return "ModuleImport[moduleName=" + moduleName + ", revision="
\r
890 + revision + ", prefix=" + prefix + "]";
\r
893 return moduleImport;
\r
897 * Traverse through given addedChilds and add only direct module childs.
\r
898 * Direct module child path size is 2 (1. module name, 2. child name).
\r
900 * @param addedChilds
\r
901 * @return map of children, where key is child QName and value is child
\r
904 private Map<QName, DataSchemaNode> buildModuleChildNodes(
\r
905 Map<List<String>, DataSchemaNodeBuilder> addedChilds) {
\r
906 final Map<QName, DataSchemaNode> childNodes = new HashMap<QName, DataSchemaNode>();
\r
907 for (Map.Entry<List<String>, DataSchemaNodeBuilder> entry : addedChilds
\r
909 if (entry.getKey().size() == 2) {
\r
910 DataSchemaNode node = entry.getValue().build();
\r
911 QName qname = entry.getValue().getQName();
\r
912 childNodes.put(qname, node);
\r
919 * Traverse through given addedGroupings and add only direct module
\r
920 * groupings. Direct module grouping path size is 2 (1. module name, 2.
\r
923 * @param addedGroupings
\r
924 * @return set of built GroupingDefinition objects
\r
926 private Set<GroupingDefinition> buildModuleGroupings(
\r
927 Map<List<String>, GroupingBuilder> addedGroupings) {
\r
928 final Set<GroupingDefinition> groupings = new HashSet<GroupingDefinition>();
\r
929 for (Map.Entry<List<String>, GroupingBuilder> entry : addedGroupings
\r
931 if (entry.getKey().size() == 2) {
\r
932 groupings.add(entry.getValue().build());
\r
939 * Traverse through given addedRpcs and build RpcDefinition objects.
\r
942 * @return set of built RpcDefinition objects
\r
944 private Set<RpcDefinition> buildModuleRpcs(
\r
945 Map<List<String>, RpcDefinitionBuilder> addedRpcs) {
\r
946 final Set<RpcDefinition> rpcs = new HashSet<RpcDefinition>();
\r
947 RpcDefinitionBuilder builder;
\r
948 for (Map.Entry<List<String>, RpcDefinitionBuilder> entry : addedRpcs
\r
950 builder = entry.getValue();
\r
951 RpcDefinition rpc = builder.build();
\r
958 * Traverse through given addedTypedefs and add only direct module typedef
\r
959 * statements. Direct module typedef path size is 2 (1. module name, 2.
\r
962 * @param addedTypedefs
\r
963 * @return set of built module typedef statements
\r
965 private Set<TypeDefinition<?>> buildModuleTypedefs(
\r
966 Map<List<String>, TypeDefinitionBuilder> addedTypedefs) {
\r
967 Set<TypeDefinition<?>> typedefs = new HashSet<TypeDefinition<?>>();
\r
968 for (Map.Entry<List<String>, TypeDefinitionBuilder> entry : addedTypedefs
\r
970 if (entry.getKey().size() == 2) {
\r
971 TypeDefinition<? extends TypeDefinition<?>> node = entry
\r
972 .getValue().build();
\r
973 typedefs.add(node);
\r
980 * Traverse through given addedUsesNodes and add only direct module uses
\r
981 * nodes. Direct module uses node path size is 2 (1. module name, 2. uses
\r
984 * @param addedUsesNodes
\r
985 * @return set of built module uses nodes
\r
987 private Set<UsesNode> buildUsesNodes(
\r
988 Map<List<String>, UsesNodeBuilder> addedUsesNodes) {
\r
989 final Set<UsesNode> usesNodeDefinitions = new HashSet<UsesNode>();
\r
990 for (Map.Entry<List<String>, UsesNodeBuilder> entry : addedUsesNodes
\r
992 if (entry.getKey().size() == 2) {
\r
993 usesNodeDefinitions.add(entry.getValue().build());
\r
996 return usesNodeDefinitions;
\r
1000 * Traverse through given addedFeatures and add only direct module features.
\r
1001 * Direct module feature path size is 2 (1. module name, 2. feature name).
\r
1003 * @param addedFeatures
\r
1004 * @return set of built module features
\r
1006 private Set<FeatureDefinition> buildModuleFeatures(
\r
1007 Map<List<String>, FeatureBuilder> addedFeatures) {
\r
1008 Set<FeatureDefinition> features = new HashSet<FeatureDefinition>();
\r
1009 for (Map.Entry<List<String>, FeatureBuilder> entry : addedFeatures
\r
1011 if (entry.getKey().size() == 2) {
\r
1012 features.add(entry.getValue().build());
\r