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 org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy;
11 import java.util.HashSet;
12 import java.util.LinkedList;
13 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
14 import com.google.common.collect.ImmutableList;
15 import com.google.common.collect.ImmutableSet;
16 import java.util.List;
18 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
19 import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition;
20 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
21 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
22 import org.opendaylight.yangtools.yang.common.QName;
23 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
24 import java.util.Collection;
25 import org.opendaylight.yangtools.yang.model.api.stmt.InputStatement;
26 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
27 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
29 public class InputEffectiveStatementImpl extends
30 AbstractEffectiveDocumentedDataNodeContainer<QName, InputStatement>
31 implements ContainerSchemaNode {
33 private final QName qname;
34 private final SchemaPath path;
35 private final boolean presence;
39 boolean configuration = true;
40 ContainerSchemaNode original;
41 ConstraintDefinition constraints;
43 private ImmutableSet<AugmentationSchema> augmentations;
44 private ImmutableList<UnknownSchemaNode> unknownNodes;
46 public InputEffectiveStatementImpl(
47 StmtContext<QName, InputStatement, EffectiveStatement<QName, InputStatement>> ctx) {
50 qname = ctx.getStatementArgument();
51 path = Utils.getSchemaPath(ctx);
52 presence = (firstEffective(PresenceEffectiveStatementImpl.class) == null) ? false
54 this.constraints = new EffectiveConstraintDefinitionImpl(this);
56 initSubstatementCollectionsAndFields();
60 private void initCopyType(
61 StmtContext<QName, InputStatement, EffectiveStatement<QName, InputStatement>> ctx) {
63 List<TypeOfCopy> copyTypesFromOriginal = ctx.getCopyHistory();
65 if(copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_AUGMENTATION)) {
68 if(copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES)) {
71 if(copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES_AUGMENTATION)) {
72 addedByUses = augmenting = true;
75 if (ctx.getOriginalCtx() != null) {
76 original = (ContainerSchemaNode) ctx.getOriginalCtx().buildEffective();
80 private void initSubstatementCollectionsAndFields() {
81 Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
83 List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
84 Set<AugmentationSchema> augmentationsInit = new HashSet<>();
86 boolean configurationInit = false;
87 for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
88 if (effectiveStatement instanceof UnknownSchemaNode) {
89 UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
90 unknownNodesInit.add(unknownNode);
92 if (effectiveStatement instanceof AugmentationSchema) {
93 AugmentationSchema augmentationSchema = (AugmentationSchema) effectiveStatement;
94 augmentationsInit.add(augmentationSchema);
96 if (!configurationInit
97 && effectiveStatement instanceof ConfigEffectiveStatementImpl) {
98 ConfigEffectiveStatementImpl configStmt = (ConfigEffectiveStatementImpl) effectiveStatement;
99 this.configuration = configStmt.argument();
100 configurationInit = true;
104 this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
105 this.augmentations = ImmutableSet.copyOf(augmentationsInit);
109 public QName getQName() {
114 public SchemaPath getPath() {
119 public boolean isAugmenting() {
124 public boolean isAddedByUses() {
129 public boolean isConfiguration() {
130 return configuration;
134 public ConstraintDefinition getConstraints() {
139 public Set<AugmentationSchema> getAvailableAugmentations() {
140 return augmentations;
144 public boolean isPresenceContainer() {
149 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
154 public int hashCode() {
155 final int prime = 31;
157 result = prime * result + ((qname == null) ? 0 : qname.hashCode());
158 result = prime * result + ((path == null) ? 0 : path.hashCode());
163 public boolean equals(final Object obj) {
170 if (getClass() != obj.getClass()) {
173 InputEffectiveStatementImpl other = (InputEffectiveStatementImpl) obj;
175 if (other.qname != null) {
178 } else if (!qname.equals(other.qname)) {
182 if (other.path != null) {
185 } else if (!path.equals(other.path)) {
192 public String toString() {
193 return "RPC input " + qname.getLocalName();