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;
12 import java.util.HashSet;
13 import java.util.LinkedList;
14 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
15 import com.google.common.collect.ImmutableList;
16 import com.google.common.collect.ImmutableSet;
17 import java.util.List;
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.SchemaPath;
22 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
23 import org.opendaylight.yangtools.yang.common.QName;
24 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
25 import java.util.Collection;
26 import org.opendaylight.yangtools.yang.model.api.stmt.OutputStatement;
27 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
28 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
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;
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 // :TODO init other fields
57 initSubstatementCollections();
61 private void initCopyType(
62 StmtContext<QName, OutputStatement, EffectiveStatement<QName, OutputStatement>> ctx) {
64 TypeOfCopy typeOfCopy = ctx.getTypeOfCopy();
66 case ADDED_BY_AUGMENTATION:
68 original = (ContainerSchemaNode) ctx.getOriginalCtx()
73 original = (ContainerSchemaNode) ctx.getOriginalCtx()
81 private void initSubstatementCollections() {
82 Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
84 List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
85 Set<AugmentationSchema> augmentationsInit = new HashSet<>();
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);
98 this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
99 this.augmentations = ImmutableSet.copyOf(augmentationsInit);
103 public QName getQName() {
108 public SchemaPath getPath() {
113 public boolean isAugmenting() {
118 public boolean isAddedByUses() {
123 public boolean isConfiguration() {
124 return configuration;
128 public ConstraintDefinition getConstraints() {
133 public Set<AugmentationSchema> getAvailableAugmentations() {
134 return augmentations;
138 public boolean isPresenceContainer() {
143 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
148 public int hashCode() {
149 final int prime = 31;
151 result = prime * result + ((qname == null) ? 0 : qname.hashCode());
152 result = prime * result + ((path == null) ? 0 : path.hashCode());
157 public boolean equals(final Object obj) {
164 if (getClass() != obj.getClass()) {
167 OutputEffectiveStatementImpl other = (OutputEffectiveStatementImpl) obj;
169 if (other.qname != null) {
172 } else if (!qname.equals(other.qname)) {
176 if (other.path != null) {
179 } else if (!path.equals(other.path)) {
186 public String toString() {
187 return "RPC Output " + qname.getLocalName();