2 * Copyright (c) 2015 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.yangtools.yang.parser.stmt.rfc6020.effective;
10 import com.google.common.collect.ImmutableList;
11 import com.google.common.collect.ImmutableSet;
13 import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNameToModuleQName;
14 import java.util.Collection;
15 import java.util.HashSet;
16 import java.util.LinkedList;
17 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
19 import java.util.Date;
20 import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleImpl;
21 import java.util.List;
23 import org.opendaylight.yangtools.yang.common.QNameModule;
24 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
25 import org.opendaylight.yangtools.yang.model.api.Deviation;
26 import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition;
27 import org.opendaylight.yangtools.yang.model.api.FeatureDefinition;
28 import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
29 import org.opendaylight.yangtools.yang.model.api.ModuleImport;
30 import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
31 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
32 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
33 import org.opendaylight.yangtools.concepts.Immutable;
34 import org.opendaylight.yangtools.yang.model.api.Module;
35 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
36 import org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement;
38 public class ModuleEffectiveStatementImpl extends
39 AbstractEffectiveDocumentedDataNodeContainer<String, ModuleStatement>
40 implements Module, Immutable {
42 private final QNameModule qnameModule;
43 private final String name;
44 private String sourcePath;
45 private String prefix;
46 private String yangVersion;
47 private String organization;
48 private String contact;
49 private ImmutableSet<ModuleImport> imports;
50 private ImmutableSet<Module> submodules;
51 private ImmutableSet<FeatureDefinition> features;
52 private ImmutableSet<NotificationDefinition> notifications;
53 private ImmutableSet<AugmentationSchema> augmentations;
54 private ImmutableSet<RpcDefinition> rpcs;
55 private ImmutableSet<Deviation> deviations;
56 private ImmutableList<ExtensionDefinition> extensionNodes;
57 private ImmutableSet<IdentitySchemaNode> identities;
58 private ImmutableList<UnknownSchemaNode> unknownNodes;
59 private String source;
61 public ModuleEffectiveStatementImpl(
62 StmtContext<String, ModuleStatement, ?> ctx) {
66 qnameModule = ctx.getFromNamespace(ModuleNameToModuleQName.class, name);
67 // :TODO init other fields
69 initSubstatementCollections();
73 private void initSubstatementCollections() {
74 Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
76 LinkedList<UnknownSchemaNode> unknownNodes = new LinkedList<UnknownSchemaNode>();
77 HashSet<AugmentationSchema> augmentations = new HashSet<AugmentationSchema>();
79 for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
80 if (effectiveStatement instanceof UnknownSchemaNode) {
81 UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
82 unknownNodes.add(unknownNode);
84 if (effectiveStatement instanceof AugmentationSchema) {
85 AugmentationSchema augmentationSchema = (AugmentationSchema) effectiveStatement;
86 augmentations.add(augmentationSchema);
90 this.unknownNodes = ImmutableList.copyOf(unknownNodes);
91 this.augmentations = ImmutableSet.copyOf(augmentations);
93 // :TODO other substatement collections ...
97 public String getModuleSourcePath() {
102 public URI getNamespace() {
103 return qnameModule.getNamespace();
107 public String getName() {
112 public Date getRevision() {
113 return qnameModule.getRevision();
117 public String getPrefix() {
122 public String getYangVersion() {
127 public String getOrganization() {
132 public String getContact() {
137 public Set<ModuleImport> getImports() {
142 public Set<Module> getSubmodules() {
147 public Set<FeatureDefinition> getFeatures() {
152 public Set<NotificationDefinition> getNotifications() {
153 return notifications;
157 public Set<AugmentationSchema> getAugmentations() {
158 return augmentations;
162 public Set<RpcDefinition> getRpcs() {
167 public Set<Deviation> getDeviations() {
172 public List<ExtensionDefinition> getExtensionSchemaNodes() {
173 return extensionNodes;
177 public Set<IdentitySchemaNode> getIdentities() {
182 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
187 public String getSource() {
192 public int hashCode() {
193 final int prime = 31;
195 result = prime * result + ((name == null) ? 0 : name.hashCode());
196 result = prime * result
197 + ((yangVersion == null) ? 0 : yangVersion.hashCode());
198 result = prime * result + qnameModule.hashCode();
203 public boolean equals(final Object obj) {
210 if (getClass() != obj.getClass()) {
213 ModuleEffectiveStatementImpl other = (ModuleEffectiveStatementImpl) obj;
215 if (other.name != null) {
218 } else if (!name.equals(other.name)) {
221 if (!qnameModule.equals(other.qnameModule)) {
224 if (yangVersion == null) {
225 if (other.yangVersion != null) {
228 } else if (!yangVersion.equals(other.yangVersion)) {
234 // private static <T extends SchemaNode> Set<T> toImmutableSortedSet(final
235 // Set<T> original) {
236 // TreeSet<T> sorted = new TreeSet<>(Comparators.SCHEMA_NODE_COMP);
237 // sorted.addAll(original);
238 // return Collections.unmodifiableSet(sorted);
242 public String toString() {
243 StringBuilder sb = new StringBuilder(ModuleImpl.class.getSimpleName());
245 sb.append("name=").append(name);
246 sb.append(", namespace=").append(getNamespace());
247 sb.append(", revision=").append(getRevision());
248 sb.append(", prefix=").append(prefix);
249 sb.append(", yangVersion=").append(yangVersion);
251 return sb.toString();
255 public QNameModule getQNameModule() {