Java Code Examples for java.beans.IntrospectionException#getMessage()

The following examples show how to use java.beans.IntrospectionException#getMessage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReflectUtils.java    From JobX with Apache License 2.0 6 votes vote down vote up
/**
 * java反射bean的set方法
 *
 * @param clazz     javaBean对象
 * @param fieldName 字段名称
 * @return set方法
 */
public static Method setter(Class<?> clazz, String fieldName) {
    AssertUtils.notNull(clazz, fieldName);
    try {
        PropertyDescriptor[] objPds = Introspector.getBeanInfo(clazz).getPropertyDescriptors();

        for (int i = 0; objPds.length > 1 && i < objPds.length; i++) {
            //跳出从object继承的class属性,源上必须有get方法
            if (Class.class == objPds[i].getPropertyType()
                    || objPds[i].getReadMethod() == null) {
                continue;
            }

            if (objPds[i].getName().equals(fieldName)) {
                return objPds[i].getWriteMethod();
            }
        }

    } catch (IntrospectionException e) {
        throw new RuntimeException(e.getMessage());
    }

    return null;
}
 
Example 2
Source File: ReflectUitls.java    From opencron with Apache License 2.0 6 votes vote down vote up
/**
 * 
 * java反射bean的set方法
 * 
 * @param clazz
 *            javaBean对象
 * @param fieldName
 *            字段名称
 * 
 * @return set方法
 */
public static Method setter(Class<?> clazz, String fieldName) {
       AssertUtils.notNull(clazz,fieldName);
       try {
           PropertyDescriptor[] objPds = Introspector.getBeanInfo(clazz).getPropertyDescriptors();

           for (int i = 0; objPds.length > 1 && i < objPds.length; i++) {
               //跳出从object继承的class属性,源上必须有get方法
               if (Class.class == objPds[i].getPropertyType()
                       || objPds[i].getReadMethod() == null) {
                   continue;
               }

               if (objPds[i].getName().equals(fieldName)){
                   return objPds[i].getWriteMethod();
               }
           }

       } catch (IntrospectionException e) {
           throw new RuntimeException(e.getMessage());
       }

       return null;
}
 
Example 3
Source File: BeanProcessor.java    From jforgame with Apache License 2.0 5 votes vote down vote up
private PropertyDescriptor[] propertyDescriptors(Class<?> c)
        throws SQLException
{
    BeanInfo beanInfo = null;
    try
    {
        beanInfo = Introspector.getBeanInfo(c);
    }
    catch (IntrospectionException e)
    {
        throw new SQLException("Bean introspection failed: " + e.getMessage());
    }
    return beanInfo.getPropertyDescriptors();
}
 
Example 4
Source File: ReflectUtils.java    From JobX with Apache License 2.0 5 votes vote down vote up
/**
 * java反射bean的get方法
 *
 * @param clazz     javaBean对象类型
 * @param fieldName 字段名称
 * @return get方法
 */
public static Method getter(Class<?> clazz, String fieldName) throws NoSuchMethodException {
    // get+字段名第一个字母小写,得到get方法名

    // 拿到拷贝源上的属性器数组
    try {
        PropertyDescriptor[] objPds = Introspector.getBeanInfo(clazz).getPropertyDescriptors();

        for (int i = 0; objPds.length > 1 && i < objPds.length; i++) {
            //跳出从object继承的class属性,源上必须有get方法
            if (Class.class == objPds[i].getPropertyType()
                    || objPds[i].getReadMethod() == null) {
                continue;
            }

            if (objPds[i].getName().equals(fieldName)) {
                return objPds[i].getReadMethod();
            }
        }

    } catch (IntrospectionException e) {
        throw new NoSuchMethodException(e.getMessage());
    }

    return null;

}
 
Example 5
Source File: ReflectUitls.java    From opencron with Apache License 2.0 5 votes vote down vote up
/**
 * 
 * java反射bean的get方法
 * 
 * @param clazz
 *            javaBean对象类型
 * @param fieldName
 *            字段名称
 * 
 * @return get方法
 */
public static Method getter(Class<?> clazz, String fieldName) throws NoSuchMethodException {
	// get+字段名第一个字母小写,得到get方法名

       // 拿到拷贝源上的属性器数组
       try {
           PropertyDescriptor[] objPds = Introspector.getBeanInfo(clazz).getPropertyDescriptors();

           for (int i = 0; objPds.length > 1 && i < objPds.length; i++) {
               //跳出从object继承的class属性,源上必须有get方法
               if (Class.class == objPds[i].getPropertyType()
                       || objPds[i].getReadMethod() == null) {
                   continue;
               }

               if (objPds[i].getName().equals(fieldName)){
                   return objPds[i].getReadMethod();
               }
           }

       } catch (IntrospectionException e) {
           throw new NoSuchMethodException(e.getMessage());
       }

       return null;

}
 
Example 6
Source File: MapModel.java    From lorne_core with Apache License 2.0 5 votes vote down vote up
private PropertyDescriptor[] propertyDescriptors(Class<?> c) throws SQLException {
    BeanInfo beanInfo = null;
    try {
        beanInfo = Introspector.getBeanInfo(c);
    } catch (IntrospectionException var4) {
        throw new SQLException("Bean introspection failed: " + var4.getMessage());
    }
    return beanInfo.getPropertyDescriptors();
}
 
Example 7
Source File: BeanProcessor.java    From cuba with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a PropertyDescriptor[] for the given Class.
 *
 * @param c The Class to retrieve PropertyDescriptors for.
 * @return A PropertyDescriptor[] describing the Class.
 * @throws SQLException if introspection failed.
 */
private PropertyDescriptor[] propertyDescriptors(Class c)
    throws SQLException {
    // Introspector caches BeanInfo classes for better performance
    BeanInfo beanInfo;
    try {
        beanInfo = Introspector.getBeanInfo(c);

    } catch (IntrospectionException e) {
        throw new SQLException(
            "Bean introspection failed: " + e.getMessage());
    }

    return beanInfo.getPropertyDescriptors();
}
 
Example 8
Source File: MyBeanItem.java    From sensorhub with Mozilla Public License 2.0 5 votes vote down vote up
protected PropertyDescriptor[] getGettersAndSetters(Class<?> beanClass)
{
    try
    {
        return Introspector.getBeanInfo(beanClass).getPropertyDescriptors();
    }
    catch (IntrospectionException e)
    {
        throw new RuntimeException(e.getMessage());
    }
}
 
Example 9
Source File: BeanPropertyHandler.java    From snakerflow with Apache License 2.0 5 votes vote down vote up
/**
 * 由Introspector返回指定类型的BeanInfo对象,再返回需要的属性描述对象数组PropertyDescriptor[]
 * @param c
 * @return PropertyDescriptor[]
 * @throws SQLException
 */
private PropertyDescriptor[] propertyDescriptors(Class<?> c)
		throws SQLException {
	BeanInfo beanInfo = null;
	try {
		beanInfo = Introspector.getBeanInfo(c);
	} catch (IntrospectionException e) {
		throw new SQLException("Bean introspection failed: "
				+ e.getMessage());
	}

	return beanInfo.getPropertyDescriptors();
}