KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > jms > serverless > jndi > GroupContext


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.jms.serverless.jndi;
8
9 import java.net.URL JavaDoc;
10 import java.util.Enumeration JavaDoc;
11 import java.util.HashMap JavaDoc;
12 import java.util.HashSet JavaDoc;
13 import java.util.Hashtable JavaDoc;
14 import java.util.Iterator JavaDoc;
15 import java.util.Map JavaDoc;
16 import java.util.Set JavaDoc;
17 import javax.jms.ConnectionFactory JavaDoc;
18 import javax.jms.Destination JavaDoc;
19 import javax.naming.Context JavaDoc;
20 import javax.naming.Name JavaDoc;
21 import javax.naming.NameNotFoundException JavaDoc;
22 import javax.naming.NameParser JavaDoc;
23 import javax.naming.NamingEnumeration JavaDoc;
24 import javax.naming.NamingException JavaDoc;
25 import org.jboss.jms.serverless.GroupConnectionFactory;
26 import org.jboss.jms.serverless.GroupQueue;
27 import org.jboss.jms.serverless.GroupTopic;
28 import org.jboss.jms.serverless.NotImplementedException;
29 import org.jboss.logging.Logger;
30
31 /**
32  * A Context that can be used to locally lookup ConnectionFactories and Destinations. It gets
33  * the mapping it needs from the JNDI environment (jndi.properties).
34  *
35  * @author Ovidiu Feodorov <ovidiu@jboss.org>
36  * @version $Revision: 1.1 $ $Date: 2004/04/15 22:54:21 $
37  *
38  **/

39 class GroupContext implements Context JavaDoc {
40
41     private static final Logger log = Logger.getLogger(GroupContext.class);
42
43     public static final String JavaDoc PROPERTY_NAME_PREFIX = "jms.serverless.jndi.";
44     public static final String JavaDoc CONNECTION_FACTORY_TOKEN = "connectionFactory.";
45     public static final String JavaDoc DESTINATION_TOKEN = "destination.";
46
47     //
48
// cache of the environment; the names found in the environment are cached here, so they
49
// can be used to lazy instantiate the administered objects.
50
//
51
private Map JavaDoc connFactoryInfo; // (jndi name (String) - stack file name (String))
52
private Set JavaDoc topicInfo; // jndi name (String)
53
private Set JavaDoc queueInfo; // jndi name (String)
54

55     //
56
// local cache - the instances that have been looked up once are cached here.
57
//
58

59     // (connection factory JNDI name (String) - ConnectionFactory instance)
60
private Map JavaDoc connFactories; // (jndi name (String) - ConnectionFactory instance)
61
private Map JavaDoc topics; // (jndi name (String) - Topic instance)
62
private Map JavaDoc queues; // (jndi name (String) - Queue instance)
63

64     /**
65      * @param environment - The possibly null JNDI environment, as received by the
66      * InitialContextFactory.
67      **/

68     GroupContext(Hashtable JavaDoc environment) {
69
70         connFactoryInfo = new HashMap JavaDoc();
71         topicInfo = new HashSet JavaDoc();
72         queueInfo = new HashSet JavaDoc();
73         cacheAdministeredObjectInfo(environment);
74         connFactories = new HashMap JavaDoc();
75         topics = new HashMap JavaDoc();
76         queues = new HashMap JavaDoc();
77     }
78
79
80     /**
81      * Extracts the properties associated with SLJMS administered objects and caches them.
82      **/

83     private void cacheAdministeredObjectInfo(Hashtable JavaDoc environment) {
84
85         if (environment == null) {
86             return;
87         }
88
89         for(Enumeration JavaDoc e = environment.keys(); e.hasMoreElements(); ) {
90             String JavaDoc prop = (String JavaDoc)e.nextElement();
91             if (!prop.startsWith(PROPERTY_NAME_PREFIX)) {
92                 continue;
93             }
94             String JavaDoc key = prop.substring(PROPERTY_NAME_PREFIX.length());
95             if (key.startsWith(CONNECTION_FACTORY_TOKEN)) {
96                 connFactoryInfo.put(key.substring(CONNECTION_FACTORY_TOKEN.length()),
97                                     environment.get(prop));
98             }
99             else if (key.startsWith(DESTINATION_TOKEN)) {
100                 String JavaDoc destJNDIName = key.substring(DESTINATION_TOKEN.length());
101                 String JavaDoc destType = ((String JavaDoc)environment.get(prop)).toLowerCase();
102                 if ("topic".equals(destType)) {
103                     topicInfo.add(destJNDIName);
104                 }
105                 else if ("queue".equals(destType)) {
106                     queueInfo.add(destJNDIName);
107                 }
108             }
109         }
110     }
111
112     public Object JavaDoc lookup(Name JavaDoc name) throws NamingException JavaDoc {
113         throw new NotImplementedException();
114     }
115
116     public Object JavaDoc lookup(String JavaDoc name) throws NamingException JavaDoc {
117
118         // try to fist find it in cache
119

120         Object JavaDoc o = null;
121         if ((o = connFactories.get(name)) != null) {
122             return o;
123         }
124         if ((o = topics.get(name)) != null) {
125             return o;
126         }
127         if ((o = queues.get(name)) != null) {
128             return o;
129         }
130         
131         // not in cache, build it
132

133         String JavaDoc stackConfigFileName = (String JavaDoc)connFactoryInfo.get(name);
134         
135         if (stackConfigFileName != null) {
136             ConnectionFactory JavaDoc cf = new GroupConnectionFactory(stackConfigFileName);
137             connFactories.put(name, cf);
138             return cf;
139         }
140         if (topicInfo.contains(name)) {
141             Destination JavaDoc t = new GroupTopic(name);
142             topics.put(name, t);
143             return t;
144         }
145         if (queueInfo.contains(name)) {
146             Destination JavaDoc q = new GroupQueue(name);
147             queues.put(name, q);
148             return q;
149         }
150         throw new NameNotFoundException JavaDoc(name+" not found");
151     }
152
153     public void bind(Name JavaDoc name, Object JavaDoc obj) throws NamingException JavaDoc {
154         throw new NotImplementedException();
155     }
156
157     public void bind(String JavaDoc name, Object JavaDoc obj) throws NamingException JavaDoc {
158         throw new NotImplementedException();
159     }
160
161     public void rebind(Name JavaDoc name, Object JavaDoc obj) throws NamingException JavaDoc {
162         throw new NotImplementedException();
163     }
164
165     public void rebind(String JavaDoc name, Object JavaDoc obj) throws NamingException JavaDoc {
166         throw new NotImplementedException();
167     }
168
169     public void unbind(Name JavaDoc name) throws NamingException JavaDoc {
170         throw new NotImplementedException();
171     }
172
173     public void unbind(String JavaDoc name) throws NamingException JavaDoc {
174         throw new NotImplementedException();
175     }
176
177     public void rename(Name JavaDoc oldName, Name JavaDoc newName) throws NamingException JavaDoc {
178         throw new NotImplementedException();
179     }
180
181     public void rename(String JavaDoc oldName, String JavaDoc newName) throws NamingException JavaDoc {
182         throw new NotImplementedException();
183     }
184
185     public NamingEnumeration JavaDoc list(Name JavaDoc name) throws NamingException JavaDoc {
186         throw new NotImplementedException();
187     }
188
189     public NamingEnumeration JavaDoc list(String JavaDoc name) throws NamingException JavaDoc {
190         throw new NotImplementedException();
191     }
192
193     public NamingEnumeration JavaDoc listBindings(Name JavaDoc name) throws NamingException JavaDoc {
194         throw new NotImplementedException();
195     }
196
197     public NamingEnumeration JavaDoc listBindings(String JavaDoc name) throws NamingException JavaDoc {
198         throw new NotImplementedException();
199     }
200
201     public void destroySubcontext(Name JavaDoc name) throws NamingException JavaDoc {
202         throw new NotImplementedException();
203     }
204
205     public void destroySubcontext(String JavaDoc name) throws NamingException JavaDoc {
206         throw new NotImplementedException();
207     }
208
209     public Context JavaDoc createSubcontext(Name JavaDoc name) throws NamingException JavaDoc {
210         throw new NotImplementedException();
211     }
212
213     public Context JavaDoc createSubcontext(String JavaDoc name) throws NamingException JavaDoc {
214         throw new NotImplementedException();
215     }
216
217     public Object JavaDoc lookupLink(Name JavaDoc name) throws NamingException JavaDoc {
218         throw new NotImplementedException();
219     }
220
221     public Object JavaDoc lookupLink(String JavaDoc name) throws NamingException JavaDoc {
222         throw new NotImplementedException();
223     }
224
225     public NameParser JavaDoc getNameParser(Name JavaDoc name) throws NamingException JavaDoc {
226         throw new NotImplementedException();
227     }
228
229     public NameParser JavaDoc getNameParser(String JavaDoc name) throws NamingException JavaDoc {
230         throw new NotImplementedException();
231     }
232
233     public Name JavaDoc composeName(Name JavaDoc name, Name JavaDoc prefix) throws NamingException JavaDoc {
234         throw new NotImplementedException();
235     }
236
237     public String JavaDoc composeName(String JavaDoc name, String JavaDoc prefix) throws NamingException JavaDoc {
238         throw new NotImplementedException();
239     }
240
241     public Object JavaDoc addToEnvironment(String JavaDoc propName, Object JavaDoc propVal) throws NamingException JavaDoc {
242         throw new NotImplementedException();
243     }
244
245     public Object JavaDoc removeFromEnvironment(String JavaDoc propName) throws NamingException JavaDoc {
246         throw new NotImplementedException();
247     }
248
249     public Hashtable JavaDoc getEnvironment() throws NamingException JavaDoc {
250         throw new NotImplementedException();
251     }
252
253     public void close() throws NamingException JavaDoc {
254         throw new NotImplementedException();
255     }
256
257     public String JavaDoc getNameInNamespace() throws NamingException JavaDoc {
258         throw new NotImplementedException();
259     }
260
261 }
262
Popular Tags