commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r1066839 - /commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/DigesterImpl.java
Date Thu, 03 Feb 2011 15:53:01 GMT
Author: simonetripodi
Date: Thu Feb  3 15:53:00 2011
New Revision: 1066839

URL: http://svn.apache.org/viewvc?rev=1066839&view=rev
Log:
added temporary implementation of method to lookup TypeConverter<T> instances

Modified:
    commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/DigesterImpl.java

Modified: commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/DigesterImpl.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/DigesterImpl.java?rev=1066839&r1=1066838&r2=1066839&view=diff
==============================================================================
--- commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/DigesterImpl.java
(original)
+++ commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/DigesterImpl.java
Thu Feb  3 15:53:00 2011
@@ -32,6 +32,8 @@ import java.util.List;
 import java.util.Map;
 import java.util.Stack;
 
+import org.apache.commons.beanutils.ConvertUtils;
+import org.apache.commons.beanutils.Converter;
 import org.apache.commons.digester3.spi.Rules;
 import org.apache.commons.digester3.spi.Substitutor;
 import org.apache.commons.digester3.spi.TypeConverter;
@@ -1230,9 +1232,30 @@ final class DigesterImpl implements Dige
     /**
      * {@inheritDoc}
      */
-    public <T> TypeConverter<T> lookupConverter(Class<T> type) {
-        // TODO empty for now
-        return null;
+    public <T> TypeConverter<T> lookupConverter(final Class<T> type) {
+        // TODO temporary implementation, will be changed for final version
+
+        final Converter converter = ConvertUtils.lookup(type);
+
+        if (converter == null) {
+            return null; // use check delegated to users
+        }
+
+        if (converter instanceof BeanUtilsConverterFacade) {
+            return (TypeConverter<T>) ((BeanUtilsConverterFacade) converter).getWrappedConverter();
+        }
+
+        return new TypeConverter<T>() {
+
+            public T convert(String value) {
+                Object result = converter.convert(type, value);
+                if (result == null) {
+                    return null;
+                }
+                return type.cast(result);
+            }
+
+        };
     }
 
 }



Mime
View raw message