1 22 package org.jnp.interfaces; 23 24 import java.util.Hashtable ; 25 import javax.naming.CompoundName ; 26 import javax.naming.Context ; 27 import javax.naming.Name ; 28 import javax.naming.NamingException ; 29 import javax.naming.Reference ; 30 import javax.naming.spi.*; 31 32 39 public class NamingContextFactory 40 implements InitialContextFactory, ObjectFactory 41 { 42 public Context getInitialContext(Hashtable env) 44 throws NamingException 45 { 46 String providerURL = (String ) env.get(Context.PROVIDER_URL); 47 Name prefix = null; 48 51 int comma = providerURL != null ? providerURL.indexOf(',') : -1; 52 if( providerURL != null && comma < 0 ) 53 { 54 Name name = new CompoundName (providerURL, NamingParser.syntax); 55 String serverInfo = NamingContext.parseNameForScheme(name, env); 56 if( serverInfo != null ) 57 { 58 env = (Hashtable ) env.clone(); 59 env.put(Context.PROVIDER_URL, serverInfo); 61 Name parsedName = (Name ) env.get(NamingContext.JNP_PARSED_NAME); 63 if( parsedName != null ) 64 prefix = parsedName; 65 else 66 prefix = name; 67 } 68 } 69 return new NamingContext(env, prefix, null); 70 } 71 72 public Object getObjectInstance(Object obj, 74 Name name, 75 Context nameCtx, 76 Hashtable environment) 77 throws Exception 78 { 79 Context ctx = getInitialContext(environment); 81 Reference ref = (Reference )obj; 82 return ctx.lookup((String )ref.get("URL").getContent()); 83 } 84 85 } 86 | Popular Tags |