1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 package com.mjh.switchrmi.jndi;
28
29 import java.util.*;
30
31 import javax.naming.*;
32 import javax.naming.spi.*;
33
34 import org.apache.log4j.*;
35
36 public class JndiContextImplFactory
37 implements InitialContextFactory
38 {
39 private static final Logger log =
40 Logger.getLogger(JndiContextImplFactory.class.getName());
41 static Map contextsByName = new HashMap();
42
43 public JndiContextImplFactory()
44 {
45 }
46
47 public Context getInitialContext(Hashtable env)
48 throws NamingException
49 {
50 boolean debug = log.isDebugEnabled();
51
52 if (debug)
53 {
54 log.debug("env = " + env);
55 }
56
57 JndiContextImpl ctx = null;
58
59 try
60 {
61 String resourceName = (String) env.get(Context.PROVIDER_URL);
62
63 if (debug)
64 {
65 log.debug("From env: resourceName = " + resourceName);
66 }
67
68 if (resourceName == null)
69 {
70 resourceName = System.getProperty(Context.PROVIDER_URL);
71
72 if (debug)
73 {
74 log.debug("From System: resourceName = " + resourceName);
75 }
76 }
77
78 String contextName =
79 (resourceName == null) ? "default" : resourceName;
80
81 ctx = (JndiContextImpl) contextsByName.get(contextName);
82
83 if (ctx == null)
84 {
85 ctx = new JndiContextImpl();
86
87 if (resourceName == null)
88 {
89 RmiConfiguration cgf = new RmiConfiguration(ctx);
90 }
91 else
92 {
93 RmiConfiguration cgf =
94 new RmiConfiguration(ctx, resourceName);
95 }
96
97 contextsByName.put(contextName, ctx);
98 }
99
100 if (debug)
101 {
102 log.debug("ctx = " + ctx);
103 }
104 }
105 catch (NamingException nex)
106 {
107 throw nex;
108 }
109 catch (Exception ex)
110 {
111 if (debug)
112 {
113 ex.printStackTrace();
114 }
115
116 throw new NamingException(ex.toString());
117 }
118
119 return ctx;
120 }
121 }