FileDocCategorySizeDatePackage
OpenType.javaAPI DocJava SE 6 API14133Tue Jun 10 00:26:16 BST 2008javax.management.openmbean

OpenType

public abstract class OpenType extends Object implements Serializable
The 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.
param
the Java type that instances described by this type must have. For example, {@link SimpleType#INTEGER} is a {@code SimpleType} which is a subclass of {@code OpenType}, meaning that an attribute, parameter, or return value that is described as a {@code SimpleType.INTEGER} must have Java type {@link Integer}.
version
3.38 06/06/13
author
Sun Microsystems, Inc.
since
1.5
since.unbundled
JMX 1.1

Fields Summary
static final long
serialVersionUID
public static final List
ALLOWED_CLASSNAMES_LIST
List 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
isArray
Tells if this type describes an array (checked in constructor).
private transient Descriptor
descriptor
Cached 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.
 

param
className The fully qualified Java class name of the open data values this open type describes. The valid Java class names allowed 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).
 
param
typeName The name given to the open type this instance represents; cannot be a null or empty string.
 
param
description The human readable description of the open type this instance represents; cannot be a null or empty string.
 
throws
IllegalArgumentException if className, typeName or description is a null or empty string
 
throws
OpenDataException if className is not one of the allowed Java class names for open data

    
    /* *** 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 voidcheckClassNameOverride()

        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 booleanequals(java.lang.Object obj)
Compares the specified obj parameter with this open type instance for equality.

param
obj the object to compare to.
return
true if this object and obj are equal.

public java.lang.StringgetClassName()
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
the class name.


	return className;
    
public java.lang.StringgetDescription()
Returns the text description of this OpenType instance.

return
the description.


	return description;
    
synchronized javax.management.DescriptorgetDescriptor()

        if (descriptor == null) {
            descriptor = new ImmutableDescriptor(new String[] {"openType"},
                                                 new Object[] {this});
        }
        return descriptor;
    
public java.lang.StringgetTypeName()
Returns the name of this OpenType instance.

return
the type name.


	return typeName;
    
public abstract inthashCode()

public booleanisArray()
Returns true if the open data values this open type describes are arrays, false otherwise.

return
true if this is an array type.


	return isArray;
    
booleanisAssignableFrom(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.

param
ot the type to be tested.
return
true if {@code ot} is assignable to this open type.

        return this.equals(ot);
    
public abstract booleanisValue(java.lang.Object obj)
Tests whether obj is a value for this open type.

param
obj the object to be tested for validity.
return
true if obj is a value for this open type, false otherwise.

private static booleanoverridesGetClassName(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 voidreadObject(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.StringtoString()
Returns a string representation of this open type instance.

return
the string representation.

private static java.lang.Stringvalid(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.StringvalidClassName(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;