1 24 package org.objectweb.jalisto.se.jca; 25 26 import org.objectweb.jalisto.se.exception.JcaException; 27 import org.objectweb.jalisto.se.impl.trace.Trace; 28 import org.objectweb.jalisto.se.api.Session; 29 import org.objectweb.jalisto.se.jca.data.JalistoConnectionRequestInfo; 30 31 import javax.naming.NamingException ; 32 import javax.naming.Reference ; 33 import javax.naming.StringRefAddr ; 34 import javax.resource.NotSupportedException ; 35 import javax.resource.ResourceException ; 36 import javax.resource.cci.*; 37 import javax.resource.spi.ConnectionManager ; 38 import javax.resource.spi.ConnectionRequestInfo ; 39 import javax.resource.spi.ManagedConnectionFactory ; 40 import java.io.ObjectStreamException ; 41 42 public class JalistoConnectionFactory implements ResourceAdapterMetaData, ConnectionFactory { 43 44 public JalistoConnectionFactory(ConnectionManager connectionManager, JalistoManagedConnectionFactory mcFactory) 45 throws Exception { 46 super(); 47 this.trace = mcFactory.getTrace(); 48 trace.println(Trace.JCA, TRACE_ID + " constructor"); 49 this.connectionManager = connectionManager; 50 this.mcf = mcFactory; 51 } 52 53 public JalistoConnectionFactory(ManagedConnectionFactory mcf, ConnectionManager cm) throws Exception { 54 this(cm, (JalistoManagedConnectionFactory) mcf); 55 } 56 57 58 public Session getSession(String userid, String password) { 59 synchronized (this) { 60 Session result; 61 try { 62 JalistoConnectionSpec spec = new JalistoConnectionSpec(); 63 spec.setUserName(userid); 64 spec.setPassword(password); 65 result = (Session) getConnection(spec); 66 } catch (ResourceException re) { 67 throw new JcaException(PMGET_EXCEPTION_MSG, re); 68 } 69 return result; 70 } 71 } 72 73 public synchronized Session getSession() { 74 synchronized (this) { 75 Session result; 76 try { 77 result = (Session) getConnection(); 78 } catch (ResourceException re) { 79 throw new JcaException(PMGET_EXCEPTION_MSG, re); 80 } 81 return result; 82 } 83 } 84 85 86 private Object writeReplace() throws ObjectStreamException { 87 trace.println(Trace.JCA, TRACE_ID + " writeReplace"); 88 JalistoCfSerializationWrapper wrapper = new JalistoCfSerializationWrapper(); 89 try { 90 wrapper.setReference(this.getReference()); 91 wrapper.setManagedConnectionFactory(mcf); 92 wrapper.setConnectionManager(connectionManager); 93 } catch (NamingException e) { 94 throw new JcaException("Cannot save reference before serialization", e); 95 } 96 return wrapper; 97 } 98 99 100 101 102 public void setConnectionDriverName(String connectionDriverName) { 103 this.connectionDriverName = connectionDriverName; 104 } 105 106 public void setConnectionPassword(String connectionPassword) { 107 this.connectionPassword = connectionPassword; 108 } 109 110 public void setConnectionURL(String connectionURL) { 111 this.connectionURL = connectionURL; 112 } 113 114 public void setConnectionUserName(String connectionUserName) { 115 this.connectionUserName = connectionUserName; 116 } 117 118 public String getConnectionDriverName() { 119 return connectionDriverName; 120 } 121 122 public String getConnectionPassword() { 123 return connectionPassword; 124 } 125 126 public String getConnectionURL() { 127 return connectionURL; 128 } 129 130 public String getConnectionUserName() { 131 return connectionUserName; 132 } 133 134 135 136 public javax.resource.cci.Connection getConnection() throws ResourceException { 137 synchronized (this) { 138 return getConnection(null); 139 } 140 } 141 142 public javax.resource.cci.Connection getConnection(ConnectionSpec spec) throws ResourceException { 143 synchronized (this) { 144 trace.println(Trace.JCA, TRACE_ID + " getConnection({0})", spec); 145 ConnectionRequestInfo infos = new JalistoConnectionRequestInfo(spec); 146 return (javax.resource.cci.Connection ) connectionManager.allocateConnection(mcf, infos); 147 } 148 } 149 150 public RecordFactory getRecordFactory() throws ResourceException { 151 synchronized (this) { 152 try { 153 throw new NotSupportedException ("getRecordFactory()"); 154 } catch (Exception e) { 155 e.printStackTrace(); 156 } 157 return null; 158 } 159 } 160 161 public ResourceAdapterMetaData getMetaData() throws ResourceException { 162 synchronized (this) { 163 trace.println(Trace.JCA, TRACE_ID + " getMetaData()"); 164 return this; 165 } 166 } 167 168 169 170 171 public String getAdapterName() { 172 synchronized (this) { 173 return null; 174 } 175 } 176 177 public String getAdapterShortDescription() { 178 synchronized (this) { 179 return RESDESC; 180 } 181 } 182 183 public String getAdapterVendorName() { 184 synchronized (this) { 185 return null; 186 } 187 } 188 189 public String getAdapterVersion() { 190 synchronized (this) { 191 return null; 192 } 193 } 194 195 public String getSpecVersion() { 196 return null; 197 } 198 199 public boolean supportsExecuteWithInputAndOutputRecord() { 200 return false; 201 } 202 203 public boolean supportsExecuteWithInputRecordOnly() { 204 return false; 205 } 206 207 public boolean supportsLocalTransactionDemarcation() { 208 return false; 209 } 210 211 public String [] getInteractionSpecsSupported() { 212 synchronized (this) { 213 return null; 214 } 215 } 216 217 218 219 public void setReference(Reference reference) { 220 synchronized (this) { 221 trace.println(Trace.JCA, TRACE_ID + " set new reference = {0}", reference); 222 } 223 } 224 225 public Reference getReference() throws NamingException { 226 synchronized (this) { 227 JalistoObjectFactory.setTrace(trace); 228 trace.println(Trace.JCA, TRACE_ID + " get reference"); 229 230 Reference ref = new Reference (this.getClass().getName(), DRIVER_NAMING_FACTORY_NAME, null); 231 232 ref.add(new StringRefAddr (this.NAMINGPROPNAME, this.RESNAME)); 234 ref.add(new StringRefAddr (JalistoObjectFactory.JALISTOID, this.toString())); 235 JalistoObjectFactory.addConnectionFactory(this.toString(), this); 236 trace.println(Trace.JCA, TRACE_ID + " the reference is \n{0}", ref); 237 238 return ref; 239 } 240 } 241 242 243 private ConnectionManager connectionManager = null; 244 private JalistoManagedConnectionFactory mcf = null; 245 private transient Trace trace; 246 247 private String connectionDriverName; 248 private String connectionURL; private String connectionUserName; 250 private String connectionPassword; 251 252 private static final String PMGET_EXCEPTION_MSG = "Error while getting a JalistoSession"; 253 private static final String TRACE_ID = "[JalistoConnectionFactory]"; 254 private static final String DRIVER_NAMING_FACTORY_NAME = "org.objectweb.jalisto.se.jca.JalistoObjectFactory"; 255 private static final String NAMINGPROPNAME = "xcalia.jalisto"; 256 private static final String RESNAME = "Xcalia Jalisto Connector Adapter 1.0"; 257 private static final String RESDESC = "This is a generic Xcalia Connector adapter for Jalisto"; 258 } 259 | Popular Tags |