1 package org.apache.ojb.otm.connector; 2 3 17 18 import javax.resource.spi.ConnectionEvent ; 19 import javax.resource.spi.ConnectionEventListener ; 20 import java.util.Vector ; 21 22 26 27 public class OTMConnectionEventListener implements ConnectionEventListener 28 { 29 private Vector m_listeners = null; 30 31 public OTMConnectionEventListener() 32 { 33 m_listeners = new Vector (); 34 } 35 36 void sendEvent(ConnectionEvent ce) 37 { 38 Vector list = (Vector ) m_listeners.clone(); 39 int size = list.size(); 40 for (int i = 0; i < size; i++) 41 { 42 ConnectionEventListener l = 43 (ConnectionEventListener ) 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 ("Illegal eventType: " + ce.getId()); 63 } 64 } 65 } 66 67 void addConnectorListener(ConnectionEventListener l) 68 { 69 m_listeners.addElement(l); 70 } 71 72 void removeConnectorListener(ConnectionEventListener l) 73 { 74 m_listeners.removeElement(l); 75 } 76 77 public void connectionClosed(ConnectionEvent event) 78 { 79 } 81 82 public void connectionErrorOccurred(ConnectionEvent event) 83 { 84 sendEvent(event); 85 } 86 87 public void localTransactionCommitted(ConnectionEvent event) 88 { 89 sendEvent(event); 90 } 91 92 public void localTransactionStarted(ConnectionEvent event) 93 { 94 sendEvent(event); 95 } 96 97 public void localTransactionRolledback(ConnectionEvent event) 98 { 99 sendEvent(event); 100 } 101 } 102 | Popular Tags |