KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis > components > jms > JMSVendorAdapterFactory


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

16
17 package org.apache.axis.components.jms;
18
19 import org.apache.axis.AxisProperties;
20 import java.util.HashMap JavaDoc;
21
22 /**
23  * Discovery class used to locate vendor adapters. Switch the default
24  * JNDI-based implementation by using the
25  * org.apache.axis.components.jms.JMSVendorAdapter system property
26  *
27  * @author Jaime Meritt (jmeritt@sonicsoftware.com)
28  * @author Ray Chun (rchun@sonicsoftware.com)
29  */

30 public class JMSVendorAdapterFactory
31 {
32     private static HashMap JavaDoc s_adapters = new HashMap JavaDoc();
33     private final static String JavaDoc VENDOR_PKG = "org.apache.axis.components.jms";
34
35     static {
36         AxisProperties.setClassDefault(JMSVendorAdapter.class,
37                                        VENDOR_PKG + ".JNDIVendorAdapter");
38     }
39
40     public static final JMSVendorAdapter getJMSVendorAdapter()
41     {
42         return (JMSVendorAdapter)AxisProperties.newInstance(JMSVendorAdapter.class);
43     }
44
45     public static final JMSVendorAdapter getJMSVendorAdapter(String JavaDoc vendorId)
46     {
47         // check to see if the adapter has already been instantiated
48
if (s_adapters.containsKey(vendorId))
49             return (JMSVendorAdapter)s_adapters.get(vendorId);
50
51         // create a new instance
52
JMSVendorAdapter adapter = null;
53         try
54         {
55             Class JavaDoc vendorClass = Class.forName(getVendorAdapterClassname(vendorId));
56             adapter = (JMSVendorAdapter)vendorClass.newInstance();
57         }
58         catch (Exception JavaDoc e)
59         {
60             return null;
61         }
62
63         synchronized (s_adapters)
64         {
65             if (s_adapters.containsKey(vendorId))
66                 return (JMSVendorAdapter)s_adapters.get(vendorId);
67
68             if (adapter != null)
69                 s_adapters.put(vendorId, adapter);
70         }
71
72         return adapter;
73     }
74
75     private static String JavaDoc getVendorAdapterClassname(String JavaDoc vendorId)
76     {
77         StringBuffer JavaDoc sb = new StringBuffer JavaDoc(VENDOR_PKG).append(".");
78         sb.append(vendorId);
79         sb.append("VendorAdapter");
80
81         return sb.toString();
82     }
83 }
Popular Tags