2 * Copyright (c) 2018 Pantheon Technologies, s.r.o. 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;
10 import com.google.common.base.MoreObjects;
11 import com.google.common.base.Verify;
12 import com.google.common.collect.ImmutableSet;
13 import java.util.HashSet;
14 import java.util.LinkedHashSet;
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.OperationDefinition;
20 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
21 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
22 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
23 import org.opendaylight.yangtools.yang.model.api.stmt.InputEffectiveStatement;
24 import org.opendaylight.yangtools.yang.model.api.stmt.OutputEffectiveStatement;
25 import org.opendaylight.yangtools.yang.model.api.stmt.TypedefEffectiveStatement;
26 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
28 @Deprecated(forRemoval = true)
29 public abstract class AbstractEffectiveOperationDefinition<D extends DeclaredStatement<QName>>
30 extends AbstractEffectiveSchemaNode<D> implements OperationDefinition {
31 private final ImmutableSet<TypeDefinition<?>> typeDefinitions;
32 private final ImmutableSet<GroupingDefinition> groupings;
33 private final ContainerSchemaNode input;
34 private final ContainerSchemaNode output;
36 protected AbstractEffectiveOperationDefinition(final StmtContext<QName, D, ?> ctx) {
38 input = findAsContainer(this, InputEffectiveStatement.class);
39 output = findAsContainer(this, OutputEffectiveStatement.class);
42 final Set<GroupingDefinition> groupingsInit = new HashSet<>();
43 final Set<TypeDefinition<?>> mutableTypeDefinitions = new LinkedHashSet<>();
44 for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
45 if (effectiveStatement instanceof GroupingDefinition
46 && !groupingsInit.add((GroupingDefinition) effectiveStatement)) {
47 throw EffectiveStmtUtils.createNameCollisionSourceException(ctx, effectiveStatement);
49 if (effectiveStatement instanceof TypedefEffectiveStatement) {
50 final TypeDefinition<?> type = ((TypedefEffectiveStatement) effectiveStatement).getTypeDefinition();
51 if (!mutableTypeDefinitions.add(type)) {
52 throw EffectiveStmtUtils.createNameCollisionSourceException(ctx, effectiveStatement);
56 this.groupings = ImmutableSet.copyOf(groupingsInit);
57 this.typeDefinitions = ImmutableSet.copyOf(mutableTypeDefinitions);
60 private static ContainerSchemaNode findAsContainer(final EffectiveStatement<?, ?> parent,
61 final Class<? extends EffectiveStatement<QName, ?>> statementType) {
62 final EffectiveStatement<?, ?> statement = parent.findFirstEffectiveSubstatement(statementType).get();
63 Verify.verify(statement instanceof ContainerSchemaNode, "Child statement %s is not a ContainerSchemaNode");
64 return (ContainerSchemaNode) statement;
68 public final ContainerSchemaNode getInput() {
73 public final ContainerSchemaNode getOutput() {
78 public final Set<TypeDefinition<?>> getTypeDefinitions() {
79 return typeDefinitions;
83 public final Set<GroupingDefinition> getGroupings() {
88 public final String toString() {
89 return MoreObjects.toStringHelper(this).add("qname", getQName()).add("path", getPath()).add("input", input)
90 .add("output", output).toString();