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.rfc7950.stmt.rpc;
10 import com.google.common.base.Verify;
11 import com.google.common.collect.ImmutableSet;
12 import java.util.HashSet;
13 import java.util.LinkedHashSet;
14 import java.util.Objects;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
18 import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
19 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
20 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
21 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
22 import org.opendaylight.yangtools.yang.model.api.stmt.InputEffectiveStatement;
23 import org.opendaylight.yangtools.yang.model.api.stmt.OutputEffectiveStatement;
24 import org.opendaylight.yangtools.yang.model.api.stmt.RpcEffectiveStatement;
25 import org.opendaylight.yangtools.yang.model.api.stmt.RpcStatement;
26 import org.opendaylight.yangtools.yang.model.api.stmt.TypedefEffectiveStatement;
27 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.AbstractEffectiveSchemaNode;
28 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.EffectiveStmtUtils;
29 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
31 final class RpcEffectiveStatementImpl extends AbstractEffectiveSchemaNode<RpcStatement>
32 implements RpcDefinition, RpcEffectiveStatement {
33 private final ContainerSchemaNode input;
34 private final ContainerSchemaNode output;
35 private final Set<TypeDefinition<?>> typeDefinitions;
36 private final Set<GroupingDefinition> groupings;
38 RpcEffectiveStatementImpl(final StmtContext<QName, RpcStatement,
39 EffectiveStatement<QName, RpcStatement>> ctx) {
41 input = findAsContainer(this, InputEffectiveStatement.class);
42 output = findAsContainer(this, OutputEffectiveStatement.class);
45 Set<GroupingDefinition> groupingsInit = new HashSet<>();
46 Set<TypeDefinition<?>> mutableTypeDefinitions = new LinkedHashSet<>();
47 for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
48 if (effectiveStatement instanceof GroupingDefinition) {
49 GroupingDefinition groupingDefinition = (GroupingDefinition) effectiveStatement;
50 groupingsInit.add(groupingDefinition);
52 if (effectiveStatement instanceof TypedefEffectiveStatement) {
53 TypedefEffectiveStatement typeDef = (TypedefEffectiveStatement) effectiveStatement;
54 TypeDefinition<?> type = typeDef.getTypeDefinition();
55 if (!mutableTypeDefinitions.contains(type)) {
56 mutableTypeDefinitions.add(type);
58 throw EffectiveStmtUtils.createNameCollisionSourceException(ctx, effectiveStatement);
62 this.groupings = ImmutableSet.copyOf(groupingsInit);
63 this.typeDefinitions = ImmutableSet.copyOf(mutableTypeDefinitions);
66 private static ContainerSchemaNode findAsContainer(final EffectiveStatement<?, ?> parent,
67 final Class<? extends EffectiveStatement<QName, ?>> statementType) {
68 final EffectiveStatement<?, ?> statement = parent.findFirstEffectiveSubstatement(statementType).get();
69 Verify.verify(statement instanceof ContainerSchemaNode, "Child statement %s is not a ContainerSchemaNode");
70 return (ContainerSchemaNode) statement;
74 public ContainerSchemaNode getInput() {
79 public ContainerSchemaNode getOutput() {
84 public Set<TypeDefinition<?>> getTypeDefinitions() {
85 return typeDefinitions;
89 public Set<GroupingDefinition> getGroupings() {
94 public int hashCode() {
97 result = prime * result + Objects.hashCode(getQName());
98 result = prime * result + Objects.hashCode(getPath());
103 public boolean equals(final Object obj) {
110 if (getClass() != obj.getClass()) {
113 final RpcEffectiveStatementImpl other = (RpcEffectiveStatementImpl) obj;
114 return Objects.equals(getQName(), other.getQName()) && Objects.equals(getPath(), other.getPath());
118 public String toString() {
119 return RpcEffectiveStatementImpl.class.getSimpleName() + "["
120 + "qname=" + getQName()
121 + ", path=" + getPath()
123 + ", output=" + output