1 45 package org.exolab.jms.client; 46 47 import java.util.Enumeration ; 48 import java.util.HashMap ; 49 import java.util.Hashtable ; 50 import javax.naming.Context ; 51 import javax.naming.Name ; 52 import javax.naming.Reference ; 53 import javax.naming.StringRefAddr ; 54 import javax.naming.spi.ObjectFactory ; 55 56 57 67 public class JmsConnectionFactoryBuilder 68 implements ObjectFactory { 69 70 91 public Object getObjectInstance(Object object, Name name, Context context, 92 Hashtable environment) throws Exception { 93 Object result = null; 94 95 if (object instanceof Reference ) { 96 Reference ref = (Reference ) object; 97 String clazz = ref.getClassName(); 98 99 if (clazz.equals(JmsConnectionFactory.class.getName()) 100 || clazz.equals(JmsXAConnectionFactory.class.getName())) { 101 102 StringRefAddr serverClass = 103 (StringRefAddr ) ref.get("serverClass"); 104 String serverClassName = (String ) serverClass.getContent(); 105 106 107 HashMap properties = new HashMap (); 110 Enumeration iter = ref.getAll(); 111 while (iter.hasMoreElements()) { 112 StringRefAddr addr = (StringRefAddr ) iter.nextElement(); 113 properties.put(addr.getType(), addr.getContent()); 114 } 115 116 if (clazz.equals(JmsConnectionFactory.class.getName())) { 118 result = new JmsConnectionFactory(serverClassName, 119 properties, environment); 120 } else { 121 result = new JmsXAConnectionFactory(serverClassName, 122 properties, 123 environment); 124 } 125 } 126 } 127 return result; 128 } 129 } 130 131 | Popular Tags |