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.BelongsToStatement;
32 import org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleStatement;
33 import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleImpl;
34 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
36 import com.google.common.collect.ImmutableList;
37 import com.google.common.collect.ImmutableSet;
38 import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNameToModuleQName;
40 import static org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils.firstAttributeOf;
42 public class SubmoduleEffectiveStatementImpl extends
43 AbstractEffectiveDocumentedDataNodeContainer<String, SubmoduleStatement> 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 SubmoduleEffectiveStatementImpl(StmtContext<String, SubmoduleStatement, ?> ctx) {
69 String belongsToModuleName = firstAttributeOf(ctx.declaredSubstatements(), BelongsToStatement.class);
70 final QNameModule belongsToModule = ctx.getFromNamespace(ModuleNameToModuleQName.class, belongsToModuleName);
71 qNameModule = QNameModule.create(belongsToModule.getNamespace(), belongsToModule.getRevision());
73 for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
74 if (effectiveStatement instanceof PrefixEffectiveStatementImpl) {
75 prefix = ((PrefixEffectiveStatementImpl) effectiveStatement).argument();
77 if (effectiveStatement instanceof YangVersionEffectiveStatementImpl) {
78 yangVersion = ((YangVersionEffectiveStatementImpl) effectiveStatement).argument();
80 if (effectiveStatement instanceof OrganizationEffectiveStatementImpl) {
81 organization = ((OrganizationEffectiveStatementImpl) effectiveStatement).argument();
83 if (effectiveStatement instanceof ContactEffectiveStatementImpl) {
84 contact = ((ContactEffectiveStatementImpl) effectiveStatement).argument();
88 source = ctx.getStatementSource().name();
90 initSubstatementCollections();
93 private void initSubstatementCollections() {
94 Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
96 List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
97 Set<AugmentationSchema> augmentationsInit = new HashSet<>();
98 Set<ModuleImport> importsInit = new HashSet<>();
99 Set<Module> submodulesInit = new HashSet<>();
100 Set<NotificationDefinition> notificationsInit = new HashSet<>();
101 Set<RpcDefinition> rpcsInit = new HashSet<>();
102 Set<Deviation> deviationsInit = new HashSet<>();
103 Set<IdentitySchemaNode> identitiesInit = new HashSet<>();
104 Set<FeatureDefinition> featuresInit = new HashSet<>();
105 List<ExtensionDefinition> extensionNodesInit = new LinkedList<>();
107 for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
108 if (effectiveStatement instanceof UnknownSchemaNode) {
109 unknownNodesInit.add((UnknownSchemaNode) effectiveStatement);
111 if (effectiveStatement instanceof AugmentationSchema) {
112 augmentationsInit.add((AugmentationSchema) effectiveStatement);
114 if (effectiveStatement instanceof ModuleImport) {
115 importsInit.add((ModuleImport) effectiveStatement);
117 if (effectiveStatement instanceof Module) {
118 submodulesInit.add((Module) effectiveStatement);
120 if (effectiveStatement instanceof NotificationDefinition) {
121 notificationsInit.add((NotificationDefinition) effectiveStatement);
123 if (effectiveStatement instanceof RpcDefinition) {
124 rpcsInit.add((RpcDefinition) effectiveStatement);
126 if (effectiveStatement instanceof Deviation) {
127 deviationsInit.add((Deviation) effectiveStatement);
129 if (effectiveStatement instanceof IdentitySchemaNode) {
130 identitiesInit.add((IdentitySchemaNode) effectiveStatement);
132 if (effectiveStatement instanceof FeatureDefinition) {
133 featuresInit.add((FeatureDefinition) effectiveStatement);
135 if (effectiveStatement instanceof ExtensionDefinition) {
136 extensionNodesInit.add((ExtensionDefinition) effectiveStatement);
140 this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
141 this.augmentations = ImmutableSet.copyOf(augmentationsInit);
142 this.imports = ImmutableSet.copyOf(importsInit);
143 this.submodules = ImmutableSet.copyOf(submodulesInit);
144 this.notifications = ImmutableSet.copyOf(notificationsInit);
145 this.rpcs = ImmutableSet.copyOf(rpcsInit);
146 this.deviations = ImmutableSet.copyOf(deviationsInit);
147 this.identities = ImmutableSet.copyOf(identitiesInit);
148 this.features = ImmutableSet.copyOf(featuresInit);
149 this.extensionNodes = ImmutableList.copyOf(extensionNodesInit);
153 public String getModuleSourcePath() {
158 public URI getNamespace() {
159 return qNameModule.getNamespace();
163 public String getName() {
168 public Date getRevision() {
169 return qNameModule.getRevision();
173 public String getPrefix() {
178 public String getYangVersion() {
183 public String getOrganization() {
188 public String getContact() {
193 public Set<ModuleImport> getImports() {
198 public Set<Module> getSubmodules() {
203 public Set<FeatureDefinition> getFeatures() {
208 public Set<NotificationDefinition> getNotifications() {
209 return notifications;
213 public Set<AugmentationSchema> getAugmentations() {
214 return augmentations;
218 public Set<RpcDefinition> getRpcs() {
223 public Set<Deviation> getDeviations() {
228 public List<ExtensionDefinition> getExtensionSchemaNodes() {
229 return extensionNodes;
233 public Set<IdentitySchemaNode> getIdentities() {
238 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
243 public String getSource() {
248 public int hashCode() {
249 final int prime = 31;
251 result = prime * result + ((name == null) ? 0 : name.hashCode());
252 result = prime * result + ((yangVersion == null) ? 0 : yangVersion.hashCode());
253 result = prime * result + qNameModule.hashCode();
258 public boolean equals(final Object obj) {
265 if (getClass() != obj.getClass()) {
268 SubmoduleEffectiveStatementImpl other = (SubmoduleEffectiveStatementImpl) obj;
270 if (other.name != null) {
273 } else if (!name.equals(other.name)) {
276 if (!qNameModule.equals(other.qNameModule)) {
279 if (yangVersion == null) {
280 if (other.yangVersion != null) {
283 } else if (!yangVersion.equals(other.yangVersion)) {
290 public String toString() {
291 StringBuilder sb = new StringBuilder(ModuleImpl.class.getSimpleName());
293 sb.append("name=").append(name);
294 sb.append(", namespace=").append(getNamespace());
295 sb.append(", revision=").append(getRevision());
296 sb.append(", prefix=").append(prefix);
297 sb.append(", yangVersion=").append(yangVersion);
299 return sb.toString();
303 public QNameModule getQNameModule() {