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
9 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
11 import java.util.ArrayList;
12 import java.util.List;
13 import org.opendaylight.yangtools.yang.common.QName;
14 import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition;
15 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
16 import org.opendaylight.yangtools.yang.model.api.Status;
17 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
18 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
19 import org.opendaylight.yangtools.yang.model.api.stmt.ExtensionStatement;
20 import org.opendaylight.yangtools.yang.model.api.stmt.UnknownStatement;
21 import org.opendaylight.yangtools.yang.parser.spi.ExtensionNamespace;
22 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
23 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy;
24 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
26 public class UnknownEffectiveStatementImpl extends EffectiveStatementBase<String, UnknownStatement<String>> implements
29 private boolean augmenting;
30 private boolean addedByUses;
31 private UnknownSchemaNode original;
33 private final QName qName;
34 private final SchemaPath path;
35 private ExtensionDefinition extension;
36 private String description;
37 private String reference;
38 private Status status = Status.CURRENT;
39 private final List<UnknownSchemaNode> unknownNodes = new ArrayList<>();
40 private QName nodeType;
41 private String nodeParameter;
43 public UnknownEffectiveStatementImpl(final StmtContext<String, UnknownStatement<String>, ?> ctx) {
46 final StmtContext<?, ExtensionStatement, EffectiveStatement<QName, ExtensionStatement>> extensionInit = ctx
47 .getAllFromNamespace(ExtensionNamespace.class).get(ctx.getPublicDefinition().getStatementName());
48 if (extensionInit == null) {
50 nodeType = ctx.getPublicDefinition().getArgumentName();
52 if (argument() == null || argument().isEmpty()) {
55 qName = QName.create(Utils.qNameFromArgument(ctx, ctx.getStatementArgument()).getModule(), argument());
58 extension = (ExtensionEffectiveStatementImpl) extensionInit.buildEffective();
59 nodeType = extension.getQName();
61 if (argument() == null || argument().isEmpty()) {
62 qName = extension.getQName();
64 qName = QName.create(Utils.qNameFromArgument(ctx, ctx.getStatementArgument()).getModule(), argument());
68 path = Utils.getSchemaPath(ctx);
69 nodeParameter = argument();
71 // TODO init other fields (see Bug1412Test)
73 for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
74 if (effectiveStatement instanceof DescriptionEffectiveStatementImpl) {
75 description = ((DescriptionEffectiveStatementImpl) effectiveStatement).argument();
77 if (effectiveStatement instanceof ReferenceEffectiveStatementImpl) {
78 reference = ((ReferenceEffectiveStatementImpl) effectiveStatement).argument();
80 if (effectiveStatement instanceof UnknownEffectiveStatementImpl) {
81 unknownNodes.add((UnknownEffectiveStatementImpl) effectiveStatement);
88 private void initCopyType(final StmtContext<String, UnknownStatement<String>, ?> ctx) {
90 List<TypeOfCopy> copyTypesFromOriginal = ctx.getCopyHistory();
92 if (copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_AUGMENTATION)) {
95 if (copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES)) {
98 if (copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES_AUGMENTATION)) {
99 addedByUses = augmenting = true;
102 if (ctx.getOriginalCtx() != null) {
103 original = (UnknownSchemaNode) ctx.getOriginalCtx().buildEffective();
108 public QName getNodeType() {
113 public String getNodeParameter() {
114 return nodeParameter;
118 public boolean isAddedByUses() {
123 public ExtensionDefinition getExtensionDefinition() {
128 public QName getQName() {
133 public SchemaPath getPath() {
138 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
143 public String getDescription() {
148 public String getReference() {
153 public Status getStatus() {
158 public int hashCode() {
159 final int prime = 31;
161 result = prime * result + ((qName == null) ? 0 : qName.hashCode());
162 result = prime * result + ((path == null) ? 0 : path.hashCode());
163 result = prime * result + ((nodeType == null) ? 0 : nodeType.hashCode());
164 result = prime * result + ((nodeParameter == null) ? 0 : nodeParameter.hashCode());
169 public boolean equals(final Object obj) {
176 if (getClass() != obj.getClass()) {
179 UnknownEffectiveStatementImpl other = (UnknownEffectiveStatementImpl) obj;
181 if (other.qName != null) {
184 } else if (!qName.equals(other.qName)) {
188 if (other.path != null) {
191 } else if (!path.equals(other.path)) {
194 if (nodeType == null) {
195 if (other.nodeType != null) {
198 } else if (!nodeType.equals(other.nodeType)) {
201 if (nodeParameter == null) {
202 if (other.nodeParameter != null) {
205 } else if (!nodeParameter.equals(other.nodeParameter)) {
212 public String toString() {
213 StringBuilder sb = new StringBuilder();
214 sb.append(nodeType.getNamespace());
216 sb.append(nodeType.getLocalName());
218 sb.append(nodeParameter);
219 return sb.toString();