1. /*
  2. * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
  3. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  4. */
  5. package javax.resource.spi;
  6. import javax.resource.ResourceException;
  7. import java.util.EventObject;
  8. /** The ConnectionEvent class provides information about the source of
  9. * a connection related event.A ConnectionEvent instance contains the
  10. * following information:
  11. * <UL>
  12. * <LI>Type of the connection event
  13. * <LI>ManagedConnection instance that generated the connection event.
  14. * A ManagedConnection instance is returned from the method
  15. * ConnectionEvent.getSource.
  16. * <LI>Connection handle associated with the ManagedConnection instance;
  17. * required for the CONNECTION_CLOSED event and optional for the
  18. * other event types.
  19. * <LI>Optionally, an exception indicating the connection related error.
  20. * Note that exception is used for CONNECTION_ERROR_OCCURRED.
  21. * </UL>
  22. *
  23. * <p>This class defines following types of event notifications:
  24. * <UL>
  25. * <LI>CONNECTION_CLOSED
  26. * <LI>LOCAL_TRANSACTION_STARTED
  27. * <LI>LOCAL_TRANSACTION_COMMITTED
  28. * <LI>LOCAL_TRANSACTION_ROLLEDBACK
  29. * <LI>CONNECTION_ERROR_OCCURRED
  30. * </UL>
  31. *
  32. * @version 0.5
  33. * @author Rahul Sharma
  34. * @see javax.resource.spi.ConnectionEventListener
  35. */
  36. public class ConnectionEvent extends java.util.EventObject {
  37. /** Event notification that an application component has closed the
  38. * connection
  39. **/
  40. public static final int CONNECTION_CLOSED = 1;
  41. /** Event notification that a Resource Manager Local Transaction was
  42. * started on the connection
  43. **/
  44. public static final int LOCAL_TRANSACTION_STARTED = 2;
  45. /** Event notification that a Resource Manager Local Transaction was
  46. * committed on the connection
  47. **/
  48. public static final int LOCAL_TRANSACTION_COMMITTED = 3;
  49. /** Event notification that a Resource Manager Local Transaction was
  50. * rolled back on the connection
  51. **/
  52. public static final int LOCAL_TRANSACTION_ROLLEDBACK = 4;
  53. /** Event notification that an error occurred on the connection.
  54. * This event indicates that the ManagedConnection instance is
  55. * now invalid and unusable.
  56. **/
  57. public static final int CONNECTION_ERROR_OCCURRED = 5;
  58. /** Exception associated with the <code>ConnectionEvent</code>
  59. * instance.
  60. *
  61. * @serial
  62. **/
  63. private Exception exception;
  64. /** Type of the event
  65. **/
  66. protected int id;
  67. private Object connectionHandle;
  68. /**
  69. * Construct a ConnectionEvent object. Exception defaults to null.
  70. *
  71. * @param source ManagedConnection that is the
  72. * source of the event
  73. * @param eid type of the Connection event
  74. */
  75. public ConnectionEvent(ManagedConnection source, int eid) {
  76. super(source);
  77. this.id = eid;
  78. }
  79. /**
  80. * Construct a ConnectionEvent object.
  81. *
  82. * @param source ManagedConnection that is the
  83. * source of the event
  84. * @param exception exception about to be thrown to the application
  85. * @param eid type of the Connection event
  86. */
  87. public ConnectionEvent(ManagedConnection source, int eid,
  88. Exception exception) {
  89. super(source);
  90. this.exception = exception;
  91. this.id = eid;
  92. }
  93. /**Get the connection handle associated with the Managed
  94. * Connection instance. Used for CONNECTION_CLOSED event.
  95. * @Return the connection handle. May be null
  96. */
  97. public Object getConnectionHandle() {
  98. return connectionHandle;
  99. }
  100. /**
  101. * Set the connection handle. Used for CONNECTION_CLOSED event
  102. */
  103. public void setConnectionHandle(Object connectionHandle) {
  104. this.connectionHandle = connectionHandle;
  105. }
  106. /**Get the exception. May be null.
  107. *
  108. * @return the exception about to be thrown.
  109. */
  110. public Exception getException() {
  111. return exception;
  112. }
  113. /**Get the type of event
  114. **/
  115. public
  116. int getId() {
  117. return id;
  118. }
  119. }