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 java.util.HashSet;
11 import java.util.LinkedList;
12 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.OutputStatement;
26 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
27 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
29 public class OutputEffectiveStatementImpl extends
30 AbstractEffectiveDocumentedDataNodeContainer<QName, OutputStatement>
31 implements ContainerSchemaNode {
33 private final QName qname;
34 private final SchemaPath path;
35 private final boolean presence;
39 boolean configuration;
40 ContainerSchemaNode original;
41 ConstraintDefinition constraints;
43 private ImmutableSet<AugmentationSchema> augmentations;
44 private ImmutableList<UnknownSchemaNode> unknownNodes;
46 public OutputEffectiveStatementImpl(
47 StmtContext<QName, OutputStatement, EffectiveStatement<QName, OutputStatement>> ctx) {
50 qname = ctx.getStatementArgument();
51 path = Utils.getSchemaPath(ctx);
52 presence = (firstEffective(PresenceEffectiveStatementImpl.class) == null) ? false
54 // :TODO init other fields
56 initSubstatementCollections();
59 private void initSubstatementCollections() {
60 Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
62 List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
63 Set<AugmentationSchema> augmentationsInit = new HashSet<>();
65 for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
66 if (effectiveStatement instanceof UnknownSchemaNode) {
67 UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
68 unknownNodesInit.add(unknownNode);
70 if (effectiveStatement instanceof AugmentationSchema) {
71 AugmentationSchema augmentationSchema = (AugmentationSchema) effectiveStatement;
72 augmentationsInit.add(augmentationSchema);
76 this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
77 this.augmentations = ImmutableSet.copyOf(augmentationsInit);
81 public QName getQName() {
86 public SchemaPath getPath() {
91 public boolean isAugmenting() {
96 public boolean isAddedByUses() {
101 public boolean isConfiguration() {
102 return configuration;
106 public ConstraintDefinition getConstraints() {
111 public Set<AugmentationSchema> getAvailableAugmentations() {
112 return augmentations;
116 public boolean isPresenceContainer() {
121 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
126 public int hashCode() {
127 final int prime = 31;
129 result = prime * result + ((qname == null) ? 0 : qname.hashCode());
130 result = prime * result + ((path == null) ? 0 : path.hashCode());
135 public boolean equals(final Object obj) {
142 if (getClass() != obj.getClass()) {
145 OutputEffectiveStatementImpl other = (OutputEffectiveStatementImpl) obj;
147 if (other.qname != null) {
150 } else if (!qname.equals(other.qname)) {
154 if (other.path != null) {
157 } else if (!path.equals(other.path)) {
164 public String toString() {
165 return "RPC Output " + qname.getLocalName();