KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.HashMap JavaDoc;
20
21 import javax.jms.ConnectionFactory JavaDoc;
22 import javax.jms.QueueConnectionFactory JavaDoc;
23 import javax.jms.TopicConnectionFactory JavaDoc;
24
25 import org.apache.axis.utils.BeanPropertyDescriptor;
26 import org.apache.axis.utils.BeanUtils;
27 import org.apache.axis.utils.ClassUtils;
28
29 /**
30  * Uses ClassUtils.forName and reflection to configure ConnectionFactory. Uses
31  * the input sessions to create destinations.
32  *
33  * @author Jaime Meritt (jmeritt@sonicsoftware.com)
34  */

35 public abstract class BeanVendorAdapter extends JMSVendorAdapter
36 {
37     protected final static String JavaDoc CONNECTION_FACTORY_CLASS =
38                                         "transport.jms.ConnectionFactoryClass";
39
40     public QueueConnectionFactory JavaDoc getQueueConnectionFactory(HashMap JavaDoc cfConfig)
41         throws Exception JavaDoc
42     {
43         return (QueueConnectionFactory JavaDoc)getConnectionFactory(cfConfig);
44     }
45
46     public TopicConnectionFactory JavaDoc getTopicConnectionFactory(HashMap JavaDoc cfConfig)
47         throws Exception JavaDoc
48     {
49         return (TopicConnectionFactory JavaDoc)getConnectionFactory(cfConfig);
50     }
51
52     private ConnectionFactory JavaDoc getConnectionFactory(HashMap JavaDoc cfConfig)
53         throws Exception JavaDoc
54     {
55         String JavaDoc classname = (String JavaDoc)cfConfig.get(CONNECTION_FACTORY_CLASS);
56         if(classname == null || classname.trim().length() == 0)
57             throw new IllegalArgumentException JavaDoc("noCFClass");
58
59         Class JavaDoc factoryClass = ClassUtils.forName(classname);
60         ConnectionFactory JavaDoc factory = (ConnectionFactory JavaDoc)factoryClass.newInstance();
61         callSetters(cfConfig, factoryClass, factory);
62         return factory;
63     }
64
65     private void callSetters(HashMap JavaDoc cfConfig,
66                              Class JavaDoc factoryClass,
67                              ConnectionFactory JavaDoc factory)
68       throws Exception JavaDoc
69     {
70         BeanPropertyDescriptor[] bpd = BeanUtils.getPd(factoryClass);
71         for(int i = 0; i < bpd.length; i++)
72         {
73             BeanPropertyDescriptor thisBPD = bpd[i];
74             String JavaDoc propName = thisBPD.getName();
75             if(cfConfig.containsKey(propName))
76             {
77                 Object JavaDoc value = cfConfig.get(propName);
78                 if(value == null)
79                     continue;
80
81                 String JavaDoc validType = thisBPD.getType().getName();
82                 if(!value.getClass().getName().equals(validType))
83                     throw new IllegalArgumentException JavaDoc("badType");
84                 if(!thisBPD.isWriteable())
85                     throw new IllegalArgumentException JavaDoc("notWriteable");
86                 if(thisBPD.isIndexed())
87                     throw new IllegalArgumentException JavaDoc("noIndexedSupport");
88                 thisBPD.set(factory, value);
89             }
90         }
91     }
92 }
Popular Tags