KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfox > ejb > HandleImpl


1 /* JFox, the OpenSource J2EE Application Server
2  *
3  * Distributable under GNU LGPL license by gun.org
4  * more details please visit http://www.huihoo.org/jfox
5  */

6
7 package org.jfox.ejb;
8
9 import java.lang.reflect.Proxy JavaDoc;
10 import java.rmi.RemoteException JavaDoc;
11 import javax.ejb.EJBObject JavaDoc;
12 import javax.ejb.Handle JavaDoc;
13
14 import org.jfox.ioc.connector.ConnectorInvoker;
15
16 /**
17  * @author <a HREF="mailto:young_yy@hotmail.com">Young Yang</a>
18  */

19
20 public class HandleImpl implements Handle JavaDoc {
21     private ConnectorInvoker invocationHandler = null;
22
23     public HandleImpl(ConnectorInvoker invocationHandler) {
24         this.invocationHandler = invocationHandler;
25     }
26
27     public EJBObject JavaDoc getEJBObject() throws RemoteException JavaDoc {
28         try {
29             ClassLoader JavaDoc ctxLoader = Thread.currentThread().getContextClassLoader();
30             // get the EJBObject class name
31
EJBObjectId objectId = (EJBObjectId)invocationHandler.getClientId();
32             String JavaDoc remoteInterfaceName = objectId.getRemoteInterfaceName();
33             Class JavaDoc remoteInterface = ctxLoader.loadClass(remoteInterfaceName);
34             // 构造本地的 EJBObject 代理对象
35
return (EJBObject JavaDoc) Proxy.newProxyInstance(ctxLoader,
36                     new Class JavaDoc[]{remoteInterface},
37                     invocationHandler);
38         }
39         catch(Exception JavaDoc e) {
40             e.printStackTrace();
41             return null;
42         }
43     }
44
45     public static void main(String JavaDoc[] args) {
46
47     }
48 }
Popular Tags