KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > jca > fs > FSManagedConnection


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.jca.fs;
23
24 import java.util.ArrayList JavaDoc;
25 import java.io.PrintWriter JavaDoc;
26 import javax.resource.spi.ManagedConnection JavaDoc;
27 import javax.resource.spi.ConnectionEventListener JavaDoc;
28 import javax.resource.spi.ConnectionRequestInfo JavaDoc;
29 import javax.resource.spi.LocalTransaction JavaDoc;
30 import javax.resource.spi.ManagedConnectionMetaData JavaDoc;
31 import javax.resource.spi.ConnectionEvent JavaDoc;
32 import javax.resource.ResourceException JavaDoc;
33 import javax.transaction.xa.XAResource JavaDoc;
34 import javax.security.auth.Subject JavaDoc;
35
36 import org.jboss.logging.Logger;
37
38 /**
39  *
40  * @author Scott.Stark@jboss.org
41  * @version $Revision: 37406 $
42  */

43 public class FSManagedConnection implements ManagedConnection JavaDoc
44 {
45    static Logger log = Logger.getLogger(FSManagedConnection.class);
46    ArrayList JavaDoc listeners = new ArrayList JavaDoc();
47    FSDirContext conn;
48
49    /** Creates new FSManagedConnection */
50    public FSManagedConnection(Subject JavaDoc subject,
51       FSRequestInfo fsInfo)
52    {
53       log.debug("ctor, fsInfo="+fsInfo);
54    }
55
56    public void addConnectionEventListener(ConnectionEventListener JavaDoc connectionEventListener)
57    {
58       log.debug("addConnectionEventListener, listener="+connectionEventListener,
59          new Exception JavaDoc("CalledBy:"));
60       listeners.add(connectionEventListener);
61    }
62    public void removeConnectionEventListener(ConnectionEventListener JavaDoc connectionEventListener)
63    {
64       log.debug("removeConnectionEventListener, listener="+connectionEventListener,
65          new Exception JavaDoc("CalledBy:"));
66       listeners.remove(connectionEventListener);
67    }
68
69    public void associateConnection(Object JavaDoc obj) throws ResourceException JavaDoc
70    {
71       log.debug("associateConnection, obj="+obj, new Exception JavaDoc("CalledBy:"));
72       conn = (FSDirContext) obj;
73       conn.setManagedConnection(this);
74    }
75
76    public void cleanup() throws ResourceException JavaDoc
77    {
78       log.debug("cleanup");
79    }
80    
81    public void destroy() throws ResourceException JavaDoc
82    {
83       log.debug("destroy");
84    }
85    
86    public Object JavaDoc getConnection(Subject JavaDoc subject, ConnectionRequestInfo JavaDoc info)
87       throws ResourceException JavaDoc
88    {
89       log.debug("getConnection, subject="+subject+", info="+info,
90          new Exception JavaDoc("CalledBy:"));
91       if( conn == null )
92          conn = new FSDirContext(this);
93       return conn;
94    }
95
96    public LocalTransaction JavaDoc getLocalTransaction() throws ResourceException JavaDoc
97    {
98       log.debug("getLocalTransaction");
99       return null;
100    }
101    
102    public ManagedConnectionMetaData JavaDoc getMetaData() throws ResourceException JavaDoc
103    {
104       log.debug("getMetaData");
105       return new FSManagedConnectionMetaData();
106    }
107    
108    public XAResource JavaDoc getXAResource() throws ResourceException JavaDoc
109    {
110       log.debug("getXAResource");
111       return null;
112    }
113
114    public PrintWriter JavaDoc getLogWriter() throws ResourceException JavaDoc
115    {
116       return null;
117    }
118    public void setLogWriter(PrintWriter JavaDoc out) throws ResourceException JavaDoc
119    {
120    }
121
122    protected void close()
123    {
124       ConnectionEvent JavaDoc ce = new ConnectionEvent JavaDoc(this, ConnectionEvent.CONNECTION_CLOSED);
125       ce.setConnectionHandle(conn);
126       fireConnectionEvent(ce);
127    }
128
129    protected void fireConnectionEvent(ConnectionEvent JavaDoc evt)
130    {
131       for(int i=listeners.size()-1; i >= 0; i--)
132       {
133          ConnectionEventListener JavaDoc listener = (ConnectionEventListener JavaDoc) 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