package javax.management.relation;
import org.jboss.mx.util.Serialization;
import javax.management.NotCompliantMBeanException;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.ObjectStreamField;
import java.io.Serializable;
public class RoleInfo
implements Serializable
{
public static int ROLE_CARDINALITY_INFINITY = -1;
private String name;
private String referencedMBeanClassName;
boolean isReadable;
boolean isWritable;
int minDegree;
int maxDegree;
String description;
private static final long serialVersionUID;
private static final ObjectStreamField[] serialPersistentFields;
static
{
switch (Serialization.version)
{
case Serialization.V1R0:
serialVersionUID = 7227256952085334351L;
serialPersistentFields = new ObjectStreamField[]
{
new ObjectStreamField("myDescription", String.class),
new ObjectStreamField("myIsReadableFlg", Boolean.TYPE),
new ObjectStreamField("myIsWritableFlg", Boolean.TYPE),
new ObjectStreamField("myMaxDegree", Integer.TYPE),
new ObjectStreamField("myMinDegree", Integer.TYPE),
new ObjectStreamField("myName", String.class),
new ObjectStreamField("myRefMBeanClassName", String.class)
};
break;
default:
serialVersionUID = 2504952983494636987L;
serialPersistentFields = new ObjectStreamField[]
{
new ObjectStreamField("description", String.class),
new ObjectStreamField("isReadable", Boolean.TYPE),
new ObjectStreamField("isWritable", Boolean.TYPE),
new ObjectStreamField("maxDegree", Integer.TYPE),
new ObjectStreamField("minDegree", Integer.TYPE),
new ObjectStreamField("name", String.class),
new ObjectStreamField("referencedMBeanClassName", String.class)
};
}
}
public RoleInfo(RoleInfo other)
throws IllegalArgumentException
{
if (other == null)
throw new IllegalArgumentException("Null role info");
this.name = other.name;
this.referencedMBeanClassName = other.referencedMBeanClassName;
this.isReadable = other.isReadable;
this.isWritable = other.isWritable;
this.minDegree = other.minDegree;
this.maxDegree = other.maxDegree;
this.description = other.description;
}
public RoleInfo(String name, String className)
throws IllegalArgumentException, ClassNotFoundException,
NotCompliantMBeanException
{
this(name, className, true, true);
}
public RoleInfo(String name, String className, boolean readable, boolean writable)
throws IllegalArgumentException, ClassNotFoundException, NotCompliantMBeanException
{
if (name == null)
throw new IllegalArgumentException("Null name");
if (className == null)
throw new IllegalArgumentException("Null class name");
this.name = name;
this.referencedMBeanClassName = className;
this.isReadable = readable;
this.isWritable = writable;
minDegree = 1;
maxDegree = 1;
}
public RoleInfo(String name, String className, boolean readable, boolean writable, int minDegree, int maxDegree, String description)
throws IllegalArgumentException, ClassNotFoundException, NotCompliantMBeanException, InvalidRoleInfoException
{
if (name == null)
throw new IllegalArgumentException("Null name");
if (className == null)
throw new IllegalArgumentException("Null class name");
if (minDegree < ROLE_CARDINALITY_INFINITY)
throw new InvalidRoleInfoException("invalid minimum");
if (maxDegree < ROLE_CARDINALITY_INFINITY)
throw new InvalidRoleInfoException("invalid maximum");
if (maxDegree < minDegree && maxDegree != ROLE_CARDINALITY_INFINITY)
throw new InvalidRoleInfoException("maximum less than minimum");
if (minDegree == ROLE_CARDINALITY_INFINITY && maxDegree != ROLE_CARDINALITY_INFINITY)
throw new InvalidRoleInfoException("maximum less than minimum");
this.name = name;
this.referencedMBeanClassName = className;
this.minDegree = minDegree;
this.maxDegree = maxDegree;
this.isReadable = readable;
this.isWritable = writable;
this.description = description;
}
public boolean checkMinDegree(int value)
{
if (minDegree == ROLE_CARDINALITY_INFINITY)
return value >= ROLE_CARDINALITY_INFINITY;
else
return value >= minDegree;
}
public boolean checkMaxDegree(int value)
{
if(maxDegree == ROLE_CARDINALITY_INFINITY)
return maxDegree >= ROLE_CARDINALITY_INFINITY;
else
return value <= maxDegree;
}
public String getDescription()
{
return description;
}
public int getMinDegree()
{
return minDegree;
}
public int getMaxDegree()
{
return maxDegree;
}
public String getName()
{
return name;
}
public String getRefMBeanClassName()
{
return referencedMBeanClassName;
}
public boolean isReadable()
{
return isReadable;
}
public boolean isWritable()
{
return isWritable;
}
public String toString()
{
StringBuffer buffer = new StringBuffer("RoleInfo for name: (");
buffer.append(name);
buffer.append(") class name: (");
buffer.append(referencedMBeanClassName);
buffer.append(") description: (");
buffer.append(description);
buffer.append(") readable: (");
buffer.append(isReadable);
buffer.append(") writable: (");
buffer.append(isWritable);
buffer.append(") minimum degree: (");
buffer.append(minDegree);
buffer.append(") maximum degree: (");
buffer.append(maxDegree);
buffer.append(")");
return buffer.toString();
}
private void readObject(ObjectInputStream ois)
throws IOException, ClassNotFoundException
{
switch (Serialization.version)
{
case Serialization.V1R0:
ObjectInputStream.GetField getField = ois.readFields();
description = (String) getField.get("myDescription", null);
isReadable = getField.get("myIsReadableFlg", false);
isWritable = getField.get("myIsWritableFlg", false);
maxDegree = getField.get("myMaxDegree", 1);
minDegree = getField.get("myMinDegree", 1);
name = (String) getField.get("myName", null);
referencedMBeanClassName = (String) getField.get("myRefMBeanClassName", 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("myDescription", description);
putField.put("myIsReadableFlg", isReadable);
putField.put("myIsWritableFlg", isWritable);
putField.put("myMaxDegree", maxDegree);
putField.put("myMinDegree", minDegree);
putField.put("myName", name);
putField.put("myRefMBeanClassName", referencedMBeanClassName);
oos.writeFields();
break;
default:
oos.defaultWriteObject();
}
}
}