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));
}
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());
}
}
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());
}
}
}
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());
}
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
}
}
Aggregations