harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r482307 - in /harmony/enhanced/classlib/trunk/modules/beans/src: main/java/java/beans/ main/java/org/apache/harmony/beans/internal/nls/ test/java/org/apache/harmony/beans/tests/java/beans/
Date Mon, 04 Dec 2006 19:32:09 GMT
Author: ayza
Date: Mon Dec  4 11:32:08 2006
New Revision: 482307

URL: http://svn.apache.org/viewvc?view=rev&rev=482307
Log:
Fixes for numerous bugs in EventSetDescriptor. Now all tests from EventSetDescriptorTest pass
on Harmony as well as on RI.

Modified:
    harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/BeanInfoImpl.java
    harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/EventSetDescriptor.java
    harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/internal/nls/messages.properties
    harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/EventSetDescriptorTest.java

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/BeanInfoImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/BeanInfoImpl.java?view=diff&rev=482307&r1=482306&r2=482307
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/BeanInfoImpl.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/BeanInfoImpl.java
Mon Dec  4 11:32:08 2006
@@ -50,10 +50,12 @@
 
     public PropertyDescriptor[] getPropertyDescriptors() {
         if (propertyDescriptors == null) {
-            HashMap<String, PropertyDescriptor> result = new HashMap<String, PropertyDescriptor>();
+            HashMap<String, PropertyDescriptor> result =
+                    new HashMap<String, PropertyDescriptor>();
 
             if (beanClass != null) {
-                List<Method> beanClassMethodsArrayList = getPublicMethods(beanClass);
+                List<Method> beanClassMethodsArrayList =
+                        getPublicMethods(beanClass);
 
                 ArrayList<Method> setters = new ArrayList<Method>();
                 ArrayList<Method> getters = new ArrayList<Method>();
@@ -126,7 +128,8 @@
 
     public EventSetDescriptor[] getEventSetDescriptors() {
         if (eventSetDescriptors == null) {
-            Map<String, EventSetDescriptor> result = new HashMap<String, EventSetDescriptor>();
+            Map<String, EventSetDescriptor> result =
+                    new HashMap<String, EventSetDescriptor>();
             List<Method> beanClassMethodsArrayList = getPublicMethods(beanClass);
 
             for (Method method : beanClassMethodsArrayList) {
@@ -159,14 +162,9 @@
                             // name and
                             // listener name extracted from registration method
                             // are the same
-                            int k = listenerTypeName.lastIndexOf('$');
-                            String listenerNameFromParam;
+                            String listenerNameFromParam =
+                                    extractShortClassName(listenerTypeName);
                             
-                            k = (k == -1 ?
-                                    listenerTypeName.lastIndexOf('.') : k);
-                            listenerNameFromParam = listenerTypeName
-                                    .substring(k + 1); //$NON-NLS-1$
-
                             String listenerNameFromMethod = listenerCoreName
                                     + "Listener"; //$NON-NLS-1$
 
@@ -179,7 +177,8 @@
                             // package (and encapsulating type if any) 
                             // with listener
                             String eventTypeName = listenerTypeName.substring(
-                                    0, k + 1) //$NON-NLS-1$
+                                    0, listenerTypeName.indexOf(
+                                            listenerNameFromParam))
                                     + listenerCoreName + "Event"; //$NON-NLS-1$
 
                             // classes generated from classes names
@@ -198,7 +197,8 @@
                             }
 
                             Method[] methods = listenerType.getMethods();
-                            Vector<Method> listenerMethodsVec = new Vector<Method>();
+                            Vector<Method> listenerMethodsVec =
+                                    new Vector<Method>();
                             for (Method element : methods) {
                                 Class<?>[] listenerMethodParams = element
                                         .getParameterTypes();
@@ -350,7 +350,8 @@
             throws Exception {
         String result = null;
 
-        if (methodName.startsWith("set") || methodName.startsWith("get")) { //$NON-NLS-1$
//$NON-NLS-2$
+        if (methodName.startsWith("set") //$NON-NLS-1$ 
+                || methodName.startsWith("get")) { //$NON-NLS-2$
             result = methodName.substring(3);
             result = Introspector.decapitalize(result);
         } else if (methodName.startsWith("is")) { //$NON-NLS-1$
@@ -451,6 +452,17 @@
         } // methods loop
     } // end of method
 
+    /**
+     * @param fullClassName full name of the class
+     * @return name with package and encapsulating class info omitted 
+     */
+    static String extractShortClassName(String fullClassName) {
+        int k = fullClassName.lastIndexOf('$');
+        
+        k = (k == -1 ? fullClassName.lastIndexOf('.') : k);
+        return fullClassName.substring(k + 1);
+    }
+    
     private Class<?> beanClass = null;
 
     private PropertyDescriptor[] propertyDescriptors = null;

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/EventSetDescriptor.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/EventSetDescriptor.java?view=diff&rev=482307&r1=482306&r2=482307
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/EventSetDescriptor.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/EventSetDescriptor.java
Mon Dec  4 11:32:08 2006
@@ -19,14 +19,15 @@
 
 import java.lang.reflect.Method;
 import java.util.ArrayList;
-import java.util.Iterator;
 import java.util.TooManyListenersException;
 import org.apache.harmony.beans.internal.nls.Messages;
 
 public class EventSetDescriptor extends FeatureDescriptor {
     private Class<?> listenerType;
 
-    private final ArrayList<MethodDescriptor> listenerMethodDescriptors = new ArrayList<MethodDescriptor>();
+    private ArrayList<MethodDescriptor> listenerMethodDescriptors;
+
+    private Method[] listenerMethods;
 
     private Method getListenerMethod;
 
@@ -38,112 +39,111 @@
 
     private boolean inDefaultEventSet = true;
 
-    public EventSetDescriptor(Class<?> sourceClass, String eventSetName, Class<?>
listenerType,
-            String listenerMethodName) throws IntrospectionException {
-        super();
-        if (eventSetName == null) {
-            throw new NullPointerException();
-        }
+    public EventSetDescriptor(Class<?> sourceClass, String eventSetName,
+            Class<?> listenerType, String listenerMethodName)
+            throws IntrospectionException {
+        Method m;
+
+        checkNotNull(sourceClass, eventSetName, listenerType,
+                listenerMethodName);
+
         setName(eventSetName);
         setDisplayName(eventSetName);
         this.listenerType = listenerType;
-        this.listenerMethodDescriptors.add(new MethodDescriptor(findMethodByName(listenerType,
-                listenerMethodName)));
-        this.addListenerMethod = findMethodByPrefix(sourceClass, "add", "", //$NON-NLS-1$
//$NON-NLS-2$
-                listenerType);
-        this.removeListenerMethod = findMethodByPrefix(sourceClass, "remove", //$NON-NLS-1$
-                "", listenerType); //$NON-NLS-1$
+        m = findListenerMethodByName(listenerMethodName);
+        checkEventType(eventSetName, m);
+        listenerMethodDescriptors = new ArrayList<MethodDescriptor>();
+        listenerMethodDescriptors.add(new MethodDescriptor(m));
+        addListenerMethod = findMethodByPrefix(
+                sourceClass, "add", ""); //$NON-NLS-1$ //$NON-NLS-2$
+        removeListenerMethod = findMethodByPrefix(
+                sourceClass, "remove", ""); //$NON-NLS-1$ //$NON-NLS-2$
+
         if (addListenerMethod == null && removeListenerMethod == null) {
-            throw new IntrospectionException(Messages.getString("beans.38")); //$NON-NLS-1$
+            throw new IntrospectionException(
+                    Messages.getString("beans.38")); //$NON-NLS-1$
         }
-        this.getListenerMethod = findMethodByPrefix(sourceClass, "get", "s", //$NON-NLS-1$
//$NON-NLS-2$
-                listenerType);
-        this.unicast = isUnicastByDefault(addListenerMethod);
+
+        getListenerMethod = findMethodByPrefix(
+                sourceClass, "get", "s"); //$NON-NLS-1$ //$NON-NLS-2$
+        unicast = isUnicastByDefault(addListenerMethod);
+    }
+
+    public EventSetDescriptor(Class<?> sourceClass, String eventSetName,
+            Class<?> listenerType, String[] listenerMethodNames,
+            String addListenerMethodName, String removeListenerMethodName)
+            throws IntrospectionException {
+        this(sourceClass, eventSetName, listenerType,
+                listenerMethodNames, addListenerMethodName,
+                removeListenerMethodName, null);
+        
     }
 
-    public EventSetDescriptor(Class<?> sourceClass, String eventSetName, Class<?>
listenerType,
-            String[] listenerMethodNames, String addListenerMethodName,
-            String removeListenerMethodName) throws IntrospectionException {
-        super();
+    public EventSetDescriptor(Class<?> sourceClass, String eventSetName,
+            Class<?> listenerType, String[] listenerMethodNames,
+            String addListenerMethodName, String removeListenerMethodName,
+            String getListenerMethodName) throws IntrospectionException {
+
+        checkNotNull(sourceClass, eventSetName, listenerType,
+                listenerMethodNames);
+
         setName(eventSetName);
         setDisplayName(eventSetName);
         this.listenerType = listenerType;
-        if (listenerMethodNames == null) {
-            throw new NullPointerException();
-        }
+
+        listenerMethodDescriptors = new ArrayList<MethodDescriptor>();
         for (String element : listenerMethodNames) {
-            try {
-                listenerMethodDescriptors.add(new MethodDescriptor(findMethodByName(
-                        listenerType, element)));
-            } catch (IntrospectionException ie) {
-                listenerMethodDescriptors.clear();
-                throw ie;
-            }
+            Method m = findListenerMethodByName(element);
+
+            checkEventType(eventSetName, m);
+            listenerMethodDescriptors.add(new MethodDescriptor(m));
         }
-        this.addListenerMethod = findMethodByName(listenerType, addListenerMethodName);
-        this.removeListenerMethod = findMethodByName(listenerType, removeListenerMethodName);
-        this.getListenerMethod = null;
-        this.unicast = isUnicastByDefault(addListenerMethod);
-    }
 
-    public EventSetDescriptor(Class<?> sourceClass, String eventSetName, Class<?>
listenerType,
-            String[] listenerMethodNames, String addListenerMethodName,
-            String removeListenerMethodName, String getListenerMethodName)
-            throws IntrospectionException {
-        super();
-        setName(eventSetName);
-        setDisplayName(eventSetName);
-        this.listenerType = listenerType;
-        if (listenerMethodNames == null) {
-            throw new NullPointerException();
+        if (addListenerMethodName != null) {
+            this.addListenerMethod = findAddRemoveListenerMethod(
+                    sourceClass, addListenerMethodName);
         }
-        for (String element : listenerMethodNames) {
-            try {
-                listenerMethodDescriptors.add(new MethodDescriptor(findMethodByName(
-                        listenerType, element)));
-            } catch (IntrospectionException ie) {
-                listenerMethodDescriptors.clear();
-                throw ie;
-            }
+        if (removeListenerMethodName != null) {
+            this.removeListenerMethod = findAddRemoveListenerMethod(
+                    sourceClass, removeListenerMethodName);
+        }
+        if (getListenerMethodName != null) {
+            this.getListenerMethod = findGetListenerMethod(
+                    sourceClass, getListenerMethodName);
         }
-        this.addListenerMethod = findMethodByName(listenerType, addListenerMethodName);
-        this.removeListenerMethod = findMethodByName(listenerType, removeListenerMethodName);
-        this.getListenerMethod = findMethodByName(listenerType, getListenerMethodName);
         this.unicast = isUnicastByDefault(addListenerMethod);
     }
 
     public EventSetDescriptor(String eventSetName, Class<?> listenerType,
-            Method[] listenerMethods, Method addListenerMethod, Method removeListenerMethod)
-            throws IntrospectionException {
-        super();
-        setName(eventSetName);
-        setDisplayName(eventSetName);
-        this.listenerType = listenerType;
-        if (listenerMethods != null) {
-            for (Method element : listenerMethods) {
-                if (checkMethod(listenerType, element)) {
-                    this.listenerMethodDescriptors.add(new MethodDescriptor(element));
-                }
-            }
-        }
-        this.addListenerMethod = addListenerMethod;
-        this.removeListenerMethod = removeListenerMethod;
+            Method[] listenerMethods, Method addListenerMethod,
+            Method removeListenerMethod) throws IntrospectionException {
+        this(eventSetName, listenerType, listenerMethods, addListenerMethod,
+                removeListenerMethod, null);
     }
 
     public EventSetDescriptor(String eventSetName, Class<?> listenerType,
-            Method[] listenerMethods, Method addListenerMethod, Method removeListenerMethod,
-            Method getListenerMethod) throws IntrospectionException {
-        super();
+            Method[] listenerMethods, Method addListenerMethod,
+            Method removeListenerMethod, Method getListenerMethod)
+            throws IntrospectionException {
+
         setName(eventSetName);
         setDisplayName(eventSetName);
         this.listenerType = listenerType;
+
+        this.listenerMethods = listenerMethods;
         if (listenerMethods != null) {
+            listenerMethodDescriptors = new ArrayList<MethodDescriptor>();
+
             for (Method element : listenerMethods) {
+                // XXX do we need this check?
+                //checkEventType(eventSetName, element);
                 if (checkMethod(listenerType, element)) {
-                    this.listenerMethodDescriptors.add(new MethodDescriptor(element));
+                    this.listenerMethodDescriptors.add(
+                            new MethodDescriptor(element));
                 }
             }
         }
+
         this.addListenerMethod = addListenerMethod;
         this.removeListenerMethod = removeListenerMethod;
         this.getListenerMethod = getListenerMethod;
@@ -151,47 +151,106 @@
     }
 
     public EventSetDescriptor(String eventSetName, Class<?> listenerType,
-            MethodDescriptor[] listenerMethodDescriptors, Method addListenerMethod,
-            Method removeListenerMethod) throws IntrospectionException {
-        super();
-        setName(eventSetName);
-        setDisplayName(eventSetName);
-        this.listenerType = listenerType;
+            MethodDescriptor[] listenerMethodDescriptors,
+            Method addListenerMethod, Method removeListenerMethod)
+            throws IntrospectionException {
+        this(eventSetName, listenerType, null, addListenerMethod,
+                removeListenerMethod, null);
+
         if (listenerMethodDescriptors != null) {
+            this.listenerMethodDescriptors = new ArrayList<MethodDescriptor>();
+
             for (MethodDescriptor element : listenerMethodDescriptors) {
                 Method listenerMethod = element.getMethod();
+
+                // XXX
+                //checkEventType(eventSetName, listenerMethod);
                 if (checkMethod(listenerType, listenerMethod)) {
                     this.listenerMethodDescriptors.add(element);
                 }
             }
         }
-        this.addListenerMethod = addListenerMethod;
-        this.removeListenerMethod = removeListenerMethod;
-        this.getListenerMethod = null;
-        this.unicast = isUnicastByDefault(addListenerMethod);
     }
 
+    // ensures that there is no nulls
+    private void checkNotNull(Object sourceClass, Object eventSetName,
+            Object listenerType, Object listenerMethodName) {
+        if (sourceClass == null) {
+            throw new NullPointerException(Messages.getString("beans.0C"));
+        }
+        if (eventSetName == null) {
+            throw new NullPointerException(Messages.getString("beans.53"));
+        }
+        if (listenerType == null) {
+            throw new NullPointerException(Messages.getString("beans.54"));
+        }
+        if (listenerMethodName == null) {
+            throw new NullPointerException(Messages.getString("beans.52"));
+        }
+    }
+
+    /**
+     * Checks that given listener method has an argument of the valid type. 
+     * @param eventSetName event set name
+     * @param listenerMethod listener method
+     * @throws IntrospectionException if check fails
+     */
+    private static void checkEventType(String eventSetName,
+            Method listenerMethod) throws IntrospectionException {
+        Class<?>[] params = listenerMethod.getParameterTypes();
+        String firstParamTypeName = null;
+        String eventTypeName = prepareEventTypeName(eventSetName);
+        
+        if (params.length > 0) {
+            firstParamTypeName = BeanInfoImpl.extractShortClassName(
+                    params[0].getName());
+        }
+        
+        if (firstParamTypeName == null ||
+                !firstParamTypeName.equals(eventTypeName)) {
+            throw new IntrospectionException(
+                    Messages.getString("beans.51", //$NON-NLS-1$
+                            listenerMethod.getName(), eventTypeName));
+        }   
+    }
+    
+    private static String prepareEventTypeName(String eventSetName) {
+        StringBuilder sb = new StringBuilder();
+
+        if (eventSetName != null && eventSetName.length() > 0) {
+            sb.append(Character.toUpperCase(eventSetName.charAt(0)));
+            
+            if (eventSetName.length() > 1) {
+                sb.append(eventSetName.substring(1));
+            }
+        }
+
+        sb.append("Event"); //$NON-NLS-1$
+        return sb.toString();
+    }
+    
     public Method[] getListenerMethods() {
-        Method[] result = new Method[listenerMethodDescriptors.size()];
-        Iterator<MethodDescriptor> i = listenerMethodDescriptors.iterator();
-        int idx = 0;
-        while (i.hasNext()) {
-            MethodDescriptor md = i.next();
-            result[idx] = md.getMethod();
-            idx++;
+        int i = 0;
+
+        if (listenerMethods != null) {
+            return listenerMethods;
+        }
+
+        if (listenerMethodDescriptors != null) {
+            listenerMethods = new Method[listenerMethodDescriptors.size()];
+            for (MethodDescriptor md : listenerMethodDescriptors) {
+                listenerMethods[i++] = md.getMethod();
+            }
+            return listenerMethods;
         }
-        return result;
+
+        return null;
     }
 
     public MethodDescriptor[] getListenerMethodDescriptors() {
-        MethodDescriptor[] result = new MethodDescriptor[listenerMethodDescriptors.size()];
-        Iterator<MethodDescriptor> i = listenerMethodDescriptors.iterator();
-        int idx = 0;
-        while (i.hasNext()) {
-            result[idx] = i.next();
-            idx++;
-        }
-        return result;
+        return listenerMethodDescriptors == null ? null :
+                listenerMethodDescriptors.toArray(
+                       new MethodDescriptor[listenerMethodDescriptors.size()]);
     }
 
     public Method getRemoveListenerMethod() {
@@ -226,50 +285,98 @@
         return inDefaultEventSet;
     }
 
-    private Class<?> getEventType(Class<?> listenerType) throws ClassNotFoundException
{
+    /**
+     * @return type of event associated with the current event set descriptor
+     * @throws ClassNotFoundException if event class is not found
+     */
+    private Class<?> getEventType() throws ClassNotFoundException {
         String listenerTypeName = listenerType.getName();
-        int idx = listenerTypeName.lastIndexOf("Listener"); //$NON-NLS-1$
-        String eventTypeName = listenerTypeName;
-        if (idx != -1) {
-            eventTypeName = listenerTypeName.substring(0, idx) + "Event"; //$NON-NLS-1$
-        }
+        String prefix = listenerTypeName.substring(0,
+                listenerTypeName.indexOf(
+                        BeanInfoImpl.extractShortClassName(listenerTypeName)));
+        String eventTypeName = prefix + prepareEventTypeName(getName());
+        
         return Class.forName(eventTypeName, true, listenerType.getClassLoader());
     }
 
     private boolean checkMethod(Class<?> listenerType, Method listenerMethod)
             throws IntrospectionException {
-        if (listenerMethod != null
-                && !listenerMethod.getDeclaringClass().isAssignableFrom(listenerType))
{
+        if (listenerMethod != null && listenerType != null &&    
+            !listenerMethod.getDeclaringClass().isAssignableFrom(listenerType)) {
             throw new IntrospectionException(Messages.getString("beans.31", //$NON-NLS-1$
                     listenerMethod.getName(), listenerType.getName()));
         }
         return true;
     }
 
-    private Method findMethodByName(Class<?> listenerType, String listenerMethodName)
+    /**
+     * Searches for the method in listener that has the given name. Parameter
+     * check is also performed for found methods.
+     * @param listenerMethodName name of listener method
+     * @return found method if any
+     * @throws IntrospectionException if no method is found or other error
+     * has occured
+     */
+    private Method findListenerMethodByName(String listenerMethodName) 
             throws IntrospectionException {
         try {
-            return listenerType.getMethod(listenerMethodName,
-                    new Class[] { getEventType(listenerType) });
+            return listenerType.getMethod(listenerMethodName, getEventType());
         } catch (NoSuchMethodException nsme) {
-            throw new IntrospectionException(Messages.getString("beans.31", //$NON-NLS-1$
+            throw new IntrospectionException(Messages.getString(
+                    "beans.31", //$NON-NLS-1$
                     listenerMethodName, listenerType.getName()));
         } catch (ClassNotFoundException cnfe) {
             throw new IntrospectionException(Messages.getString(
                     "beans.32", listenerType.getName())); //$NON-NLS-1$
         }
     }
+    
+    /**
+     * Searches for {add|remove}Listener methods in the event source.
+     * Parameter check is also performed.
+     * @param sourceClass event source class
+     * @param methodName method name to search
+     * @return found method
+     * @throws IntrospectionException if no valid method found
+     */
+    private Method findAddRemoveListenerMethod(Class<?> sourceClass,
+            String methodName) throws IntrospectionException {
+        try {
+            return sourceClass.getMethod(methodName, listenerType);
+        } catch (Exception e) {
+            throw new IntrospectionException(
+                    Messages.getString("beans.31", //$NON-NLS-1$
+                            methodName, listenerType.getName()));
+        }
+    }
+
+    /**
+     * @param sourceClass class of event source
+     * @param methodName name of the custom getListeners() method
+     * @return found Method object for custom getListener or null if nothing
+     *  is found
+     */
+    private Method findGetListenerMethod(Class<?> sourceClass,
+            String methodName) {
+        try {
+            return sourceClass.getMethod(methodName);
+        } catch (Exception e) {
+            // RI keeps silence here and just retunrs null
+            return null;
+        }
+    }
+
+    private Method findMethodByPrefix(Class<?> sourceClass,
+            String prefix, String postfix) {
+        String shortName = BeanInfoImpl.extractShortClassName(
+                listenerType.getName());
+        String methodName = prefix + shortName + postfix;
 
-    private Method findMethodByPrefix(Class<?> sourceClass, String prefix, String postfix,
-            Class<?> listenerType) {
-        String fullName = listenerType.getName();
-        int idx = fullName.lastIndexOf("."); //$NON-NLS-1$
-        String methodName = prefix + fullName.substring(idx + 1) + postfix;
         try {
             if (prefix.equals("get")) { //$NON-NLS-1$
-                return sourceClass.getMethod(methodName, new Class[] {});
+                return sourceClass.getMethod(methodName);
             }
-            return sourceClass.getMethod(methodName, new Class[] { listenerType });
+            return sourceClass.getMethod(methodName, listenerType);
         } catch (NoSuchMethodException nsme) {
             return null;
         }
@@ -287,43 +394,46 @@
         return false;
     }
 
-    private static Method checkRegistrationMethod(Class<?> listenerType,
-            Method registrationMethod) throws IntrospectionException {
-        if (registrationMethod == null) {
-            return null;
-        }
-        Class<?> returnType = registrationMethod.getReturnType();
-        Class<?>[] parameterTypes;
-        if (returnType != void.class) {
-            throw new IntrospectionException(Messages.getString(
-                    "beans.33", registrationMethod.getName())); //$NON-NLS-1$
-        }
-        parameterTypes = registrationMethod.getParameterTypes();
-        if (parameterTypes == null || parameterTypes.length != 1) {
-            throw new IntrospectionException(Messages.getString(
-                    "beans.34", registrationMethod.getName())); //$NON-NLS-1$
-        } else if (parameterTypes[0] != listenerType) {
-            throw new IntrospectionException(Messages.getString(
-                    "beans.35", listenerType.getName())); //$NON-NLS-1$
-        } else {
-            return registrationMethod;
-        }
-    }
 
-    private static Method checkGetListenerMethod(Class<?> listenerType, Method getListenerMethod)
-            throws IntrospectionException {
-        if (getListenerMethod == null) {
-            return null;
-        }
-        Class<?>[] parameterTypes = getListenerMethod.getParameterTypes();
-        Class<?> returnType;
-        if (parameterTypes.length != 0) {
-            throw new IntrospectionException(Messages.getString("beans.36")); //$NON-NLS-1$
-        }
-        returnType = getListenerMethod.getReturnType();
-        if (returnType.isArray() && returnType.getComponentType() == listenerType)
{
-            return getListenerMethod;
-        }
-        throw new IntrospectionException(Messages.getString("beans.37")); //$NON-NLS-1$
-    }
+//TODO investigate, do we need the following code?
+
+//    private static Method checkRegistrationMethod(Class<?> listenerType,
+//            Method registrationMethod) throws IntrospectionException {
+//        if (registrationMethod == null) {
+//            return null;
+//        }
+//        Class<?> returnType = registrationMethod.getReturnType();
+//        Class<?>[] parameterTypes;
+//        if (returnType != void.class) {
+//            throw new IntrospectionException(Messages.getString(
+//                    "beans.33", registrationMethod.getName())); //$NON-NLS-1$
+//        }
+//        parameterTypes = registrationMethod.getParameterTypes();
+//        if (parameterTypes == null || parameterTypes.length != 1) {
+//            throw new IntrospectionException(Messages.getString(
+//                    "beans.34", registrationMethod.getName())); //$NON-NLS-1$
+//        } else if (parameterTypes[0] != listenerType) {
+//            throw new IntrospectionException(Messages.getString(
+//                    "beans.35", listenerType.getName())); //$NON-NLS-1$
+//        } else {
+//            return registrationMethod;
+//        }
+//    }
+
+//    private static Method checkGetListenerMethod(Class<?> listenerType, Method getListenerMethod)
+//            throws IntrospectionException {
+//        if (getListenerMethod == null) {
+//            return null;
+//        }
+//        Class<?>[] parameterTypes = getListenerMethod.getParameterTypes();
+//        Class<?> returnType;
+//        if (parameterTypes.length != 0) {
+//            throw new IntrospectionException(Messages.getString("beans.36")); //$NON-NLS-1$
+//        }
+//        returnType = getListenerMethod.getReturnType();
+//        if (returnType.isArray() && returnType.getComponentType() == listenerType)
{
+//            return getListenerMethod;
+//        }
+//        throw new IntrospectionException(Messages.getString("beans.37")); //$NON-NLS-1$
+//    }
 }

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/internal/nls/messages.properties
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/internal/nls/messages.properties?view=diff&rev=482307&r1=482306&r2=482307
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/internal/nls/messages.properties
(original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/internal/nls/messages.properties
Mon Dec  4 11:32:08 2006
@@ -64,7 +64,7 @@
 beans.2E=PropertyVetoException was thrown while removing a child: {0}; Original error message:{1}
 beans.2F=Target child is null
 beans.30=PropertyVetoException was thrown while adding a child: {0}; Original error message:{1}
-beans.31=No method "{0}" for {1} found.
+beans.31=No valid method {0} for {1} found.
 beans.32=Cannot acquire event type from {0} listener.
 beans.33={0} does not return <void>
 beans.34={0} should have a single input parameter
@@ -96,4 +96,7 @@
 beans.4E=stopClass is not ancestor of beanClass
 beans.4F=search path is null
 beans.50=not an indexed property
-
+beans.51=Listener method {0} should have parameter of type {1}
+beans.52=listenerMethodName(s) is null
+beans.53=eventSetName is null
+beans.54=listenerType is null

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/EventSetDescriptorTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/EventSetDescriptorTest.java?view=diff&rev=482307&r1=482306&r2=482307
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/EventSetDescriptorTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/EventSetDescriptorTest.java
Mon Dec  4 11:32:08 2006
@@ -25,6 +25,8 @@
 import java.lang.reflect.Method;
 
 import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
 
 import org.apache.harmony.beans.tests.support.OtherBean;
 import org.apache.harmony.beans.tests.support.SampleListener;
@@ -36,6 +38,21 @@
  * Unit test for EventSetDescriptor
  */
 public class EventSetDescriptorTest extends TestCase {
+    
+    public EventSetDescriptorTest() {}
+    
+    public EventSetDescriptorTest(String s) {
+        super(s);
+    }
+    
+    public static TestSuite suite() {
+//        TestSuite suite = new TestSuite();
+        TestSuite suite = new TestSuite(EventSetDescriptorTest.class);
+
+//        suite.addTest(new EventSetDescriptorTest(
+//                "testEventSetDescriptorClassStringClassString"));
+        return suite;
+    }
 
     /*
      * Class under test for void EventSetDescriptor(Class, String, Class,
@@ -78,11 +95,13 @@
         String listenerMethodName = eventSetName;
         Class<MockSourceClass> sourceClass = MockSourceClass.class;
         Class<?> listenerType = MockPropertyChangeListener.class;
+
         try {
             new EventSetDescriptor(sourceClass, "FFF", listenerType,
                     listenerMethodName);
             fail("Should throw IntrospectionException.");
         } catch (IntrospectionException e) {
+            // valid
         }
     }
 
@@ -130,8 +149,16 @@
         Class<MockSourceClass> sourceClass = MockSourceClass.class;
         Class<?> listenerType = MockPropertyChangeListener.class;
 
-        new EventSetDescriptor(sourceClass, "", listenerType,
-                listenerMethodName);
+        try {
+            // RI doesn't throw exception here but this doesn't really make
+            // much sense. Moreover, it is against the java.beans 
+            // package description: null values or empty Strings are not
+            // valid parameters unless explicitly stated
+            new EventSetDescriptor(sourceClass, "", listenerType,
+                    listenerMethodName);
+        } catch (IntrospectionException e) {
+            // valid
+        }
     }
 
     /*
@@ -145,6 +172,7 @@
         Class<?> listenerType = MockPropertyChangeListener.class;
         EventSetDescriptor esd = new EventSetDescriptor(sourceClass,
                 eventSetName, listenerType, listenerMethodName);
+
         assertEquals(listenerMethodName, esd.getListenerMethods()[0].getName());
     }
 
@@ -287,6 +315,8 @@
                 .getName());
         assertEquals(listenerMethodNames[1], esd.getListenerMethods()[1]
                 .getName());
+        assertEquals(MockPropertyChangeEvent.class, esd.getListenerMethods()[1]
+                .getParameterTypes()[0]);        
         assertEquals(2, esd.getListenerMethodDescriptors().length);
         assertEquals(listenerMethodNames[0],
                 esd.getListenerMethodDescriptors()[0].getMethod().getName());
@@ -377,30 +407,17 @@
         String addMethod = "addMockPropertyChangeListener";
         String removeMethod = "removeMockPropertyChangeListener";
 
-        EventSetDescriptor esd = new EventSetDescriptor(sourceClass,
-                eventSetName, listenerType, listenerMethodNames, addMethod,
-                removeMethod);
-        assertEquals(addMethod, esd.getAddListenerMethod().getName());
-        assertEquals(removeMethod, esd.getRemoveListenerMethod().getName());
-        assertNull(esd.getGetListenerMethod());
-        assertEquals(2, esd.getListenerMethods().length);
-        assertEquals(listenerMethodNames[0], esd.getListenerMethods()[0]
-                .getName());
-        assertEquals(listenerMethodNames[1], esd.getListenerMethods()[1]
-                .getName());
-        // ESD does not check parameter type.
-        assertEquals(MockPropertyChangeEvent.class, esd.getListenerMethods()[1]
-                .getParameterTypes()[0]);
-
-        assertEquals(2, esd.getListenerMethodDescriptors().length);
-        assertEquals(listenerMethodNames[0],
-                esd.getListenerMethodDescriptors()[0].getMethod().getName());
-        assertEquals(listenerMethodNames[1],
-                esd.getListenerMethodDescriptors()[1].getMethod().getName());
-
-        assertEquals(listenerType, esd.getListenerType());
-        assertTrue(esd.isInDefaultEventSet());
-        assertFalse(esd.isUnicast());
+        try {
+            // RI doesn't throw exception here but this
+            // is against the java.beans package description:
+            // null values or empty Strings are not
+            // valid parameters unless explicitly stated
+            EventSetDescriptor esd = new EventSetDescriptor(sourceClass,
+                    eventSetName, listenerType, listenerMethodNames, addMethod,
+                    removeMethod);            
+        } catch (IntrospectionException e) {
+            // valid
+        }
     }
 
     /*
@@ -613,7 +630,7 @@
         String addMethod = "addMockPropertyChangeListener";
         String removeMethod = "removeMockPropertyChangeListener";
         String getMethod = null;
-        ;
+
         EventSetDescriptor esd = new EventSetDescriptor(sourceClass,
                 eventSetName, listenerType, listenerMethodNames, addMethod,
                 removeMethod, getMethod);
@@ -675,6 +692,10 @@
         assertEquals(addMethod, esd.getAddListenerMethod());
         assertEquals(removeMethod, esd.getRemoveListenerMethod());
         assertNull(esd.getGetListenerMethod());
+
+        // RI reports true in the following assertion, so it returns exactly
+        // the same array as it was specified in the EventSetDescriptor
+        // construtor. 
         assertEquals(listenerMethods, esd.getListenerMethods());
 
         assertEquals(2, esd.getListenerMethodDescriptors().length);
@@ -713,7 +734,6 @@
         assertEquals(addMethod, esd.getAddListenerMethod());
         assertEquals(removeMethod, esd.getRemoveListenerMethod());
         assertNull(esd.getGetListenerMethod());
-        assertEquals(listenerMethods, esd.getListenerMethods());
 
         assertEquals(2, esd.getListenerMethodDescriptors().length);
         assertEquals(listenerMethods[0], esd.getListenerMethodDescriptors()[0]
@@ -736,21 +756,22 @@
         Class<?> listenerType = MockPropertyChangeListener.class;
         Method[] listenerMethods = new Method[] {
                 listenerType.getMethod("mockPropertyChange",
-                        new Class[] { MockPropertyChangeEvent.class }),
+                        MockPropertyChangeEvent.class),
                 listenerType.getMethod("mockPropertyChange2",
-                        new Class[] { MockPropertyChangeEvent.class }), };
+                        MockPropertyChangeEvent.class) };
         Class<MockSourceClass> sourceClass = MockSourceClass.class;
         Method addMethod = sourceClass.getMethod(
-                "addMockPropertyChangeListener", new Class[] { listenerType });
+                "addMockPropertyChangeListener", listenerType);
         Method removeMethod = sourceClass.getMethod(
-                "removeMockPropertyChangeListener",
-                new Class[] { listenerType });
+                "removeMockPropertyChangeListener", listenerType);
         EventSetDescriptor esd = new EventSetDescriptor(eventSetName,
                 listenerType, listenerMethods, addMethod, removeMethod);
 
         assertEquals(addMethod, esd.getAddListenerMethod());
         assertEquals(removeMethod, esd.getRemoveListenerMethod());
         assertNull(esd.getGetListenerMethod());
+
+        //RI asserts to true here
         assertEquals(listenerMethods, esd.getListenerMethods());
 
         assertEquals(2, esd.getListenerMethodDescriptors().length);
@@ -774,15 +795,14 @@
         Class<?> listenerType = MockPropertyChangeListener.class;
         Method[] listenerMethods = new Method[] {
                 listenerType.getMethod("mockPropertyChange",
-                        new Class[] { MockPropertyChangeEvent.class }),
+                        MockPropertyChangeEvent.class),
                 listenerType.getMethod("mockPropertyChange2",
-                        new Class[] { MockPropertyChangeEvent.class }), };
+                        MockPropertyChangeEvent.class) };
         Class<MockSourceClass> sourceClass = MockSourceClass.class;
         Method addMethod = sourceClass.getMethod(
-                "addMockPropertyChangeListener", new Class[] { listenerType });
+                "addMockPropertyChangeListener", listenerType);
         Method removeMethod = sourceClass.getMethod(
-                "removeMockPropertyChangeListener",
-                new Class[] { listenerType });
+                "removeMockPropertyChangeListener", listenerType);
         EventSetDescriptor esd = new EventSetDescriptor(eventSetName, null,
                 listenerMethods, addMethod, removeMethod);
 
@@ -811,10 +831,9 @@
         Class<?> listenerType = MockPropertyChangeListener.class;
         Class<MockSourceClass> sourceClass = MockSourceClass.class;
         Method addMethod = sourceClass.getMethod(
-                "addMockPropertyChangeListener", new Class[] { listenerType });
+                "addMockPropertyChangeListener", listenerType);
         Method removeMethod = sourceClass.getMethod(
-                "removeMockPropertyChangeListener",
-                new Class[] { listenerType });
+                "removeMockPropertyChangeListener", listenerType);
         EventSetDescriptor esd = new EventSetDescriptor(eventSetName,
                 listenerType, (Method[]) null, addMethod, removeMethod);
 
@@ -1031,18 +1050,17 @@
         Class<?> listenerType = MockPropertyChangeListener.class;
         Method[] listenerMethods = {
                 listenerType.getMethod("mockPropertyChange",
-                        new Class[] { MockPropertyChangeEvent.class }),
+                        MockPropertyChangeEvent.class),
                 listenerType.getMethod("mockPropertyChange2",
-                        new Class[] { MockPropertyChangeEvent.class }), };
+                        MockPropertyChangeEvent.class)};
         MethodDescriptor[] listenerMethodDescriptors = {
                 new MethodDescriptor(listenerMethods[0]),
                 new MethodDescriptor(listenerMethods[1]), };
         Class<MockSourceClass> sourceClass = MockSourceClass.class;
         Method addMethod = sourceClass.getMethod(
-                "addMockPropertyChangeListener", new Class[] { listenerType });
+                "addMockPropertyChangeListener", listenerType);
         Method removeMethod = sourceClass.getMethod(
-                "removeMockPropertyChangeListener",
-                new Class[] { listenerType });
+                "removeMockPropertyChangeListener", listenerType);
 
         EventSetDescriptor esd = new EventSetDescriptor(eventSetName,
                 listenerType, listenerMethodDescriptors, addMethod,
@@ -1075,10 +1093,9 @@
 
         Class<MockSourceClass> sourceClass = MockSourceClass.class;
         Method addMethod = sourceClass.getMethod(
-                "addMockPropertyChangeListener", new Class[] { listenerType });
+                "addMockPropertyChangeListener", listenerType);
         Method removeMethod = sourceClass.getMethod(
-                "removeMockPropertyChangeListener",
-                new Class[] { listenerType });
+                "removeMockPropertyChangeListener", listenerType);
 
         EventSetDescriptor esd = new EventSetDescriptor(eventSetName,
                 listenerType, (MethodDescriptor[]) null, addMethod,
@@ -1098,22 +1115,22 @@
         Class<?> listenerType = MockPropertyChangeListener.class;
         Method[] listenerMethods = {
                 listenerType.getMethod("mockPropertyChange",
-                        new Class[] { MockPropertyChangeEvent.class }),
-                listenerType.getMethod("mockPropertyChange_Invalid",
-                        (Class[]) null), };
+                        MockPropertyChangeEvent.class),
+                listenerType.getMethod("mockPropertyChange_Invalid") };
         MethodDescriptor[] listenerMethodDescriptors = {
                 new MethodDescriptor(listenerMethods[0]),
-                new MethodDescriptor(listenerMethods[1]), };
+                new MethodDescriptor(listenerMethods[1]) };
         Class<MockSourceClass> sourceClass = MockSourceClass.class;
         Method addMethod = sourceClass.getMethod(
-                "addMockPropertyChangeListener", new Class[] { listenerType });
+                "addMockPropertyChangeListener", listenerType);
         Method removeMethod = sourceClass.getMethod(
-                "removeMockPropertyChangeListener",
-                new Class[] { listenerType });
+                "removeMockPropertyChangeListener", listenerType);
 
+        // RI doesn't check parameters of listener methods
         EventSetDescriptor esd = new EventSetDescriptor(eventSetName,
                 listenerType, listenerMethodDescriptors, addMethod,
                 removeMethod);
+
         assertEquals(0, esd.getListenerMethods()[1].getParameterTypes().length);
         assertEquals(listenerMethodDescriptors[1], esd
                 .getListenerMethodDescriptors()[1]);
@@ -1125,18 +1142,17 @@
         Class<?> listenerType = MockPropertyChangeListener.class;
         Method[] listenerMethods = {
                 listenerType.getMethod("mockPropertyChange",
-                        new Class[] { MockPropertyChangeEvent.class }),
+                        MockPropertyChangeEvent.class),
                 listenerType.getMethod("mockPropertyChange2",
-                        new Class[] { MockPropertyChangeEvent.class }), };
+                        MockPropertyChangeEvent.class) };
         MethodDescriptor[] listenerMethodDescriptors = {
                 new MethodDescriptor(listenerMethods[0]),
                 new MethodDescriptor(listenerMethods[1]), };
         Class<MockSourceClass> sourceClass = MockSourceClass.class;
         Method addMethod = sourceClass.getMethod(
-                "addMockPropertyChangeListener", new Class[] { listenerType });
+                "addMockPropertyChangeListener", listenerType);
         Method removeMethod = sourceClass.getMethod(
-                "removeMockPropertyChangeListener",
-                new Class[] { listenerType });
+                "removeMockPropertyChangeListener", listenerType);
 
         EventSetDescriptor esd = new EventSetDescriptor(eventSetName,
                 listenerType, listenerMethodDescriptors, addMethod,
@@ -1205,18 +1221,17 @@
         Class<?> listenerType = MockPropertyChangeListener.class;
         Method[] listenerMethods = {
                 listenerType.getMethod("mockPropertyChange",
-                        new Class[] { MockPropertyChangeEvent.class }),
+                        MockPropertyChangeEvent.class),
                 listenerType.getMethod("mockPropertyChange2",
-                        new Class[] { MockPropertyChangeEvent.class }), };
+                        MockPropertyChangeEvent.class) };
         MethodDescriptor[] listenerMethodDescriptors = {
                 new MethodDescriptor(listenerMethods[0]),
                 new MethodDescriptor(listenerMethods[1]), };
         Class<MockSourceClass> sourceClass = MockSourceClass.class;
         Method addMethod = sourceClass.getMethod(
-                "addMockPropertyChangeListener", new Class[] { listenerType });
+                "addMockPropertyChangeListener",listenerType);
         Method removeMethod = sourceClass.getMethod(
-                "removeMockPropertyChangeListener",
-                new Class[] { listenerType });
+                "removeMockPropertyChangeListener", listenerType);
 
         EventSetDescriptor esd = new EventSetDescriptor(eventSetName,
                 listenerType, listenerMethodDescriptors, addMethod,



Mime
View raw message