1 22 package org.jnp.interfaces.java; 23 24 import java.util.Hashtable ; 25 import javax.naming.*; 26 import javax.naming.spi.*; 27 28 import org.jnp.interfaces.NamingContext; 29 import org.jnp.interfaces.Naming; 30 31 39 public class javaURLContextFactory 40 implements ObjectFactory 41 { 42 44 46 private static ThreadLocal server = new ThreadLocal (); 48 49 public static void setRoot(Naming srv) 50 { 51 server.set(srv); 53 } 54 55 public static Naming getRoot() 56 { 57 return (Naming)server.get(); 59 } 60 61 63 65 public Object getObjectInstance(Object obj, 67 Name name, 68 Context nameCtx, 69 Hashtable environment) 70 throws Exception 71 { 72 if (obj == null) 73 return new NamingContext(environment, name, (Naming)server.get()); 74 else if (obj instanceof String ) 75 { 76 String url = (String )obj; 77 Context ctx = new NamingContext(environment, name, (Naming)server.get()); 78 79 Name n = ctx.getNameParser(name).parse(url.substring(url.indexOf(":")+1)); 80 if (n.size() >= 3) 81 { 82 if (n.get(0).toString().equals("") && 84 n.get(1).toString().equals("")) 85 { 86 ctx.addToEnvironment(Context.PROVIDER_URL, n.get(2)); 87 } 88 } 89 return ctx; 90 } else 91 { 92 return null; 93 } 94 } 95 96 98 100 102 104 } | Popular Tags |