Search in sources :

Example 76 with IntrospectionException

use of java.beans.IntrospectionException in project j2objc by google.

the class FakeFox01BeanInfo method getPropertyDescriptors.

@Override
public PropertyDescriptor[] getPropertyDescriptors() {
    PropertyDescriptor propertyDesc = null;
    try {
        propertyDesc = new PropertyDescriptor("fox01", clazz);
        propertyDesc.setDisplayName(propertyDesc.getDisplayName() + suffix);
    } catch (IntrospectionException e) {
        e.printStackTrace();
    }
    return new PropertyDescriptor[] { propertyDesc };
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) IntrospectionException(java.beans.IntrospectionException)

Example 77 with IntrospectionException

use of java.beans.IntrospectionException in project j2objc by google.

the class PropertyDescriptorTest method testPropertyDescriptorStringClass.

/*
     * Class under test for void PropertyDescriptor(String, Class)
     */
public void testPropertyDescriptorStringClass() throws IntrospectionException {
    String propertyName = "propertyOne";
    Class<MockJavaBean> beanClass = MockJavaBean.class;
    PropertyDescriptor pd = new PropertyDescriptor(propertyName, beanClass);
    String capitalName = propertyName.substring(0, 1).toUpperCase() + propertyName.substring(1);
    assertEquals(String.class, pd.getPropertyType());
    assertEquals("get" + capitalName, pd.getReadMethod().getName());
    assertEquals("set" + capitalName, pd.getWriteMethod().getName());
    assertFalse(pd.isBound());
    assertFalse(pd.isConstrained());
    assertEquals(propertyName, pd.getDisplayName());
    assertEquals(propertyName, pd.getName());
    assertEquals(propertyName, pd.getShortDescription());
    assertNotNull(pd.attributeNames());
    assertFalse(pd.isExpert());
    assertFalse(pd.isHidden());
    assertFalse(pd.isPreferred());
    propertyName = "propertyWithoutGet";
    try {
        new PropertyDescriptor(propertyName, beanClass);
        fail("Should throw IntrospectionException");
    } catch (IntrospectionException e) {
    }
    try {
        new PropertyDescriptor(propertyName, beanClass, "getPropertyWithoutGet", "setPropertyWithoutGet");
        fail("Should throw IntrospectionException");
    } catch (IntrospectionException e) {
    }
    propertyName = "propertyWithoutSet";
    beanClass = MockJavaBean.class;
    try {
        new PropertyDescriptor(propertyName, beanClass);
        fail("Should throw IntrospectionException");
    } catch (IntrospectionException e) {
    }
    propertyName = "propertyWithDifferentGetSet";
    try {
        new PropertyDescriptor(propertyName, beanClass);
        fail("Should throw IntrospectionException");
    } catch (IntrospectionException e) {
    }
    propertyName = "propertyWithInvalidGet";
    new PropertyDescriptor(propertyName, beanClass);
    propertyName = "propertyWithoutPublicGet";
    try {
        new PropertyDescriptor(propertyName, beanClass);
        fail("Should throw IntrospectionException");
    } catch (IntrospectionException e) {
    }
    propertyName = "propertyWithGet1Param";
    try {
        new PropertyDescriptor(propertyName, beanClass);
        fail("Should throw IntrospectionException");
    } catch (IntrospectionException e) {
    }
    propertyName = "propertyWithIs1Param";
    PropertyDescriptor pd2 = new PropertyDescriptor(propertyName, beanClass);
    assertEquals("getPropertyWithIs1Param", pd2.getReadMethod().getName());
    propertyName = "propertyWithSet2Param";
    try {
        new PropertyDescriptor(propertyName, beanClass);
        fail("Should throw IntrospectionException");
    } catch (IntrospectionException e) {
    }
    propertyName = "propertyWithIsGet";
    PropertyDescriptor pd3 = new PropertyDescriptor(propertyName, beanClass);
    assertEquals("isPropertyWithIsGet", pd3.getReadMethod().getName());
    propertyName = "propertyWithVoidGet";
    try {
        new PropertyDescriptor(propertyName, beanClass);
        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)

Example 78 with IntrospectionException

use of java.beans.IntrospectionException in project j2objc by google.

the class PropertyDescriptorTest method testSetWriteMethod_Invalid_NoArgs.

/**
     * write method without argument
     */
public void testSetWriteMethod_Invalid_NoArgs() throws SecurityException, NoSuchMethodException, IntrospectionException {
    Class<MockJavaBean> beanClass = MockJavaBean.class;
    String propertyName = "PropertyOne";
    Method writeMethod = beanClass.getMethod("get" + "PropertyTwo", (Class[]) null);
    PropertyDescriptor pd = new PropertyDescriptor(propertyName, null, null);
    assertNull(pd.getWriteMethod());
    try {
        pd.setWriteMethod(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 79 with IntrospectionException

use of java.beans.IntrospectionException in project j2objc by google.

the class PropertyDescriptorTest method testSetReadMethod_Invalid_withArg.

/**
     * 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) {
    }
}
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 80 with IntrospectionException

use of java.beans.IntrospectionException in project cobar by alibaba.

the class ParameterMapping method getDescriptors.

private static PropertyDescriptor[] getDescriptors(Class<?> clazz) {
    PropertyDescriptor[] pds;
    List<PropertyDescriptor> list;
    PropertyDescriptor[] pds2 = descriptors.get(clazz);
    if (null == pds2) {
        try {
            BeanInfo beanInfo = Introspector.getBeanInfo(clazz);
            pds = beanInfo.getPropertyDescriptors();
            list = new ArrayList<PropertyDescriptor>();
            for (int i = 0; i < pds.length; i++) {
                if (null != pds[i].getPropertyType()) {
                    list.add(pds[i]);
                }
            }
            pds2 = new PropertyDescriptor[list.size()];
            list.toArray(pds2);
        } catch (IntrospectionException ie) {
            ie.printStackTrace();
            pds2 = new PropertyDescriptor[0];
        }
    }
    descriptors.put(clazz, pds2);
    return (pds2);
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) BeanInfo(java.beans.BeanInfo) IntrospectionException(java.beans.IntrospectionException)

Aggregations

IntrospectionException (java.beans.IntrospectionException)111 PropertyDescriptor (java.beans.PropertyDescriptor)65 Method (java.lang.reflect.Method)46 BeanInfo (java.beans.BeanInfo)44 MockJavaBean (org.apache.harmony.beans.tests.support.mock.MockJavaBean)24 InvocationTargetException (java.lang.reflect.InvocationTargetException)18 IndexedPropertyDescriptor (java.beans.IndexedPropertyDescriptor)17 ArrayList (java.util.ArrayList)11 HashMap (java.util.HashMap)10 Field (java.lang.reflect.Field)9 EventSetDescriptor (java.beans.EventSetDescriptor)7 List (java.util.List)6 Map (java.util.Map)6 MessageFormat (java.text.MessageFormat)5 UUID (java.util.UUID)5 Assert (org.springframework.util.Assert)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 Optional (java.util.Optional)4 RecursiveChildrenListManager (cern.gp.explorer.test.helpers.RecursiveChildrenListManager)3 SimpleDemoBean (cern.gp.explorer.test.helpers.SimpleDemoBean)3