1 55 56 package org.jboss.axis.components.jms; 57 58 import org.jboss.axis.utils.BeanPropertyDescriptor; 59 import org.jboss.axis.utils.BeanUtils; 60 import org.jboss.axis.utils.ClassUtils; 61 62 import javax.jms.ConnectionFactory ; 63 import javax.jms.QueueConnectionFactory ; 64 import javax.jms.TopicConnectionFactory ; 65 import java.util.HashMap ; 66 67 73 public class BeanVendorAdapter extends JMSVendorAdapter 74 { 75 protected final static String CONNECTION_FACTORY_CLASS = 76 "transport.jms.ConnectionFactoryClass"; 77 78 public QueueConnectionFactory getQueueConnectionFactory(HashMap cfConfig) 79 throws Exception 80 { 81 return (QueueConnectionFactory )getConnectionFactory(cfConfig); 82 } 83 84 public TopicConnectionFactory getTopicConnectionFactory(HashMap cfConfig) 85 throws Exception 86 { 87 return (TopicConnectionFactory )getConnectionFactory(cfConfig); 88 } 89 90 private ConnectionFactory getConnectionFactory(HashMap cfConfig) 91 throws Exception 92 { 93 String classname = (String )cfConfig.get(CONNECTION_FACTORY_CLASS); 94 if (classname == null || classname.trim().length() == 0) 95 throw new IllegalArgumentException ("noCFClass"); 96 97 Class factoryClass = ClassUtils.forName(classname); 98 ConnectionFactory factory = (ConnectionFactory )factoryClass.newInstance(); 99 callSetters(cfConfig, factoryClass, factory); 100 return factory; 101 } 102 103 private void callSetters(HashMap cfConfig, 104 Class factoryClass, 105 ConnectionFactory factory) 106 throws Exception 107 { 108 BeanPropertyDescriptor[] bpd = BeanUtils.getPd(factoryClass); 109 for (int i = 0; i < bpd.length; i++) 110 { 111 BeanPropertyDescriptor thisBPD = bpd[i]; 112 String propName = thisBPD.getName(); 113 if (cfConfig.containsKey(propName)) 114 { 115 Object value = cfConfig.get(propName); 116 if (value == null) 117 continue; 118 119 String validType = thisBPD.getType().getName(); 120 if (!value.getClass().getName().equals(validType)) 121 throw new IllegalArgumentException ("badType"); 122 if (!thisBPD.isWriteable()) 123 throw new IllegalArgumentException ("notWriteable"); 124 if (thisBPD.isIndexed()) 125 throw new IllegalArgumentException ("noIndexedSupport"); 126 thisBPD.set(factory, value); 127 } 128 } 129 } 130 } | Popular Tags |