Search in sources :

Example 6 with IntrospectionException

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;
}
Also used : JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) XStreamImplicit(com.thoughtworks.xstream.annotations.XStreamImplicit) Arrays(java.util.Arrays) XStreamAlias(com.thoughtworks.xstream.annotations.XStreamAlias) XStreamOmitField(com.thoughtworks.xstream.annotations.XStreamOmitField) Introspector(java.beans.Introspector) AbstractDescribedSObjectBase(org.apache.camel.component.salesforce.api.dto.AbstractDescribedSObjectBase) BeanInfo(java.beans.BeanInfo) Objects.requireNonNull(java.util.Objects.requireNonNull) JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore) StreamSupport(java.util.stream.StreamSupport) RestError(org.apache.camel.component.salesforce.api.dto.RestError) Method(java.lang.reflect.Method) AbstractSObjectBase(org.apache.camel.component.salesforce.api.dto.AbstractSObjectBase) Set(java.util.Set) Collectors(java.util.stream.Collectors) IntrospectionException(java.beans.IntrospectionException) Serializable(java.io.Serializable) InvocationTargetException(java.lang.reflect.InvocationTargetException) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) PropertyDescriptor(java.beans.PropertyDescriptor) Optional(java.util.Optional) ObjectHelper(org.apache.camel.util.ObjectHelper) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) PropertyDescriptor(java.beans.PropertyDescriptor) BeanInfo(java.beans.BeanInfo) IntrospectionException(java.beans.IntrospectionException) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 7 with IntrospectionException

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;
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) BeanInfo(java.beans.BeanInfo) IntrospectionException(java.beans.IntrospectionException)

Example 8 with IntrospectionException

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;
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) HashMap(java.util.HashMap) BeanInfo(java.beans.BeanInfo) IntrospectionException(java.beans.IntrospectionException)

Example 9 with IntrospectionException

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) {
    }
}
Also used : MockJavaBean(org.apache.harmony.beans.tests.support.mock.MockJavaBean) PropertyDescriptor(java.beans.PropertyDescriptor) IntrospectionException(java.beans.IntrospectionException) Method(java.lang.reflect.Method)

Example 10 with IntrospectionException

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) {
    }
}
Also used : MockJavaBean(org.apache.harmony.beans.tests.support.mock.MockJavaBean) PropertyDescriptor(java.beans.PropertyDescriptor) IntrospectionException(java.beans.IntrospectionException) Method(java.lang.reflect.Method)

Aggregations

IntrospectionException (java.beans.IntrospectionException)94 PropertyDescriptor (java.beans.PropertyDescriptor)54 BeanInfo (java.beans.BeanInfo)38 Method (java.lang.reflect.Method)38 MockJavaBean (org.apache.harmony.beans.tests.support.mock.MockJavaBean)24 IndexedPropertyDescriptor (java.beans.IndexedPropertyDescriptor)16 InvocationTargetException (java.lang.reflect.InvocationTargetException)8 HashMap (java.util.HashMap)7 EventSetDescriptor (java.beans.EventSetDescriptor)6 ArrayList (java.util.ArrayList)6 Field (java.lang.reflect.Field)5 RecursiveChildrenListManager (cern.gp.explorer.test.helpers.RecursiveChildrenListManager)3 SimpleDemoBean (cern.gp.explorer.test.helpers.SimpleDemoBean)3 GPNode (cern.gp.nodes.GPNode)3 Map (java.util.Map)3 ResourceBundle (java.util.ResourceBundle)3 TreeExplorer (cern.gp.explorer.TreeExplorer)2 DefaultActionGroup (com.intellij.openapi.actionSystem.DefaultActionGroup)2 MethodDescriptor (java.beans.MethodDescriptor)2 SimpleBeanInfo (java.beans.SimpleBeanInfo)2