01: /* JFox, the OpenSource J2EE Application Server
02: *
03: * Copyright (C) 2002 huihoo.com
04: * Distributable under GNU LGPL license
05: * See the GNU Lesser General Public License for more details.
06: */
07:
08: package org.huihoo.jfox.jndi;
09:
10: import javax.naming.Context;
11: import javax.naming.NamingException;
12: import javax.naming.Name;
13: import javax.naming.Reference;
14: import java.util.Hashtable;
15: import java.net.URL;
16:
17: /**
18: *
19: * @author <a href="mailto:young_yy@hotmail.com">Young Yang</a>
20: */
21:
22: public class InitialContextFactoryImpl implements
23: javax.naming.spi.InitialContextFactory,
24: javax.naming.spi.ObjectFactory {
25:
26: public Context getInitialContext(Hashtable env)
27: throws NamingException {
28: if (env == null) {
29: env = JNDIProperties.getDefaultEnvironment();
30: } else {
31: env = JNDIProperties.mergeEnvironment(env);
32: }
33: return new ContextSupport("/", env);
34: }
35:
36: // will perform after urlContextFactory failed and if set Context.OBJECT_FACTORY
37: public Object getObjectInstance(Object obj, Name name, Context ctx,
38: Hashtable environment) throws Exception {
39: // Context ctx = getInitialContext(environment);
40: Reference ref = (Reference) obj;
41: String url_string = (String) ref.get("URL").getContent();
42: URL url = new URL(url_string);
43: return url.getContent();
44: }
45:
46: public static void main(String[] args) {
47:
48: }
49: }
|