Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/activemq/jndi/ActiveMQWASInitialContextFactory.java


1   /**
2    *
3    * Copyright 2005 Pawel Tucholski
4    *
5    * Licensed under the Apache License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    *
9    * http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   *
17   **/
18  package org.activemq.jndi;
19  
20  import javax.naming.Context;
21  import javax.naming.NamingException;
22  import java.util.Hashtable;
23  import java.util.Iterator;
24  import java.util.Map;
25  
26  /**
27   * This implementation of <CODE>InitialContextFactory</CODE> should be used when ActiveMQ is used as WebSphere Generic JMS Provider.
28   * It is proved that it works on WebSphere 5.1. The reason for using this class is that custom property defined for Generic JMS Provider
29   * are passed to InitialContextFactory only if it begins with java.naming or javax.naming prefix.
30   * Additionaly provider url for the JMS provider can not contain ',' character that is necessary when the list of nodes is provided.
31   * So the role of this class is to transform properties before passing it to <CODE>ActiveMQInitialContextFactory</CODE>.
32   */
33  public class ActiveMQWASInitialContextFactory extends ActiveMQInitialContextFactory {
34  
35      /**
36       * @see javax.naming.spi.InitialContextFactory#getInitialContext(java.util.Hashtable)
37       */
38      public Context getInitialContext(Hashtable environment) throws NamingException {
39  
40          return super.getInitialContext(transformEnvironment(environment));
41      }
42  
43      /**
44       * Performs following transformation of properties:
45       * <ul>
46       * <li>(java.naming.queue.xxx.yyy,value)=>(queue.xxx/yyy,value)
47       * <li>(java.naming.topic.xxx.yyy,value)=>(topic.xxx/yyy,value)
48       * <li>(java.naming.connectionFactoryNames,value)=>(connectionFactoryNames,value)
49       * <li>(java.naming.provider.url,url1;url2)=>java.naming.provider.url,url1,url1)
50       * <ul>
51       *
52       * @param environment properties for transformation
53       * @return environment after transformation
54       */
55      protected Hashtable transformEnvironment(Hashtable environment) {
56  
57          Hashtable environment1 = new Hashtable();
58  
59          Iterator it = environment.entrySet().iterator();
60  
61          while (it.hasNext()) {
62              Map.Entry entry = (Map.Entry) it.next();
63              String key = (String) entry.getKey();
64              String value = (String) entry.getValue();
65  
66              if (key.startsWith("java.naming.queue")) {
67                  String key1 = key.substring("java.naming.queue.".length());
68                  key1 = key1.replace('.', '/');
69                  environment1.put("queue." + key1, value);
70              }
71              else if (key.startsWith("java.naming.topic")) {
72                  String key1 = key.substring("java.naming.topic.".length());
73                  key1 = key1.replace('.', '/');
74                  environment1.put("topic." + key1, value);
75              }
76              else if (key.startsWith("java.naming.connectionFactoryNames")) {
77                  String key1 = key.substring("java.naming.".length());
78                  environment1.put(key1, value);
79              }
80              else if (key.startsWith(Context.PROVIDER_URL)) {
81                  // websphere administration console does not exept , character in provider url, so ; must be used
82                  // all ; to ,
83                  value = value.replace(';', ',');
84                  environment1.put(Context.PROVIDER_URL, value);
85              }
86              else {
87                  environment1.put(key, value);
88              }
89          }
90  
91          return environment1;
92      }
93  }
94