KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfox > ioc > connector > AbstractConnectorInvoker


1 /*
2  * Copyright (c) 2004 Your Corporation. All Rights Reserved.
3  */

4 package org.jfox.ioc.connector;
5
6 import java.lang.reflect.Method JavaDoc;
7 import java.lang.reflect.Proxy JavaDoc;
8 import java.util.HashMap JavaDoc;
9 import java.util.Map JavaDoc;
10
11 import org.jfox.ioc.util.Methods;
12
13 /**
14  * @author <a HREF="mailto:yy.young@gmail.com">Young Yang</a>
15  */

16
17 public abstract class AbstractConnectorInvoker implements ConnectorInvoker {
18     protected ObjectId clientId;
19     protected ConnectorRemote remote;
20
21     protected transient Map JavaDoc<Method JavaDoc,String JavaDoc> methods = new HashMap JavaDoc<Method JavaDoc,String JavaDoc>();
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 JavaDoc invoke(Object JavaDoc proxy, Method JavaDoc method, Object JavaDoc[] args) throws Throwable JavaDoc {
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 JavaDoc(clientId.hashCode());
38         }
39         return doInvoke(proxy,method,args);
40     }
41
42     protected String JavaDoc getMethodHash(Method JavaDoc method){
43         if(methods == null) {
44             methods = new HashMap JavaDoc<Method JavaDoc, String JavaDoc>();
45         }
46         if(methods.containsKey(method)){
47             return methods.get(method);
48         }
49         else {
50             String JavaDoc hash = String.valueOf(Methods.getMethodHash(method));
51             methods.put(method,hash);
52             return hash;
53         }
54     }
55
56     protected abstract Object JavaDoc doInvoke(Object JavaDoc proxy, Method JavaDoc method, Object JavaDoc[] args) throws Throwable JavaDoc;
57
58 }
59
60
Popular Tags