1 17 18 19 package org.apache.naming.factory; 20 21 import org.apache.naming.EjbRef; 22 23 import javax.naming.Context ; 24 import javax.naming.InitialContext ; 25 import javax.naming.Name ; 26 import javax.naming.Reference ; 27 import javax.naming.RefAddr ; 28 import javax.naming.spi.ObjectFactory ; 29 import java.util.Hashtable ; 30 import java.util.Properties ; 31 32 39 public class OpenEjbFactory implements ObjectFactory { 40 41 42 44 45 protected static final String DEFAULT_OPENEJB_FACTORY = 46 "org.openejb.client.LocalInitialContextFactory"; 47 48 49 51 52 57 public Object getObjectInstance(Object obj, Name name, Context nameCtx, 58 Hashtable environment) 59 throws Exception { 60 61 Object beanObj = null; 62 63 if (obj instanceof EjbRef) { 64 65 Reference ref = (Reference ) obj; 66 67 String factory = DEFAULT_OPENEJB_FACTORY; 68 RefAddr factoryRefAddr = ref.get("openejb.factory"); 69 if (factoryRefAddr != null) { 70 factory = factoryRefAddr.getContent().toString(); 72 } 73 74 Properties env = new Properties (); 75 env.put(Context.INITIAL_CONTEXT_FACTORY, factory); 76 77 RefAddr linkRefAddr = ref.get("openejb.link"); 78 if (linkRefAddr != null) { 79 String ejbLink = linkRefAddr.getContent().toString(); 80 beanObj = (new InitialContext (env)).lookup(ejbLink); 81 } 82 83 } 84 85 return beanObj; 86 87 } 88 89 90 } 91 | Popular Tags |