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.annotations.Beta;
11 import com.google.common.base.MoreObjects;
12 import com.google.common.base.Verify;
13 import com.google.common.collect.ImmutableSet;
14 import java.util.HashSet;
15 import java.util.LinkedHashSet;
17 import org.opendaylight.yangtools.yang.common.QName;
18 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
20 import org.opendaylight.yangtools.yang.model.api.OperationDefinition;
21 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
22 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
23 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
24 import org.opendaylight.yangtools.yang.model.api.stmt.InputEffectiveStatement;
25 import org.opendaylight.yangtools.yang.model.api.stmt.OutputEffectiveStatement;
26 import org.opendaylight.yangtools.yang.model.api.stmt.TypedefEffectiveStatement;
27 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
30 public abstract class AbstractEffectiveOperationDefinition<D extends DeclaredStatement<QName>>
31 extends AbstractEffectiveSchemaNode<D> implements OperationDefinition {
32 private final ImmutableSet<TypeDefinition<?>> typeDefinitions;
33 private final ImmutableSet<GroupingDefinition> groupings;
34 private final ContainerSchemaNode input;
35 private final ContainerSchemaNode output;
37 protected AbstractEffectiveOperationDefinition(final StmtContext<QName, D, ?> ctx) {
39 input = findAsContainer(this, InputEffectiveStatement.class);
40 output = findAsContainer(this, OutputEffectiveStatement.class);
43 final Set<GroupingDefinition> groupingsInit = new HashSet<>();
44 final Set<TypeDefinition<?>> mutableTypeDefinitions = new LinkedHashSet<>();
45 for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
46 if (effectiveStatement instanceof GroupingDefinition
47 && !groupingsInit.add((GroupingDefinition) effectiveStatement)) {
48 throw EffectiveStmtUtils.createNameCollisionSourceException(ctx, effectiveStatement);
50 if (effectiveStatement instanceof TypedefEffectiveStatement) {
51 final TypeDefinition<?> type = ((TypedefEffectiveStatement) effectiveStatement).getTypeDefinition();
52 if (!mutableTypeDefinitions.add(type)) {
53 throw EffectiveStmtUtils.createNameCollisionSourceException(ctx, effectiveStatement);
57 this.groupings = ImmutableSet.copyOf(groupingsInit);
58 this.typeDefinitions = ImmutableSet.copyOf(mutableTypeDefinitions);
61 private static ContainerSchemaNode findAsContainer(final EffectiveStatement<?, ?> parent,
62 final Class<? extends EffectiveStatement<QName, ?>> statementType) {
63 final EffectiveStatement<?, ?> statement = parent.findFirstEffectiveSubstatement(statementType).get();
64 Verify.verify(statement instanceof ContainerSchemaNode, "Child statement %s is not a ContainerSchemaNode");
65 return (ContainerSchemaNode) statement;
69 public final ContainerSchemaNode getInput() {
74 public final ContainerSchemaNode getOutput() {
79 public final Set<TypeDefinition<?>> getTypeDefinitions() {
80 return typeDefinitions;
84 public final Set<GroupingDefinition> getGroupings() {
89 public final String toString() {
90 return MoreObjects.toStringHelper(this).add("qname", getQName()).add("path", getPath()).add("input", input)
91 .add("output", output).toString();