Index: CoerceToDecimal.java
===================================================================
--- CoerceToDecimal.java	(revision 2649)
+++ CoerceToDecimal.java	(revision 2650)
@@ -28,6 +28,7 @@
 import java.text.ParsePosition;
 import java.util.Date;
 import java.util.Locale;
+import org.apache.commons.lang3.BooleanUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.gvsig.tools.dataTypes.AbstractCoercion;
 import org.gvsig.tools.dataTypes.Coercion;
@@ -42,106 +43,111 @@
 @SuppressWarnings("UseSpecificCatch")
 public class CoerceToDecimal extends AbstractCoercion {
 
-  @Override
-  public Object coerce(Object value) throws CoercionException {
-    if (value == null || value instanceof BigDecimal) {
-      return value;
+    @Override
+    public Object coerce(Object value) throws CoercionException {
+        if (value == null || value instanceof BigDecimal) {
+            return value;
+        }
+        return coerce(value, DataTypeUtils.coerceContextDefaultDecimal());
     }
-    return coerce(value, DataTypeUtils.coerceContextDefaultDecimal());
-  }
 
-  @Override
-  public Object coerce(Object value, CoercionContext context) throws CoercionException {
-    if (value == null ) {
-      return value;
-    }
-    CoercionContextDecimal theContext;
-    if (context instanceof CoercionContextDecimal) {
-      theContext = (CoercionContextDecimal) context;
-    } else {
-      if (context instanceof CoercionContextLocale) {
-        theContext = DataTypeUtils.coerceContextDecimal(((CoercionContextLocale) context).locale());
-      } else {
-        theContext = DataTypeUtils.coerceContextDefaultDecimal();
-      }
-    }
-    BigDecimal num;
-    try {
-      if (value instanceof BigDecimal) {
-        num = (BigDecimal) value;
-        
-      } else if (value instanceof Number) {
-        num = new BigDecimal(((Number) value).doubleValue(), theContext.getMathContext());
+    @Override
+    public Object coerce(Object value, CoercionContext context) throws CoercionException {
+        if (value == null) {
+            return value;
+        }
+        CoercionContextDecimal theContext;
+        if (context instanceof CoercionContextDecimal) {
+            theContext = (CoercionContextDecimal) context;
+        } else {
+            if (context instanceof CoercionContextLocale) {
+                theContext = DataTypeUtils.coerceContextDecimal(((CoercionContextLocale) context).locale());
+            } else {
+                theContext = DataTypeUtils.coerceContextDefaultDecimal();
+            }
+        }
+        BigDecimal num;
+        try {
+            if (value instanceof BigDecimal) {
+                num = (BigDecimal) value;
 
-      } else if (value instanceof Boolean) {
-        num = new BigDecimal((boolean) value ? 1 : 0, theContext.getMathContext());
-        
-      } else if (value instanceof Date) {
-        num = new BigDecimal(((Date) value).getTime(), theContext.getMathContext());
+            } else if (value instanceof Number) {
+                num = new BigDecimal(((Number) value).doubleValue(), theContext.getMathContext());
 
-      } else {
-        String s = value.toString().trim().toLowerCase();
-        if (StringUtils.isBlank(s)) {
-          return null;
-        }
-        if (s.startsWith("0x")) {
-          num = new BigDecimal(Long.parseLong(s.substring(2), 16), theContext.getMathContext());
+            } else if (value instanceof Boolean) {
+                num = new BigDecimal((boolean) value ? 1 : 0, theContext.getMathContext());
 
-        } else {
-          if (s.startsWith("+")) {
-            s = s.substring(1);
-          }
-          ParsePosition p = new ParsePosition(0);
-          DecimalFormat nf = (DecimalFormat) NumberFormat.getInstance(theContext.locale());
-          nf.setParseBigDecimal(true);
-          num = (BigDecimal) nf.parse(s, p);
-          if (p.getErrorIndex() > 0 || p.getIndex() < s.length()) {
-            throw new CoercionException("Can't coerce '" + s + "' to BigDecimal with locale " + theContext.locale().getLanguage() + "(error index " + p.getErrorIndex() + ", index " + p.getIndex() + ").");
-          }
+            } else if (value instanceof Date) {
+                num = new BigDecimal(((Date) value).getTime(), theContext.getMathContext());
+
+            } else {
+                String s = value.toString().trim().toLowerCase();
+                if (StringUtils.isBlank(s)) {
+                    return null;
+                }
+                if (s.startsWith("0x")) {
+                    num = new BigDecimal(Long.parseLong(s.substring(2), 16), theContext.getMathContext());
+
+                } else {
+                    Boolean bool = BooleanUtils.toBooleanObject(s);
+                    if (bool != null) {
+                        num = ((boolean) bool ? BigDecimal.ONE : BigDecimal.ZERO);
+                    } else {
+                        if (s.startsWith("+")) {
+                            s = s.substring(1);
+                        }
+                        ParsePosition p = new ParsePosition(0);
+                        DecimalFormat nf = (DecimalFormat) NumberFormat.getInstance(theContext.locale());
+                        nf.setParseBigDecimal(true);
+                        num = (BigDecimal) nf.parse(s, p);
+                        if (p.getErrorIndex() > 0 || p.getIndex() < s.length()) {
+                            throw new CoercionException("Can't coerce '" + s + "' to BigDecimal with locale " + theContext.locale().getLanguage() + "(error index " + p.getErrorIndex() + ", index " + p.getIndex() + ").");
+                        }
+                    }
+                }
+            }
+            if (theContext.hasScale() && num.scale() != theContext.scale()) {
+                // Ojo, que este set no es un set. Contruye un nuevo BigDecimal, no
+                // modifica el existente.
+                num = num.setScale(theContext.scale(), theContext.roundMode());
+            }
+            if (theContext.hasPrecision() && num.precision() > theContext.precision()) {
+                throw new ArithmeticException("Overflow");
+            }
+            return num;
+        } catch (CoercionException e) {
+            throw e;
+        } catch (Exception e) {
+            throw new CoercionException("Can't coerce '" + value.toString() + "' to BigDecimal with locale " + theContext.locale().getLanguage() + "'.", e);
         }
-      }
-      if( theContext.hasScale() && num.scale()!=theContext.scale()) {
-        // Ojo, que este set no es un set. Contruye un nuevo BigDecimal, no
-        // modifica el existente.
-        num = num.setScale(theContext.scale(), theContext.roundMode());
-      }
-      if( theContext.hasPrecision() && num.precision()>theContext.precision() ) {
-        throw new ArithmeticException("Overflow");
-      }
-      return num;
-    } catch (CoercionException e) {
-      throw e;
-    } catch (Exception e) {
-      throw new CoercionException("Can't coerce '" + value.toString() + "' to BigDecimal with locale " + theContext.locale().getLanguage() + "'.", e);
     }
-  }
 
-  private static BigDecimal toBigDecimal(Object value, int precision, int scale) throws CoercionException {
-      CoercionContextDecimalImpl context = new CoercionContextDecimalImpl(Locale.ENGLISH, precision, scale);
-      Coercion c = new CoerceToDecimal();              
-      BigDecimal x = (BigDecimal) c.coerce(value,context);
-      return x;
-  }
-  
-  public static void main(String[] args) throws CoercionException {
-    BigDecimal n;
+    private static BigDecimal toBigDecimal(Object value, int precision, int scale) throws CoercionException {
+        CoercionContextDecimalImpl context = new CoercionContextDecimalImpl(Locale.ENGLISH, precision, scale);
+        Coercion c = new CoerceToDecimal();
+        BigDecimal x = (BigDecimal) c.coerce(value, context);
+        return x;
+    }
 
-    n = toBigDecimal(1,6,3);
-    System.out.println("BigDecimal(1,6,3): "+n+"("+n.precision()+","+n.scale()+")");
+    public static void main(String[] args) throws CoercionException {
+        BigDecimal n;
 
-    n = toBigDecimal(10,6,3);
-    System.out.println("BigDecimal(10,6,3): "+n+"("+n.precision()+","+n.scale()+")");
+        n = toBigDecimal(1, 6, 3);
+        System.out.println("BigDecimal(1,6,3): " + n + "(" + n.precision() + "," + n.scale() + ")");
 
-    n = toBigDecimal(12.345,6,3);
-    System.out.println("BigDecimal(12.345,6,3): "+n+"("+n.precision()+","+n.scale()+")");
+        n = toBigDecimal(10, 6, 3);
+        System.out.println("BigDecimal(10,6,3): " + n + "(" + n.precision() + "," + n.scale() + ")");
 
-    n = toBigDecimal(-12.345,6,3);
-    System.out.println("BigDecimal(-12.345,6,3): "+n+"("+n.precision()+","+n.scale()+")");
+        n = toBigDecimal(12.345, 6, 3);
+        System.out.println("BigDecimal(12.345,6,3): " + n + "(" + n.precision() + "," + n.scale() + ")");
 
-    n = toBigDecimal(12.3457,6,3);
-    System.out.println("BigDecimal(12.3457,6,3): "+n+"("+n.precision()+","+n.scale()+")");
+        n = toBigDecimal(-12.345, 6, 3);
+        System.out.println("BigDecimal(-12.345,6,3): " + n + "(" + n.precision() + "," + n.scale() + ")");
 
-    n = toBigDecimal(120.3457,6,3);
-    System.out.println("BigDecimal(120.3457,6,3): "+n+"("+n.precision()+","+n.scale()+")");
-  }
+        n = toBigDecimal(12.3457, 6, 3);
+        System.out.println("BigDecimal(12.3457,6,3): " + n + "(" + n.precision() + "," + n.scale() + ")");
+
+        n = toBigDecimal(120.3457, 6, 3);
+        System.out.println("BigDecimal(120.3457,6,3): " + n + "(" + n.precision() + "," + n.scale() + ")");
+    }
 }
