Revision: 677
          http://stripes.svn.sourceforge.net/stripes/?rev=677&view=rev
Author:   bengunter
Date:     2007-12-12 05:53:24 -0800 (Wed, 12 Dec 2007)

Log Message:
-----------
Only do a containsKey check (and possibly return null) for the target class 
itself. Never accept null as a best match for any of the target class's 
superclasses or interfaces. Instead, complete the search and then cache null 
for the target class if no best match is found.

Also added a recursive call to findFormatterClass so that the directly 
implemented interfaces of each superclass are considered at the time the 
superclass itself is considered. This means that if Z extends Y extends X and Y 
implements I and a formatter is registered for both X and I, then the I 
formatter will take precedence over the X formatter for Y and Z. (Simple, no?)

Modified Paths:
--------------
    
trunk/stripes/src/net/sourceforge/stripes/format/DefaultFormatterFactory.java

Modified: 
trunk/stripes/src/net/sourceforge/stripes/format/DefaultFormatterFactory.java
===================================================================
--- 
trunk/stripes/src/net/sourceforge/stripes/format/DefaultFormatterFactory.java   
    2007-12-12 12:57:21 UTC (rev 676)
+++ 
trunk/stripes/src/net/sourceforge/stripes/format/DefaultFormatterFactory.java   
    2007-12-12 13:53:24 UTC (rev 677)
@@ -134,29 +134,29 @@
             return classCache.get(targetClass);
 
         // Check directly implemented interfaces
+        Class<? extends Formatter<?>> formatterClass;
         for (Class<?> iface : targetClass.getInterfaces()) {
-            if (formatters.containsKey(iface))
-                return cacheFormatterClass(targetClass, formatters.get(iface));
-            else if (classCache.containsKey(iface))
-                return cacheFormatterClass(targetClass, classCache.get(iface));
+            if ((formatterClass = formatters.get(iface)) != null)
+                return cacheFormatterClass(targetClass, formatterClass);
+            else if ((formatterClass = classCache.get(iface)) != null)
+                return cacheFormatterClass(targetClass, formatterClass);
         }
 
         // Check superclasses
-        Class<?> parent = targetClass;
-        while ((parent = parent.getSuperclass()) != null) {
-            if (formatters.containsKey(parent))
-                return cacheFormatterClass(targetClass, 
formatters.get(parent));
-            else if (classCache.containsKey(parent))
-                return cacheFormatterClass(targetClass, 
classCache.get(parent));
+        Class<?> parent = targetClass.getSuperclass();
+        if (parent != null) {
+            if ((formatterClass = findFormatterClass(parent)) != null) {
+                return cacheFormatterClass(targetClass, formatterClass);
+            }
         }
 
         // Check superclasses of implemented interfaces
         for (Class<?> iface : targetClass.getInterfaces()) {
             for (Class<?> superiface : iface.getInterfaces()) {
-                if (formatters.containsKey(superiface))
-                    return cacheFormatterClass(targetClass, 
formatters.get(superiface));
-                else if (classCache.containsKey(superiface))
-                    return cacheFormatterClass(targetClass, 
classCache.get(superiface));
+                if ((formatterClass = formatters.get(superiface)) != null)
+                    return cacheFormatterClass(targetClass, formatterClass);
+                else if ((formatterClass = classCache.get(superiface)) != null)
+                    return cacheFormatterClass(targetClass, formatterClass);
             }
         }
 


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
SF.Net email is sponsored by: 
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Stripes-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-development

Reply via email to