KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > otm > connector > OTMConnectionEventListener


1 package org.apache.ojb.otm.connector;
2
3 /* Copyright 2003-2005 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * 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 JavaDoc;
19 import javax.resource.spi.ConnectionEventListener JavaDoc;
20 import java.util.Vector JavaDoc;
21
22 /**
23  *
24  * @author <a HREF="mailto:mattbaird@yahoo.com">Matthew Baird<a>
25  */

26
27 public class OTMConnectionEventListener implements ConnectionEventListener JavaDoc
28 {
29     private Vector JavaDoc m_listeners = null;
30
31     public OTMConnectionEventListener()
32     {
33         m_listeners = new Vector JavaDoc();
34     }
35
36     void sendEvent(ConnectionEvent JavaDoc ce)
37     {
38         Vector JavaDoc list = (Vector JavaDoc) m_listeners.clone();
39         int size = list.size();
40         for (int i = 0; i < size; i++)
41         {
42             ConnectionEventListener JavaDoc l =
43                     (ConnectionEventListener JavaDoc) list.elementAt(i);
44             switch (ce.getId())
45             {
46                 case ConnectionEvent.CONNECTION_CLOSED:
47                     l.connectionClosed(ce);
48                     break;
49                 case ConnectionEvent.LOCAL_TRANSACTION_STARTED:
50                     l.localTransactionStarted(ce);
51                     break;
52                 case ConnectionEvent.LOCAL_TRANSACTION_COMMITTED:
53                     l.localTransactionCommitted(ce);
54                     break;
55                 case ConnectionEvent.LOCAL_TRANSACTION_ROLLEDBACK:
56                     l.localTransactionRolledback(ce);
57                     break;
58                 case ConnectionEvent.CONNECTION_ERROR_OCCURRED:
59                     l.connectionErrorOccurred(ce);
60                     break;
61                 default:
62                     throw new IllegalArgumentException JavaDoc("Illegal eventType: " + ce.getId());
63             }
64         }
65     }
66
67     void addConnectorListener(ConnectionEventListener JavaDoc l)
68     {
69         m_listeners.addElement(l);
70     }
71
72     void removeConnectorListener(ConnectionEventListener JavaDoc l)
73     {
74         m_listeners.removeElement(l);
75     }
76
77     public void connectionClosed(ConnectionEvent JavaDoc event)
78     {
79         // do nothing. The event is sent by the ConnectionImpl class
80
}
81
82     public void connectionErrorOccurred(ConnectionEvent JavaDoc event)
83     {
84         sendEvent(event);
85     }
86
87     public void localTransactionCommitted(ConnectionEvent JavaDoc event)
88     {
89         sendEvent(event);
90     }
91
92     public void localTransactionStarted(ConnectionEvent JavaDoc event)
93     {
94         sendEvent(event);
95     }
96
97     public void localTransactionRolledback(ConnectionEvent JavaDoc event)
98     {
99         sendEvent(event);
100     }
101 }
102
Popular Tags