X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-binding-broker%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fmd%2Fsal%2Fbinding%2Fimpl%2FRpcServiceAdapter.java;h=28ac50fb8df3af052690370501833e21557cc512;hp=61b32324a9d6b1c5db39e562c6a98f24e5e0e493;hb=HEAD;hpb=06e889c9c78457590b6a0b62d89a6b9f44242a9f diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/RpcServiceAdapter.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/RpcServiceAdapter.java deleted file mode 100644 index 61b32324a9..0000000000 --- a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/RpcServiceAdapter.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (c) 2015 Cisco Systems, Inc. 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.controller.md.sal.binding.impl; - -import com.google.common.collect.ImmutableMap; -import com.google.common.util.concurrent.ListenableFuture; -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.RpcService; -import org.opendaylight.yangtools.yang.common.RpcResult; -import org.opendaylight.yangtools.yang.model.api.SchemaPath; - -class RpcServiceAdapter implements InvocationHandler { - - interface InvocationDelegate { - - ListenableFuture> invoke(SchemaPath rpc, DataObject dataObject); - - } - - private final RpcService proxy; - private final ImmutableMap rpcNames; - private final Class type; - private final InvocationDelegate delegate; - - RpcServiceAdapter(Class type, ImmutableMap rpcNames, InvocationDelegate delegate) { - this.rpcNames = rpcNames; - this.type = type; - this.delegate = delegate; - this.proxy = (RpcService) Proxy.newProxyInstance(type.getClassLoader(), new Class[]{type}, this); - } - - RpcService getProxy() { - return proxy; - } - - @Override - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { - - SchemaPath rpc = rpcNames.get(method); - if(rpc != null) { - if(method.getParameterTypes().length == 0) { - return delegate.invoke(rpc, null); - } - if(args.length != 1) { - throw new IllegalArgumentException("Input must be provided."); - } - return delegate.invoke(rpc,(DataObject) args[0]); - } - - if(isObjectMethod(method)) { - return callObjectMethod(proxy, method, args); - } - throw new UnsupportedOperationException("Method " + method.toString() + "is unsupported."); - } - - private static boolean isObjectMethod(Method m) { - switch (m.getName()) { - case "toString": - return (m.getReturnType() == String.class && m.getParameterTypes().length == 0); - case "hashCode": - return (m.getReturnType() == int.class && m.getParameterTypes().length == 0); - case "equals": - return (m.getReturnType() == boolean.class && m.getParameterTypes().length == 1 && m.getParameterTypes()[0] == Object.class); - } - return false; - } - - private Object callObjectMethod(Object self, Method m, Object[] args) { - switch (m.getName()) { - case "toString": - return type.getName() + "$Adapter{delegate=" + delegate.toString()+"}"; - case "hashCode": - return System.identityHashCode(self); - case "equals": - return (self == args[0]); - } - return null; - } -}