Revision 2190 org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/dataTypes/DataTypeUtils.java

View differences:

DataTypeUtils.java
19 19
    }
20 20

  
21 21
    public static CoercionContextLocale coerceContextLocale(Locale locale) {
22
      return new CoercionContextLocaleImpl(locale);
22
      return CoercionContextLocale.create(locale);
23 23
    }
24 24
    
25 25
    public static CoercionContextLocale coerceContextDefaultLocale() {
26 26
      if( COERCE_CONTEXT_DEFAULT_LOCALE==null || 
27 27
          Locale.getDefault()!=COERCE_CONTEXT_DEFAULT_LOCALE.locale() ) {
28
        COERCE_CONTEXT_DEFAULT_LOCALE = new CoercionContextLocaleImpl(Locale.getDefault());
28
        COERCE_CONTEXT_DEFAULT_LOCALE = CoercionContextLocale.create(Locale.getDefault());
29 29
      }
30 30
      return COERCE_CONTEXT_DEFAULT_LOCALE;
31 31
    }
32 32
    
33 33
    public static CoercionContextDecimal coerceContextDefaultDecimal() {
34 34
      if( COERCE_CONTEXT_DEFAULT_DECIMAL==null ) {
35
        COERCE_CONTEXT_DEFAULT_DECIMAL = new CoercionContextDecimalImpl(
35
        COERCE_CONTEXT_DEFAULT_DECIMAL = CoercionContextDecimal.create(
36 36
                Locale.ENGLISH
37 37
        );
38 38
      }
......
44 44
          locale==COERCE_CONTEXT_DEFAULT_DECIMAL.locale() ) {
45 45
          return COERCE_CONTEXT_DEFAULT_DECIMAL;
46 46
      }
47
      return new CoercionContextDecimalImpl(locale);
47
      return CoercionContextDecimal.create(locale);
48 48
    }
49 49

  
50 50
    public static CoercionContextDecimal coerceContextDecimal(Locale locale, int precision, int scale, int roundMode) {
51
      return new CoercionContextDecimalImpl(locale,precision, scale, roundMode);
51
      return CoercionContextDecimal.create(locale,precision, scale, roundMode);
52 52
    }
53 53
    
54
    public static Object coerce(int type, Object value, Object defaultValue) {
54
    public static Coercion getCoercion(int type) {
55 55
        DataTypesManager manager = ToolsLocator.getDataTypesManager();
56 56
        DataType dataType = manager.get(type);
57
        Coercion c = dataType.getCoercion();
58
        return c;
59
    }
60
    
61
    public static Object coerce(int type, Object value, Object defaultValue) {
62
        Coercion coercer = getCoercion(type);
57 63
        try {
58
            Object x = dataType.coerce(value);
64
            Object x = coercer.coerce(value);
59 65
            if( x == null ) {
60 66
                return defaultValue;
61 67
            }
......
66 72
    }
67 73

  
68 74
    public static Object coerce(int type, Object value) throws CoercionException {
69
        DataTypesManager manager = ToolsLocator.getDataTypesManager();
70
        DataType dataType = manager.get(type);
71
        Object x = dataType.coerce(value);
75
        Coercion c = getCoercion(type);
76
        Object x = c.coerce(value);
72 77
        return x;
73 78
    }
74 79
    
......
145 150
    }
146 151
    
147 152
    public static BigDecimal toBigDecimal(Object value, int precision, int scale, BigDecimal defaultValue) {
148
      CoercionContextDecimalImpl context = new CoercionContextDecimalImpl(Locale.ENGLISH, precision, scale);
149
      DataTypesManager manager = ToolsLocator.getDataTypesManager();
150
      DataType dataType = manager.get(DataTypes.DECIMAL);
153
      CoercionContextDecimal context = CoercionContextDecimal.create(precision, scale);
154
      Coercion c = getCoercion(DataTypes.DECIMAL);
151 155
      try {
152
          BigDecimal x = (BigDecimal) dataType.coerce(value,context);
156
          BigDecimal x = (BigDecimal) c.coerce(value,context);
153 157
          if( x == null ) {
154 158
              return defaultValue;
155 159
          }

Also available in: Unified diff