001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.jca.fs;
023:
024: import java.util.ArrayList;
025: import java.io.PrintWriter;
026: import javax.resource.spi.ManagedConnection;
027: import javax.resource.spi.ConnectionEventListener;
028: import javax.resource.spi.ConnectionRequestInfo;
029: import javax.resource.spi.LocalTransaction;
030: import javax.resource.spi.ManagedConnectionMetaData;
031: import javax.resource.spi.ConnectionEvent;
032: import javax.resource.ResourceException;
033: import javax.transaction.xa.XAResource;
034: import javax.security.auth.Subject;
035:
036: import org.jboss.logging.Logger;
037:
038: /**
039: *
040: * @author Scott.Stark@jboss.org
041: * @version $Revision: 57211 $
042: */
043: public class FSManagedConnection implements ManagedConnection {
044: static Logger log = Logger.getLogger(FSManagedConnection.class);
045: ArrayList listeners = new ArrayList();
046: FSDirContext conn;
047:
048: /** Creates new FSManagedConnection */
049: public FSManagedConnection(Subject subject, FSRequestInfo fsInfo) {
050: log.debug("ctor, fsInfo=" + fsInfo);
051: }
052:
053: public void addConnectionEventListener(
054: ConnectionEventListener connectionEventListener) {
055: log.debug("addConnectionEventListener, listener="
056: + connectionEventListener, new Exception("CalledBy:"));
057: listeners.add(connectionEventListener);
058: }
059:
060: public void removeConnectionEventListener(
061: ConnectionEventListener connectionEventListener) {
062: log.debug("removeConnectionEventListener, listener="
063: + connectionEventListener, new Exception("CalledBy:"));
064: listeners.remove(connectionEventListener);
065: }
066:
067: public void associateConnection(Object obj)
068: throws ResourceException {
069: log.debug("associateConnection, obj=" + obj, new Exception(
070: "CalledBy:"));
071: conn = (FSDirContext) obj;
072: conn.setManagedConnection(this );
073: }
074:
075: public void cleanup() throws ResourceException {
076: log.debug("cleanup");
077: }
078:
079: public void destroy() throws ResourceException {
080: log.debug("destroy");
081: }
082:
083: public Object getConnection(Subject subject,
084: ConnectionRequestInfo info) throws ResourceException {
085: log.debug("getConnection, subject=" + subject + ", info="
086: + info, new Exception("CalledBy:"));
087: if (conn == null)
088: conn = new FSDirContext(this );
089: return conn;
090: }
091:
092: public LocalTransaction getLocalTransaction()
093: throws ResourceException {
094: log.debug("getLocalTransaction");
095: return null;
096: }
097:
098: public ManagedConnectionMetaData getMetaData()
099: throws ResourceException {
100: log.debug("getMetaData");
101: return new FSManagedConnectionMetaData();
102: }
103:
104: public XAResource getXAResource() throws ResourceException {
105: log.debug("getXAResource");
106: return null;
107: }
108:
109: public PrintWriter getLogWriter() throws ResourceException {
110: return null;
111: }
112:
113: public void setLogWriter(PrintWriter out) throws ResourceException {
114: }
115:
116: protected void close() {
117: ConnectionEvent ce = new ConnectionEvent(this ,
118: ConnectionEvent.CONNECTION_CLOSED);
119: ce.setConnectionHandle(conn);
120: fireConnectionEvent(ce);
121: }
122:
123: protected void fireConnectionEvent(ConnectionEvent evt) {
124: for (int i = listeners.size() - 1; i >= 0; i--) {
125: ConnectionEventListener listener = (ConnectionEventListener) listeners
126: .get(i);
127: if (evt.getId() == ConnectionEvent.CONNECTION_CLOSED)
128: listener.connectionClosed(evt);
129: else if (evt.getId() == ConnectionEvent.CONNECTION_ERROR_OCCURRED)
130: listener.connectionErrorOccurred(evt);
131: }
132: }
133: }
|