/*
 * JBoss, Home of Professional Open Source
 * Copyright 2005, JBoss Inc., and individual contributors as indicated
 * by the @authors tag. See the copyright.txt in the distribution for a
 * full listing of individual contributors.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package javax.resource.spi;

import javax.resource.ResourceException;

/**
 * The ConnectionEvent class provides information about the source of a
 * Connection related event.  A ConnectionEvent contains:<ul>
 *
 *     <li>Type of connection event.</li>
 *     <li>Managed connection instance that generated the event.</li>
 *     <li>Connection handle associated with the managed connection.</li>
 *     <li>Optionally an exception indicating an error.</li>
 *</ul><p>
 * This class is used for the following types of notifications:<ul>
 *
 *     <li>Connection closed</li>
 *     <li>Local transaction started</li>
 *     <li>Local transaction commited</li>
 *     <li>Local transaction rolled back</li>
 *     <li>Connection error occurred</li>
 *</ul>
 */

public class ConnectionEvent extends java.util.EventObject implements java.io.Serializable {

    /**
     * Connection has been closed
     */
    public static final int CONNECTION_CLOSED = 1;

    /**
     * Local transaction has been started
     */
    public static final int LOCAL_TRANSACTION_STARTED = 2;

    /**
     * Local transaction has been committed
     */
    public static final int LOCAL_TRANSACTION_COMMITTED = 3;

    /**
     * Local transaction has been rolled back 
     */
    public static final int LOCAL_TRANSACTION_ROLLEDBACK = 4;

    /**
     * Connection error has occurred
     */
    public static final int CONNECTION_ERROR_OCCURRED = 5;

    /**
     * Type of event
     */
    protected int id;

    private Exception e = null;
    private Object connectionHandle = null;

    public ConnectionEvent( ManagedConnection source, int eid ) {
        super( source );
	id = eid;
    }

    public ConnectionEvent( ManagedConnection source, int eid,
                            Exception exception ) {
	super( source );
	id = eid;
	e = exception;
    }

    /**
     * Get the event type
     */
    public int getId() {
        return id;
    }

    /**
     * Get the exception
     */
    public Exception getException() {
         return e;
    }

    /**
     * Set the ConnectionHandle
     */
    public void setConnectionHandle( Object connectionHandle ) {
        this.connectionHandle = connectionHandle;
    }

    /**
     * Get the ConnectionHandle
     */
    public Object getConnectionHandle() {
        return connectionHandle;
    }
}
