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 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.rfc6020.util.AbstractEffectiveSchemaNode;
25 import org.opendaylight.yangtools.yang.parser.rfc6020.util.EffectiveStmtUtils;
26 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
28 public class RpcEffectiveStatementImpl extends AbstractEffectiveSchemaNode<RpcStatement>
29 implements RpcDefinition, RpcEffectiveStatement {
30 private final ContainerSchemaNode input;
31 private final ContainerSchemaNode output;
32 private final Set<TypeDefinition<?>> typeDefinitions;
33 private final Set<GroupingDefinition> groupings;
35 public RpcEffectiveStatementImpl(final StmtContext<QName, RpcStatement,
36 EffectiveStatement<QName, RpcStatement>> ctx) {
38 this.input = firstEffective(InputEffectiveStatementImpl.class);
39 this.output = firstEffective(OutputEffectiveStatementImpl.class);
42 Set<GroupingDefinition> groupingsInit = new HashSet<>();
43 Set<TypeDefinition<?>> mutableTypeDefinitions = new LinkedHashSet<>();
44 for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
45 if (effectiveStatement instanceof GroupingDefinition) {
46 GroupingDefinition groupingDefinition = (GroupingDefinition) effectiveStatement;
47 groupingsInit.add(groupingDefinition);
49 if (effectiveStatement instanceof TypedefEffectiveStatement) {
50 TypedefEffectiveStatement typeDef = (TypedefEffectiveStatement) effectiveStatement;
51 TypeDefinition<?> type = typeDef.getTypeDefinition();
52 if (!mutableTypeDefinitions.contains(type)) {
53 mutableTypeDefinitions.add(type);
55 throw EffectiveStmtUtils.createNameCollisionSourceException(ctx, effectiveStatement);
59 this.groupings = ImmutableSet.copyOf(groupingsInit);
60 this.typeDefinitions = ImmutableSet.copyOf(mutableTypeDefinitions);
64 public ContainerSchemaNode getInput() {
69 public ContainerSchemaNode getOutput() {
74 public Set<TypeDefinition<?>> getTypeDefinitions() {
75 return typeDefinitions;
79 public Set<GroupingDefinition> getGroupings() {
84 public int hashCode() {
87 result = prime * result + Objects.hashCode(getQName());
88 result = prime * result + Objects.hashCode(getPath());
93 public boolean equals(final Object obj) {
100 if (getClass() != obj.getClass()) {
103 final RpcEffectiveStatementImpl other = (RpcEffectiveStatementImpl) obj;
104 return Objects.equals(getQName(), other.getQName()) && Objects.equals(getPath(), other.getPath());
108 public String toString() {
109 return RpcEffectiveStatementImpl.class.getSimpleName() + "["
110 + "qname=" + getQName()
111 + ", path=" + getPath()
113 + ", output=" + output