01: package com.bm.jndi;
02:
03: import java.util.Hashtable;
04:
05: import javax.naming.Context;
06: import javax.naming.NamingException;
07: import javax.naming.spi.InitialContextFactory;
08:
09: /**
10: * The initial context factory for the <code>MemoryContext</code> JNDI naming
11: * provider.
12: */
13: public class MemoryContextFactory implements InitialContextFactory {
14: private static final org.apache.log4j.Logger log = org.apache.log4j.Logger
15: .getLogger(MemoryContextFactory.class);
16:
17: private static Context instance;
18:
19: /**
20: * Default constructor.
21: */
22: public MemoryContextFactory() {
23: }
24:
25: public Context getInitialContext(Hashtable environment)
26: throws NamingException {
27: return getContext(environment);
28: }
29:
30: private synchronized Context getContext(Hashtable environment)
31: throws NamingException {
32: if (instance == null) {
33: log.info("Creating EJB3Unit initial JNDI context");
34: instance = new MemoryContext();
35: }
36:
37: return instance;
38: }
39:
40: }
|