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.collect.ImmutableSet;
11 import java.util.HashSet;
12 import java.util.LinkedHashSet;
13 import java.util.Objects;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
17 import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
18 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
19 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
20 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
21 import org.opendaylight.yangtools.yang.model.api.stmt.RpcEffectiveStatement;
22 import org.opendaylight.yangtools.yang.model.api.stmt.RpcStatement;
23 import org.opendaylight.yangtools.yang.model.api.stmt.TypedefEffectiveStatement;
24 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.AbstractEffectiveSchemaNode;
25 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.EffectiveStmtUtils;
26 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
27 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.InputEffectiveStatementImpl;
28 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.OutputEffectiveStatementImpl;
30 final class RpcEffectiveStatementImpl extends AbstractEffectiveSchemaNode<RpcStatement>
31 implements RpcDefinition, RpcEffectiveStatement {
32 private final ContainerSchemaNode input;
33 private final ContainerSchemaNode output;
34 private final Set<TypeDefinition<?>> typeDefinitions;
35 private final Set<GroupingDefinition> groupings;
37 RpcEffectiveStatementImpl(final StmtContext<QName, RpcStatement,
38 EffectiveStatement<QName, RpcStatement>> ctx) {
40 this.input = firstEffective(InputEffectiveStatementImpl.class);
41 this.output = firstEffective(OutputEffectiveStatementImpl.class);
44 Set<GroupingDefinition> groupingsInit = new HashSet<>();
45 Set<TypeDefinition<?>> mutableTypeDefinitions = new LinkedHashSet<>();
46 for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
47 if (effectiveStatement instanceof GroupingDefinition) {
48 GroupingDefinition groupingDefinition = (GroupingDefinition) effectiveStatement;
49 groupingsInit.add(groupingDefinition);
51 if (effectiveStatement instanceof TypedefEffectiveStatement) {
52 TypedefEffectiveStatement typeDef = (TypedefEffectiveStatement) effectiveStatement;
53 TypeDefinition<?> type = typeDef.getTypeDefinition();
54 if (!mutableTypeDefinitions.contains(type)) {
55 mutableTypeDefinitions.add(type);
57 throw EffectiveStmtUtils.createNameCollisionSourceException(ctx, effectiveStatement);
61 this.groupings = ImmutableSet.copyOf(groupingsInit);
62 this.typeDefinitions = ImmutableSet.copyOf(mutableTypeDefinitions);
66 public ContainerSchemaNode getInput() {
71 public ContainerSchemaNode getOutput() {
76 public Set<TypeDefinition<?>> getTypeDefinitions() {
77 return typeDefinitions;
81 public Set<GroupingDefinition> getGroupings() {
86 public int hashCode() {
89 result = prime * result + Objects.hashCode(getQName());
90 result = prime * result + Objects.hashCode(getPath());
95 public boolean equals(final Object obj) {
102 if (getClass() != obj.getClass()) {
105 final RpcEffectiveStatementImpl other = (RpcEffectiveStatementImpl) obj;
106 return Objects.equals(getQName(), other.getQName()) && Objects.equals(getPath(), other.getPath());
110 public String toString() {
111 return RpcEffectiveStatementImpl.class.getSimpleName() + "["
112 + "qname=" + getQName()
113 + ", path=" + getPath()
115 + ", output=" + output