/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.management;
import javax.management.*;
/**
* A mapped mxbean type maps a Java type to an open type.
* Only the following Java types are mappable
* (currently required by the platform MXBeans):
* 1. Primitive types
* 2. Wrapper classes such java.lang.Integer, etc
* 3. Classes with only getter methods and with a static "from" method
* that takes a CompositeData argument.
* 4. E[] where E is a type of 1-4 (can be multi-dimensional array)
* 5. List<E> where E is a type of 1-3
* 6. Map<K, V> where K and V are a type of 1-4
*
* OpenDataException will be thrown if a Java type is not supported.
*/
// Suppress unchecked cast warnings at line 442, 523 and 546
// Suppress unchecked calls at line 235, 284, 380 and 430.
@SuppressWarnings("unchecked")
public abstract class MappedMXBeanType {
boolean isBasicType = false;
throws OpenDataException {
if (c.isEnum()) {
mt = new EnumMXBeanType(c);
} else if (c.isArray()) {
mt = new ArrayMXBeanType(c);
} else {
mt = new CompositeDataMXBeanType(c);
}
} else if (javaType instanceof ParameterizedType) {
}
}
} else if (javaType instanceof GenericArrayType) {
mt = new GenericArrayMXBeanType(t);
}
// No open type mapped for the javaType
throw new OpenDataException(javaType +
" is not a supported MXBean type.");
}
return mt;
}
// basic types do not require data mapping
throws OpenDataException {
return mt;
}
throws OpenDataException {
mt = newMappedType(t);
}
throw new OpenDataException("Recursive data structure");
}
return mt;
}
// Convert a class to an OpenType
throws OpenDataException {
return mt.getOpenType();
}
throws OpenDataException, InvalidObjectException {
return null;
}
}
throws OpenDataException {
return null;
}
}
// Return the mapped open type
return openType;
}
boolean isBasicType() {
return isBasicType;
}
// Return the type name of the mapped open type
// For primitive types, the type name is the same as the javaType
// but the mapped open type is the wrapper class
return getMappedTypeClass().getName();
}
// Return the mapped open type
return mappedTypeClass;
}
// return name of the class or the generic type
throws OpenDataException;
throws OpenDataException, InvalidObjectException;
// Basic Types - Classes that do not require data conversion
// including primitive types and all SimpleType
//
// Mapped open type: SimpleType for corresponding basic type
//
// Data Mapping:
// T <-> T (no conversion)
//
this.basicType = c;
this.mappedTypeClass = c;
this.isBasicType = true;
}
return basicType;
}
}
return data;
}
throws OpenDataException, InvalidObjectException {
return data;
}
}
// Enum subclasses
// Mapped open type - String
//
// Data Mapping:
// Enum <-> enum's name
//
this.enumClass = c;
this.mappedTypeClass = String.class;
}
return enumClass;
}
}
}
throws OpenDataException, InvalidObjectException {
try {
} catch (IllegalArgumentException e) {
// missing enum constants
final InvalidObjectException ioe =
new InvalidObjectException("Enum constant named " +
throw ioe;
}
}
}
// Array E[]
// Mapped open type - Array with element of OpenType for E
//
// Data Mapping:
// E[] <-> openTypeData(E)[]
//
this.arrayClass = c;
int dim;
}
if (et.isPrimitive()) {
} else {
}
try {
} catch (ClassNotFoundException e) {
final OpenDataException ode =
new OpenDataException("Cannot obtain array class");
throw ode;
}
}
protected ArrayMXBeanType() {
arrayClass = null;
};
return arrayClass;
}
return arrayClass.getName();
}
// If the base element type is a basic type
// return the data as no conversion is needed.
// Primitive types are not converted to wrappers.
if (baseElementType.isBasicType()) {
return data;
}
int i = 0;
if (o == null) {
} else {
}
i++;
}
return openArray;
}
throws OpenDataException, InvalidObjectException {
// If the base element type is a basic type
// return the data as no conversion is needed.
if (baseElementType.isBasicType()) {
return data;
}
int i = 0;
if (o == null) {
} else {
}
i++;
}
return array;
}
}
int dim;
}
} else {
}
try {
} catch (ClassNotFoundException e) {
final OpenDataException ode =
new OpenDataException("Cannot obtain array class");
throw ode;
}
}
return gtype;
}
}
}
// List<E>
// Mapped open type - Array with element of OpenType for E
//
// Data Mapping:
// List<E> <-> openTypeData(E)[]
//
" not supported");
}
" not supported");
}
try {
} catch (ClassNotFoundException e) {
final OpenDataException ode =
new OpenDataException("Array class not found");
throw ode;
}
}
return javaType;
}
return typeName;
}
int i = 0;
}
return openArray;
}
throws OpenDataException, InvalidObjectException {
}
return result;
}
}
// Map<K,V>
// Mapped open type - TabularType with row type:
// CompositeType:
// "key" of openDataType(K)
// "value" of openDataType(V)
// "key" is the index name
//
// Data Mapping:
// Map<K,V> <-> TabularData
//
// FIXME: generate typeName for generic
};
final CompositeType rowType =
new CompositeType(typeName,
}
return javaType;
}
return typeName;
}
final CompositeData row =
}
return table;
}
throws OpenDataException, InvalidObjectException {
}
return result;
}
}
// Classes that have a static from method
// Mapped open type - CompositeData
//
// Data Mapping:
// Classes <-> CompositeData
//
// The name and type of items for a class are identified from
// the getter methods. For example, a class defines a method:
//
// public FooType getFoo();
//
// The composite data view for this class will contain one
// item entry for a "foo" attribute and the item type is
// one of the open types defined in the OpenType class that
// can be determined in the following manner:
// o If FooType is a primitive type, the item type a wrapper
// class for the corresponding primitive type (such as
// Integer, Long, Boolean, etc).
// o If FooType is of type CompositeData or TabularData,
// the item type is FooType.
// o If FooType is an Enum, the item type is a String and
// the value is the name of the enum constant.
// o If FooType is a class or an interface other than the above,
// the item type is CompositeData. The same convention
// can be recursively applied to the FooType class when
// constructing the composite data for the "foo" attribute.
// o If FooType is an array, the item type is an array and
// its element type is determined as described above.
//
final boolean isCompositeData;
this.javaClass = c;
this.mappedTypeClass = COMPOSITE_DATA_CLASS;
// check if a static from method exists
try {
}
});
} catch (PrivilegedActionException e) {
// ignore NoSuchMethodException since we allow classes
// that has no from method to be embeded in another class.
}
if (COMPOSITE_DATA_CLASS.isAssignableFrom(c)) {
// c implements CompositeData - set openType to null
// defer generating the CompositeType
// until the object is constructed
this.isCompositeData = true;
} else {
this.isCompositeData = false;
// Make a CompositeData containing all the getters
return javaClass.getMethods();
}
});
/* Select public methods that look like "T getX()" or "boolean
isX()", where T is not void and X is not the empty
string. Exclude "Class getClass()" inherited from Object. */
} else {
// ignore non-getter methods
continue;
}
type == void.class ||
// ignore non-getter methods
continue;
}
}
c.getName(),
nameArray, // field names
nameArray, // field descriptions
}
}
return javaClass;
}
}
if (data instanceof MemoryUsage) {
}
if (data instanceof ThreadInfo) {
}
}
}
if (data instanceof MemoryNotificationInfo) {
return MemoryNotifInfoCompositeData.
}
}
if (isCompositeData) {
// Classes that implement CompositeData
//
// construct a new CompositeDataSupport object
// so that no other classes are sent over the wire
}
" is not supported for platform MXBeans");
}
throws OpenDataException, InvalidObjectException {
if (fromMethod == null) {
throw new AssertionError("Does not support data conversion");
}
try {
} catch (IllegalAccessException e) {
// should never reach here
throw new AssertionError(e);
} catch (InvocationTargetException e) {
final OpenDataException ode =
new OpenDataException("Failed to invoke " +
throw ode;
}
}
}
"Marker to detect recursive type use -- internal use only!";
}
return description;
}
public int hashCode() {
return 0;
}
return false;
}
return false;
}
}
static {
OpenType t;
try {
t = new InProgress();
} catch (OpenDataException e) {
// Should not reach here
throw new AssertionError(e);
}
inProgress = t;
}
VOID,
};
static {
try {
final OpenType t = simpleTypes[i];
Class c;
try {
String.class.getClassLoader());
MappedMXBeanType.newBasicType(c, t);
} catch (ClassNotFoundException e) {
// the classes that these predefined types declare
// must exist!
throw new AssertionError(e);
} catch (OpenDataException e) {
throw new AssertionError(e);
}
try {
} catch (NoSuchFieldException e) {
// OK: must not be a primitive wrapper
} catch (IllegalAccessException e) {
// Should not reach here
throw new AssertionError(e);
}
}
}
} catch (OpenDataException e) {
throw new AssertionError(e);
}
}
/**
* Utility method to take a string and convert it to normal Java variable
* name capitalization. This normally means converting the first
* character from upper case to lower case, but in the (unusual) special
* case when there is more than one character and both the first and
* second characters are upper case, we leave it alone.
* <p>
* Thus "FooBah" becomes "fooBah" and "X" becomes "x", but "URL" stays
* as "URL".
*
* @param name The string to be decapitalized.
* @return The decapitalized version of the string.
*/
return name;
}
return name;
}
}
}