harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r549863 - in /harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans: BeanInfoWrapper.java Introspector.java
Date Fri, 22 Jun 2007 16:24:15 GMT
Author: ayza
Date: Fri Jun 22 09:24:07 2007
New Revision: 549863

URL: http://svn.apache.org/viewvc?view=rev&rev=549863
Log:
Applying patch from HARMONY-4049 ([classlib][beans] Compatibility: java.beans.Introspector
calculates default event index for a bean in a different way)

Modified:
    harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/BeanInfoWrapper.java
    harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/Introspector.java

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/BeanInfoWrapper.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/BeanInfoWrapper.java?view=diff&rev=549863&r1=549862&r2=549863
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/BeanInfoWrapper.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/BeanInfoWrapper.java
Fri Jun 22 09:24:07 2007
@@ -35,6 +35,10 @@
     private BeanInfoImpl impl;
 
     private BeanInfoWrapper parentBeanInfoWrapper;
+    
+    private int defaultEventIndex = -1;
+    
+    private EventSetDescriptor[] events = null;
 
     public BeanInfoWrapper(BeanInfo info, BeanInfoImpl impl) {
         this.info = info;
@@ -151,12 +155,22 @@
     public EventSetDescriptor[] getEventSetDescriptors() {
         EventSetDescriptor[] result = null;
         EventSetDescriptor[] infoResult = null;
+        String defaultEventName = null;
 
+        if (events != null) {
+        	return events;
+        }
+        
         if (info != null) {
             BeanInfo[] infos = info.getAdditionalBeanInfo();
+            int defIndex = info.getDefaultEventIndex();
 
             infoResult = info.getEventSetDescriptors();
 
+            if (defIndex >= 0 && defIndex < infoResult.length) {
+                defaultEventName = infoResult[defIndex].getName();
+            }
+
             if (infos != null) {
                 for (BeanInfo additionalInfo : infos) {
                     if (infoResult == null) {
@@ -171,23 +185,26 @@
 
         if (info == null || infoResult == null) {
             EventSetDescriptor[] implResult = impl.getEventSetDescriptors();
-
+            
             // merge with parent info
             if (parentBeanInfoWrapper != null) {
                 EventSetDescriptor[] parentResult = parentBeanInfoWrapper
                         .getEventSetDescriptors();
-                Map<String, FeatureDescriptor> hm = concatArraysUniqueByName(
-                        implResult, parentResult);
+                Map<String, FeatureDescriptor> hm;
+                Collection<FeatureDescriptor> values;
 
-                Collection<FeatureDescriptor> values = hm.values();
-                int idx = 0;
-
-                result = new EventSetDescriptor[values.size()];
-                
-                for (FeatureDescriptor fd : values) {
-                    result[idx++] = (EventSetDescriptor) fd;
+                if (defaultEventName == null) {
+                	int parentDefaultIdx = parentBeanInfoWrapper.getDefaultEventIndex();
+                	
+                	if (parentDefaultIdx >= 0 &&
+                			parentDefaultIdx < parentResult.length) {
+                		defaultEventName = parentResult[parentDefaultIdx].getName();
+                	}
                 }
 
+                hm = concatArraysUniqueByName(implResult, parentResult);
+                result = hm.values().toArray(new EventSetDescriptor[hm.size()]);
+                
                 Arrays.sort(result, new Comparator<EventSetDescriptor>() {
                     public int compare(EventSetDescriptor esd1,
                             EventSetDescriptor esd2) {
@@ -206,6 +223,14 @@
             result = infoResult;
         }
 
+        if (defaultEventName != null) {
+            for (int i = 0; i < result.length; i++) {
+                if (result[i].getName().equals(defaultEventName)) {
+                    defaultEventIndex = i;
+                }
+            }
+        }
+        
         return result;
     }
 
@@ -256,15 +281,12 @@
     }
 
     public int getDefaultEventIndex() {
-        int result = -1;
-
-        if (info != null) {
-            result = info.getDefaultEventIndex();
-        } else if (parentBeanInfoWrapper != null) {
-            result = parentBeanInfoWrapper.getDefaultEventIndex();
-        }
 
-        return result;
+    	if (events == null) {
+            events = getEventSetDescriptors();
+    	} 
+    	
+    	return defaultEventIndex;
     }
 
     void setParentToMerge(BeanInfoWrapper parentBeanInfoWrapper) {

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/Introspector.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/Introspector.java?view=diff&rev=549863&r1=549862&r2=549863
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/Introspector.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/Introspector.java
Fri Jun 22 09:24:07 2007
@@ -162,7 +162,6 @@
         // ...
 
         wrapper = new BeanInfoWrapper(beanInfo, beanInfoImpl);
-
         parent = beanClass.getSuperclass();
         
         if (parent != null && parent != stopClass) {
@@ -176,7 +175,7 @@
 
         storeBeanInfoClassInCache(wrapper, beanClass, stopClass,
                 ignoreBeanClassBeanInfo, ignoreSuperClassBeanInfo);
-
+        
         return wrapper;
     }
 



Mime
View raw message