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;
12 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
14 import java.util.ArrayList;
15 import java.util.List;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition;
18 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
19 import org.opendaylight.yangtools.yang.model.api.Status;
20 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
21 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
22 import org.opendaylight.yangtools.yang.model.api.stmt.UnknownStatement;
23 import org.opendaylight.yangtools.yang.parser.spi.ExtensionNamespace;
24 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
25 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy;
26 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
28 public class UnknownEffectiveStatementImpl extends EffectiveStatementBase<String, UnknownStatement<String>> implements
31 private boolean augmenting;
32 private boolean addedByUses;
33 private UnknownSchemaNode original;
35 private final QName qName;
36 private final SchemaPath path;
37 private ExtensionDefinition extension;
38 private String description;
39 private String reference;
40 private Status status = Status.CURRENT;
41 private final List<UnknownSchemaNode> unknownNodes = new ArrayList<>();
42 private QName nodeType;
43 private String nodeParameter;
45 public UnknownEffectiveStatementImpl(final StmtContext<String, UnknownStatement<String>, ?> ctx) {
48 extension = (ExtensionEffectiveStatementImpl) ctx.getAllFromNamespace(ExtensionNamespace.class).get(ctx
49 .getPublicDefinition().getStatementName()).buildEffective();
51 nodeType = extension.getQName();
52 nodeParameter = argument();
53 qName = argument() != null ? QName.create(Utils.qNameFromArgument(ctx, ctx.getStatementArgument()).getModule(), argument()) : null;
54 path = Utils.getSchemaPath(ctx);
56 // TODO init other fields (see Bug1412Test)
58 for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
59 if (effectiveStatement instanceof DescriptionEffectiveStatementImpl) {
60 description = ((DescriptionEffectiveStatementImpl) effectiveStatement).argument();
62 if (effectiveStatement instanceof ReferenceEffectiveStatementImpl) {
63 reference = ((ReferenceEffectiveStatementImpl) effectiveStatement).argument();
65 if (effectiveStatement instanceof UnknownEffectiveStatementImpl) {
66 unknownNodes.add((UnknownEffectiveStatementImpl) effectiveStatement);
73 private void initCopyType(
74 final StmtContext<String, UnknownStatement<String>, ?> ctx) {
76 Set<TypeOfCopy> copyTypesFromOriginal = StmtContextUtils.getCopyTypesFromOriginal(ctx);
78 if(copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_AUGMENTATION)) {
81 if(copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES)) {
84 if(copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES_AUGMENTATION)) {
85 addedByUses = augmenting = true;
88 if (ctx.getTypeOfCopy() != TypeOfCopy.ORIGINAL) {
89 original = (UnknownSchemaNode) ctx.getOriginalCtx().buildEffective();
94 public QName getNodeType() {
99 public String getNodeParameter() {
100 return nodeParameter;
104 public boolean isAddedByUses() {
109 public ExtensionDefinition getExtensionDefinition() {
114 public QName getQName() {
119 public SchemaPath getPath() {
124 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
129 public String getDescription() {
134 public String getReference() {
139 public Status getStatus() {
144 public int hashCode() {
145 final int prime = 31;
147 result = prime * result + ((qName == null) ? 0 : qName.hashCode());
148 result = prime * result + ((path == null) ? 0 : path.hashCode());
149 result = prime * result + ((nodeType == null) ? 0 : nodeType.hashCode());
150 result = prime * result + ((nodeParameter == null) ? 0 : nodeParameter.hashCode());
155 public boolean equals(final Object obj) {
162 if (getClass() != obj.getClass()) {
165 UnknownEffectiveStatementImpl other = (UnknownEffectiveStatementImpl) obj;
167 if (other.qName != null) {
170 } else if (!qName.equals(other.qName)) {
174 if (other.path != null) {
177 } else if (!path.equals(other.path)) {
180 if (nodeType == null) {
181 if (other.nodeType != null) {
184 } else if (!nodeType.equals(other.nodeType)) {
187 if (nodeParameter == null) {
188 if (other.nodeParameter != null) {
191 } else if (!nodeParameter.equals(other.nodeParameter)) {
198 public String toString() {
199 StringBuilder sb = new StringBuilder();
200 sb.append(nodeType.getNamespace());
202 sb.append(nodeType.getLocalName());
204 sb.append(nodeParameter);
205 return sb.toString();