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.collect.ImmutableList;
11 import com.google.common.collect.ImmutableSet;
12 import java.util.Collection;
13 import java.util.HashSet;
14 import java.util.LinkedList;
15 import java.util.List;
16 import java.util.Objects;
18 import org.opendaylight.yangtools.yang.common.QName;
19 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
20 import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition;
21 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
22 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
23 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
24 import org.opendaylight.yangtools.yang.model.api.stmt.OutputStatement;
25 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
26 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
27 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy;
28 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
30 public class OutputEffectiveStatementImpl extends
31 AbstractEffectiveDocumentedDataNodeContainer<QName, OutputStatement>
32 implements ContainerSchemaNode {
34 private final QName qname;
35 private final SchemaPath path;
36 private final boolean presence;
40 boolean configuration = true;
41 ContainerSchemaNode original;
42 ConstraintDefinition constraints;
44 private ImmutableSet<AugmentationSchema> augmentations;
45 private ImmutableList<UnknownSchemaNode> unknownNodes;
47 public OutputEffectiveStatementImpl(
48 StmtContext<QName, OutputStatement, EffectiveStatement<QName, OutputStatement>> ctx) {
51 qname = ctx.getStatementArgument();
52 path = Utils.getSchemaPath(ctx);
53 presence = (firstEffective(PresenceEffectiveStatementImpl.class) == null) ? false
55 this.constraints = new EffectiveConstraintDefinitionImpl(this);
57 initSubstatementCollections();
61 private void initCopyType(
62 StmtContext<QName, OutputStatement, EffectiveStatement<QName, OutputStatement>> ctx) {
64 List<TypeOfCopy> copyTypesFromOriginal = ctx.getCopyHistory();
66 if(copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_AUGMENTATION)) {
69 if(copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES)) {
72 if(copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES_AUGMENTATION)) {
73 addedByUses = augmenting = true;
76 if (ctx.getOriginalCtx() != null) {
77 original = (ContainerSchemaNode) ctx.getOriginalCtx().buildEffective();
81 private void initSubstatementCollections() {
82 Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
84 List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
85 Set<AugmentationSchema> augmentationsInit = new HashSet<>();
87 boolean configurationInit = false;
88 for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
89 if (effectiveStatement instanceof UnknownSchemaNode) {
90 UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
91 unknownNodesInit.add(unknownNode);
93 if (effectiveStatement instanceof AugmentationSchema) {
94 AugmentationSchema augmentationSchema = (AugmentationSchema) effectiveStatement;
95 augmentationsInit.add(augmentationSchema);
97 if (!configurationInit
98 && effectiveStatement instanceof ConfigEffectiveStatementImpl) {
99 ConfigEffectiveStatementImpl configStmt = (ConfigEffectiveStatementImpl) effectiveStatement;
100 this.configuration = configStmt.argument();
101 configurationInit = true;
105 this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
106 this.augmentations = ImmutableSet.copyOf(augmentationsInit);
110 public QName getQName() {
115 public SchemaPath getPath() {
120 public boolean isAugmenting() {
125 public boolean isAddedByUses() {
130 public boolean isConfiguration() {
131 return configuration;
135 public ConstraintDefinition getConstraints() {
140 public Set<AugmentationSchema> getAvailableAugmentations() {
141 return augmentations;
145 public boolean isPresenceContainer() {
150 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
155 public int hashCode() {
156 final int prime = 31;
158 result = prime * result + Objects.hashCode(qname);
159 result = prime * result + Objects.hashCode(path);
164 public boolean equals(final Object obj) {
171 if (getClass() != obj.getClass()) {
174 OutputEffectiveStatementImpl other = (OutputEffectiveStatementImpl) obj;
176 if (other.qname != null) {
179 } else if (!qname.equals(other.qname)) {
183 if (other.path != null) {
186 } else if (!path.equals(other.path)) {
193 public String toString() {
194 return "RPC Output " + qname.getLocalName();