KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > jndi > ActiveMQWASInitialContextFactory


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.activemq.jndi;
19
20 import javax.naming.Context JavaDoc;
21 import javax.naming.NamingException JavaDoc;
22 import java.util.Hashtable JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.Map JavaDoc;
25
26 /**
27  * This implementation of <CODE>InitialContextFactory</CODE> should be used
28  * when ActiveMQ is used as WebSphere Generic JMS Provider. It is proved that it
29  * works on WebSphere 5.1. The reason for using this class is that custom
30  * property defined for Generic JMS Provider are passed to InitialContextFactory
31  * only if it begins with java.naming or javax.naming prefix. Additionaly
32  * provider url for the JMS provider can not contain ',' character that is
33  * necessary when the list of nodes is provided. So the role of this class is to
34  * transform properties before passing it to <CODE>ActiveMQInitialContextFactory</CODE>.
35  *
36  * @author Pawel Tucholski
37  */

38 public class ActiveMQWASInitialContextFactory extends ActiveMQInitialContextFactory {
39
40     /**
41      * @see javax.naming.spi.InitialContextFactory#getInitialContext(java.util.Hashtable)
42      */

43     public Context JavaDoc getInitialContext(Hashtable JavaDoc environment) throws NamingException JavaDoc {
44
45         return super.getInitialContext(transformEnvironment(environment));
46     }
47
48     /**
49      * Performs following transformation of properties:
50      * <ul>
51      * <li>(java.naming.queue.xxx.yyy,value)=>(queue.xxx/yyy,value)
52      * <li>(java.naming.topic.xxx.yyy,value)=>(topic.xxx/yyy,value)
53      * <li>(java.naming.connectionFactoryNames,value)=>(connectionFactoryNames,value)
54      * <li>(java.naming.provider.url,url1;url2)=>java.naming.provider.url,url1,url1)
55      * <ul>
56      *
57      * @param environment
58      * properties for transformation
59      * @return environment after transformation
60      */

61     protected Hashtable JavaDoc transformEnvironment(Hashtable JavaDoc environment) {
62
63         Hashtable JavaDoc environment1 = new Hashtable JavaDoc();
64
65         Iterator JavaDoc it = environment.entrySet().iterator();
66
67         while (it.hasNext()) {
68             Map.Entry JavaDoc entry = (Map.Entry JavaDoc) it.next();
69             String JavaDoc key = (String JavaDoc) entry.getKey();
70             String JavaDoc value = (String JavaDoc) entry.getValue();
71
72             if (key.startsWith("java.naming.queue")) {
73                 String JavaDoc key1 = key.substring("java.naming.queue.".length());
74                 key1 = key1.replace('.', '/');
75                 environment1.put("queue." + key1, value);
76             }
77             else if (key.startsWith("java.naming.topic")) {
78                 String JavaDoc key1 = key.substring("java.naming.topic.".length());
79                 key1 = key1.replace('.', '/');
80                 environment1.put("topic." + key1, value);
81             }
82             else if (key.startsWith("java.naming.connectionFactoryNames")) {
83                 String JavaDoc key1 = key.substring("java.naming.".length());
84                 environment1.put(key1, value);
85             }
86             else if (key.startsWith("java.naming.connection")) {
87                 String JavaDoc key1 = key.substring("java.naming.".length());
88                 environment1.put(key1, value);
89             }
90             else if (key.startsWith(Context.PROVIDER_URL)) {
91                 // websphere administration console does not exept , character
92
// in provider url, so ; must be used
93
// all ; to ,
94
value = value.replace(';', ',');
95                 environment1.put(Context.PROVIDER_URL, value);
96             }
97             else {
98                 environment1.put(key, value);
99             }
100         }
101
102         return environment1;
103     }
104 }
105
Popular Tags