1 25 26 package org.objectweb.easybeans.rpc; 27 28 import java.lang.reflect.Proxy ; 29 import java.util.Hashtable ; 30 31 import javax.naming.Context ; 32 import javax.naming.Name ; 33 import javax.naming.RefAddr ; 34 import javax.naming.Reference ; 35 import javax.naming.spi.ObjectFactory ; 36 37 import org.objectweb.easybeans.api.EZBContainerException; 38 39 43 public class RemoteCallFactory implements ObjectFactory { 44 45 55 public Object getObjectInstance(final Object obj, final Name name, final Context nameCtx, final Hashtable <?, ?> environment) 56 throws Exception { 57 if (obj instanceof Reference ) { 58 Reference ref = (Reference ) obj; 59 60 RefAddr containerIDAddr = ref.get(LocalCallRef.CONTAINER_ID); 62 RefAddr factoryNameAddr = ref.get(LocalCallRef.FACTORY_NAME); 63 RefAddr itfClassNameAddr = ref.get(LocalCallRef.INTERFACE_NAME); 64 RefAddr useIDAddr = ref.get(LocalCallRef.USE_ID); 65 66 String containerID = (String ) containerIDAddr.getContent(); 67 String factoryName = (String ) factoryNameAddr.getContent(); 68 String itfClassName = (String ) itfClassNameAddr.getContent(); 69 boolean useID = Boolean.valueOf((String ) useIDAddr.getContent()).booleanValue(); 70 71 ClientRPCInvocationHandler handler = new ClientRPCInvocationHandler(containerID, factoryName, useID); 73 handler.setRMIEnv(environment); 75 76 ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); 78 79 Class clz = null; 81 try { 82 clz = classLoader.loadClass(itfClassName); 83 } catch (ClassNotFoundException e) { 84 throw new EZBContainerException("Cannot find the class '" + itfClassName + "' in Classloader '" 85 + classLoader + "'.", e); 86 } 87 88 handler.setInterfaceClass(clz); 90 91 return Proxy.newProxyInstance(classLoader, new Class [] {clz}, handler); 92 } 93 throw new IllegalStateException ("Can only build object with a reference"); 94 } 95 } 96 | Popular Tags |