1 4 package org.jfox.ioc.connector; 5 6 import java.lang.reflect.Method ; 7 import java.lang.reflect.Proxy ; 8 import java.util.HashMap ; 9 import java.util.Map ; 10 11 import org.jfox.ioc.util.Methods; 12 13 16 17 public abstract class AbstractConnectorInvoker implements ConnectorInvoker { 18 protected ObjectId clientId; 19 protected ConnectorRemote remote; 20 21 protected transient Map <Method ,String > methods = new HashMap <Method ,String >(); 22 23 protected AbstractConnectorInvoker(ObjectId clientId, ConnectorRemote remote) { 24 this.clientId = clientId; 25 this.remote = remote; 26 } 27 28 public ObjectId getClientId() { 29 return clientId; 30 } 31 32 public final Object invoke(Object proxy, Method method, Object [] args) throws Throwable { 33 if(method.equals(Methods.ToString)) { 34 return ((ConnectorInvoker) Proxy.getInvocationHandler(proxy)).getClientId().toString(); 35 } 36 else if(method.equals(Methods.HashCode)) { 37 return new Integer (clientId.hashCode()); 38 } 39 return doInvoke(proxy,method,args); 40 } 41 42 protected String getMethodHash(Method method){ 43 if(methods == null) { 44 methods = new HashMap <Method , String >(); 45 } 46 if(methods.containsKey(method)){ 47 return methods.get(method); 48 } 49 else { 50 String hash = String.valueOf(Methods.getMethodHash(method)); 51 methods.put(method,hash); 52 return hash; 53 } 54 } 55 56 protected abstract Object doInvoke(Object proxy, Method method, Object [] args) throws Throwable ; 57 58 } 59 60 | Popular Tags |