Source code: org/jnp/interfaces/NamingContextFactory.java
1 /*
2 * Distributable under LGPL license.
3 * See terms of license at gnu.org.
4 *
5 * Copyright 1999 by dreamBean Software,
6 * All rights reserved.
7 */
8 package org.jnp.interfaces;
9
10 import java.util.Hashtable;
11 import javax.naming.CompoundName;
12 import javax.naming.Context;
13 import javax.naming.Name;
14 import javax.naming.NamingException;
15 import javax.naming.Reference;
16 import javax.naming.spi.*;
17
18 /** The jnp naming provider InitialContextFactory implementation.
19
20 @see javax.naming.spi.InitialContextFactory
21
22 @author Scott.Stark@jboss.org
23 @version $Revision: 1.3.10.2 $
24 */
25 public class NamingContextFactory
26 implements InitialContextFactory, ObjectFactory
27 {
28 // InitialContextFactory implementation --------------------------
29 public Context getInitialContext(Hashtable env)
30 throws NamingException
31 {
32 String providerURL = (String) env.get(Context.PROVIDER_URL);
33 Name prefix = null;
34 /** This may be a comma separated list of provider urls in which
35 case we do not parse the urls for the requested context prefix name
36 */
37 int comma = providerURL != null ? providerURL.indexOf(',') : -1;
38 if( providerURL != null && comma < 0 )
39 {
40 Name name = new CompoundName(providerURL, NamingParser.syntax);
41 String serverInfo = NamingContext.parseNameForScheme(name);
42 if( serverInfo != null )
43 {
44 env = (Hashtable) env.clone();
45 // Set hostname:port value for the naming server
46 env.put(Context.PROVIDER_URL, serverInfo);
47 // Set the context prefix to name
48 prefix = name;
49 }
50 }
51 return new NamingContext(env, prefix, null);
52 }
53
54 // ObjectFactory implementation ----------------------------------
55 public Object getObjectInstance(Object obj,
56 Name name,
57 Context nameCtx,
58 Hashtable environment)
59 throws Exception
60 {
61 // System.out.println(obj+" "+name+" "+nameCtx+" "+environment);
62 Context ctx = getInitialContext(environment);
63 Reference ref = (Reference)obj;
64 return ctx.lookup((String)ref.get("URL").getContent());
65 }
66
67 }