You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by ay...@apache.org on 2006/11/09 11:50:30 UTC
svn commit: r472854 - in
/incubator/harmony/enhanced/classlib/trunk/modules/beans/src:
main/java/java/beans/ test/java/org/apache/harmony/beans/tests/java/beans/
Author: ayza
Date: Thu Nov 9 02:50:30 2006
New Revision: 472854
URL: http://svn.apache.org/viewvc?view=rev&rev=472854
Log:
fixes for HARMONY-1838 ([classlib][beans] java.beans.Introspector.getBeanInfo(Bean.class).getPropertyDescriptors() returns wrong object)
Modified:
incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/IndexedPropertyDescriptor.java
incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/PropertyDescriptor.java
incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/IntrospectorTest.java
Modified: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/IndexedPropertyDescriptor.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/IndexedPropertyDescriptor.java?view=diff&rev=472854&r1=472853&r2=472854
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/IndexedPropertyDescriptor.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/IndexedPropertyDescriptor.java Thu Nov 9 02:50:30 2006
@@ -49,21 +49,42 @@
public IndexedPropertyDescriptor(String propertyName, Class<?> beanClass)
throws IntrospectionException {
- super(propertyName, beanClass);
- String indexedGetterName = createDefaultMethodName(propertyName, "get"); //$NON-NLS-1$
+ super(propertyName, beanClass, null, null);
+
+ String getterName;
+ String setterName;
+ String indexedGetterName;
+ String indexedSetterName;
+
+ // array getter
+ getterName = createDefaultMethodName(propertyName, "get"); //$NON-NLS-1$
+ if (hasMethod(beanClass, getterName)) {
+ setReadMethod(beanClass, getterName);
+ }
+
+ // array setter
+ setterName = createDefaultMethodName(propertyName, "set"); //$NON-NLS-1$
+ if (hasMethod(beanClass, setterName)) {
+ setWriteMethod(beanClass, setterName);
+ }
+
+ // indexed getter
+ indexedGetterName = createDefaultMethodName(propertyName, "get"); //$NON-NLS-1$
if (hasMethod(beanClass, indexedGetterName)) {
setIndexedReadMethod(beanClass, indexedGetterName);
- } else {
- throw new IntrospectionException(Messages.getString(
- "beans.1F", propertyName)); //$NON-NLS-1$
}
- String indexedSetterName = createDefaultMethodName(propertyName, "set"); //$NON-NLS-1$
+ // indexed setter
+ indexedSetterName = createDefaultMethodName(propertyName, "set"); //$NON-NLS-1$
if (hasMethod(beanClass, indexedSetterName)) {
setIndexedWriteMethod(beanClass, indexedSetterName);
- } else {
+ }
+
+ // RI seems to behave a bit differently
+ if (indexedGetter == null && indexedSetter == null &&
+ getReadMethod() == null && getWriteMethod() == null) {
throw new IntrospectionException(Messages.getString(
- "beans.20", propertyName)); //$NON-NLS-1$
+ "beans.01", propertyName)); //$NON-NLS-1$
}
}
@@ -71,11 +92,15 @@
throws IntrospectionException {
if (indexedGetter != null) {
int modifiers = indexedGetter.getModifiers();
+ Class[] parameterTypes;
+ Class<?> returnType;
+ Class<?> indexedPropertyType;
+
if (!Modifier.isPublic(modifiers)) {
throw new IntrospectionException(Messages.getString("beans.21")); //$NON-NLS-1$
}
- Class[] parameterTypes = indexedGetter.getParameterTypes();
+ parameterTypes = indexedGetter.getParameterTypes();
if (parameterTypes.length != 1) {
throw new IntrospectionException(Messages.getString("beans.22")); //$NON-NLS-1$
}
@@ -84,8 +109,8 @@
throw new IntrospectionException(Messages.getString("beans.23")); //$NON-NLS-1$
}
- Class<?> returnType = indexedGetter.getReturnType();
- Class<?> indexedPropertyType = getIndexedPropertyType();
+ returnType = indexedGetter.getReturnType();
+ indexedPropertyType = getIndexedPropertyType();
if ((indexedPropertyType != null)
&& !returnType.equals(indexedPropertyType)) {
throw new IntrospectionException(Messages.getString("beans.24")); //$NON-NLS-1$
@@ -97,24 +122,31 @@
public void setIndexedWriteMethod(Method indexedSetter)
throws IntrospectionException {
+
if (indexedSetter != null) {
int modifiers = indexedSetter.getModifiers();
+ Class[] parameterTypes;
+ Class<?> firstParameterType;
+ Class<?> secondParameterType;
+ Class<?> propType;
+
if (!Modifier.isPublic(modifiers)) {
throw new IntrospectionException(Messages.getString("beans.25")); //$NON-NLS-1$
}
- Class[] parameterTypes = indexedSetter.getParameterTypes();
+ parameterTypes = indexedSetter.getParameterTypes();
if (parameterTypes.length != 2) {
throw new IntrospectionException(Messages.getString("beans.26")); //$NON-NLS-1$
}
- Class<?> firstParameterType = parameterTypes[0];
+ firstParameterType = parameterTypes[0];
if (!firstParameterType.equals(int.class)) {
throw new IntrospectionException(Messages.getString("beans.27")); //$NON-NLS-1$
}
- Class<?> secondParameterType = parameterTypes[1];
- if (!secondParameterType.equals(getIndexedPropertyType())) {
+ secondParameterType = parameterTypes[1];
+ propType = getIndexedPropertyType();
+ if (propType != null && !secondParameterType.equals(propType)) {
throw new IntrospectionException(Messages.getString("beans.28")); //$NON-NLS-1$
}
}
@@ -157,12 +189,13 @@
String indexedGetterName) {
Method[] getters = findMethods(beanClass, indexedGetterName);
boolean result = false;
+
for (Method element : getters) {
try {
setIndexedReadMethod(element);
result = true;
- } catch (IntrospectionException ie) {
- }
+ } catch (IntrospectionException ie) {}
+
if (result) {
break;
}
Modified: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/PropertyDescriptor.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/PropertyDescriptor.java?view=diff&rev=472854&r1=472853&r2=472854
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/PropertyDescriptor.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/PropertyDescriptor.java Thu Nov 9 02:50:30 2006
@@ -44,6 +44,7 @@
String getterName, String setterName) throws IntrospectionException {
super();
+
if (beanClass == null) {
throw new IntrospectionException(Messages.getString("beans.03")); //$NON-NLS-1$
}
@@ -64,6 +65,7 @@
throw new IntrospectionException(Messages.getString("beans.20")); //$NON-NLS-1$
}
}
+
if (getterName != null) {
if (hasMethod(beanClass, getterName)) {
setReadMethod(beanClass, getterName);
@@ -91,7 +93,9 @@
public PropertyDescriptor(String propertyName, Class<?> beanClass)
throws IntrospectionException {
- super();
+ String getterName;
+ String setterName;
+
if (beanClass == null) {
throw new IntrospectionException(Messages.getString("beans.03")); //$NON-NLS-1$
}
@@ -104,23 +108,26 @@
this.setName(propertyName);
this.setDisplayName(propertyName);
- String getterName = createDefaultMethodName(propertyName, "is"); //$NON-NLS-1$
+ getterName = createDefaultMethodName(propertyName, "is"); //$NON-NLS-1$
if (hasMethod(beanClass, getterName)) {
setReadMethod(beanClass, getterName);
} else {
getterName = createDefaultMethodName(propertyName, "get"); //$NON-NLS-1$
if (hasMethod(beanClass, getterName)) {
setReadMethod(beanClass, getterName);
- } else {
- throw new IntrospectionException(Messages.getString("beans.1F")); //$NON-NLS-1$
}
}
- String setterName = createDefaultMethodName(propertyName, "set"); //$NON-NLS-1$
+
+ setterName = createDefaultMethodName(propertyName, "set"); //$NON-NLS-1$
if (hasMethod(beanClass, setterName)) {
setWriteMethod(beanClass, setterName);
- } else {
- throw new IntrospectionException(Messages.getString("beans.20")); //$NON-NLS-1$
}
+
+ if (getter == null && setter == null) {
+ throw new IntrospectionException(Messages.getString(
+ "beans.01", propertyName)); //$NON-NLS-1$
+ }
+
}
public void setWriteMethod(Method setter) throws IntrospectionException {
@@ -260,20 +267,23 @@
Method[] findMethods(Class<?> aClass, String methodName) {
Method[] allMethods = aClass.getMethods();
Vector<Method> matchedMethods = new Vector<Method>();
+ Method[] result;
+
for (Method method : allMethods) {
if (method.getName().equals(methodName)) {
matchedMethods.add(method);
}
}
- Method[] result = new Method[matchedMethods.size()];
+ result = new Method[matchedMethods.size()];
for (int j = 0; j < matchedMethods.size(); ++j) {
result[j] = matchedMethods.elementAt(j);
}
+
return result;
}
- private void setReadMethod(Class<?> beanClass, String getterName) {
+ void setReadMethod(Class<?> beanClass, String getterName) {
boolean result = false;
Method[] getters = findMethods(beanClass, getterName);
@@ -291,7 +301,7 @@
}
}
- private void setWriteMethod(Class<?> beanClass, String setterName)
+ void setWriteMethod(Class<?> beanClass, String setterName)
throws IntrospectionException {
boolean result = false;
Modified: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/IntrospectorTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/IntrospectorTest.java?view=diff&rev=472854&r1=472853&r2=472854
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/IntrospectorTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/IntrospectorTest.java Thu Nov 9 02:50:30 2006
@@ -36,6 +36,7 @@
import java.util.TooManyListenersException;
import junit.framework.TestCase;
+import junit.framework.TestSuite;
import org.apache.harmony.beans.tests.support.ChildBean;
import org.apache.harmony.beans.tests.support.GrannyBean;
@@ -63,6 +64,12 @@
public class IntrospectorTest extends TestCase {
private String[] defaultPackage;
+
+ public IntrospectorTest(String str) {
+ super(str);
+ }
+
+ public IntrospectorTest() {}
@Override
protected void setUp() throws Exception {
@@ -1358,19 +1365,51 @@
public static class Bean3BeanInfo extends SimpleBeanInfo {
}
+ public void testGetPropertyDescriptors_H1838()
+ throws IntrospectionException {
+ // Regression for HARMONY-1838
+ PropertyDescriptor[] propertyDescriptors = Introspector.getBeanInfo(
+ Bean.class).getPropertyDescriptors();
+
+ for (PropertyDescriptor elem : propertyDescriptors) {
+ System.out.println("UUU " + elem.getName());
+ }
+ assertEquals("class", propertyDescriptors[0].getName());
+ assertEquals("prop1", propertyDescriptors[1].getName());
+ assertEquals("prop2", propertyDescriptors[2].getName());
+ assertEquals(3, propertyDescriptors.length);
+ }
+
+ public static class Bean {
+ public String getProp1(int i) {
+ return null;
+ }
+
+ public void setProp2(int i, String str) {
+ }
+ }
+
/*
*
*/
public void testGetPropertyDescriptors() throws IntrospectionException {
Class<Bean2> clazz = Bean2.class;
BeanInfo info = Introspector.getBeanInfo(clazz);
- // printInfo(info);
PropertyDescriptor[] pds = info.getPropertyDescriptors();
+
assertEquals(2, pds.length);
assertEquals("property1", pds[0].getName());
assertEquals("property8", pds[1].getName());
}
+ public static TestSuite suite() {
+// TestSuite suite = new TestSuite();
+ TestSuite suite = new TestSuite(IntrospectorTest.class);
+
+// suite.addTest(new IntrospectorTest("testGetPropertyDescriptors_H1838"));
+ return suite;
+ }
+
public static class Bean1 {
private int i;