use of java.beans.BeanInfo in project jdk8u_jdk by JetBrains.
the class Test4520754 method test4168475.
/**
* This is a regression test to ensure that 4168475 does not regress.
*/
private static void test4168475(Class type) {
String[] newPath = { "infos" };
String[] oldPath = Introspector.getBeanInfoSearchPath();
Introspector.setBeanInfoSearchPath(newPath);
BeanInfo info = getBeanInfo(Boolean.TRUE, type);
Introspector.setBeanInfoSearchPath(oldPath);
PropertyDescriptor[] pds = info.getPropertyDescriptors();
if (pds.length != 1) {
throw new Error("could not find custom BeanInfo for " + type);
}
Introspector.flushCaches();
}
use of java.beans.BeanInfo in project jdk8u_jdk by JetBrains.
the class Test4520754 method getBeanInfo.
private static BeanInfo getBeanInfo(Boolean mark, Class type) {
System.out.println("test=" + mark + " for " + type);
BeanInfo info;
try {
info = Introspector.getBeanInfo(type);
} catch (IntrospectionException exception) {
throw new Error("unexpected exception", exception);
}
if (info == null) {
throw new Error("could not find BeanInfo for " + type);
}
if (mark != info.getBeanDescriptor().getValue("test")) {
throw new Error("could not find marked BeanInfo for " + type);
}
return info;
}
use of java.beans.BeanInfo in project jdk8u_jdk by JetBrains.
the class TestBeanInfo method test.
private static void test(Class<?> type, Class<? extends BeanInfo> expected) {
BeanInfo actual;
try {
actual = Introspector.getBeanInfo(type);
type = actual.getClass();
// NON-NLS: method name
Method method = type.getDeclaredMethod("getTargetBeanInfo");
method.setAccessible(true);
actual = (BeanInfo) method.invoke(actual);
} catch (Exception exception) {
throw new Error("unexpected error", exception);
}
if ((actual == null) && (expected != null)) {
throw new Error("expected info is not found");
}
if ((actual != null) && !actual.getClass().equals(expected)) {
throw new Error("found unexpected info");
}
}
use of java.beans.BeanInfo in project jdk8u_jdk by JetBrains.
the class Test5102804 method getReference.
private static Reference getReference() {
try {
ClassLoader loader = new Loader();
Class type = Class.forName(BEAN_NAME, true, loader);
if (!type.getClassLoader().equals(loader)) {
throw new Error("Wrong class loader");
}
BeanInfo info = Introspector.getBeanInfo(type);
if (0 != info.getDefaultPropertyIndex()) {
throw new Error("Wrong bean info found");
}
return new WeakReference<Class>(type);
} catch (IntrospectionException exception) {
throw new Error("Introspection Error", exception);
} catch (ClassNotFoundException exception) {
throw new Error("Class Not Found", exception);
}
}
use of java.beans.BeanInfo in project lucene-solr by apache.
the class MetricUtils method addMXBeanMetrics.
/**
* Creates a set of metrics (gauges) that correspond to available bean properties for the provided MXBean.
* @param obj an instance of MXBean
* @param intf MXBean interface, one of {@link PlatformManagedObject}-s
* @param consumer consumer for created names and metrics
* @param <T> formal type
*/
public static <T extends PlatformManagedObject> void addMXBeanMetrics(T obj, Class<? extends T> intf, String prefix, BiConsumer<String, Metric> consumer) {
if (intf.isInstance(obj)) {
BeanInfo beanInfo;
try {
beanInfo = Introspector.getBeanInfo(intf, intf.getSuperclass(), Introspector.IGNORE_ALL_BEANINFO);
} catch (IntrospectionException e) {
LOG.warn("Unable to fetch properties of MXBean " + obj.getClass().getName());
return;
}
for (final PropertyDescriptor desc : beanInfo.getPropertyDescriptors()) {
final String name = desc.getName();
// test if it works at all
try {
desc.getReadMethod().invoke(obj);
// worked - consume it
final Gauge<?> gauge = () -> {
try {
return desc.getReadMethod().invoke(obj);
} catch (InvocationTargetException ite) {
// ignore (some properties throw UOE)
return null;
} catch (IllegalAccessException e) {
return null;
}
};
String metricName = MetricRegistry.name(prefix, name);
consumer.accept(metricName, gauge);
} catch (Exception e) {
// didn't work, skip it...
}
}
}
}
Aggregations