1 23 package org.objectweb.joram.client.connector; 24 25 import javax.jms.IllegalStateException ; 26 import javax.jms.JMSException ; 27 import javax.jms.JMSSecurityException ; 28 import javax.naming.Reference ; 29 import javax.resource.spi.ConnectionManager ; 30 import javax.resource.spi.ConnectionRequestInfo ; 31 32 import org.objectweb.util.monolog.api.BasicLevel; 33 34 38 public class OutboundConnectionFactory implements javax.jms.ConnectionFactory , 39 java.io.Serializable , 40 javax.resource.Referenceable 41 { 42 43 protected ManagedConnectionFactoryImpl mcf; 44 45 protected ConnectionManager cxManager; 46 47 48 protected Reference reference; 49 50 51 57 OutboundConnectionFactory(ManagedConnectionFactoryImpl mcf, 58 ConnectionManager cxManager) { 59 60 if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG)) 61 AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, 62 "OutboundConnectionFactory(" + mcf + 63 ", " + cxManager + ")"); 64 65 this.mcf = mcf; 66 if (cxManager != null) { 67 this.cxManager = cxManager; 68 } else { 69 this.cxManager = DefaultConnectionManager.getRef(); 70 } 71 } 72 73 74 83 public javax.jms.Connection createConnection() 84 throws JMSException { 85 if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG)) 86 AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, this + " createConnection()"); 87 88 return createConnection(mcf.userName, mcf.password); 89 } 90 91 100 public javax.jms.Connection 101 createConnection(String userName, String password) 102 throws JMSException { 103 104 if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG)) 105 AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, 106 this + " createConnection(" + userName + 107 ", " + password + ")"); 108 109 try { 110 ConnectionRequest cxRequest = 111 new ConnectionRequest(userName, password); 112 113 if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG)) 114 AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, 115 this + " createConnection cxManager = " + cxManager); 116 117 Object o = cxManager.allocateConnection(mcf, cxRequest); 118 119 if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG)) 120 AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, 121 this + " createConnection connection = " + o); 122 123 return (javax.jms.Connection ) o; 124 } catch (javax.resource.spi.SecurityException exc) { 125 throw new JMSSecurityException ("Invalid user identification: " + exc); 126 } catch (javax.resource.spi.CommException exc) { 127 throw new IllegalStateException ("Could not connect to the JORAM server: " 128 + exc); 129 } catch (javax.resource.ResourceException exc) { 130 throw new JMSException ("Could not create connection: " + exc); 131 } 132 } 133 134 135 public void setReference(Reference ref) 136 { 137 this.reference = ref; 138 } 139 140 141 public Reference getReference() 142 { 143 return reference; 144 } 145 } 146 | Popular Tags |