01: /*
02: * JFox - The most lightweight Java EE Application Server!
03: * more details please visit http://www.huihoo.org/jfox or http://www.jfox.org.cn.
04: *
05: * JFox is licenced and re-distributable under GNU LGPL.
06: */
07: package org.jfox.ejb3.naming;
08:
09: import java.util.Hashtable;
10: import javax.naming.Context;
11: import javax.naming.InitialContext;
12: import javax.naming.NamingException;
13:
14: import org.jfox.ejb3.naming.url.javaURLContextFactory;
15:
16: /**
17: * @author <a href="mailto:jfox.young@gmail.com">Young Yang</a>
18: */
19: public class JNDIContextHelper {
20:
21: private static InitialContext INITIAL_CONTEXT = null;
22:
23: public static synchronized InitialContext getInitalContext()
24: throws NamingException {
25: if (INITIAL_CONTEXT == null) {
26: Hashtable<String, String> prop = new Hashtable<String, String>();
27: prop.put(Context.INITIAL_CONTEXT_FACTORY,
28: InitialContextFactoryImpl.class.getName());
29: prop.put(Context.OBJECT_FACTORIES,
30: InitialContextFactoryImpl.class.getName());
31: prop.put(Context.URL_PKG_PREFIXES,
32: javaURLContextFactory.class.getPackage().getName());
33: prop.put(Context.PROVIDER_URL, "java://localhost");
34: INITIAL_CONTEXT = new InitialContext(prop);
35: }
36: return INITIAL_CONTEXT;
37: }
38:
39: public static Object lookup(String name) throws NamingException {
40: return getInitalContext().lookup(name);
41: }
42:
43: public static void main(String[] args) {
44:
45: }
46: }
|