1 22 package org.jboss.test.jca.fs; 23 24 import java.util.ArrayList ; 25 import java.io.PrintWriter ; 26 import javax.resource.spi.ManagedConnection ; 27 import javax.resource.spi.ConnectionEventListener ; 28 import javax.resource.spi.ConnectionRequestInfo ; 29 import javax.resource.spi.LocalTransaction ; 30 import javax.resource.spi.ManagedConnectionMetaData ; 31 import javax.resource.spi.ConnectionEvent ; 32 import javax.resource.ResourceException ; 33 import javax.transaction.xa.XAResource ; 34 import javax.security.auth.Subject ; 35 36 import org.jboss.logging.Logger; 37 38 43 public class FSManagedConnection implements ManagedConnection 44 { 45 static Logger log = Logger.getLogger(FSManagedConnection.class); 46 ArrayList listeners = new ArrayList (); 47 FSDirContext conn; 48 49 50 public FSManagedConnection(Subject subject, 51 FSRequestInfo fsInfo) 52 { 53 log.debug("ctor, fsInfo="+fsInfo); 54 } 55 56 public void addConnectionEventListener(ConnectionEventListener connectionEventListener) 57 { 58 log.debug("addConnectionEventListener, listener="+connectionEventListener, 59 new Exception ("CalledBy:")); 60 listeners.add(connectionEventListener); 61 } 62 public void removeConnectionEventListener(ConnectionEventListener connectionEventListener) 63 { 64 log.debug("removeConnectionEventListener, listener="+connectionEventListener, 65 new Exception ("CalledBy:")); 66 listeners.remove(connectionEventListener); 67 } 68 69 public void associateConnection(Object obj) throws ResourceException 70 { 71 log.debug("associateConnection, obj="+obj, new Exception ("CalledBy:")); 72 conn = (FSDirContext) obj; 73 conn.setManagedConnection(this); 74 } 75 76 public void cleanup() throws ResourceException 77 { 78 log.debug("cleanup"); 79 } 80 81 public void destroy() throws ResourceException 82 { 83 log.debug("destroy"); 84 } 85 86 public Object getConnection(Subject subject, ConnectionRequestInfo info) 87 throws ResourceException 88 { 89 log.debug("getConnection, subject="+subject+", info="+info, 90 new Exception ("CalledBy:")); 91 if( conn == null ) 92 conn = new FSDirContext(this); 93 return conn; 94 } 95 96 public LocalTransaction getLocalTransaction() throws ResourceException 97 { 98 log.debug("getLocalTransaction"); 99 return null; 100 } 101 102 public ManagedConnectionMetaData getMetaData() throws ResourceException 103 { 104 log.debug("getMetaData"); 105 return new FSManagedConnectionMetaData(); 106 } 107 108 public XAResource getXAResource() throws ResourceException 109 { 110 log.debug("getXAResource"); 111 return null; 112 } 113 114 public PrintWriter getLogWriter() throws ResourceException 115 { 116 return null; 117 } 118 public void setLogWriter(PrintWriter out) throws ResourceException 119 { 120 } 121 122 protected void close() 123 { 124 ConnectionEvent ce = new ConnectionEvent (this, ConnectionEvent.CONNECTION_CLOSED); 125 ce.setConnectionHandle(conn); 126 fireConnectionEvent(ce); 127 } 128 129 protected void fireConnectionEvent(ConnectionEvent evt) 130 { 131 for(int i=listeners.size()-1; i >= 0; i--) 132 { 133 ConnectionEventListener listener = (ConnectionEventListener ) listeners.get(i); 134 if(evt.getId() == ConnectionEvent.CONNECTION_CLOSED) 135 listener.connectionClosed(evt); 136 else if(evt.getId() == ConnectionEvent.CONNECTION_ERROR_OCCURRED) 137 listener.connectionErrorOccurred(evt); 138 } 139 } 140 } 141 | Popular Tags |