2 * Copyright (c) 2014, 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
9 package org.opendaylight.yangtools.yang.parser.builder.impl;
11 import static com.google.common.base.Preconditions.checkNotNull;
12 import com.google.common.collect.ImmutableList;
13 import com.google.common.collect.ImmutableSet;
15 import java.util.Collections;
16 import java.util.Date;
17 import java.util.List;
18 import java.util.NavigableSet;
19 import java.util.Objects;
21 import java.util.TreeSet;
22 import org.opendaylight.yangtools.concepts.Immutable;
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.Module;
30 import org.opendaylight.yangtools.yang.model.api.ModuleImport;
31 import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
32 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
33 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
34 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
35 import org.opendaylight.yangtools.yang.parser.builder.util.AbstractDocumentedDataNodeContainer;
36 import org.opendaylight.yangtools.yang.parser.builder.util.Comparators;
39 * @deprecated Pre-Beryllium implementation, scheduled for removal.
42 public final class ModuleImpl extends AbstractDocumentedDataNodeContainer implements Module, Immutable {
44 private final QNameModule qnameModule;
45 private final String name;
46 private final String sourcePath;
47 private final String prefix;
48 private final String yangVersion;
49 private final String organization;
50 private final String contact;
51 private final Set<ModuleImport> imports;
52 private final Set<Module> submodules;
53 private final Set<FeatureDefinition> features;
54 private final Set<NotificationDefinition> notifications;
55 private final Set<AugmentationSchema> augmentations;
56 private final Set<RpcDefinition> rpcs;
57 private final Set<Deviation> deviations;
58 private final List<ExtensionDefinition> extensionNodes;
59 private final Set<IdentitySchemaNode> identities;
60 private final List<UnknownSchemaNode> unknownNodes;
61 private final String source;
66 * <b>Note</b>Constructor has intentionality limited visibility to package, since
67 * this class should be only instantiated via builders.
73 ModuleImpl(final String name, final String sourcePath, final ModuleBuilder builder) {
75 this.name = checkNotNull(name, "Missing name");
76 this.sourcePath = sourcePath; //TODO: can this be nullable?
77 this.imports = ImmutableSet.<ModuleImport> copyOf(builder.imports.values());
78 this.submodules = ImmutableSet.<Module> copyOf(builder.submodules);
79 this.prefix = builder.getPrefix();
81 this.qnameModule = QNameModule.create(builder.getNamespace(),
82 builder.getRevision() == null ? null : new Date(builder.getRevision().getTime())).intern();
83 this.yangVersion = builder.getYangVersion();
84 this.organization = builder.getOrganization();
85 this.contact = builder.getContact();
86 this.features = toImmutableSortedSet(builder.getFeatures());
87 this.notifications = toImmutableSortedSet(builder.getNotifications());
88 this.augmentations = ImmutableSet.copyOf(builder.getAugments());
89 this.rpcs = toImmutableSortedSet(builder.getRpcs());
90 this.deviations = ImmutableSet.copyOf(builder.getDeviations());
91 this.extensionNodes = ImmutableList.copyOf(builder.getExtensions());
92 this.identities = ImmutableSet.copyOf(builder.getIdentities());
93 this.unknownNodes = ImmutableList.copyOf(builder.getExtensionInstances());
94 //no check for Beryllium code
95 this.source = builder.getSource();
100 public String getModuleSourcePath() {
105 public URI getNamespace() {
106 return qnameModule.getNamespace();
110 public String getName() {
115 public Date getRevision() {
116 return qnameModule.getRevision();
120 public String getPrefix() {
125 public String getYangVersion() {
130 public String getOrganization() {
135 public String getContact() {
140 public Set<ModuleImport> getImports() {
145 public Set<Module> getSubmodules() {
150 public Set<FeatureDefinition> getFeatures() {
155 public Set<NotificationDefinition> getNotifications() {
156 return notifications;
160 public Set<AugmentationSchema> getAugmentations() {
161 return augmentations;
165 public Set<RpcDefinition> getRpcs() {
170 public Set<Deviation> getDeviations() {
175 public List<ExtensionDefinition> getExtensionSchemaNodes() {
176 return extensionNodes;
180 public Set<IdentitySchemaNode> getIdentities() {
185 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
190 public String getSource() {
195 public int hashCode() {
196 final int prime = 31;
198 result = prime * result + Objects.hashCode(name);
199 result = prime * result + Objects.hashCode(yangVersion);
200 result = prime * result + qnameModule.hashCode();
205 public boolean equals(final Object obj) {
212 if (getClass() != obj.getClass()) {
215 ModuleImpl other = (ModuleImpl) obj;
217 if (other.name != null) {
220 } else if (!name.equals(other.name)) {
223 if (!qnameModule.equals(other.qnameModule)) {
226 if (yangVersion == null) {
227 if (other.yangVersion != null) {
230 } else if (!yangVersion.equals(other.yangVersion)) {
236 private static <T extends SchemaNode> Set<T> toImmutableSortedSet(final Set<T> original) {
237 NavigableSet<T> sorted = new TreeSet<>(Comparators.SCHEMA_NODE_COMP);
238 sorted.addAll(original);
239 return Collections.unmodifiableSet(sorted);
243 public String toString() {
244 StringBuilder sb = new StringBuilder(ModuleImpl.class.getSimpleName());
246 sb.append("name=").append(name);
247 sb.append(", namespace=").append(getNamespace());
248 sb.append(", revision=").append(getRevision());
249 sb.append(", prefix=").append(prefix);
250 sb.append(", yangVersion=").append(yangVersion);
252 return sb.toString();
256 public QNameModule getQNameModule() {