Author: hlship
Date: Mon Nov  6 16:38:21 2006
New Revision: 471951

URL: http://svn.apache.org/viewvc?view=rev&rev=471951
Log:
Have a specific policy for what happens when an IoC module has more than one 
constructor.

Modified:
    
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/ioc/ModuleImpl.java

Modified: 
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/ioc/ModuleImpl.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/ioc/ModuleImpl.java?view=diff&rev=471951&r1=471950&r2=471951
==============================================================================
--- 
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/ioc/ModuleImpl.java
 (original)
+++ 
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/ioc/ModuleImpl.java
 Mon Nov  6 16:38:21 2006
@@ -24,7 +24,9 @@
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Modifier;
+import java.util.Arrays;
 import java.util.Collection;
+import java.util.Comparator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -262,15 +264,29 @@
                     _moduleDef.getModuleId(),
                     builderClass));
 
-        // Use the first one.
+        if (constructors.length > 1)
+        {
+            // Sort the constructors ascending by number of parameters 
(descending); this is really
+            // just to allow the test suite to work properly across different 
JVMs (which will
+            // often order the constructors differently).
+
+            Comparator<Constructor> comparator = new Comparator<Constructor>()
+            {
+                public int compare(Constructor c1, Constructor c2)
+                {
+                    return c2.getParameterTypes().length - 
c1.getParameterTypes().length;
+                }
+            };
 
-        Constructor constructor = constructors[0];
+            Arrays.sort(constructors, comparator);
 
-        if (constructors.length > 1)
             _log.warn(IOCMessages.tooManyPublicConstructors(
                     _moduleDef.getModuleId(),
                     builderClass,
-                    constructor));
+                    constructors[0]));
+        }
+
+        Constructor constructor = constructors[0];
 
         if (_insideConstructor)
             throw new 
RuntimeException(IOCMessages.recursiveModuleConstructor(_moduleDef


Reply via email to