import org.opendaylight.yangtools.concepts.ObjectRegistration;
import org.opendaylight.yangtools.yang.binding.Action;
import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
/**
* Registration interface used by {@code action} implementations. Each action is defined in a YANG model,
* @throws IllegalArgumentException if any of the {@code validNodes} does not match {@code datastore}
* @throws UnsupportedOperationException if this service cannot handle requested datastore
*/
- <O extends DataObject, T extends Action<O, ?, ?>, S extends T> ObjectRegistration<S> registerImplementation(
- Class<T> actionInterface, S implementation, LogicalDatastoreType datastore,
- Set<DataTreeIdentifier<O>> validNodes);
+ <O extends DataObject, P extends InstanceIdentifier<O>, T extends Action<P, ?, ?>, S extends T>
+ ObjectRegistration<S> registerImplementation(Class<T> actionInterface, S implementation,
+ LogicalDatastoreType datastore, Set<DataTreeIdentifier<O>> validNodes);
- default <O extends DataObject, T extends Action<O, ?, ?>, S extends T> ObjectRegistration<S> registerImplementation(
- final Class<T> actionInterface, final S implementation, final LogicalDatastoreType datastore) {
+ default <O extends DataObject, P extends InstanceIdentifier<O>, T extends Action<P, ?, ?>, S extends T>
+ ObjectRegistration<S> registerImplementation(final Class<T> actionInterface, final S implementation,
+ final LogicalDatastoreType datastore) {
return registerImplementation(actionInterface, implementation, datastore, ImmutableSet.of());
}
- default <O extends DataObject, T extends Action<O, ?, ?>, S extends T> ObjectRegistration<S> registerImplementation(
- final Class<T> actionInterface, final S implementation) {
+ default <O extends DataObject, P extends InstanceIdentifier<O>, T extends Action<P, ?, ?>, S extends T>
+ ObjectRegistration<S> registerImplementation(final Class<T> actionInterface, final S implementation) {
return registerImplementation(actionInterface, implementation, LogicalDatastoreType.OPERATIONAL);
}
}
<O extends DataObject, T extends Action<?, ?, ?>> T getActionHandle(Class<T> actionInterface,
Set<DataTreeIdentifier<O>> validNodes);
- default <O extends DataObject, T extends Action<O, ?, ?>> T getActionHandle(final Class<T> actionInterface) {
+ default <O extends DataObject, P extends InstanceIdentifier<O>, T extends Action<P, ?, ?>> T getActionHandle(
+ final Class<T> actionInterface) {
return getActionHandle(actionInterface, ImmutableSet.of());
}
- default <O extends DataObject, T extends Action<O, ?, ?>> T getActionHandle(final Class<T> actionInterface,
- final LogicalDatastoreType dataStore, final InstanceIdentifier<O> path) {
+ default <O extends DataObject, P extends InstanceIdentifier<O>, T extends Action<P, ?, ?>> T getActionHandle(
+ final Class<T> actionInterface, final LogicalDatastoreType dataStore, final P path) {
return getActionHandle(actionInterface, ImmutableSet.of(DataTreeIdentifier.create(dataStore, path)));
}
- default <O extends DataObject, T extends Action<O, ?, ?>> T getActionHandle(final Class<T> actionInterface,
- final InstanceIdentifier<O> path) {
+ default <O extends DataObject, P extends InstanceIdentifier<O>, T extends Action<P, ?, ?>> T getActionHandle(
+ final Class<T> actionInterface, final P path) {
return getActionHandle(actionInterface, LogicalDatastoreType.OPERATIONAL, path);
}
- default <O extends DataObject, T extends Action<O, ?, ?>> T getActionHandle(final Class<T> actionInterface,
- @SuppressWarnings("unchecked") final DataTreeIdentifier<O>... nodes) {
+ default <O extends DataObject, P extends InstanceIdentifier<O>, T extends Action<P, ?, ?>> T getActionHandle(
+ final Class<T> actionInterface, @SuppressWarnings("unchecked") final DataTreeIdentifier<O>... nodes) {
return getActionHandle(actionInterface, ImmutableSet.copyOf(nodes));
}
}
extends AbstractBindingLoadingAdapter<DOMOperationService, Class<? extends Action<?, ?, ?>>, ActionAdapter>
implements ActionService {
private static final class ConstrainedAction implements Delegator<Action<?, ?, ?>>,
- Action<DataObject, RpcInput, RpcOutput> {
- private final Action<DataObject, RpcInput, RpcOutput> delegate;
+ Action<InstanceIdentifier<?>, RpcInput, RpcOutput> {
+ private final Action<InstanceIdentifier<?>, RpcInput, RpcOutput> delegate;
private final Set<? extends DataTreeIdentifier<?>> nodes;
ConstrainedAction(final Action<?, ?, ?> delegate, final Set<? extends DataTreeIdentifier<?>> nodes) {
}
@Override
- public FluentFuture<RpcResult<RpcOutput>> invoke(final InstanceIdentifier<DataObject> path,
- final RpcInput input) {
+ public FluentFuture<RpcResult<RpcOutput>> invoke(final InstanceIdentifier<?> path, final RpcInput input) {
checkState(nodes.contains(path), "Cannot service %s", path);
return delegate.invoke(path, input);
}
import static org.opendaylight.mdsal.binding.model.util.BindingTypes.choiceIn;
import static org.opendaylight.mdsal.binding.model.util.BindingTypes.identifiable;
import static org.opendaylight.mdsal.binding.model.util.BindingTypes.identifier;
+import static org.opendaylight.mdsal.binding.model.util.BindingTypes.keyedListAction;
import static org.opendaylight.mdsal.binding.model.util.BindingTypes.rpcResult;
import static org.opendaylight.mdsal.binding.model.util.Types.BOOLEAN;
import static org.opendaylight.mdsal.binding.model.util.Types.listTypeFor;
if (genType != null) {
constructGetter(parent, genType, node);
resolveDataSchemaNodes(context, genType, genType, node.getChildNodes());
- actionsToGenType(context, genType, node);
+ actionsToGenType(context, genType, node, null);
}
}
genTOBuilder.addImplementsType(identifierMarker);
genType.addImplementsType(identifiableMarker);
- actionsToGenType(context, genTOBuilder, node);
}
+ actionsToGenType(context, genType, node, genTOBuilder);
for (final DataSchemaNode schemaNode : node.getChildNodes()) {
if (!schemaNode.isAugmenting()) {
}
private <T extends DataNodeContainer & ActionNodeContainer> void actionsToGenType(final ModuleContext context,
- final Type parent, final T parentSchema) {
+ final Type parent, final T parentSchema, final Type keyType) {
for (final ActionDefinition action : parentSchema.getActions()) {
final GeneratedType input;
final GeneratedType output;
BindingMapping.MODULE_INFO_CLASS_NAME), qname.getLocalName());
annotateDeprecatedIfNecessary(action.getStatus(), builder);
- builder.addImplementsType(action(parent, input, output));
+ builder.addImplementsType(keyType != null ? keyedListAction(parent, keyType, input, output)
+ : action(parent, input, output));
addCodegenInformation(builder, context.module(), action);
context.addChildNodeType(action, builder);
resolveDataSchemaNodes(context, genType, genType, grouping.getChildNodes());
groupingsToGenTypes(context, grouping.getGroupings());
processUsesAugments(grouping, context);
- actionsToGenType(context, genType, grouping);
+ actionsToGenType(context, genType, grouping, null);
}
}
List<Type> generateTypes = new BindingGeneratorImpl().generateTypes(context);
assertNotNull(generateTypes);
- assertEquals(13, generateTypes.size());
+ assertEquals(21, generateTypes.size());
}
}
container cont {
action foo {
-
+
+ }
+ }
+
+ list lst {
+ key key;
+ leaf key {
+ type string;
+ }
+ action foo {
+
}
}
uses grp;
}
+ list grplst {
+ key key;
+ leaf key {
+ type string;
+ }
+ uses grp;
+ }
+
container othercont {
uses other;
}
import org.opendaylight.yangtools.yang.binding.Identifiable;
import org.opendaylight.yangtools.yang.binding.Identifier;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.KeyedListAction;
import org.opendaylight.yangtools.yang.binding.Notification;
import org.opendaylight.yangtools.yang.binding.NotificationListener;
import org.opendaylight.yangtools.yang.binding.RpcInput;
private static final ConcreteType ACTION = typeForClass(Action.class);
private static final ConcreteType CHILD_OF = typeForClass(ChildOf.class);
private static final ConcreteType CHOICE_IN = typeForClass(ChoiceIn.class);
+ private static final ConcreteType KEYED_LIST_ACTION = typeForClass(KeyedListAction.class);
private static final ConcreteType RPC_RESULT = typeForClass(RpcResult.class);
private BindingTypes() {
* @throws NullPointerException if any argument is is null
*/
public static ParameterizedType action(final Type parent, final Type input, final Type output) {
- return parameterizedTypeFor(ACTION, parent, input, output);
+ return parameterizedTypeFor(ACTION, instanceIdentifier(parent), input, output);
+ }
+
+ /**
+ * Type specializing {@link KeyedListAction} for a particular type.
+ *
+ * @param parent Type of parent defining the action
+ * @param keyType Type of parent's key
+ * @param input Type input type
+ * @param output Type output type
+ * @return A parameterized type corresponding to {@code KeyedListAction<ParentKey, Parent, Input, Output>}
+ * @throws NullPointerException if any argument is is null
+ */
+ public static ParameterizedType keyedListAction(final Type parent, final Type keyType, final Type input,
+ final Type output) {
+ return parameterizedTypeFor(KEYED_LIST_ACTION, keyType, parent, input, output);
}
/**
}
}
+ list lst {
+ key key;
+ leaf key {
+ type string;
+ }
+ action foo {
+
+ }
+ }
+
grouping grp {
action bar {
output {
uses grp;
}
+ list grplst {
+ key key;
+ leaf key {
+ type string;
+ }
+ uses grp;
+ }
+
container othercont {
uses other;
}
*/
@Beta
@FunctionalInterface
-public interface Action<P extends DataObject, I extends RpcInput, O extends RpcOutput> {
+public interface Action<P extends InstanceIdentifier<?>, I extends RpcInput, O extends RpcOutput> {
/**
* Invoke the action.
*
* @throws NullPointerException if any of the arguments are null
*/
@CheckReturnValue
- @NonNull FluentFuture<@NonNull RpcResult<@NonNull O>> invoke(@NonNull InstanceIdentifier<P> path, @NonNull I input);
+ @NonNull FluentFuture<@NonNull RpcResult<@NonNull O>> invoke(@NonNull P path, @NonNull I input);
}
--- /dev/null
+/*
+ * Copyright (c) 2018 Pantheon Technologies, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.binding;
+
+import com.google.common.annotations.Beta;
+import com.google.common.util.concurrent.FluentFuture;
+import javax.annotation.CheckReturnValue;
+import org.opendaylight.yangtools.yang.common.RpcResult;
+
+/**
+ * Interface extended by all interfaces generated for a YANG {@code action} instantiated in keyed lists.
+ *
+ * @author Robert Varga
+ */
+@Beta
+@FunctionalInterface
+public interface KeyedListAction<K extends Identifier<T>, T extends DataObject & Identifiable<K>,
+ I extends RpcInput, O extends RpcOutput> extends Action<KeyedInstanceIdentifier<T, K>, I, O> {
+ @Override
+ @CheckReturnValue
+ FluentFuture<RpcResult<O>> invoke(KeyedInstanceIdentifier<T, K> path, I input);
+}