use of com.sun.jmx.mbeanserver.MXBeanMapping in project spf4j by zolyfarkas.
the class Spf4jJMXBeanMapping method defaultHandler.
@SuppressFBWarnings("LEST_LOST_EXCEPTION_STACK_TRACE")
public static JMXBeanMapping defaultHandler(final Type javaType, final JMXBeanMappingSupplier mappings) throws NotSerializableException {
// falling back to MXBeanMappingFactory.DEFAULT
try {
MXBeanMapping mapping = MXBeanMappingFactory.DEFAULT.mappingForType(javaType, new MXBeanMappingFactory() {
@Override
public MXBeanMapping mappingForType(final Type t, final MXBeanMappingFactory f) throws OpenDataException {
JMXBeanMapping m;
try {
m = mappings.get(t);
} catch (NotSerializableException ex) {
OpenDataException tex = new OpenDataException(t + " is not seriablizable ");
tex.initCause(ex);
throw tex;
}
if (m != null) {
return MXBeanMappings.convert(m);
}
return MXBeanMappingFactory.DEFAULT.mappingForType(t, f);
}
});
return MXBeanMappings.convert(mapping);
} catch (OpenDataException ex) {
NotSerializableException nsex = Throwables.first(ex, NotSerializableException.class);
if (nsex != null) {
throw nsex;
} else {
throw new IllegalArgumentException("No type mapping for " + javaType, ex);
}
}
}
use of com.sun.jmx.mbeanserver.MXBeanMapping in project jdk8u_jdk by JetBrains.
the class CompositeDataInvocationHandler method invoke.
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
final String methodName = method.getName();
// Handle the methods from java.lang.Object
if (method.getDeclaringClass() == Object.class) {
if (methodName.equals("toString") && args == null)
return "Proxy[" + compositeData + "]";
else if (methodName.equals("hashCode") && args == null)
return compositeData.hashCode() + 0x43444948;
else if (methodName.equals("equals") && args.length == 1 && method.getParameterTypes()[0] == Object.class)
return equals(proxy, args[0]);
else {
// is Object and so it's safe.
return method.invoke(this, args);
}
}
String propertyName = DefaultMXBeanMappingFactory.propertyName(method);
if (propertyName == null) {
throw new IllegalArgumentException("Method is not getter: " + method.getName());
}
Object openValue;
if (compositeData.containsKey(propertyName))
openValue = compositeData.get(propertyName);
else {
String decap = DefaultMXBeanMappingFactory.decapitalize(propertyName);
if (compositeData.containsKey(decap))
openValue = compositeData.get(decap);
else {
final String msg = "No CompositeData item " + propertyName + (decap.equals(propertyName) ? "" : " or " + decap) + " to match " + methodName;
throw new IllegalArgumentException(msg);
}
}
MXBeanMapping mapping = MXBeanMappingFactory.DEFAULT.mappingForType(method.getGenericReturnType(), MXBeanMappingFactory.DEFAULT);
return mapping.fromOpenValue(openValue);
}
use of com.sun.jmx.mbeanserver.MXBeanMapping in project spf4j by zolyfarkas.
the class DefaultMXBeanMappingFactoryOpenTypeMapper method getMXBeanMappingInternal.
/**
* returns MXBeanMapping or null if type is not mappable to a OpenType.
*/
@Nullable
private synchronized JMXBeanMapping getMXBeanMappingInternal(final Type type) throws NotSerializableException {
try {
MXBeanMapping mapping = MXBeanMappingFactory.DEFAULT.mappingForType(type, new MXBeanMappingFactory() {
@Override
public MXBeanMapping mappingForType(final Type t, final MXBeanMappingFactory f) throws OpenDataException {
try {
return MXBeanMappings.convert(appenderMap.get(t).get(t));
} catch (NotSerializableException ex) {
OpenDataException tex = new OpenDataException(t + " is not serializable");
tex.initCause(ex);
throw tex;
}
}
});
return MXBeanMappings.convert(mapping);
} catch (OpenDataException ex) {
return null;
}
}
Aggregations