package javax.management;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.ObjectStreamField;
import org.jboss.mx.util.Serialization;
public class Notification
extends java.util.EventObject
{
private static final long serialVersionUID;
private static final ObjectStreamField[] serialPersistentFields = new ObjectStreamField[]
{
new ObjectStreamField("message", String.class),
new ObjectStreamField("sequenceNumber", Long.TYPE),
new ObjectStreamField("source", Object.class),
new ObjectStreamField("timeStamp", Long.TYPE),
new ObjectStreamField("type", String.class),
new ObjectStreamField("userData", Object.class)
};
private String type = null;
private long sequenceNumber = 0;
private String message = null;
private long timeStamp = System.currentTimeMillis();
private Object userData = null;
private Object mySource = null;
static
{
switch (Serialization.version)
{
case Serialization.V1R0:
serialVersionUID = 1716977971058914352L;
break;
default:
serialVersionUID = -7516092053498031989L;
}
}
public Notification(String type,
Object source,
long sequenceNumber)
{
super(source);
mySource = source;
this.type = type;
this.sequenceNumber = sequenceNumber;
this.timeStamp = System.currentTimeMillis();
}
public Notification(String type,
Object source,
long sequenceNumber,
String message)
{
this(type, source, sequenceNumber);
this.message = message;
this.timeStamp = System.currentTimeMillis();
}
public Notification(String type,
Object source,
long sequenceNumber,
long timeStamp)
{
this(type, source, sequenceNumber);
this.timeStamp = timeStamp;
}
public Notification(String type,
Object source,
long sequenceNumber,
long timeStamp,
String message)
{
this(type, source, sequenceNumber, timeStamp);
this.message = message;
}
public Object getSource()
{
return mySource;
}
public void setSource(Object source)
{
if (source instanceof String)
{
try
{
super.source = new ObjectName((String)source);
}
catch (MalformedObjectNameException e)
{
throw new IllegalArgumentException("malformed object name: " + source);
}
}
else if (source instanceof ObjectName)
{
super.source = source;
}
else throw new IllegalArgumentException("Notification source must be an object name");
mySource = super.source;
}
public long getSequenceNumber()
{
return sequenceNumber;
}
public void setSequenceNumber(long sequenceNumber)
{
this.sequenceNumber = sequenceNumber;
}
public String getType()
{
return type;
}
public long getTimeStamp()
{
return timeStamp;
}
public void setTimeStamp(long timeStamp)
{
this.timeStamp = timeStamp;
}
public String getMessage()
{
return message;
}
public Object getUserData()
{
return userData;
}
public void setUserData(Object userData)
{
this.userData = userData;
}
public String toString()
{
StringBuffer tmp = new StringBuffer(getClass().getName());
tmp.append('[');
tmp.append("source=");
tmp.append(this.getSource());
tmp.append(",type=");
tmp.append(this.getType());
tmp.append(",sequenceNumber=");
tmp.append(this.getSequenceNumber());
tmp.append(",timeStamp=");
tmp.append(this.getTimeStamp());
tmp.append(",message=");
tmp.append(this.getMessage());
tmp.append(",userData=");
tmp.append(this.getUserData());
tmp.append(']');
return tmp.toString();
}
private void readObject(ObjectInputStream ois)
throws IOException, ClassNotFoundException
{
ObjectInputStream.GetField getField = ois.readFields();
message = (String) getField.get("message", null);
sequenceNumber = getField.get("sequenceNumber", 0L);
mySource = getField.get("source", null);
timeStamp = getField.get("timeStamp", 0L);
type = (String) getField.get("type", null);
userData = getField.get("userData", null);
source=mySource;
}
private void writeObject(ObjectOutputStream oos)
throws IOException
{
ObjectOutputStream.PutField putField = oos.putFields();
putField.put("message", message);
putField.put("sequenceNumber", sequenceNumber);
putField.put("source", mySource);
putField.put("timeStamp", timeStamp);
putField.put("type", type);
putField.put("userData", userData);
oos.writeFields();
}
}