OpenTypepublic abstract class OpenType extends Object implements SerializableThe OpenType class is the parent abstract class of all classes which describe the actual open type
of open data values.
An open type is defined by:
- the fully qualified Java class name of the open data values this type describes;
note that only a limited set of Java classes is allowed for open data values
(see {@link #ALLOWED_CLASSNAMES_LIST ALLOWED_CLASSNAMES_LIST}),
- its name,
- its description.
|
Fields Summary |
---|
static final long | serialVersionUID | public static final List | ALLOWED_CLASSNAMES_LISTList of the fully qualified names of the Java classes allowed for open
data values. A multidimensional array of any one of these classes or
their corresponding primitive types is also an allowed class for open
data values.
ALLOWED_CLASSNAMES_LIST = {
"java.lang.Void",
"java.lang.Boolean",
"java.lang.Character",
"java.lang.Byte",
"java.lang.Short",
"java.lang.Integer",
"java.lang.Long",
"java.lang.Float",
"java.lang.Double",
"java.lang.String",
"java.math.BigDecimal",
"java.math.BigInteger",
"java.util.Date",
"javax.management.ObjectName",
CompositeData.class.getName(),
TabularData.class.getName() } ;
| public static final String[] | ALLOWED_CLASSNAMES | private String | className | private String | description | private String | typeName | private transient boolean | isArrayTells if this type describes an array (checked in constructor). | private transient Descriptor | descriptorCached Descriptor for this OpenType, constructed on demand. |
Constructors Summary |
---|
protected OpenType(String className, String typeName, String description)Constructs an OpenType instance (actually a subclass instance as OpenType is abstract),
checking for the validity of the given parameters.
The validity constraints are described below for each parameter.
/* *** Constructor *** */
checkClassNameOverride();
this.typeName = valid("typeName", typeName);
this.description = valid("description", description);
this.className = validClassName(className);
this.isArray = (this.className != null && this.className.startsWith("["));
| OpenType(String className, String typeName, String description, boolean isArray)
this.className = valid("className",className);
this.typeName = valid("typeName", typeName);
this.description = valid("description", description);
this.isArray = isArray;
|
Methods Summary |
---|
private void | checkClassNameOverride()
if (this.getClass().getClassLoader() == null)
return; // We trust bootstrap classes.
if (overridesGetClassName(this.getClass())) {
final GetPropertyAction getExtendOpenTypes =
new GetPropertyAction("jmx.extend.open.types");
if (AccessController.doPrivileged(getExtendOpenTypes) == null) {
throw new SecurityException("Cannot override getClassName() " +
"unless -Djmx.extend.open.types");
}
}
| public abstract boolean | equals(java.lang.Object obj)Compares the specified obj parameter with this
open type instance for equality.
| public java.lang.String | getClassName()Returns the fully qualified Java class name of the open data values
this open type describes.
The only possible Java class names for open data values are listed in
{@link #ALLOWED_CLASSNAMES_LIST ALLOWED_CLASSNAMES_LIST}.
A multidimensional array of any one of these classes or their
corresponding primitive types is also an allowed class,
in which case the class name follows the rules defined by the method
{@link Class#getName() getName()} of java.lang.Class .
For example, a 3-dimensional array of Strings has for class name
"[[[Ljava.lang.String; " (without the quotes),
a 3-dimensional array of Integers has for class name
"[[[Ljava.lang.Integer; " (without the quotes),
and a 3-dimensional array of int has for class name
"[[[I " (without the quotes)
return className;
| public java.lang.String | getDescription()Returns the text description of this OpenType instance.
return description;
| synchronized javax.management.Descriptor | getDescriptor()
if (descriptor == null) {
descriptor = new ImmutableDescriptor(new String[] {"openType"},
new Object[] {this});
}
return descriptor;
| public java.lang.String | getTypeName()Returns the name of this OpenType instance.
return typeName;
| public abstract int | hashCode()
| public boolean | isArray()Returns true if the open data values this open
type describes are arrays, false otherwise.
return isArray;
| boolean | isAssignableFrom(javax.management.openmbean.OpenType ot)Tests whether values of the given type can be assigned to this open type.
The default implementation of this method returns true only if the
types are equal.
return this.equals(ot);
| public abstract boolean | isValue(java.lang.Object obj)Tests whether obj is a value for this open type.
| private static boolean | overridesGetClassName(java.lang.Class c)
return AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
public Boolean run() {
try {
return (c.getMethod("getClassName").getDeclaringClass() !=
OpenType.class);
} catch (Exception e) {
return true; // fail safe
}
}
});
| private void | readObject(java.io.ObjectInputStream in)Deserializes an {@link OpenType} from an {@link java.io.ObjectInputStream}.
checkClassNameOverride();
ObjectInputStream.GetField fields = in.readFields();
final String classNameField;
final String descriptionField;
final String typeNameField;
try {
classNameField =
validClassName((String) fields.get("className", null));
descriptionField =
valid("description", (String) fields.get("description", null));
typeNameField =
valid("typeName", (String) fields.get("typeName", null));
} catch (Exception e) {
IOException e2 = new InvalidObjectException(e.getMessage());
e2.initCause(e);
throw e2;
}
className = classNameField;
description = descriptionField;
typeName = typeNameField;
isArray = (className.startsWith("["));
| public abstract java.lang.String | toString()Returns a string representation of this open type instance.
| private static java.lang.String | valid(java.lang.String argName, java.lang.String argValue)
if (argValue == null || (argValue = argValue.trim()).equals(""))
throw new IllegalArgumentException("Argument " + argName +
" cannot be null or empty");
return argValue;
| private static java.lang.String | validClassName(java.lang.String className)
className = valid("className", className);
// Check if className describes an array class, and determines its elements' class name.
// (eg: a 3-dimensional array of Strings has for class name: "[[[Ljava.lang.String;")
//
int n = 0;
while (className.startsWith("[", n)) {
n++;
}
String eltClassName; // class name of array elements
boolean isPrimitiveArray = false;
if (n > 0) {
if (className.startsWith("L", n) && className.endsWith(";")) {
// removes the n leading '[' + the 'L' characters
// and the last ';' character
eltClassName = className.substring(n+1, className.length()-1);
} else if (n == className.length() - 1) {
// removes the n leading '[' characters
eltClassName = className.substring(n, className.length());
isPrimitiveArray = true;
} else {
throw new OpenDataException("Argument className=\"" + className +
"\" is not a valid class name");
}
} else {
// not an array
eltClassName = className;
}
// Check that eltClassName's value is one of the allowed basic data types for open data
//
boolean ok = false;
if (isPrimitiveArray) {
ok = ArrayType.isPrimitiveContentType(eltClassName);
} else {
ok = ALLOWED_CLASSNAMES_LIST.contains(eltClassName);
}
if ( ! ok ) {
throw new OpenDataException("Argument className=\""+ className +
"\" is not one of the allowed Java class names for open data.");
}
return className;
|
|