2 * Copyright (c) 2021 PANTHEON.tech, 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.mdsal.binding.generator.impl.reactor;
10 import java.util.List;
11 import org.opendaylight.mdsal.binding.generator.impl.rt.DefaultActionRuntimeType;
12 import org.opendaylight.mdsal.binding.model.api.GeneratedType;
13 import org.opendaylight.mdsal.binding.model.api.Type;
14 import org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedTypeBuilder;
15 import org.opendaylight.mdsal.binding.model.ri.BindingTypes;
16 import org.opendaylight.mdsal.binding.model.ri.Types;
17 import org.opendaylight.mdsal.binding.runtime.api.ActionRuntimeType;
18 import org.opendaylight.mdsal.binding.runtime.api.RuntimeType;
19 import org.opendaylight.yangtools.yang.binding.contract.Naming;
20 import org.opendaylight.yangtools.yang.binding.contract.StatementNamespace;
21 import org.opendaylight.yangtools.yang.model.api.stmt.ActionEffectiveStatement;
24 * Generator corresponding to a {@code action} statement.
26 final class ActionGenerator extends AbstractInvokableGenerator<ActionEffectiveStatement, ActionRuntimeType> {
27 ActionGenerator(final ActionEffectiveStatement statement, final AbstractCompositeGenerator<?, ?> parent) {
28 super(statement, parent);
32 StatementNamespace namespace() {
33 return StatementNamespace.ACTION;
37 ClassPlacement classPlacement() {
38 // We do not generate Actions for groupings as they are inexact, and do not capture an actual instantiation --
39 // therefore they do not have an InstanceIdentifier. We still need to allocate a package name for the purposes
40 // of generating shared classes for input/output
41 return getParent() instanceof GroupingGenerator ? ClassPlacement.PHANTOM : ClassPlacement.TOP_LEVEL;
45 void addImplementedType(final TypeBuilderFactory builderFactory, final GeneratedTypeBuilder builder,
46 final GeneratedType input, final GeneratedType output) {
47 final var parent = getParent();
48 final var parentType = Type.of(parent.typeName());
49 if (parent instanceof ListGenerator list) {
50 final var keyGen = list.keyGenerator();
52 final var keyType = keyGen.getGeneratedType(builderFactory);
53 builder.addImplementsType(BindingTypes.keyedListAction(parentType, keyType, input, output));
54 builder.addMethod(Naming.ACTION_INVOKE_NAME).setAbstract(true)
55 .addParameter(BindingTypes.keyedInstanceIdentifier(parentType, keyType), "path")
56 .addParameter(input, "input")
57 .setReturnType(Types.listenableFutureTypeFor(BindingTypes.rpcResult(output)))
58 .addAnnotation(OVERRIDE_ANNOTATION);
62 builder.addImplementsType(BindingTypes.action(parentType, input, output));
63 builder.addMethod(Naming.ACTION_INVOKE_NAME).setAbstract(true)
64 .addParameter(BindingTypes.instanceIdentifier(parentType), "path")
65 .addParameter(input, "input")
66 .setReturnType(Types.listenableFutureTypeFor(BindingTypes.rpcResult(output)))
67 .addAnnotation(OVERRIDE_ANNOTATION);
71 CompositeRuntimeTypeBuilder<ActionEffectiveStatement, ActionRuntimeType> createBuilder(
72 final ActionEffectiveStatement statement) {
73 return new InvokableRuntimeTypeBuilder<>(statement) {
75 ActionRuntimeType build(final GeneratedType generatedType, final ActionEffectiveStatement statement,
76 final List<RuntimeType> childTypes) {
77 return new DefaultActionRuntimeType(generatedType, statement, childTypes);