package javax.management.relation;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.ObjectStreamField;
import java.util.ArrayList;
import java.util.List;
import javax.management.Notification;
import javax.management.ObjectName;
import org.jboss.mx.util.Serialization;
public class RelationNotification
extends Notification
{
public static final String RELATION_BASIC_CREATION = "jmx.relation.creation.basic";
public static final String RELATION_BASIC_REMOVAL = "jmx.relation.removal.basic";
public static final String RELATION_BASIC_UPDATE = "jmx.relation.update.basic";
public static final String RELATION_MBEAN_CREATION = "jmx.relation.creation.mbean";
public static final String RELATION_MBEAN_REMOVAL = "jmx.relation.removal.mbean";
public static final String RELATION_MBEAN_UPDATE = "jmx.relation.update.mbean";
private static int CREATION_REMOVAL = 0;
private static int UPDATE = 1;
private List unregisterMBeanList;
private List newRoleValue;
private ObjectName relationObjName;
private List oldRoleValue;
private String relationId;
private String relationTypeName;
private String roleName;
private static final long serialVersionUID;
private static final ObjectStreamField[] serialPersistentFields;
static
{
switch (Serialization.version)
{
case Serialization.V1R0:
serialVersionUID = -2126464566505527147L;
serialPersistentFields = new ObjectStreamField[]
{
new ObjectStreamField("myNewRoleValue", ArrayList.class),
new ObjectStreamField("myOldRoleValue", ArrayList.class),
new ObjectStreamField("myRelId", String.class),
new ObjectStreamField("myRelObjName", ObjectName.class),
new ObjectStreamField("myRelTypeName", String.class),
new ObjectStreamField("myRoleName", String.class),
new ObjectStreamField("myUnregMBeanList", ArrayList.class)
};
break;
default:
serialVersionUID = -6871117877523310399L;
serialPersistentFields = new ObjectStreamField[]
{
new ObjectStreamField("newRoleValue", List.class),
new ObjectStreamField("oldRoleValue", List.class),
new ObjectStreamField("relationId", String.class),
new ObjectStreamField("relationObjName", ObjectName.class),
new ObjectStreamField("relationTypeName", String.class),
new ObjectStreamField("roleName", String.class),
new ObjectStreamField("unregisterMBeanList", List.class),
};
}
}
public RelationNotification(String type, Object source, long sequenceNumber,
long timeStamp, String message, String relationId,
String relTypeName, ObjectName relObjName, List unregMBeans)
throws IllegalArgumentException
{
super(type, source, sequenceNumber, timeStamp, message);
init(CREATION_REMOVAL, type, source, sequenceNumber, timeStamp, message,
relationId, relTypeName, relObjName, unregMBeans, null, null, null);
}
public RelationNotification(String type, Object source, long sequenceNumber,
long timeStamp, String message, String relationId,
String relTypeName, ObjectName relObjName, String roleName,
List newRoleValue, List oldRoleValue)
throws IllegalArgumentException
{
super(type, source, sequenceNumber, timeStamp, message);
init(UPDATE, type, source, sequenceNumber, timeStamp, message, relationId,
relTypeName, relObjName, null, roleName, newRoleValue, oldRoleValue);
}
public List getMBeansToUnregister()
{
if (unregisterMBeanList == null)
return new ArrayList();
else
return new ArrayList(unregisterMBeanList);
}
public List getNewRoleValue()
{
if (newRoleValue == null)
return new ArrayList();
else
return new ArrayList(newRoleValue);
}
public ObjectName getObjectName()
{
return relationObjName;
}
public List getOldRoleValue()
{
if (oldRoleValue == null)
return new ArrayList();
else
return new ArrayList(oldRoleValue);
}
public String getRelationId()
{
return relationId;
}
public String getRelationTypeName()
{
return relationTypeName;
}
public String getRoleName()
{
return roleName;
}
private void init(int which, String type, Object source,
long sequenceNumber, long timeStamp, String message,
String relationId, String relTypeName, ObjectName relObjName,
List unregMBeans, String roleName, List newRoleValue,
List oldRoleValue)
throws IllegalArgumentException
{
if (type == null)
throw new IllegalArgumentException("null notification type");
if (which == CREATION_REMOVAL && type != RELATION_BASIC_CREATION &&
type != RELATION_BASIC_REMOVAL && type != RELATION_MBEAN_CREATION &&
type != RELATION_MBEAN_REMOVAL)
throw new IllegalArgumentException("Invalid creation/removal notifcation");
if (which == UPDATE && type != RELATION_BASIC_UPDATE &&
type != RELATION_MBEAN_UPDATE)
throw new IllegalArgumentException("Invalid update notifcation");
if (type == null)
throw new IllegalArgumentException("null source");
if (relationId == null)
throw new IllegalArgumentException("null relation id");
if (relTypeName == null)
throw new IllegalArgumentException("null relation type name");
if (which == UPDATE && roleName == null)
throw new IllegalArgumentException("null role name");
if (which == UPDATE && newRoleValue == null)
throw new IllegalArgumentException("null new role value");
if (which == UPDATE && oldRoleValue == null)
throw new IllegalArgumentException("null old role value");
this.relationId = relationId;
this.relationTypeName = relTypeName;
this.relationObjName = relObjName;
if (unregMBeans != null)
this.unregisterMBeanList = new ArrayList(unregMBeans);
if (roleName != null)
this.roleName = roleName;
if (newRoleValue != null)
this.newRoleValue = new ArrayList(newRoleValue);
if (oldRoleValue != null)
this.oldRoleValue = new ArrayList(oldRoleValue);
}
private void readObject(ObjectInputStream ois)
throws IOException, ClassNotFoundException
{
switch (Serialization.version)
{
case Serialization.V1R0:
ObjectInputStream.GetField getField = ois.readFields();
newRoleValue = (ArrayList) getField.get("myNewRoleValue", null);
oldRoleValue = (ArrayList) getField.get("myOldRoleValue", null);
relationId = (String) getField.get("myRelId", null);
relationObjName = (ObjectName) getField.get("myRelObjName", null);
relationTypeName = (String) getField.get("myRelTypeName", null);
roleName = (String) getField.get("myRoleName", null);
unregisterMBeanList = (ArrayList) getField.get("myUnregMBeanList", null);
break;
default:
ois.defaultReadObject();
}
}
private void writeObject(ObjectOutputStream oos)
throws IOException
{
switch (Serialization.version)
{
case Serialization.V1R0:
ObjectOutputStream.PutField putField = oos.putFields();
putField.put("myNewRoleValue", newRoleValue);
putField.put("myOldRoleValue", oldRoleValue);
putField.put("myRelId", relationId);
putField.put("myRelObjName", relationObjName);
putField.put("myRelTypeName", relationTypeName);
putField.put("myRoleName", roleName);
putField.put("myUnregMBeanList", unregisterMBeanList);
oos.writeFields();
break;
default:
oos.defaultWriteObject();
}
}
}