Title: [waffle-scm] [745] trunk/waffle-core/src/test/java/org/codehaus/waffle/bind/ognl: Refactored OgnlValueConverter to not cache converters, for the moment.
Revision
745
Author
mauro
Date
2008-06-19 11:52:58 -0500 (Thu, 19 Jun 2008)

Log Message

Refactored OgnlValueConverter to not cache converters, for the moment.  Since new converters can be registered after instantiation, care needs to be taken to have a proper caching strategy, possibly using a caching library, such as ehcache.  Caching could be provided via decorating approach. 

Modified Paths

Diff

Modified: trunk/waffle-core/src/main/java/org/codehaus/waffle/bind/ognl/OgnlValueConverterFinder.java (744 => 745)

--- trunk/waffle-core/src/main/java/org/codehaus/waffle/bind/ognl/OgnlValueConverterFinder.java	2008-06-19 16:30:45 UTC (rev 744)
+++ trunk/waffle-core/src/main/java/org/codehaus/waffle/bind/ognl/OgnlValueConverterFinder.java	2008-06-19 16:52:58 UTC (rev 745)
@@ -7,9 +7,7 @@
 
 import java.lang.reflect.Type;
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 
 import org.codehaus.waffle.bind.ValueConverter;
 import org.codehaus.waffle.bind.ValueConverterFinder;
@@ -17,7 +15,7 @@
 
 /**
  * <p>
- * Implementation of <code>ValueConverterFinder</code> which caches converters found per type and uses
+ * Implementation of <code>ValueConverterFinder</code> which uses
  * <code>OgnlValueConverter</code> as default converter.
  * </p>
  * <p>
@@ -30,9 +28,10 @@
  */
 public class OgnlValueConverterFinder implements ValueConverterFinder {
 
-    private static final List<ValueConverter> DEFAULT_CONVERTERS = asList(new EnumValueConverter(), new OgnlValueConverter());
+    private static final OgnlValueConverter OGNL_VALUE_CONVERTER = new OgnlValueConverter();
+
+    private static final List<? extends ValueConverter> INITIAL_CONVERTERS = asList(new EnumValueConverter());
     
-    private final Map<Type, ValueConverter> cache = new HashMap<Type, ValueConverter>();
     private final List<ValueConverter> converters;
 
     public OgnlValueConverterFinder() {
@@ -43,26 +42,19 @@
         this.converters = new ArrayList<ValueConverter>();
         if (converters != null) {
             this.converters.addAll(asList(converters));
-            this.converters.addAll(DEFAULT_CONVERTERS);
+            this.converters.addAll(INITIAL_CONVERTERS);
         } else {
-            this.converters.addAll(DEFAULT_CONVERTERS);
+            this.converters.addAll(INITIAL_CONVERTERS);
         }
     }
 
     public ValueConverter findConverter(Type type) {
-        if (cache.containsKey(type)) { // cache hit
-            return cache.get(type);
-        }
-
         for (ValueConverter converter : converters) {
             if (converter.accept(type)) {
-                cache.put(type, converter);
                 return converter;
             }
         }
-
-        cache.put(type, null); // cache the null
-        return null;
+        return OGNL_VALUE_CONVERTER;
     }
 
     public void registerConverter(ValueConverter converter) {

Modified: trunk/waffle-core/src/test/java/org/codehaus/waffle/bind/ognl/DelegatingTypeConverterTest.java (744 => 745)

--- trunk/waffle-core/src/test/java/org/codehaus/waffle/bind/ognl/DelegatingTypeConverterTest.java	2008-06-19 16:30:45 UTC (rev 744)
+++ trunk/waffle-core/src/test/java/org/codehaus/waffle/bind/ognl/DelegatingTypeConverterTest.java	2008-06-19 16:52:58 UTC (rev 745)
@@ -68,11 +68,4 @@
         assertSame(controller, converter.convertValue("propertyName", "foobar", FakeControllerWithListMethods.class));
     }
 
-    @Test
-    public void canReturnValueIfNotConverterFoundForTypeThatIsNotAClass() throws IntrospectionException {
-        DelegatingTypeConverter converter = new DelegatingTypeConverter(new OgnlValueConverterFinder(), bindMonitor);
-        assertEquals("one,two", converter.convertValue("propertyName", "one,two", FakeControllerWithListMethods
-                .methodParameterType("listOfStrings")));
-    }
-
 }


To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Reply via email to