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.Collection;
11 import java.util.HashSet;
12 import java.util.LinkedList;
13 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
14 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
15 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
16 import org.opendaylight.yangtools.yang.model.api.stmt.RpcStatement;
17 import com.google.common.collect.ImmutableList;
18 import com.google.common.collect.ImmutableSet;
19 import java.util.List;
21 import org.opendaylight.yangtools.yang.common.QName;
22 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
23 import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
24 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
25 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
26 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
27 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
29 public class RpcEffectiveStatementImpl extends AbstractEffectiveDocumentedNode<QName, RpcStatement> implements RpcDefinition {
30 private final QName qname;
31 private final SchemaPath path;
33 private ContainerSchemaNode input;
34 private ContainerSchemaNode output;
36 ImmutableSet<TypeDefinition<?>> typeDefinitions;
37 ImmutableSet<GroupingDefinition> groupings;
38 ImmutableList<UnknownSchemaNode> unknownNodes;
40 public RpcEffectiveStatementImpl(StmtContext<QName, RpcStatement, EffectiveStatement<QName, RpcStatement>> ctx) {
42 this.qname = ctx.getStatementArgument();
43 this.path = Utils.getSchemaPath(ctx);
49 private void initSubstatements() {
50 Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
52 List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
53 Set<GroupingDefinition> groupingsInit = new HashSet<>();
54 Set<TypeDefinition<?>> typeDefinitionsInit = new HashSet<>();
56 for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
57 if (effectiveStatement instanceof UnknownSchemaNode) {
58 UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
59 unknownNodesInit.add(unknownNode);
61 if (effectiveStatement instanceof GroupingDefinition) {
62 GroupingDefinition groupingDefinition = (GroupingDefinition) effectiveStatement;
63 groupingsInit.add(groupingDefinition);
65 if (effectiveStatement instanceof TypeDefinition) {
66 TypeDefinition<?> typeDefinition = (TypeDefinition<?>) effectiveStatement;
67 typeDefinitionsInit.add(typeDefinition);
69 if (this.input == null && effectiveStatement instanceof InputEffectiveStatementImpl) {
70 this.input = (InputEffectiveStatementImpl) effectiveStatement;
72 if (this.output == null && effectiveStatement instanceof OutputEffectiveStatementImpl) {
73 this.output = (OutputEffectiveStatementImpl) effectiveStatement;
77 this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
78 this.groupings = ImmutableSet.copyOf(groupingsInit);
79 this.typeDefinitions = ImmutableSet.copyOf(typeDefinitionsInit);
83 public QName getQName() {
88 public SchemaPath getPath() {
93 public ContainerSchemaNode getInput() {
97 void setInput(final ContainerSchemaNode input) {
102 public ContainerSchemaNode getOutput() {
106 void setOutput(final ContainerSchemaNode output) {
107 this.output = output;
111 public Set<TypeDefinition<?>> getTypeDefinitions() {
112 return typeDefinitions;
116 public Set<GroupingDefinition> getGroupings() {
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 final RpcEffectiveStatementImpl other = (RpcEffectiveStatementImpl) 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 StringBuilder sb = new StringBuilder(RpcEffectiveStatementImpl.class.getSimpleName());
169 sb.append(", path=");
171 sb.append(", input=");
173 sb.append(", output=");
176 return sb.toString();