KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > resource > spi > ConnectionEvent


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package javax.resource.spi;
25
26 import javax.resource.ResourceException JavaDoc;
27 import java.util.EventObject JavaDoc;
28
29 /** The ConnectionEvent class provides information about the source of
30  * a connection related event.A ConnectionEvent instance contains the
31  * following information:
32  * <UL>
33  * <LI>Type of the connection event
34  * <LI>ManagedConnection instance that generated the connection event.
35  * A ManagedConnection instance is returned from the method
36  * ConnectionEvent.getSource.
37  * <LI>Connection handle associated with the ManagedConnection instance;
38  * required for the CONNECTION_CLOSED event and optional for the
39  * other event types.
40  * <LI>Optionally, an exception indicating the connection related error.
41  * Note that exception is used for CONNECTION_ERROR_OCCURRED.
42  * </UL>
43  *
44  * <p>This class defines following types of event notifications:
45  * <UL>
46  * <LI>CONNECTION_CLOSED
47  * <LI>LOCAL_TRANSACTION_STARTED
48  * <LI>LOCAL_TRANSACTION_COMMITTED
49  * <LI>LOCAL_TRANSACTION_ROLLEDBACK
50  * <LI>CONNECTION_ERROR_OCCURRED
51  * </UL>
52  *
53  * @version 0.5
54  * @author Rahul Sharma
55  * @see javax.resource.spi.ConnectionEventListener
56  */

57
58 public class ConnectionEvent extends java.util.EventObject JavaDoc {
59
60   /** Event notification that an application component has closed the
61    * connection
62   **/

63   public static final int CONNECTION_CLOSED = 1;
64
65   /** Event notification that a Resource Manager Local Transaction was
66    * started on the connection
67   **/

68   public static final int LOCAL_TRANSACTION_STARTED = 2;
69
70   /** Event notification that a Resource Manager Local Transaction was
71    * committed on the connection
72   **/

73   public static final int LOCAL_TRANSACTION_COMMITTED = 3;
74
75   /** Event notification that a Resource Manager Local Transaction was
76    * rolled back on the connection
77   **/

78   public static final int LOCAL_TRANSACTION_ROLLEDBACK = 4;
79
80   /** Event notification that an error occurred on the connection.
81    * This event indicates that the ManagedConnection instance is
82    * now invalid and unusable.
83   **/

84   public static final int CONNECTION_ERROR_OCCURRED = 5;
85
86
87   /** Exception associated with the <code>ConnectionEvent</code>
88    * instance.
89    *
90    * @serial
91   **/

92   private Exception JavaDoc exception;
93
94   /** Type of the event
95   **/

96   protected int id;
97
98   private Object JavaDoc connectionHandle;
99   
100   /**
101    * Construct a ConnectionEvent object. Exception defaults to null.
102    *
103    * @param source ManagedConnection that is the
104    * source of the event
105    * @param eid type of the Connection event
106    */

107   public ConnectionEvent(ManagedConnection JavaDoc source, int eid) {
108     super(source);
109     this.id = eid;
110   }
111
112   /**
113    * Construct a ConnectionEvent object.
114    *
115    * @param source ManagedConnection that is the
116    * source of the event
117    * @param exception exception about to be thrown to the application
118    * @param eid type of the Connection event
119    */

120   public ConnectionEvent(ManagedConnection JavaDoc source, int eid,
121              Exception JavaDoc exception) {
122     super(source);
123     this.exception = exception;
124     this.id = eid;
125   }
126
127   /**Get the connection handle associated with the Managed
128    * Connection instance. Used for CONNECTION_CLOSED event.
129    *
130    * @return the connection handle. May be null
131    */

132   public Object JavaDoc getConnectionHandle() {
133     return connectionHandle;
134   }
135
136   /**
137    * Set the connection handle. Used for CONNECTION_CLOSED event
138    */

139   public void setConnectionHandle(Object JavaDoc connectionHandle) {
140     this.connectionHandle = connectionHandle;
141   }
142
143  
144   /**
145    * Get the exception. May be null.
146    *
147    * @return the exception about to be thrown.
148    */

149   public Exception JavaDoc getException() {
150     return exception;
151   }
152
153   /**
154    * Get the type of event
155    */

156   public
157   int getId() {
158     return id;
159   }
160 }
161
162
163
164
165
166
Popular Tags