Replace SchemaPath with SchemaNodeIdentifier.Absolute/QName
[mdsal.git] / binding / mdsal-binding-dom-adapter / src / main / java / org / opendaylight / mdsal / binding / dom / adapter / ActionAdapter.java
index 70259f29840a504180a377aca24e70593e38b9a7..a8ccb88d196526d9204e98131941e7e88073bfc3 100644 (file)
@@ -8,10 +8,11 @@
 package org.opendaylight.mdsal.binding.dom.adapter;
 
 import static java.util.Objects.requireNonNull;
+import static org.opendaylight.mdsal.binding.dom.adapter.StaticConfiguration.ENABLE_CODEC_SHORTCUT;
 import static org.opendaylight.yangtools.yang.common.YangConstants.operationInputQName;
 
-import com.google.common.util.concurrent.FluentFuture;
 import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
 import com.google.common.util.concurrent.MoreExecutors;
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
@@ -25,23 +26,24 @@ import org.opendaylight.yangtools.yang.binding.Action;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.RpcInput;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
 
 @NonNullByDefault
 final class ActionAdapter extends AbstractBindingAdapter<DOMActionService> implements InvocationHandler {
     private final Class<? extends Action<?, ?, ?>> type;
     private final NodeIdentifier inputName;
-    private final SchemaPath schemaPath;
+    private final Absolute actionPath;
 
-    ActionAdapter(final BindingToNormalizedNodeCodec codec, final DOMActionService delegate,
+    ActionAdapter(final AdapterContext codec, final DOMActionService delegate,
             final Class<? extends Action<?, ?, ?>> type) {
         super(codec, delegate);
         this.type = requireNonNull(type);
-        this.schemaPath = getCodec().getActionPath(type);
-        this.inputName = NodeIdentifier.create(operationInputQName(schemaPath.getLastComponent().getModule()));
+        this.actionPath = currentSerializer().getActionPath(type);
+        this.inputName = NodeIdentifier.create(operationInputQName(actionPath.lastNodeIdentifier().getModule()));
     }
 
-    @Override public @Nullable Object invoke(final @Nullable Object proxy, final @Nullable Method method,
+    @Override
+    public @Nullable Object invoke(final @Nullable Object proxy, final @Nullable Method method,
             final Object @Nullable [] args) throws Throwable {
         switch (method.getName()) {
             case "equals":
@@ -63,19 +65,22 @@ final class ActionAdapter extends AbstractBindingAdapter<DOMActionService> imple
                 if (args.length == 2) {
                     final InstanceIdentifier<?> path = (InstanceIdentifier<?>) requireNonNull(args[0]);
                     final RpcInput input = (RpcInput) requireNonNull(args[1]);
-                    final FluentFuture<? extends DOMActionResult> future = getDelegate().invokeAction(schemaPath,
-                        new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL, getCodec().toNormalized(path)),
-                        getCodec().toLazyNormalizedNodeActionInput(type, inputName, input));
+                    final CurrentAdapterSerializer serializer = currentSerializer();
+                    final ListenableFuture<? extends DOMActionResult> future = getDelegate().invokeAction(actionPath,
+                        new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL,
+                            serializer.toYangInstanceIdentifier(path)),
+                        serializer.toLazyNormalizedNodeActionInput(type, inputName, input));
 
                     // Invocation returned a future we know about -- return that future instead
-                    if (future instanceof BindingRpcFutureAware) {
+                    if (ENABLE_CODEC_SHORTCUT && future instanceof BindingRpcFutureAware) {
                         return ((BindingRpcFutureAware) future).getBindingFuture();
                     }
 
                     return Futures.transform(future,
                         dom -> RpcResultUtil.rpcResultFromDOM(dom.getErrors(), dom.getOutput()
-                            .map(output -> getCodec().fromNormalizedNodeActionOutput(type, output))
-                            .orElse(null)), MoreExecutors.directExecutor());
+                            .map(output -> serializer.fromNormalizedNodeActionOutput(type, output))
+                            .orElse(null)),
+                        MoreExecutors.directExecutor());
                 }
                 break;
             default: