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.base.MoreObjects;
11 import java.util.Date;
12 import java.util.Objects;
13 import org.opendaylight.yangtools.concepts.SemVer;
14 import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
15 import org.opendaylight.yangtools.yang.model.api.Module;
16 import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
17 import org.opendaylight.yangtools.yang.model.api.ModuleImport;
18 import org.opendaylight.yangtools.yang.model.api.stmt.ImportStatement;
19 import org.opendaylight.yangtools.yang.parser.spi.meta.MissingSubstatementException;
20 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
21 import org.opendaylight.yangtools.yang.parser.spi.source.ImpPrefixToOpenconfigVerModuleIdentifier;
23 public class ImportEffectiveStatementImpl extends DeclaredEffectiveStatementBase<String, ImportStatement> implements
26 private final String moduleName;
27 private final Date revision;
28 private final SemVer semVer;
29 private final String prefix;
30 private final String description;
31 private final String reference;
33 public ImportEffectiveStatementImpl(final StmtContext<String, ImportStatement, ?> ctx) {
36 moduleName = ctx.getStatementArgument();
37 PrefixEffectiveStatementImpl prefixStmt = firstEffective(PrefixEffectiveStatementImpl.class);
38 if (prefixStmt != null) {
39 this.prefix = prefixStmt.argument();
41 throw new MissingSubstatementException("Prefix is mandatory substatement of import statement",
42 ctx.getStatementSourceReference());
45 if (!ctx.isEnabledOpenconfigVersioning()) {
46 RevisionDateEffectiveStatementImpl revisionDateStmt = firstEffective(RevisionDateEffectiveStatementImpl.class);
47 this.revision = (revisionDateStmt == null) ? SimpleDateFormatUtil.DEFAULT_DATE_IMP : revisionDateStmt
49 this.semVer = Module.DEFAULT_OPENCONFIG_VERSION;
51 ModuleIdentifier importedModuleIdentifier = ctx.getFromNamespace(ImpPrefixToOpenconfigVerModuleIdentifier.class, prefix);
52 revision = importedModuleIdentifier.getRevision();
53 semVer = importedModuleIdentifier.getOpenconfigVersion();
56 DescriptionEffectiveStatementImpl descriptionStmt = firstEffective(DescriptionEffectiveStatementImpl.class);
57 this.description = (descriptionStmt != null) ? descriptionStmt.argument() : null;
59 ReferenceEffectiveStatementImpl referenceStmt = firstEffective(ReferenceEffectiveStatementImpl.class);
60 this.reference = (referenceStmt != null) ? referenceStmt.argument() : null;
64 public String getModuleName() {
69 public Date getRevision() {
74 public SemVer getOpenconfigVersion() {
79 public String getPrefix() {
84 public String getDescription() {
89 public String getReference() {
94 public int hashCode() {
95 return Objects.hash(moduleName, revision, prefix, semVer, description, reference);
99 public boolean equals(final Object obj) {
106 if (getClass() != obj.getClass()) {
109 ImportEffectiveStatementImpl other = (ImportEffectiveStatementImpl) obj;
110 return Objects.equals(moduleName, other.moduleName) && Objects.equals(revision, other.revision)
111 && Objects.equals(semVer, other.semVer) && Objects.equals(prefix, other.prefix)
112 && Objects.equals(description, other.description) && Objects.equals(reference, other.reference);
116 public String toString() {
117 return MoreObjects.toStringHelper(this).add("moduleName", getModuleName())
118 .add("revision", getRevision()).add("openconfig version", getOpenconfigVersion())
119 .add("prefix", getPrefix()).add("description", getDescription())
120 .add("reference", getReference()).toString();