01: package org.apache.ojb.otm.connector;
02:
03: /* Copyright 2003-2005 The Apache Software Foundation
04: *
05: * Licensed under the Apache License, Version 2.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: import javax.resource.spi.ConnectionEvent;
19: import javax.resource.spi.ConnectionEventListener;
20: import java.util.Vector;
21:
22: /**
23: *
24: * @author <a href="mailto:mattbaird@yahoo.com">Matthew Baird<a>
25: */
26:
27: public class OTMConnectionEventListener implements
28: ConnectionEventListener {
29: private Vector m_listeners = null;
30:
31: public OTMConnectionEventListener() {
32: m_listeners = new Vector();
33: }
34:
35: void sendEvent(ConnectionEvent ce) {
36: Vector list = (Vector) m_listeners.clone();
37: int size = list.size();
38: for (int i = 0; i < size; i++) {
39: ConnectionEventListener l = (ConnectionEventListener) list
40: .elementAt(i);
41: switch (ce.getId()) {
42: case ConnectionEvent.CONNECTION_CLOSED:
43: l.connectionClosed(ce);
44: break;
45: case ConnectionEvent.LOCAL_TRANSACTION_STARTED:
46: l.localTransactionStarted(ce);
47: break;
48: case ConnectionEvent.LOCAL_TRANSACTION_COMMITTED:
49: l.localTransactionCommitted(ce);
50: break;
51: case ConnectionEvent.LOCAL_TRANSACTION_ROLLEDBACK:
52: l.localTransactionRolledback(ce);
53: break;
54: case ConnectionEvent.CONNECTION_ERROR_OCCURRED:
55: l.connectionErrorOccurred(ce);
56: break;
57: default:
58: throw new IllegalArgumentException(
59: "Illegal eventType: " + ce.getId());
60: }
61: }
62: }
63:
64: void addConnectorListener(ConnectionEventListener l) {
65: m_listeners.addElement(l);
66: }
67:
68: void removeConnectorListener(ConnectionEventListener l) {
69: m_listeners.removeElement(l);
70: }
71:
72: public void connectionClosed(ConnectionEvent event) {
73: // do nothing. The event is sent by the ConnectionImpl class
74: }
75:
76: public void connectionErrorOccurred(ConnectionEvent event) {
77: sendEvent(event);
78: }
79:
80: public void localTransactionCommitted(ConnectionEvent event) {
81: sendEvent(event);
82: }
83:
84: public void localTransactionStarted(ConnectionEvent event) {
85: sendEvent(event);
86: }
87:
88: public void localTransactionRolledback(ConnectionEvent event) {
89: sendEvent(event);
90: }
91: }
|