1 6 7 package org.jfox.jndi.url.java; 8 9 import java.util.Hashtable ; 10 import javax.naming.Context ; 11 import javax.naming.Name ; 12 import javax.naming.spi.ObjectFactory ; 13 14 import org.jfox.jndi.ContextImpl; 15 import org.jfox.jndi.JNDIProperties; 16 17 22 23 public class javaURLContextFactory implements ObjectFactory { 24 public Object getObjectInstance(Object obj, 25 Name name, 26 Context nameCtx, 27 Hashtable environment) 28 throws Exception { 29 30 if(obj == null) obj = JNDIProperties.PROVIDER_URL + "/"; 31 if(obj instanceof String ) { 32 String url = (String ) obj; 33 34 int index = url.indexOf('/', url.indexOf("://") + 4); 36 String provider = url.substring(0, index); 37 38 if(provider.indexOf(':', provider.indexOf(":") + 2) < 0) { provider += ":" + JNDIProperties.DEFAULT_PORT; 40 } 41 42 Hashtable env = (Hashtable ) environment.clone(); 43 env.put(Context.PROVIDER_URL, provider); 44 ContextImpl context = new ContextImpl("/", env); 45 return context; 46 } 47 else { 48 return null; 49 } 50 } 51 52 } 53 | Popular Tags |