1
2
3
4
5
6
7
8
9
10 package nl.tudelft.simulation.naming;
11
12 import java.util.Hashtable;
13
14 import javax.naming.Context;
15 import javax.naming.spi.InitialContextFactory;
16
17 import nl.tudelft.simulation.logger.Logger;
18
19 /***
20 * A factory for JVMContext instances, automatically invoked by JNDI when the
21 * correct jndi.properties file has been used.
22 * <p>
23 * (c) copyright 2003 <a href="http://www.simulation.tudelft.nl">Delft
24 * University of Technology </a>, the Netherlands. <br>
25 * See for project information <a href="http://www.simulation.tudelft.nl">
26 * www.simulation.tudelft.nl </a> <br>
27 * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
28 * License (GPL) </a>, no warranty <br>
29 *
30 * @author <a href="http://www.simulation.tudelft.nl/people/jacobs.html">Peter
31 * Jacobs </a>
32 * @version 1.2 2004-03-24
33 * @since 1.0
34 */
35 public class JVMContextFactory implements InitialContextFactory
36 {
37 /*** context refers to the static JVMContext */
38 private static JVMContext context = null;
39
40 /***
41 * @see javax.naming.spi.InitialContextFactory #getInitialContext(Hashtable)
42 */
43 public synchronized Context getInitialContext(final Hashtable environment)
44 {
45 if (JVMContextFactory.context == null)
46 {
47 environment.remove("java.naming.factory.initial");
48 if (environment.size() != 0)
49 {
50 Logger.warning(this, "getInitialContext",
51 "unused environment variables in jndi.properties");
52 }
53 JVMContextFactory.context = new JVMContext();
54 }
55 return context;
56 }
57 }