package javax.resource.spi;
import java.io.Serializable;
import java.io.ObjectStreamField;
import java.io.ObjectInputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.EventObject;
import org.jboss.util.id.SerialVersion;
public class ConnectionEvent extends EventObject
{
static final long serialVersionUID;
private static final ObjectStreamField[] serialPersistentFields;
private static final int ID_IDX = 0;
private static final int EXCEPTION_IDX = 1;
private static final int CONN_HANDLE_IDX = 2;
static
{
if (SerialVersion.version == SerialVersion.LEGACY)
{
serialVersionUID = 2776168349823367611L;
serialPersistentFields = new ObjectStreamField[] {
new ObjectStreamField("id", int.class),
new ObjectStreamField("e", Exception.class),
new ObjectStreamField("connectionHandle", Object.class)
};
}
else
{
serialVersionUID = 5611772461379563249L;
serialPersistentFields = new ObjectStreamField[] {
new ObjectStreamField("id", int.class),
new ObjectStreamField("exception", Exception.class),
new ObjectStreamField("connectionHandle", Object.class)
};
}
}
public static final int CONNECTION_CLOSED = 1;
public static final int LOCAL_TRANSACTION_STARTED = 2;
public static final int LOCAL_TRANSACTION_COMMITTED = 3;
public static final int LOCAL_TRANSACTION_ROLLEDBACK = 4;
public static final int CONNECTION_ERROR_OCCURRED = 5;
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;
}
public int getId()
{
return id;
}
public Exception getException()
{
return e;
}
public void setConnectionHandle(Object connectionHandle)
{
this.connectionHandle = connectionHandle;
}
public Object getConnectionHandle()
{
return connectionHandle;
}
private void readObject(ObjectInputStream ois)
throws ClassNotFoundException, IOException
{
ObjectInputStream.GetField fields = ois.readFields();
String name = serialPersistentFields[ID_IDX].getName();
this.id = fields.get(name, CONNECTION_ERROR_OCCURRED);
name = serialPersistentFields[EXCEPTION_IDX].getName();
this.e = (Exception) fields.get(name, null);
name = serialPersistentFields[CONN_HANDLE_IDX].getName();
this.connectionHandle = fields.get(name, null);
}
private void writeObject(ObjectOutputStream oos)
throws IOException
{
ObjectOutputStream.PutField fields = oos.putFields();
String name = serialPersistentFields[ID_IDX].getName();
fields.put(name, id);
name = serialPersistentFields[EXCEPTION_IDX].getName();
fields.put(name, e);
name = serialPersistentFields[CONN_HANDLE_IDX].getName();
fields.put(name, connectionHandle);
oos.writeFields();
}
}