1 23 package org.objectweb.joram.client.connector; 24 25 import javax.naming.Context ; 26 import javax.naming.Name ; 27 import javax.naming.Reference ; 28 29 import org.objectweb.util.monolog.api.BasicLevel; 30 31 35 public class ObjectFactoryImpl implements javax.naming.spi.ObjectFactory 36 { 37 String cf = 38 "org.objectweb.joram.client.connector.OutboundConnectionFactory"; 39 String qcf = 40 "org.objectweb.joram.client.connector.OutboundQueueConnectionFactory"; 41 String tcf = 42 "org.objectweb.joram.client.connector.OutboundTopicConnectionFactory"; 43 44 45 46 public Object getObjectInstance(Object obj, 47 Name name, 48 Context ctx, 49 java.util.Hashtable env) 50 throws Exception { 51 52 if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG)) 53 AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, this + " getObjectInstance(" + obj + 54 ", " + name + 55 ", " + ctx + 56 ", " + env + ")"); 57 58 Reference ref = (Reference ) obj; 59 60 String hostName = (String ) ref.get("hostName").getContent(); 61 Integer serverPort = 62 new Integer ((String ) ref.get("serverPort").getContent()); 63 String userName = (String ) ref.get("userName").getContent(); 64 String password = (String ) ref.get("password").getContent(); 65 66 ManagedConnectionFactoryImpl mcf = null; 67 68 if (ref.getClassName().equals(cf)) 69 mcf = new ManagedConnectionFactoryImpl(); 70 else if (ref.getClassName().equals(qcf)) 71 mcf = new ManagedQueueConnectionFactoryImpl(); 72 else if (ref.getClassName().equals(tcf)) 73 mcf = new ManagedTopicConnectionFactoryImpl(); 74 else 75 return null; 76 77 mcf.setCollocated(new Boolean (false)); 78 mcf.setHostName(hostName); 79 mcf.setServerPort(serverPort); 80 mcf.setUserName(userName); 81 mcf.setPassword(password); 82 83 try { 84 return mcf.createConnectionFactory(); 85 } 86 catch (Exception exc) { 87 return null; 88 } 89 } 90 } 91 | Popular Tags |