use of java.beans.PropertyDescriptor in project jdk8u_jdk by JetBrains.
the class Test6194788 method main.
public static void main(String[] args) throws IntrospectionException {
test(Grand.class, new PropertyDescriptor("index", Grand.class));
test(Grand.class, new IndexedPropertyDescriptor("name", Grand.class, null, null, "getName", "setName"));
test(Parent.class, new PropertyDescriptor("parentIndex", Parent.class));
test(Parent.class, new IndexedPropertyDescriptor("parentName", Parent.class));
test(Child.class, new PropertyDescriptor("childIndex", Child.class));
test(Child.class, new IndexedPropertyDescriptor("childName", Child.class));
}
use of java.beans.PropertyDescriptor in project jdk8u_jdk by JetBrains.
the class Test6660539 method main.
public static void main(String[] args) throws Exception {
for (PropertyDescriptor pd : getPropertyDescriptors()) {
pd.setDisplayName(NAME);
}
ThreadGroup group = new ThreadGroup(NAME);
Thread thread = new Thread(group, new Test6660539());
thread.start();
thread.join();
}
use of java.beans.PropertyDescriptor in project jdk8u_jdk by JetBrains.
the class Test6707231 method test.
private static void test(Class<?> actual, Class<?> expected) {
PropertyDescriptor pd = BeanUtils.getPropertyDescriptor(actual, "value");
Class<?> getter = pd.getReadMethod().getDeclaringClass();
Class<?> setter = pd.getWriteMethod().getDeclaringClass();
if ((getter != expected) || (setter != expected)) {
throw new Error(actual.getName());
}
}
use of java.beans.PropertyDescriptor in project beam by apache.
the class PipelineOptionsFactory method getPropertyDescriptors.
/**
* This method is meant to emulate the behavior of {@link Introspector#getBeanInfo(Class, int)}
* to construct the list of {@link PropertyDescriptor}.
*
* <p>TODO: Swap back to using Introspector once the proxy class issue with AppEngine is
* resolved.
*/
private static List<PropertyDescriptor> getPropertyDescriptors(Set<Method> methods, Class<? extends PipelineOptions> beanClass) throws IntrospectionException {
SortedMap<String, Method> propertyNamesToGetters = new TreeMap<>();
for (Map.Entry<String, Method> entry : PipelineOptionsReflector.getPropertyNamesToGetters(methods).entries()) {
propertyNamesToGetters.put(entry.getKey(), entry.getValue());
}
List<PropertyDescriptor> descriptors = Lists.newArrayList();
List<TypeMismatch> mismatches = new ArrayList<>();
Set<String> usedDescriptors = Sets.newHashSet();
/*
* Add all the getter/setter pairs to the list of descriptors removing the getter once
* it has been paired up.
*/
for (Method method : methods) {
String methodName = method.getName();
if (!methodName.startsWith("set") || method.getParameterTypes().length != 1 || method.getReturnType() != void.class) {
continue;
}
String propertyName = Introspector.decapitalize(methodName.substring(3));
Method getterMethod = propertyNamesToGetters.remove(propertyName);
// Validate that the getter and setter property types are the same.
if (getterMethod != null) {
Type getterPropertyType = getterMethod.getGenericReturnType();
Type setterPropertyType = method.getGenericParameterTypes()[0];
if (!getterPropertyType.equals(setterPropertyType)) {
TypeMismatch mismatch = new TypeMismatch();
mismatch.propertyName = propertyName;
mismatch.getterPropertyType = getterPropertyType;
mismatch.setterPropertyType = setterPropertyType;
mismatches.add(mismatch);
continue;
}
}
// getter and setter).
if (!usedDescriptors.contains(propertyName)) {
descriptors.add(new PropertyDescriptor(propertyName, getterMethod, method));
usedDescriptors.add(propertyName);
}
}
throwForTypeMismatches(mismatches);
// Add the remaining getters with missing setters.
for (Map.Entry<String, Method> getterToMethod : propertyNamesToGetters.entrySet()) {
descriptors.add(new PropertyDescriptor(getterToMethod.getKey(), getterToMethod.getValue(), null));
}
return descriptors;
}
use of java.beans.PropertyDescriptor 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