package javax.management.relation;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.ObjectStreamField;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.jboss.mx.util.Serialization;
public class Role
implements Serializable
{
private String name;
private List objectNameList;
private static final long serialVersionUID;
private static final ObjectStreamField[] serialPersistentFields;
static
{
switch (Serialization.version)
{
case Serialization.V1R0:
serialVersionUID = -1959486389343113026L;
serialPersistentFields = new ObjectStreamField[]
{
new ObjectStreamField("myName", String.class),
new ObjectStreamField("myObjNameList", List.class)
};
break;
default:
serialVersionUID = -279985518429862552L;
serialPersistentFields = new ObjectStreamField[]
{
new ObjectStreamField("name", String.class),
new ObjectStreamField("objectNameList", List.class)
};
}
}
public static String roleValueToString(List roleValue)
throws IllegalArgumentException
{
if (roleValue == null)
throw new IllegalArgumentException("null roleValue");
StringBuffer buffer = new StringBuffer();
Iterator iterator = roleValue.iterator();
while (iterator.hasNext())
{
buffer.append(iterator.next());
if (iterator.hasNext())
buffer.append("\n");
}
return buffer.toString();
}
public Role(String roleName, List roleValue)
throws IllegalArgumentException
{
setRoleName(roleName);
setRoleValue(roleValue);
}
public String getRoleName()
{
return name;
}
public List getRoleValue()
{
return new ArrayList(objectNameList);
}
public void setRoleName(String roleName)
throws IllegalArgumentException
{
if (roleName == null)
throw new IllegalArgumentException("Null roleName");
name = roleName;
}
public void setRoleValue(List roleValue)
throws IllegalArgumentException
{
if (roleValue == null)
throw new IllegalArgumentException("Null roleValue");
objectNameList = new ArrayList(roleValue);
}
public synchronized Object clone()
{
return new Role(name, objectNameList);
}
public synchronized String toString()
{
StringBuffer buffer = new StringBuffer();
buffer.append("Role@");
buffer.append(System.identityHashCode(this));
buffer.append(" RoleName(");
buffer.append(name);
buffer.append(") ObjectNames (");
Iterator iterator = objectNameList.iterator();
while (iterator.hasNext())
{
buffer.append(iterator.next());
if (iterator.hasNext())
buffer.append(" & ");
}
buffer.append(")");
return buffer.toString();
}
private void readObject(ObjectInputStream ois)
throws IOException, ClassNotFoundException
{
switch (Serialization.version)
{
case Serialization.V1R0:
ObjectInputStream.GetField getField = ois.readFields();
name = (String) getField.get("myName", null);
objectNameList = (List) getField.get("myObjNameList", 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("myName", name);
putField.put("myObjNameList", objectNameList);
oos.writeFields();
break;
default:
oos.defaultWriteObject();
}
}
}