geronimo-xbean-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dblev...@apache.org
Subject svn commit: r636209 - /geronimo/xbean/trunk/xbean-reflect/src/main/java/org/apache/xbean/propertyeditor/PropertyEditors.java
Date Wed, 12 Mar 2008 05:51:58 GMT
Author: dblevins
Date: Tue Mar 11 22:51:56 2008
New Revision: 636209

URL: http://svn.apache.org/viewvc?rev=636209&view=rev
Log:
Allow enum converters to be overriden by property editors

Modified:
    geronimo/xbean/trunk/xbean-reflect/src/main/java/org/apache/xbean/propertyeditor/PropertyEditors.java

Modified: geronimo/xbean/trunk/xbean-reflect/src/main/java/org/apache/xbean/propertyeditor/PropertyEditors.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-reflect/src/main/java/org/apache/xbean/propertyeditor/PropertyEditors.java?rev=636209&r1=636208&r2=636209&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-reflect/src/main/java/org/apache/xbean/propertyeditor/PropertyEditors.java
(original)
+++ geronimo/xbean/trunk/xbean-reflect/src/main/java/org/apache/xbean/propertyeditor/PropertyEditors.java
Tue Mar 11 22:51:56 2008
@@ -175,6 +175,11 @@
             return true;
         }
 
+        converter = findBuiltinConverter(type);
+        if (converter != null) {
+            return true;
+        }
+        
         return false;
     }
 
@@ -239,20 +244,39 @@
 
         // fall back to a property editor
         PropertyEditor editor = findEditor(type);
-        if (editor == null) {
+
+
+        if (editor != null) {// create the object value
+            editor.setAsText(value);
+            Object objectValue = null;
+            try {
+                objectValue = editor.getValue();
+            } catch (Exception e) {
+                throw new PropertyEditorException("Error while converting \"" + value + "\"
to a " + clazz.getSimpleName() +
+                        " using the property editor " + editor.getClass().getSimpleName(),
e);
+            }
+            return objectValue;
+        }
+
+        converter = findBuiltinConverter(type);
+
+        if (converter == null) {
             throw new PropertyEditorException("Unable to find PropertyEditor for " + clazz.getSimpleName());
         }
 
-        // create the object value
-        editor.setAsText(value);
-        Object objectValue = null;
-        try {
-            objectValue = editor.getValue();
-        } catch (Exception e) {
-            throw new PropertyEditorException("Error while converting \"" + value + "\" to
a " + clazz.getSimpleName() +
-                    " using the property editor " + editor.getClass().getSimpleName(), e);
+        return converter.toObject(value);
+    }
+
+    private static Converter findBuiltinConverter(Type type) {
+        if (type == null) throw new NullPointerException("type is null");
+
+        Class clazz = toClass(type);
+
+        if (Enum.class.isAssignableFrom(clazz)){
+            return new EnumConverter(clazz);
         }
-        return objectValue;
+
+        return null;       
     }
 
     private static Converter findConverter(Type type) {
@@ -298,7 +322,7 @@
                     return new GenericCollectionConverter(ArrayList.class, converter);
                 }
             }
-            
+
             return null;
         }
 
@@ -335,10 +359,6 @@
         // we're outta here if we got one.
         if (converter != null) {
             return converter;
-        }
-
-        if (Enum.class.isAssignableFrom(clazz)){
-            return new EnumConverter(clazz);
         }
 
         Class[] declaredClasses = clazz.getDeclaredClasses();



Mime
View raw message