< prev index next >
jdk/src/java.management/share/classes/sun/management/MappedMXBeanType.java
Print this page
*** 1,7 ****
/*
! * Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
--- 1,7 ----
/*
! * Copyright (c) 2004, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
*** 36,49 ****
import java.io.InvalidObjectException;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
- import javax.management.*;
import javax.management.openmbean.*;
import static javax.management.openmbean.SimpleType.*;
- import com.sun.management.VMOption;
/**
* 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):
--- 36,47 ----
*** 111,121 ****
MappedMXBeanType mt = new BasicMXBeanType(c, ot);
convertedTypes.put(c, mt);
return mt;
}
! static synchronized MappedMXBeanType getMappedType(Type t)
throws OpenDataException {
MappedMXBeanType mt = convertedTypes.get(t);
if (mt == null) {
mt = newMappedType(t);
}
--- 109,119 ----
MappedMXBeanType mt = new BasicMXBeanType(c, ot);
convertedTypes.put(c, mt);
return mt;
}
! public static synchronized MappedMXBeanType getMappedType(Type t)
throws OpenDataException {
MappedMXBeanType mt = convertedTypes.get(t);
if (mt == null) {
mt = newMappedType(t);
}
*** 150,160 ****
MappedMXBeanType mt = getMappedType(t);
return mt.toOpenTypeData(data);
}
// Return the mapped open type
! OpenType<?> getOpenType() {
return openType;
}
boolean isBasicType() {
return isBasicType;
--- 148,158 ----
MappedMXBeanType mt = getMappedType(t);
return mt.toOpenTypeData(data);
}
// Return the mapped open type
! public OpenType<?> getOpenType() {
return openType;
}
boolean isBasicType() {
return isBasicType;
*** 175,188 ****
abstract Type getJavaType();
// return name of the class or the generic type
abstract String getName();
! abstract Object toOpenTypeData(Object javaTypeData)
throws OpenDataException;
! abstract Object toJavaTypeData(Object openTypeData)
throws OpenDataException, InvalidObjectException;
// Basic Types - Classes that do not require data conversion
// including primitive types and all SimpleType
//
--- 173,186 ----
abstract Type getJavaType();
// return name of the class or the generic type
abstract String getName();
! public abstract Object toOpenTypeData(Object javaTypeData)
throws OpenDataException;
! public abstract Object toJavaTypeData(Object openTypeData)
throws OpenDataException, InvalidObjectException;
// Basic Types - Classes that do not require data conversion
// including primitive types and all SimpleType
//
*** 206,220 ****
String getName() {
return basicType.getName();
}
! Object toOpenTypeData(Object data) throws OpenDataException {
return data;
}
! Object toJavaTypeData(Object data)
throws OpenDataException, InvalidObjectException {
return data;
}
}
--- 204,218 ----
String getName() {
return basicType.getName();
}
! public Object toOpenTypeData(Object data) throws OpenDataException {
return data;
}
! public Object toJavaTypeData(Object data)
throws OpenDataException, InvalidObjectException {
return data;
}
}
*** 241,255 ****
String getName() {
return enumClass.getName();
}
! Object toOpenTypeData(Object data) throws OpenDataException {
return ((Enum) data).name();
}
! Object toJavaTypeData(Object data)
throws OpenDataException, InvalidObjectException {
try {
return Enum.valueOf(enumClass, (String) data);
} catch (IllegalArgumentException e) {
--- 239,253 ----
String getName() {
return enumClass.getName();
}
! public Object toOpenTypeData(Object data) throws OpenDataException {
return ((Enum) data).name();
}
! public Object toJavaTypeData(Object data)
throws OpenDataException, InvalidObjectException {
try {
return Enum.valueOf(enumClass, (String) data);
} catch (IllegalArgumentException e) {
*** 313,323 ****
String getName() {
return arrayClass.getName();
}
! Object toOpenTypeData(Object data) throws OpenDataException {
// 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;
--- 311,321 ----
String getName() {
return arrayClass.getName();
}
! public Object toOpenTypeData(Object data) throws OpenDataException {
// 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;
*** 338,348 ****
}
return openArray;
}
! Object toJavaTypeData(Object data)
throws OpenDataException, InvalidObjectException {
// If the base element type is a basic type
// return the data as no conversion is needed.
if (baseElementType.isBasicType()) {
--- 336,346 ----
}
return openArray;
}
! public Object toJavaTypeData(Object data)
throws OpenDataException, InvalidObjectException {
// If the base element type is a basic type
// return the data as no conversion is needed.
if (baseElementType.isBasicType()) {
*** 455,465 ****
String getName() {
return typeName;
}
! Object toOpenTypeData(Object data) throws OpenDataException {
final List<Object> list = (List<Object>) data;
final Object[] openArray = (Object[])
Array.newInstance(paramType.getMappedTypeClass(),
list.size());
--- 453,463 ----
String getName() {
return typeName;
}
! public Object toOpenTypeData(Object data) throws OpenDataException {
final List<Object> list = (List<Object>) data;
final Object[] openArray = (Object[])
Array.newInstance(paramType.getMappedTypeClass(),
list.size());
*** 468,478 ****
openArray[i++] = paramType.toOpenTypeData(o);
}
return openArray;
}
! Object toJavaTypeData(Object data)
throws OpenDataException, InvalidObjectException {
final Object[] openArray = (Object[]) data;
List<Object> result = new ArrayList<>(openArray.length);
for (Object o : openArray) {
--- 466,476 ----
openArray[i++] = paramType.toOpenTypeData(o);
}
return openArray;
}
! public Object toJavaTypeData(Object data)
throws OpenDataException, InvalidObjectException {
final Object[] openArray = (Object[]) data;
List<Object> result = new ArrayList<>(openArray.length);
for (Object o : openArray) {
*** 536,546 ****
String getName() {
return typeName;
}
! Object toOpenTypeData(Object data) throws OpenDataException {
final Map<Object,Object> map = (Map<Object,Object>) data;
final TabularType tabularType = (TabularType) openType;
final TabularData table = new TabularDataSupport(tabularType);
final CompositeType rowType = tabularType.getRowType();
--- 534,544 ----
String getName() {
return typeName;
}
! public Object toOpenTypeData(Object data) throws OpenDataException {
final Map<Object,Object> map = (Map<Object,Object>) data;
final TabularType tabularType = (TabularType) openType;
final TabularData table = new TabularDataSupport(tabularType);
final CompositeType rowType = tabularType.getRowType();
*** 554,564 ****
table.put(row);
}
return table;
}
! Object toJavaTypeData(Object data)
throws OpenDataException, InvalidObjectException {
final TabularData td = (TabularData) data;
Map<Object, Object> result = new HashMap<>();
--- 552,562 ----
table.put(row);
}
return table;
}
! public Object toJavaTypeData(Object data)
throws OpenDataException, InvalidObjectException {
final TabularData td = (TabularData) data;
Map<Object, Object> result = new HashMap<>();
*** 603,614 ****
// o If FooType is an array, the item type is an array and
// its element type is determined as described above.
//
static class CompositeDataMXBeanType extends MappedMXBeanType {
final Class<?> javaClass;
! final boolean isCompositeData;
Method fromMethod = null;
CompositeDataMXBeanType(Class<?> c) throws OpenDataException {
this.javaClass = c;
this.mappedTypeClass = COMPOSITE_DATA_CLASS;
--- 601,613 ----
// o If FooType is an array, the item type is an array and
// its element type is determined as described above.
//
static class CompositeDataMXBeanType extends MappedMXBeanType {
final Class<?> javaClass;
! boolean isCompositeData = false;
Method fromMethod = null;
+ Method toMethod = null;
CompositeDataMXBeanType(Class<?> c) throws OpenDataException {
this.javaClass = c;
this.mappedTypeClass = COMPOSITE_DATA_CLASS;
*** 622,631 ****
--- 621,650 ----
} catch (PrivilegedActionException e) {
// ignore NoSuchMethodException since we allow classes
// that has no from method to be embeded in another class.
}
+ // check if a static "toCompositeData" method exists
+ try {
+ toMethod = AccessController.doPrivileged(new PrivilegedExceptionAction<Method>() {
+ public Method run() throws NoSuchMethodException {
+ Method m = javaClass.getDeclaredMethod("toCompositeData", javaClass);
+ if (m != null
+ && CompositeData.class.isAssignableFrom(m.getReturnType())
+ && Modifier.isStatic(m.getModifiers())) {
+ m.setAccessible(true);
+ return m;
+ } else {
+ return null;
+ }
+ }
+ });
+ } 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;
*** 689,699 ****
String getName() {
return javaClass.getName();
}
! Object toOpenTypeData(Object data) throws OpenDataException {
if (data instanceof MemoryUsage) {
return MemoryUsageCompositeData.toCompositeData((MemoryUsage) data);
}
if (data instanceof ThreadInfo) {
--- 708,734 ----
String getName() {
return javaClass.getName();
}
! public Object toOpenTypeData(Object data) throws OpenDataException {
! if (toMethod != null) {
! try {
! return toMethod.invoke(null, data);
! } catch (IllegalAccessException e) {
! // should never reach here
! throw new AssertionError(e);
! } catch (InvocationTargetException e) {
! final OpenDataException ode
! = new OpenDataException("Failed to invoke "
! + toMethod.getName() + " to convert " + javaClass.getName()
! + " to CompositeData");
! ode.initCause(e);
! throw ode;
! }
! }
!
if (data instanceof MemoryUsage) {
return MemoryUsageCompositeData.toCompositeData((MemoryUsage) data);
}
if (data instanceof ThreadInfo) {
*** 710,723 ****
if (data instanceof MemoryNotificationInfo) {
return MemoryNotifInfoCompositeData.
toCompositeData((MemoryNotificationInfo) data);
}
- if (data instanceof VMOption) {
- return VMOptionCompositeData.toCompositeData((VMOption) data);
- }
-
if (isCompositeData) {
// Classes that implement CompositeData
//
// construct a new CompositeDataSupport object
// so that no other classes are sent over the wire
--- 745,754 ----
*** 730,740 ****
throw new OpenDataException(javaClass.getName() +
" is not supported for platform MXBeans");
}
! Object toJavaTypeData(Object data)
throws OpenDataException, InvalidObjectException {
if (fromMethod == null) {
throw new AssertionError("Does not support data conversion");
}
--- 761,771 ----
throw new OpenDataException(javaClass.getName() +
" is not supported for platform MXBeans");
}
! public Object toJavaTypeData(Object data)
throws OpenDataException, InvalidObjectException {
if (fromMethod == null) {
throw new AssertionError("Does not support data conversion");
}
< prev index next >