Author: michiel
Date: 2009-06-02 23:57:49 +0200 (Tue, 02 Jun 2009)
New Revision: 35587

Modified:
   mmbase/trunk/src/org/mmbase/datatypes/BooleanDataType.java
Log:
cast also e.g. a collection of one string ['true'] or so

Modified: mmbase/trunk/src/org/mmbase/datatypes/BooleanDataType.java
===================================================================
--- mmbase/trunk/src/org/mmbase/datatypes/BooleanDataType.java  2009-06-02 
21:54:01 UTC (rev 35586)
+++ mmbase/trunk/src/org/mmbase/datatypes/BooleanDataType.java  2009-06-02 
21:57:49 UTC (rev 35587)
@@ -18,7 +18,7 @@
  */
 public class BooleanDataType extends BasicDataType<Boolean> {
 
-    private static final long serialVersionUID = 1L; 
+    private static final long serialVersionUID = 1L;
 
     /**
      * Constructor for a boolean datatype (either a primitive boolean type or 
the Boolean class).
@@ -52,21 +52,19 @@
         Object preCast = preCast(value, cloud, node, field);
         if (preCast == null) return null;
         if (value instanceof Boolean) return (Boolean) value;
-        if (value instanceof String) {
-            String s = ((String)value).toLowerCase();
-            if ("".equals(value)) return null;
-            if ("true".equals(s)) return Boolean.TRUE;
-            if ("false".equals(s)) return Boolean.FALSE;
-            if ("1".equals(s)) return Boolean.TRUE;
-            if ("0".equals(s)) return Boolean.FALSE;
-            throw new CastException("'" + value + "' of type " + 
value.getClass().getName() + "  cannot be cast to boolean");
-        }
+
         if (value instanceof Number) {
             double d = ((Number) value).doubleValue();
             if (d == 1.0) return Boolean.TRUE;
             if (d == 0.0) return Boolean.FALSE;
             throw new CastException("The number '" + value + "' cannot be cast 
to boolean (boolean is 0 or 1)");
         }
-        throw new CastException("'" + value + "' cannot be cast to boolean 
(boolean is 0 or 1)");
+        String s = org.mmbase.util.Casting.toString(value).toLowerCase();
+        if ("".equals(s)) return null;
+        if ("true".equals(s)) return Boolean.TRUE;
+        if ("false".equals(s)) return Boolean.FALSE;
+        if ("1".equals(s)) return Boolean.TRUE;
+        if ("0".equals(s)) return Boolean.FALSE;
+        throw new CastException("'" + value + "' of type " + 
value.getClass().getName() + "  cannot be cast to boolean");
     }
 }

_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs

Reply via email to