use of java.beans.BeanInfo in project charts by vaadin.
the class ChartDesignAttributeHandler method resolveSupportedAttributes.
/**
* Resolves the supported attributes and corresponding getters and setters
* for the class using introspection. After resolving, the information is
* cached internally by this class
*
* @param clazz
* the class to resolve the supported attributes for
*/
private static void resolveSupportedAttributes(Class<?> clazz) {
if (clazz == null) {
throw new IllegalArgumentException("The clazz can not be null");
}
if (CACHE.containsKey(clazz)) {
// NO-OP
return;
}
BeanInfo beanInfo;
try {
beanInfo = Introspector.getBeanInfo(clazz);
} catch (IntrospectionException e) {
throw new RuntimeException("Could not get supported attributes for class " + clazz.getName());
}
AttributeCacheEntry entry = new AttributeCacheEntry();
for (PropertyDescriptor descriptor : beanInfo.getPropertyDescriptors()) {
Method getter = descriptor.getReadMethod();
Method setter = descriptor.getWriteMethod();
Class<?> propertyType = descriptor.getPropertyType();
if (getter != null && setter != null && propertyType != null && getFormatter().canConvert(propertyType)) {
String attribute = toAttributeName(descriptor.getName());
entry.addAttribute(attribute, getter, setter);
}
}
CACHE.put(clazz, entry);
}
use of java.beans.BeanInfo in project JWildfire by thargor6.
the class Action method importProperties.
public void importProperties(ManagedObject pManagedObject) {
BeanInfo beanInfo = pManagedObject.getBeanInfo();
if (beanInfo != null) {
PropertyDescriptor[] props = beanInfo.getPropertyDescriptors();
if (props != null) {
for (PropertyDescriptor prop : props) {
Method readMethod = prop.getReadMethod();
if (readMethod != null) {
try {
Object val = readMethod.invoke(pManagedObject);
Class<?> cls = prop.getPropertyType();
if (cls == Color.class) {
Color color = (Color) val;
String name = prop.getName();
Parameter param;
param = new Parameter();
parameterList.add(param);
param.setName(name + ".r");
param.setValue(color != null ? String.valueOf(color.getRed()) : null);
param = new Parameter();
parameterList.add(param);
param.setName(name + ".g");
param.setValue(color != null ? String.valueOf(color.getGreen()) : null);
param = new Parameter();
parameterList.add(param);
param.setName(name + ".b");
param.setValue(color != null ? String.valueOf(color.getBlue()) : null);
} else {
Parameter param = new Parameter();
parameterList.add(param);
param.setName(prop.getName());
param.setValue(val != null ? val.toString() : "");
}
} catch (Throwable ex) {
ex.printStackTrace();
}
}
}
}
}
}
use of java.beans.BeanInfo in project JessMA by ldcsaa.
the class BeanHelper method getPropDescByName.
/**
* 获取指定类型 Java Bean 的名称为 name 的属性描述对象
*
* @param startClass : Bean 类型
* @param stopClass : 截止查找的父类类型
* @param name : 属性名称
* @return 描述对象映射,找不到属性则返回 null
*/
public static final PropertyDescriptor getPropDescByName(Class<?> startClass, Class<?> stopClass, String name) {
try {
BeanInfo info = Introspector.getBeanInfo(startClass, stopClass);
PropertyDescriptor[] pds = info.getPropertyDescriptors();
for (PropertyDescriptor pd : pds) {
if (pd.getName().equals(name))
return pd;
}
} catch (IntrospectionException e) {
throw new RuntimeException(e);
}
return null;
}
use of java.beans.BeanInfo in project JessMA by ldcsaa.
the class BeanHelper method getPropDescMap.
/**
* 获取指定类型 Java Bean 的所有属性描述(包括 stopClass 及更高层父类除外的所有父类定义的属性)
*
* @param startClass : Bean 类型
* @param stopClass : 截止查找的父类类型
* @return 属性名 / 描述对象映射
*/
public static final Map<String, PropertyDescriptor> getPropDescMap(Class<?> startClass, Class<?> stopClass) {
Map<String, PropertyDescriptor> map = new HashMap<String, PropertyDescriptor>();
try {
BeanInfo info = Introspector.getBeanInfo(startClass, stopClass);
PropertyDescriptor[] pds = info.getPropertyDescriptors();
for (PropertyDescriptor pd : pds) map.put(pd.getName(), pd);
} catch (IntrospectionException e) {
throw new RuntimeException(e);
}
return map;
}
use of java.beans.BeanInfo in project abstools by abstools.
the class Bean method init.
private void init() {
try {
BeanInfo beanInfo = Introspector.getBeanInfo(dataClass);
PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
for (int i = 0; i < propertyDescriptors.length; i++) {
PropertyDescriptor property = propertyDescriptors[i];
if (property.getWriteMethod() != null && property.getWriteMethod().isAnnotationPresent(Adjustable.class)) {
String key = property.getWriteMethod().getAnnotation(Adjustable.class).key();
if (key.equals("")) {
key = norm(property.getName());
}
order.put(key, norm(property.getName()));
properties.put(norm(property.getName()), property);
if (getValue(property) == null) {
// may not be null when called in the process of deserialization
// (see readObject)
setValue(property, NullValueProvider.getNullValue(property.getPropertyType()));
}
}
}
} catch (RuntimeException e) {
throw e;
} catch (Throwable t) {
t.printStackTrace();
throw new IllegalStateException("FATAL: data class introspection was not successful");
}
}
Aggregations