1 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 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 } | Popular Tags |