use of java.beans.IntrospectionException in project camel by apache.
the class SObjectTree method updateGeneralObjectId.
boolean updateGeneralObjectId(final String id, final Object object) {
final Class<? extends Object> clazz = object.getClass();
final BeanInfo beanInfo;
try {
beanInfo = Introspector.getBeanInfo(clazz);
} catch (final IntrospectionException e) {
throw new IllegalStateException(e);
}
final PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
final Optional<PropertyDescriptor> maybeIdProperty = Arrays.stream(propertyDescriptors).filter(pd -> "id".equals(pd.getName())).findFirst();
if (maybeIdProperty.isPresent()) {
final Method readMethod = maybeIdProperty.get().getReadMethod();
try {
readMethod.invoke(object, id);
return true;
} catch (IllegalAccessException | InvocationTargetException e) {
throw new IllegalStateException(e);
}
}
return false;
}
use of java.beans.IntrospectionException 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.IntrospectionException 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.IntrospectionException in project j2objc by google.
the class PropertyDescriptorTest method testPropertyDescriptorStringMethodMethod_ReadMethodInvalid.
public void testPropertyDescriptorStringMethodMethod_ReadMethodInvalid() throws SecurityException, NoSuchMethodException, IntrospectionException {
String propertyName = "PropertyOne";
Class<MockJavaBean> beanClass = MockJavaBean.class;
String anotherProp = "PropertyTwo";
Method readMethod = beanClass.getMethod("get" + anotherProp, (Class[]) null);
Method writeMethod = beanClass.getMethod("set" + propertyName, new Class[] { String.class });
try {
new PropertyDescriptor(propertyName, readMethod, writeMethod);
fail("Should throw IntrospectionException.");
} catch (IntrospectionException e) {
}
}
use of java.beans.IntrospectionException in project j2objc by google.
the class PropertyDescriptorTest method testPropertyDescriptorStringMethodMethod_PropertyNameNull.
public void testPropertyDescriptorStringMethodMethod_PropertyNameNull() throws SecurityException, NoSuchMethodException, IntrospectionException {
String propertyName = "PropertyOne";
Class<MockJavaBean> beanClass = MockJavaBean.class;
Method readMethod = beanClass.getMethod("get" + propertyName, (Class[]) null);
Method writeMethod = beanClass.getMethod("set" + propertyName, new Class[] { String.class });
try {
new PropertyDescriptor(null, readMethod, writeMethod);
fail("Should throw IntrospectionException.");
} catch (IntrospectionException e) {
}
}
Aggregations