1 45 46 47 package org.openejb.core.ivm.naming.java; 48 49 50 import java.util.Hashtable ; 51 52 import javax.naming.Context ; 53 import javax.naming.Name ; 54 import javax.naming.NamingException ; 55 import javax.naming.spi.InitialContextFactory ; 56 import javax.naming.spi.ObjectFactory ; 57 58 import org.openejb.core.DeploymentInfo; 59 import org.openejb.core.ThreadContext; 60 75 public class javaURLContextFactory implements ObjectFactory , InitialContextFactory { 76 77 public Context getInitialContext(Hashtable env) throws NamingException { 78 return getContext(); 79 } 80 public Object getObjectInstance( Object obj, Name name, Context nameCtx, Hashtable env ) 81 throws NamingException { 82 if(obj == null){ 83 87 return getContext(); 88 }else if(obj instanceof java.lang.String ){ 89 String string = (String )obj; 90 if(string.startsWith("java:comp")||string.startsWith("java:openejb")){ 91 95 string = string.substring(string.indexOf(':')); 96 Context encRoot = getContext(); 97 return encRoot.lookup(string); 98 } 99 } 100 return null; 101 } 102 public Object getObjectInstance( Object obj, Hashtable env ) 103 throws NamingException { 104 return getContext(); 105 } 106 107 public Context getContext(){ 108 Context jndiCtx = null; 109 110 if( !ThreadContext.isValid() ){ 111 return org.openejb.OpenEJB.getJNDIContext(); 112 } 113 114 DeploymentInfo di = ThreadContext.getThreadContext().getDeploymentInfo(); 115 if ( di != null ) { 116 return di.getJndiEnc(); 117 } else { 118 return org.openejb.OpenEJB.getJNDIContext(); 119 } 120 } 121 } 122 | Popular Tags |