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;
11 import java.util.Collection;
12 import java.util.Date;
13 import java.util.HashSet;
14 import java.util.LinkedList;
15 import java.util.List;
18 import org.opendaylight.yangtools.concepts.Immutable;
19 import org.opendaylight.yangtools.yang.common.QNameModule;
20 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
21 import org.opendaylight.yangtools.yang.model.api.Deviation;
22 import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition;
23 import org.opendaylight.yangtools.yang.model.api.FeatureDefinition;
24 import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
25 import org.opendaylight.yangtools.yang.model.api.Module;
26 import org.opendaylight.yangtools.yang.model.api.ModuleImport;
27 import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
28 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
29 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
30 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
31 import org.opendaylight.yangtools.yang.model.api.stmt.IncludeStatement;
32 import org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement;
33 import org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleStatement;
34 import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleImpl;
35 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
36 import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNameToModuleQName;
38 import com.google.common.collect.ImmutableList;
39 import com.google.common.collect.ImmutableSet;
40 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.IncludedModuleContext;
42 public class ModuleEffectiveStatementImpl extends AbstractEffectiveDocumentedDataNodeContainer<String, ModuleStatement>
43 implements Module, Immutable {
45 private final QNameModule qNameModule;
46 private final String name;
47 private String sourcePath;
48 private String prefix;
49 private String yangVersion;
50 private String organization;
51 private String contact;
52 private ImmutableSet<ModuleImport> imports;
53 private ImmutableSet<Module> submodules;
54 private ImmutableSet<FeatureDefinition> features;
55 private ImmutableSet<NotificationDefinition> notifications;
56 private ImmutableSet<AugmentationSchema> augmentations;
57 private ImmutableSet<RpcDefinition> rpcs;
58 private ImmutableSet<Deviation> deviations;
59 private ImmutableList<ExtensionDefinition> extensionNodes;
60 private ImmutableSet<IdentitySchemaNode> identities;
61 private ImmutableList<UnknownSchemaNode> unknownNodes;
62 private String source;
64 public ModuleEffectiveStatementImpl(StmtContext<String, ModuleStatement, ?> ctx) {
68 qNameModule = ctx.getFromNamespace(ModuleNameToModuleQName.class, name);
70 for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
71 if (effectiveStatement instanceof PrefixEffectiveStatementImpl) {
72 prefix = ((PrefixEffectiveStatementImpl) effectiveStatement).argument();
74 if (effectiveStatement instanceof YangVersionEffectiveStatementImpl) {
75 yangVersion = ((YangVersionEffectiveStatementImpl) effectiveStatement).argument();
77 if (effectiveStatement instanceof OrganizationEffectiveStatementImpl) {
78 organization = ((OrganizationEffectiveStatementImpl) effectiveStatement).argument();
80 if (effectiveStatement instanceof ContactEffectiveStatementImpl) {
81 contact = ((ContactEffectiveStatementImpl) effectiveStatement).argument();
85 source = ctx.getStatementSource().name();
87 //ctx.getFromNamespace(IncludedModuleContext.class, ) //ModuleIdentifier
89 initSubstatementCollections();
92 private void initSubstatementCollections() {
93 Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
95 List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
96 Set<AugmentationSchema> augmentationsInit = new HashSet<>();
97 Set<ModuleImport> importsInit = new HashSet<>();
98 Set<Module> submodulesInit = new HashSet<>();
99 Set<NotificationDefinition> notificationsInit = new HashSet<>();
100 Set<RpcDefinition> rpcsInit = new HashSet<>();
101 Set<Deviation> deviationsInit = new HashSet<>();
102 Set<IdentitySchemaNode> identitiesInit = new HashSet<>();
103 Set<FeatureDefinition> featuresInit = new HashSet<>();
104 List<ExtensionDefinition> extensionNodesInit = new LinkedList<>();
108 for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
109 if (effectiveStatement instanceof UnknownSchemaNode) {
110 unknownNodesInit.add((UnknownSchemaNode) effectiveStatement);
112 if (effectiveStatement instanceof AugmentationSchema) {
113 augmentationsInit.add((AugmentationSchema) effectiveStatement);
115 if (effectiveStatement instanceof ModuleImport) {
116 importsInit.add((ModuleImport) effectiveStatement);
118 if (effectiveStatement instanceof IncludeEffectiveStatementImpl) {
119 // ((IncludeEffectiveStatementImpl) effectiveStatement).
121 if (effectiveStatement instanceof NotificationDefinition) {
122 notificationsInit.add((NotificationDefinition) effectiveStatement);
124 if (effectiveStatement instanceof RpcDefinition) {
125 rpcsInit.add((RpcDefinition) effectiveStatement);
127 if (effectiveStatement instanceof Deviation) {
128 deviationsInit.add((Deviation) effectiveStatement);
130 if (effectiveStatement instanceof IdentitySchemaNode) {
131 identitiesInit.add((IdentitySchemaNode) effectiveStatement);
133 if (effectiveStatement instanceof FeatureDefinition) {
134 featuresInit.add((FeatureDefinition) effectiveStatement);
136 if (effectiveStatement instanceof ExtensionDefinition) {
137 extensionNodesInit.add((ExtensionDefinition) effectiveStatement);
141 this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
142 this.augmentations = ImmutableSet.copyOf(augmentationsInit);
143 this.imports = ImmutableSet.copyOf(importsInit);
144 this.submodules = ImmutableSet.copyOf(submodulesInit);
145 this.notifications = ImmutableSet.copyOf(notificationsInit);
146 this.rpcs = ImmutableSet.copyOf(rpcsInit);
147 this.deviations = ImmutableSet.copyOf(deviationsInit);
148 this.identities = ImmutableSet.copyOf(identitiesInit);
149 this.features = ImmutableSet.copyOf(featuresInit);
150 this.extensionNodes = ImmutableList.copyOf(extensionNodesInit);
154 public String getModuleSourcePath() {
159 public URI getNamespace() {
160 return qNameModule.getNamespace();
164 public String getName() {
169 public Date getRevision() {
170 return qNameModule.getRevision();
174 public String getPrefix() {
179 public String getYangVersion() {
184 public String getOrganization() {
189 public String getContact() {
194 public Set<ModuleImport> getImports() {
199 public Set<Module> getSubmodules() {
204 public Set<FeatureDefinition> getFeatures() {
209 public Set<NotificationDefinition> getNotifications() {
210 return notifications;
214 public Set<AugmentationSchema> getAugmentations() {
215 return augmentations;
219 public Set<RpcDefinition> getRpcs() {
224 public Set<Deviation> getDeviations() {
229 public List<ExtensionDefinition> getExtensionSchemaNodes() {
230 return extensionNodes;
234 public Set<IdentitySchemaNode> getIdentities() {
239 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
244 public String getSource() {
249 public int hashCode() {
250 final int prime = 31;
252 result = prime * result + ((name == null) ? 0 : name.hashCode());
253 result = prime * result + ((yangVersion == null) ? 0 : yangVersion.hashCode());
254 result = prime * result + qNameModule.hashCode();
259 public boolean equals(final Object obj) {
266 if (getClass() != obj.getClass()) {
269 ModuleEffectiveStatementImpl other = (ModuleEffectiveStatementImpl) obj;
271 if (other.name != null) {
274 } else if (!name.equals(other.name)) {
277 if (!qNameModule.equals(other.qNameModule)) {
280 if (yangVersion == null) {
281 if (other.yangVersion != null) {
284 } else if (!yangVersion.equals(other.yangVersion)) {
291 public String toString() {
292 StringBuilder sb = new StringBuilder(ModuleImpl.class.getSimpleName());
294 sb.append("name=").append(name);
295 sb.append(", namespace=").append(getNamespace());
296 sb.append(", revision=").append(getRevision());
297 sb.append(", prefix=").append(prefix);
298 sb.append(", yangVersion=").append(yangVersion);
300 return sb.toString();
304 public QNameModule getQNameModule() {