Source code: org/apache/axis/components/jms/BeanVendorAdapter.java
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;
20
21 import javax.jms.ConnectionFactory;
22 import javax.jms.QueueConnectionFactory;
23 import javax.jms.TopicConnectionFactory;
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 CONNECTION_FACTORY_CLASS =
38 "transport.jms.ConnectionFactoryClass";
39
40 public QueueConnectionFactory getQueueConnectionFactory(HashMap cfConfig)
41 throws Exception
42 {
43 return (QueueConnectionFactory)getConnectionFactory(cfConfig);
44 }
45
46 public TopicConnectionFactory getTopicConnectionFactory(HashMap cfConfig)
47 throws Exception
48 {
49 return (TopicConnectionFactory)getConnectionFactory(cfConfig);
50 }
51
52 private ConnectionFactory getConnectionFactory(HashMap cfConfig)
53 throws Exception
54 {
55 String classname = (String)cfConfig.get(CONNECTION_FACTORY_CLASS);
56 if(classname == null || classname.trim().length() == 0)
57 throw new IllegalArgumentException("noCFClass");
58
59 Class factoryClass = ClassUtils.forName(classname);
60 ConnectionFactory factory = (ConnectionFactory)factoryClass.newInstance();
61 callSetters(cfConfig, factoryClass, factory);
62 return factory;
63 }
64
65 private void callSetters(HashMap cfConfig,
66 Class factoryClass,
67 ConnectionFactory factory)
68 throws Exception
69 {
70 BeanPropertyDescriptor[] bpd = BeanUtils.getPd(factoryClass);
71 for(int i = 0; i < bpd.length; i++)
72 {
73 BeanPropertyDescriptor thisBPD = bpd[i];
74 String propName = thisBPD.getName();
75 if(cfConfig.containsKey(propName))
76 {
77 Object value = cfConfig.get(propName);
78 if(value == null)
79 continue;
80
81 String validType = thisBPD.getType().getName();
82 if(!value.getClass().getName().equals(validType))
83 throw new IllegalArgumentException("badType");
84 if(!thisBPD.isWriteable())
85 throw new IllegalArgumentException("notWriteable");
86 if(thisBPD.isIndexed())
87 throw new IllegalArgumentException("noIndexedSupport");
88 thisBPD.set(factory, value);
89 }
90 }
91 }
92 }