harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zhouke...@apache.org
Subject svn commit: r943853 - in /harmony/enhanced/java/trunk/classlib/modules/beans/src: main/java/java/beans/Introspector.java test/java/org/apache/harmony/beans/tests/java/beans/IntrospectorTest.java
Date Thu, 13 May 2010 09:20:01 GMT
Author: zhoukevin
Date: Thu May 13 09:19:48 2010
New Revision: 943853

URL: http://svn.apache.org/viewvc?rev=943853&view=rev
Log:
Fix a defect of java.beans.Introspector class: If a class provides explicit BeanInfo about
itself then we add that to the BeanInfo information we obtained from analyzing any derived
classes. In addition, add a test case for recreation.

Modified:
    harmony/enhanced/java/trunk/classlib/modules/beans/src/main/java/java/beans/Introspector.java
    harmony/enhanced/java/trunk/classlib/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/IntrospectorTest.java

Modified: harmony/enhanced/java/trunk/classlib/modules/beans/src/main/java/java/beans/Introspector.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/beans/src/main/java/java/beans/Introspector.java?rev=943853&r1=943852&r2=943853&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/beans/src/main/java/java/beans/Introspector.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/beans/src/main/java/java/beans/Introspector.java
Thu May 13 09:19:48 2010
@@ -286,36 +286,42 @@ public class Introspector extends java.l
     }
 
     private static BeanInfo getExplicitBeanInfo(Class<?> beanClass) {
-        BeanInfo theBeanInfo = null;
         String beanInfoClassName = beanClass.getName() + "BeanInfo"; //$NON-NLS-1$
-        try{
-            theBeanInfo = loadBeanInfo(beanInfoClassName, beanClass);
-            return theBeanInfo;
-        }catch(Exception e){
-            //fall through
+        try {
+            return loadBeanInfo(beanInfoClassName, beanClass);
+        } catch (Exception e) {
+            // fall through
         }
+
         int index = beanInfoClassName.lastIndexOf('.');
-        String beanInfoName = index>=0? beanInfoClassName.substring(index+1):beanInfoClassName;
+        String beanInfoName = index >= 0 ? beanInfoClassName
+                .substring(index + 1) : beanInfoClassName;
+        BeanInfo theBeanInfo = null;
+        BeanDescriptor beanDescriptor = null;
         for (int i = 0; i < searchPath.length; i++) {
             beanInfoClassName = searchPath[i] + "." + beanInfoName; //$NON-NLS-1$
-            try{
+            try {
                 theBeanInfo = loadBeanInfo(beanInfoClassName, beanClass);
-                
-                // find the beanInfo of the given beanClass, check whether the
-                // beanInfo is consistent with the given beanClass
-                Class<?> beanClassOfBeanInfo = theBeanInfo.getBeanDescriptor()
-                        .getBeanClass();
-                if (beanClassOfBeanInfo.equals(beanClass)) {
-                    break;
-                } 
-            }catch(Exception e){
-                //ignore, try next one
+            } catch (Exception e) {
+                // ignore, try next one
+                continue;
+            }
+            beanDescriptor = theBeanInfo.getBeanDescriptor();
+            if (beanDescriptor != null
+                    && beanClass == beanDescriptor.getBeanClass()) {
+                return theBeanInfo;
             }
         }
-        return theBeanInfo;
+        if (BeanInfo.class.isAssignableFrom(beanClass)) {
+            try {
+                return loadBeanInfo(beanClass.getName(), beanClass);
+            } catch (Exception e) {
+                // fall through
+            }
+        }
+        return null;
     }
 
-
     /*
      * Method which attempts to instantiate a BeanInfo object of the supplied
      * classname

Modified: harmony/enhanced/java/trunk/classlib/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/IntrospectorTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/IntrospectorTest.java?rev=943853&r1=943852&r2=943853&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/IntrospectorTest.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/IntrospectorTest.java
Thu May 13 09:19:48 2010
@@ -450,7 +450,60 @@ public class IntrospectorTest extends Te
         } catch (IntrospectionException e) {
         }
     }
-    
+
+    /*
+     * BeanClass provide bean info about itself
+     */
+    public static class MockBeanInfo4BeanClassSelf implements BeanInfo {
+
+        public void setValue(String v) throws Exception {
+        }
+
+        public int getValue() {
+            return 0;
+        }
+
+        public BeanDescriptor getBeanDescriptor() {
+            return null;
+        }
+
+        public EventSetDescriptor[] getEventSetDescriptors() {
+            return new EventSetDescriptor[0];
+        }
+
+        public int getDefaultEventIndex() {
+            return -1;
+        }
+
+        public int getDefaultPropertyIndex() {
+            return -1;
+        }
+
+        public PropertyDescriptor[] getPropertyDescriptors() {
+            return new PropertyDescriptor[0];
+        }
+
+        public MethodDescriptor[] getMethodDescriptors() {
+            return new MethodDescriptor[0];
+        }
+
+        public BeanInfo[] getAdditionalBeanInfo() {
+            return null;
+        }
+
+        public Image getIcon(int iconKind) {
+            return null;
+        }
+    }
+
+    public void test_BeanInfo_Self() throws Exception {
+        BeanInfo info = Introspector
+                .getBeanInfo(MockBeanInfo4BeanClassSelf.class);
+        assertEquals(0, info.getMethodDescriptors().length);
+        assertEquals(0, info.getPropertyDescriptors().length);
+        assertEquals(0, info.getEventSetDescriptors().length);
+    }
+
     /*
      * Introspect static methods
      */



Mime
View raw message