Java Code Examples for java.beans.PropertyDescriptor#setReadMethod()

The following examples show how to use java.beans.PropertyDescriptor#setReadMethod() . 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: PropertyDescriptorTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * String invalidGetMethod(String arg)
 */
public void testSetReadMethod_Invalid_withArg() throws SecurityException,
        NoSuchMethodException, IntrospectionException {
    Class<MockJavaBean> beanClass = MockJavaBean.class;
    String propertyName = "PropertyOne";
    Method readMethod = beanClass.getMethod("invalidGetMethod",
            new Class[] { String.class });
    PropertyDescriptor pd = new PropertyDescriptor(propertyName, null, null);

    assertNull(pd.getReadMethod());
    try {
        pd.setReadMethod(readMethod);
        fail("Should throw IntrospectionException.");
    } catch (IntrospectionException e) {
    }
}
 
Example 2
Source File: PropertyDescriptorTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * String invalidGetMethod(String arg)
 */
public void testSetReadMethod_Invalid_returnVoid()
        throws SecurityException, NoSuchMethodException,
        IntrospectionException {
    Class<MockJavaBean> beanClass = MockJavaBean.class;
    String propertyName = "PropertyOne";
    Method readMethod = beanClass.getMethod("invalidGetMethod",
            (Class[]) null);
    PropertyDescriptor pd = new PropertyDescriptor(propertyName, null, null);

    assertNull(pd.getReadMethod());
    try {
        pd.setReadMethod(readMethod);
        fail("Should throw IntrospectionException.");
    } catch (IntrospectionException e) {
    }
}
 
Example 3
Source File: PropertyDescriptorTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * Read method is incompatible with write method getPropertyOn vs.
 * setPropertyTow
 */
public void testSetReadMethod_ReadWriteIncompatible()
        throws SecurityException, NoSuchMethodException,
        IntrospectionException {
    Class<MockJavaBean> beanClass = MockJavaBean.class;
    String propertyName = "PropertyOne";
    Method readMethod = beanClass.getMethod("get" + "PropertyOne",
            (Class[]) null);
    Method writeMethod = beanClass.getMethod("set" + "PropertyTwo",
            new Class[] { Integer.class });

    PropertyDescriptor pd = new PropertyDescriptor(propertyName, null,
            writeMethod);

    assertNull(pd.getReadMethod());
    try {
        pd.setReadMethod(readMethod);
        fail("Should throw IntrospectionException.");
    } catch (IntrospectionException e) {
    }
}
 
Example 4
Source File: BeanValidator.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
public static <T> void findBooleanIsMethods(Class<T> clazz, PropertyDescriptor descriptor)
        throws IntrospectionException {
    if (descriptor.getReadMethod() == null && descriptor.getPropertyType() == Boolean.class) {
        try {
            PropertyDescriptor pd = new PropertyDescriptor(descriptor.getName(), clazz);
            descriptor.setReadMethod(pd.getReadMethod());
        } catch (IntrospectionException e) {
        }
    }
}
 
Example 5
Source File: BeanValidator.java    From kylin with Apache License 2.0 5 votes vote down vote up
public static <T> void findBooleanIsMethods(Class<T> clazz, PropertyDescriptor descriptor)
        throws IntrospectionException {
    if (descriptor.getReadMethod() == null && descriptor.getPropertyType() == Boolean.class) {
        try {
            PropertyDescriptor pd = new PropertyDescriptor(descriptor.getName(), clazz);
            descriptor.setReadMethod(pd.getReadMethod());
        } catch (IntrospectionException e) {
        }
    }
}
 
Example 6
Source File: PropertyDescriptorTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
public void testSetReadMethod() throws SecurityException,
        NoSuchMethodException, IntrospectionException {
    Class<MockJavaBean> beanClass = MockJavaBean.class;
    String propertyName = "PropertyOne";
    Method readMethod = beanClass.getMethod("get" + propertyName,
            (Class[]) null);
    PropertyDescriptor pd = new PropertyDescriptor(propertyName, null, null);

    assertNull(pd.getReadMethod());
    pd.setReadMethod(readMethod);
    assertSame(readMethod, pd.getReadMethod());
}
 
Example 7
Source File: PropertyDescriptorTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
public void testSetReadMethod_Null() throws SecurityException,
        NoSuchMethodException, IntrospectionException {
    Class<MockJavaBean> beanClass = MockJavaBean.class;
    String propertyName = "PropertyOne";
    Method readMethod = beanClass.getMethod("get" + propertyName,
            (Class[]) null);
    PropertyDescriptor pd = new PropertyDescriptor(propertyName,
            readMethod, null);

    assertSame(readMethod, pd.getReadMethod());
    pd.setReadMethod(null);
    assertNull(pd.getReadMethod());
}
 
Example 8
Source File: PropertyDescriptorTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Read method is incompatible with property name getPropertyTwo vs.
 * PropertyOne (writeMethod=null)
 */
public void testSetReadMethod_Invalid() throws SecurityException,
        NoSuchMethodException, IntrospectionException {
    Class<MockJavaBean> beanClass = MockJavaBean.class;
    String propertyName = "PropertyOne";
    Method readMethod = beanClass.getMethod("get" + "PropertyTwo",
            (Class[]) null);
    PropertyDescriptor pd = new PropertyDescriptor(propertyName, null, null);

    assertNull(pd.getReadMethod());
    pd.setReadMethod(readMethod);
    assertSame(readMethod, pd.getReadMethod());
}
 
Example 9
Source File: BeanValidator.java    From Kylin with Apache License 2.0 5 votes vote down vote up
public static <T> void findBooleanIsMethods(Class<T> clazz, PropertyDescriptor descriptor) throws IntrospectionException {
    if (descriptor.getReadMethod() == null && descriptor.getPropertyType() == Boolean.class) {
        try {
            PropertyDescriptor pd = new PropertyDescriptor(descriptor.getName(), clazz);
            descriptor.setReadMethod(pd.getReadMethod());
        } catch (IntrospectionException e) {
        }
    }
}