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 29 import javax.naming.Reference ; 30 import javax.resource.ResourceException ; 31 import javax.resource.spi.ConnectionManager ; 32 import java.io.ObjectStreamException ; 33 import java.io.PrintWriter ; 34 import java.io.Serializable ; 35 36 public class JalistoCfSerializationWrapper implements Serializable { 37 38 public JalistoCfSerializationWrapper() { 39 } 40 41 public void setConnectionManager(ConnectionManager cm) { 42 this.connectionManager = cm; 43 } 44 45 public void setManagedConnectionFactory(JalistoManagedConnectionFactory jdomcf) { 46 try { 47 logger = jdomcf.getLogWriter(); 48 } catch (ResourceException e) { 49 } 50 51 connectionURL = jdomcf.getConnectionURL(); 52 connectionDriverName = jdomcf.getConnectionDriverName(); 53 hashCode = jdomcf.hashCode(); 54 } 55 56 public void setReference(Reference ref) { 57 reference = ref; 58 } 59 60 public Object readResolve() throws ObjectStreamException { 61 if (trace != null) { 62 trace.println(Trace.JCA, TRACE_ID + " readResolve"); 63 } 64 65 JalistoConnectionFactory result = null; 66 67 if (reference != null) { 68 result = (JalistoConnectionFactory) JalistoObjectFactory.getConnectionFactory(reference); 69 } 70 71 if (result == null) { 72 try { 74 JalistoManagedConnectionFactory managedConnectionFactory = new JalistoManagedConnectionFactory(); 75 managedConnectionFactory.setLogWriter(logger); 76 managedConnectionFactory.setConnectionURL(connectionURL); 77 managedConnectionFactory.setConnectionDriverName(connectionDriverName); 78 managedConnectionFactory.setHashCode(hashCode); 79 result = (JalistoConnectionFactory) managedConnectionFactory.createConnectionFactory(connectionManager); 80 } catch (ResourceException e) { 81 throw new JcaException("Cannot create new ConnectionFactory instance", e); 82 } 83 } 84 85 return result; 86 } 87 88 89 private ConnectionManager connectionManager = null; 90 private String connectionDriverName = null; 91 private String connectionURL = null; 92 93 private PrintWriter logger = null; 94 private Reference reference = null; 95 96 private Trace trace = null; 97 private int hashCode = 0; 98 99 100 private static final String TRACE_ID = "[JalistoCfSerializationWrapper]"; 101 102 static final long serialVersionUID = -7589377087964761669L; 103 } 104 | Popular Tags |