Search in sources :

Example 91 with IndexedPropertyDescriptor

use of java.beans.IndexedPropertyDescriptor in project jdk8u_jdk by JetBrains.

the class Test6194788 method main.

public static void main(String[] args) throws IntrospectionException {
    test(Grand.class, new PropertyDescriptor("index", Grand.class));
    test(Grand.class, new IndexedPropertyDescriptor("name", Grand.class, null, null, "getName", "setName"));
    test(Parent.class, new PropertyDescriptor("parentIndex", Parent.class));
    test(Parent.class, new IndexedPropertyDescriptor("parentName", Parent.class));
    test(Child.class, new PropertyDescriptor("childIndex", Child.class));
    test(Child.class, new IndexedPropertyDescriptor("childName", Child.class));
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) IndexedPropertyDescriptor(java.beans.IndexedPropertyDescriptor) IndexedPropertyDescriptor(java.beans.IndexedPropertyDescriptor)

Example 92 with IndexedPropertyDescriptor

use of java.beans.IndexedPropertyDescriptor in project jdk8u_jdk by JetBrains.

the class BeanUtils method reportPropertyDescriptor.

/**
     * Reports all the interesting information in an Indexed/PropertyDescrptor.
     */
public static void reportPropertyDescriptor(PropertyDescriptor pd) {
    System.out.println("property name:  " + pd.getName());
    System.out.println("         type:  " + pd.getPropertyType());
    System.out.println("         read:  " + pd.getReadMethod());
    System.out.println("         write: " + pd.getWriteMethod());
    if (pd instanceof IndexedPropertyDescriptor) {
        IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;
        System.out.println(" indexed type: " + ipd.getIndexedPropertyType());
        System.out.println(" indexed read: " + ipd.getIndexedReadMethod());
        System.out.println(" indexed write: " + ipd.getIndexedWriteMethod());
    }
}
Also used : IndexedPropertyDescriptor(java.beans.IndexedPropertyDescriptor)

Example 93 with IndexedPropertyDescriptor

use of java.beans.IndexedPropertyDescriptor in project opennms by OpenNMS.

the class BeanInfoManager method initialize.

// -------------------------------------
/**
 * Initializes by mapping property names to BeanInfoProperties
 */
void initialize(Logger pLogger) throws ELException {
    try {
        mBeanInfo = Introspector.getBeanInfo(mBeanClass);
        mPropertyByName = new HashMap();
        mIndexedPropertyByName = new HashMap();
        PropertyDescriptor[] pds = mBeanInfo.getPropertyDescriptors();
        for (int i = 0; pds != null && i < pds.length; i++) {
            // Treat as both an indexed property and a normal property
            PropertyDescriptor pd = pds[i];
            if (pd instanceof IndexedPropertyDescriptor) {
                IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;
                Method readMethod = getPublicMethod(ipd.getIndexedReadMethod());
                Method writeMethod = getPublicMethod(ipd.getIndexedWriteMethod());
                BeanInfoIndexedProperty property = new BeanInfoIndexedProperty(readMethod, writeMethod, ipd);
                mIndexedPropertyByName.put(ipd.getName(), property);
            }
            Method readMethod = getPublicMethod(pd.getReadMethod());
            Method writeMethod = getPublicMethod(pd.getWriteMethod());
            BeanInfoProperty property = new BeanInfoProperty(readMethod, writeMethod, pd);
            mPropertyByName.put(pd.getName(), property);
        }
        mEventSetByName = new HashMap();
        EventSetDescriptor[] esds = mBeanInfo.getEventSetDescriptors();
        for (int i = 0; esds != null && i < esds.length; i++) {
            EventSetDescriptor esd = esds[i];
            mEventSetByName.put(esd.getName(), esd);
        }
    } catch (IntrospectionException exc) {
        if (pLogger.isLoggingWarning()) {
            pLogger.logWarning(Constants.EXCEPTION_GETTING_BEANINFO, exc, mBeanClass.getName());
        }
    }
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) IndexedPropertyDescriptor(java.beans.IndexedPropertyDescriptor) HashMap(java.util.HashMap) IntrospectionException(java.beans.IntrospectionException) IndexedPropertyDescriptor(java.beans.IndexedPropertyDescriptor) Method(java.lang.reflect.Method) EventSetDescriptor(java.beans.EventSetDescriptor)

Example 94 with IndexedPropertyDescriptor

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

the class IndexedPropertyDescriptorTest method testSetIndexedWriteMethod.

public void testSetIndexedWriteMethod() throws IntrospectionException, NoSuchMethodException, NoSuchMethodException {
    String propertyName = "PropertyFour";
    Class<MockJavaBean> beanClass = MockJavaBean.class;
    Method readMethod = beanClass.getMethod("get" + propertyName, (Class[]) null);
    Method writeMethod = beanClass.getMethod("set" + propertyName, new Class[] { String[].class });
    Method indexedReadMethod = beanClass.getMethod("get" + propertyName, new Class[] { Integer.TYPE });
    Method indexedWriteMethod = beanClass.getMethod("set" + propertyName, new Class[] { Integer.TYPE, String.class });
    IndexedPropertyDescriptor ipd = new IndexedPropertyDescriptor(propertyName, readMethod, writeMethod, indexedReadMethod, null);
    assertNull(ipd.getIndexedWriteMethod());
    ipd.setIndexedWriteMethod(indexedWriteMethod);
    assertSame(indexedWriteMethod, ipd.getIndexedWriteMethod());
}
Also used : MockJavaBean(org.apache.harmony.beans.tests.support.mock.MockJavaBean) IndexedPropertyDescriptor(java.beans.IndexedPropertyDescriptor) Method(java.lang.reflect.Method)

Example 95 with IndexedPropertyDescriptor

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

the class IndexedPropertyDescriptorTest method testSetIndexedWriteMethod_InvalidIndexType.

public void testSetIndexedWriteMethod_InvalidIndexType() throws IntrospectionException, NoSuchMethodException, NoSuchMethodException {
    String propertyName = "PropertyFour";
    Class<MockJavaBean> beanClass = MockJavaBean.class;
    Method readMethod = beanClass.getMethod("get" + propertyName, (Class[]) null);
    Method writeMethod = beanClass.getMethod("set" + propertyName, new Class[] { String[].class });
    Method indexedReadMethod = beanClass.getMethod("get" + propertyName, new Class[] { Integer.TYPE });
    IndexedPropertyDescriptor ipd = new IndexedPropertyDescriptor(propertyName, readMethod, writeMethod, indexedReadMethod, null);
    assertNull(ipd.getIndexedWriteMethod());
    Method badArgType = beanClass.getMethod("setPropertyFourInvalid2", new Class[] { String.class, String.class });
    try {
        ipd.setIndexedWriteMethod(badArgType);
        fail("Should throw IntrospectionException");
    } catch (IntrospectionException e) {
    }
    ipd = new IndexedPropertyDescriptor("data", NormalBean.class);
    ipd.setIndexedReadMethod(null);
    try {
        ipd.setIndexedWriteMethod(NormalBean.class.getMethod("setData", Integer.TYPE, Integer.TYPE));
        fail("should throw IntrospectionException");
    } catch (IntrospectionException e) {
    // expected
    }
}
Also used : MockJavaBean(org.apache.harmony.beans.tests.support.mock.MockJavaBean) IntrospectionException(java.beans.IntrospectionException) IndexedPropertyDescriptor(java.beans.IndexedPropertyDescriptor) Method(java.lang.reflect.Method)

Aggregations

IndexedPropertyDescriptor (java.beans.IndexedPropertyDescriptor)197 Method (java.lang.reflect.Method)167 PropertyDescriptor (java.beans.PropertyDescriptor)142 BeanInfo (java.beans.BeanInfo)126 SimpleBeanInfo (java.beans.SimpleBeanInfo)126 FakeFox01BeanInfo (org.apache.harmony.beans.tests.support.mock.FakeFox01BeanInfo)126 MockJavaBean (org.apache.harmony.beans.tests.support.mock.MockJavaBean)49 IntrospectionException (java.beans.IntrospectionException)17 EventSetDescriptor (java.beans.EventSetDescriptor)3 MethodDescriptor (java.beans.MethodDescriptor)2 PropertyInfo (cern.gp.beans.PropertyInfo)1 CachingStrategy (cern.gp.nodes.cache.CachingStrategy)1 NoCachingStrategy (cern.gp.nodes.cache.NoCachingStrategy)1 StickyCachingStrategy (cern.gp.nodes.cache.StickyCachingStrategy)1 TimeLimitedCachingStrategy (cern.gp.nodes.cache.TimeLimitedCachingStrategy)1 KeyEvent (java.awt.event.KeyEvent)1 KeyListener (java.awt.event.KeyListener)1 BeanDescriptor (java.beans.BeanDescriptor)1 FeatureDescriptor (java.beans.FeatureDescriptor)1 IndexedPropertyChangeEvent (java.beans.IndexedPropertyChangeEvent)1