Revision 2083

View differences:

org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/dataTypes/DataTypesManager.java
65 65

  
66 66
    public int addtype(int type, String subtype, String name,
67 67
        Class defaultClass, Coercion coercion, String iconName, 
68
        int max_precision, int default_precision, int default_scale);
68
        boolean fixedPrecision, int max_precision, 
69
        int default_precision, int default_scale);
69 70

  
70 71
    public Coercion getCoercion(int type);
71 72

  
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/dataTypes/DataType.java
98 98
  
99 99
  public boolean supportScale();
100 100

  
101
  public int getMaxPrecision();
102
  
103
  public int getDefaultPrecision();
104
  
105
  public int getDefaultScale();
106
  
107
  public boolean isFixedPrecision();
108
  
101 109
  public NumberPrecisionAndScale fixPrecisionAndScale(int precision, int scale);
102 110
}
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/dataTypes/impl/DefaultDataTypesManager.java
38 38
import org.gvsig.tools.dataTypes.Coercion;
39 39
import org.gvsig.tools.dataTypes.CoercionException;
40 40
import org.gvsig.tools.dataTypes.DataType;
41
import static org.gvsig.tools.dataTypes.DataType.BYTE_DEFAULT_PRECISION;
42
import static org.gvsig.tools.dataTypes.DataType.BYTE_MAX_PRECISION;
41 43
import static org.gvsig.tools.dataTypes.DataType.DECIMAL_DEFAULT_PRECISION;
42 44
import static org.gvsig.tools.dataTypes.DataType.DECIMAL_DEFAULT_SCALE;
43 45
import static org.gvsig.tools.dataTypes.DataType.DECIMAL_MAX_PRECISION;
......
47 49
import static org.gvsig.tools.dataTypes.DataType.FLOAT_DEFAULT_PRECISION;
48 50
import static org.gvsig.tools.dataTypes.DataType.FLOAT_DEFAULT_SCALE;
49 51
import static org.gvsig.tools.dataTypes.DataType.FLOAT_MAX_PRECISION;
52
import static org.gvsig.tools.dataTypes.DataType.INT_DEFAULT_PRECISION;
53
import static org.gvsig.tools.dataTypes.DataType.INT_MAX_PRECISION;
54
import static org.gvsig.tools.dataTypes.DataType.LONG_DEFAULT_PRECISION;
55
import static org.gvsig.tools.dataTypes.DataType.LONG_MAX_PRECISION;
50 56
import org.gvsig.tools.dataTypes.DataTypes;
51 57
import org.gvsig.tools.dataTypes.DataTypesManager;
58
import static org.gvsig.tools.dataTypes.impl.DefaultDataType.NO_SUPPORT_SCALE;
52 59
import org.gvsig.tools.dataTypes.impl.coercion.CoerceToDecimal;
53 60
import org.gvsig.tools.dataTypes.impl.coercion.CoerceToBoolean;
54 61
import org.gvsig.tools.dataTypes.impl.coercion.CoerceToByte;
......
72 79

  
73 80
public class DefaultDataTypesManager implements DataTypesManager, DataTypes {
74 81

  
75
    private static final Logger LOG = LoggerFactory
76
        .getLogger(DefaultDataTypesManager.class);
82
  private static final Logger LOG = LoggerFactory
83
          .getLogger(DefaultDataTypesManager.class);
77 84

  
78
    private static final int NEWINDEXES_AT = OBJECT + 1;
85
  private static final int NEWINDEXES_AT = OBJECT + 1;
79 86

  
80
    private final DataType[] types = new DefaultDataType[MAX_TYPE_VALUE];
87
  private final DataType[] types = new DefaultDataType[MAX_TYPE_VALUE];
81 88

  
82
    public DefaultDataTypesManager() {
83
        
84
        this.addtype(BOOLEAN, null, "Boolean", Boolean.class,
85
            new CoerceToBoolean(), "datatype-boolean");
86
        this.addtype(BYTE, null, "Byte", Byte.class, new CoerceToByte());
87
        this.addtype(CHAR, null, "Char", Character.class, new CoerceToString());
88
        this.addtype(INT, null, "Integer", Integer.class, new CoerceToInt(), "datatype-integer");
89
        this.addtype(LONG, null, "Long", Long.class, new CoerceToLong(),"datatype-long");
90
        this.addtype(FLOAT, null, "Float", Float.class, new CoerceToFloat(),"datatype-float", FLOAT_MAX_PRECISION, FLOAT_DEFAULT_PRECISION, FLOAT_DEFAULT_SCALE);
91
        this.addtype(DOUBLE, null, "Double", Double.class, new CoerceToDouble(),"datatype-double", DOUBLE_MAX_PRECISION, DOUBLE_DEFAULT_PRECISION, DOUBLE_DEFAULT_SCALE);
92
        this.addtype(DECIMAL, null, "Decimal", BigDecimal.class, new CoerceToDecimal(),"datatype-decimal",DECIMAL_MAX_PRECISION, DECIMAL_DEFAULT_PRECISION, DECIMAL_DEFAULT_SCALE);
93
        this.addtype(STRING, null, "String", String.class, new CoerceToString(), "datatype-string");
94
        this.addtype(DATE, SUBTYPE_DATE, "Date", Date.class, new CoerceToDate(),"datatype-date");
95
        this.addtype(TIME, SUBTYPE_DATE, "Time", Date.class, new CoerceToTime(),"datatype-time");
89
  public DefaultDataTypesManager() {
90

  
91
    this.addtype(BOOLEAN, null, "Boolean", Boolean.class, new CoerceToBoolean(), 
92
            "datatype-boolean"
93
    );
94
    this.addtype(BYTE, null, "Byte", Byte.class, new CoerceToByte(),
95
            "datatype-byte",
96
            true, BYTE_MAX_PRECISION, BYTE_DEFAULT_PRECISION
97
    );
98
    this.addtype(CHAR, null, "Char", Character.class, new CoerceToString());
99
    this.addtype(INT, null, "Integer", Integer.class, new CoerceToInt(), 
100
            "datatype-integer", 
101
            true, INT_MAX_PRECISION, INT_DEFAULT_PRECISION
102
    );
103
    this.addtype(LONG, null, "Long", Long.class, new CoerceToLong(), 
104
            "datatype-long", 
105
            true, LONG_MAX_PRECISION, LONG_DEFAULT_PRECISION
106
    );
107
    this.addtype(FLOAT, null, "Float", Float.class, new CoerceToFloat(), 
108
            "datatype-float", 
109
            false, FLOAT_MAX_PRECISION, FLOAT_DEFAULT_PRECISION, FLOAT_DEFAULT_SCALE
110
    );
111
    this.addtype(DOUBLE, null, "Double", Double.class, new CoerceToDouble(), 
112
            "datatype-double", 
113
            false, DOUBLE_MAX_PRECISION, DOUBLE_DEFAULT_PRECISION, DOUBLE_DEFAULT_SCALE
114
    );
115
    this.addtype(DECIMAL, null, "Decimal", BigDecimal.class, new CoerceToDecimal(), 
116
            "datatype-decimal", 
117
            false, DECIMAL_MAX_PRECISION, DECIMAL_DEFAULT_PRECISION, DECIMAL_DEFAULT_SCALE
118
    );
119
    this.addtype(STRING, null, "String", String.class, new CoerceToString(), "datatype-string");
120
    this.addtype(DATE, SUBTYPE_DATE, "Date", Date.class, new CoerceToDate(), "datatype-date");
121
    this.addtype(TIME, SUBTYPE_DATE, "Time", Date.class, new CoerceToTime(), "datatype-time");
96 122
//        this.addtype(TIMESTAMP, null, "Timestamp", Timestamp.class, new CoerceToTimestamp(),"datatype-timestamp");
97
        this.addtype(TIMESTAMP, null, "Timestamp", Date.class, new CoerceToDateTime(),"datatype-timestamp");
98
        this.addtype(VERSION, null, "Version", Version.class, new CoerceToVersion());
123
    this.addtype(TIMESTAMP, null, "Timestamp", Date.class, new CoerceToDateTime(), "datatype-timestamp");
124
    this.addtype(VERSION, null, "Version", Version.class, new CoerceToVersion());
99 125

  
100
        this.addtype(BYTEARRAY, null, "ByteArray", 
101
                (new byte[1]).getClass(), 
102
                new CoerceToBytearray(),
103
                "datatype-bytearray"
104
        );
105
        this.addtype(FILE, SUBTYPE_FILE, "File", File.class, new CoerceToFile());
106
        this.addtype(FOLDER, SUBTYPE_FOLDER, "Folder", File.class, new CoerceToFile());
107
        this.addtype(DYNOBJECT, null, "DynObject", DynObject.class, null);
108
        this.addtype(URL, null, "URL", URL.class, new CoerceToURL());
109
        this.addtype(URI, null, "URI", URI.class, new CoerceToURI());
126
    this.addtype(BYTEARRAY, null, "ByteArray",
127
            (new byte[1]).getClass(),
128
            new CoerceToBytearray(),
129
            "datatype-bytearray"
130
    );
131
    this.addtype(FILE, SUBTYPE_FILE, "File", File.class, new CoerceToFile());
132
    this.addtype(FOLDER, SUBTYPE_FOLDER, "Folder", File.class, new CoerceToFile());
133
    this.addtype(DYNOBJECT, null, "DynObject", DynObject.class, null);
134
    this.addtype(URL, null, "URL", URL.class, new CoerceToURL());
135
    this.addtype(URI, null, "URI", URI.class, new CoerceToURI());
110 136

  
111
        this.addtype(ARRAY, null, "Array", (new Object[1]).getClass(), null);
112
        this.addtype(LIST, null, "List", List.class, null);
113
        this.addtype(SET, null, "Set", Set.class, null);
114
        this.addtype(MAP, null, "Map", Map.class, null);
137
    this.addtype(ARRAY, null, "Array", (new Object[1]).getClass(), null);
138
    this.addtype(LIST, null, "List", List.class, null);
139
    this.addtype(SET, null, "Set", Set.class, null);
140
    this.addtype(MAP, null, "Map", Map.class, null);
115 141

  
116
        this.addtype(OBJECT, null, "Object", Object.class, new CoerceToObject(),"datatype-object");
117
    }
142
    this.addtype(OBJECT, null, "Object", Object.class, new CoerceToObject(), "datatype-object");
143
  }
118 144

  
119
    @Override
120
    public final synchronized int addtype(int type, String subtype, String name,
121
        Class defaultClass, Coercion coercion) {
122
        return addtype(type, subtype, name, defaultClass, coercion, null, 0, 0, 0);
123
    }
124
    
125
    public final synchronized int addtype(int type, String subtype, String name,
126
        Class defaultClass, Coercion coercion, String iconName) {
127
        return addtype(type, subtype, name, defaultClass, coercion, iconName, 0, 0, 0);
128
    }
129
    
130
    @Override
131
    public final synchronized int addtype(int type, String subtype, String name,
132
        Class defaultClass, Coercion coercion, String iconName, 
133
        int max_precision, int default_precision, int default_scale) {
134
        if (type == INVALID) {
135
            type = getNewObjectIndexType();
136
        }
137
        if (type < 1 || type > MAX_TYPE_VALUE) {
138
            throw new IllegalArgumentException("Wrong type "
139
                + Integer.toHexString(type).toUpperCase() + ".");
140
        }
145
  @Override
146
  public final synchronized int addtype(int type, String subtype, String name,
147
          Class defaultClass, Coercion coercion) {
148
    return addtype(type, subtype, name, defaultClass, coercion, null, false, 0, 0, 0);
149
  }
141 150

  
142
        try {
143
            // Check if the type has been already registereds
144
            get(type);
145
            throw new IllegalArgumentException("type "
146
                + Integer.toHexString(type).toUpperCase() + ", name " + name
147
                + ", already registered as " + getTypeName(type) + ".");
148
        } catch (IllegalArgumentException e) {
149
            // OK, the type is still not registered.
150
        }
151
  public final synchronized int addtype(int type, String subtype, String name,
152
          Class defaultClass, Coercion coercion, String iconName) {
153
    return addtype(type, subtype, name, defaultClass, coercion, iconName, false, 0, 0, 0);
154
  }
151 155

  
152
        DataType dataType = new DefaultDataType(
153
                type, subtype, name, defaultClass, coercion, iconName,
154
                max_precision, default_precision, default_scale
155
        );
156
        types[type] = dataType;
157
        LOG.info("Registered data type {}.", dataType.toString());
158
        return type;
156
  public final synchronized int addtype(int type, String subtype, String name,
157
          Class defaultClass, Coercion coercion, String iconName,
158
          boolean fixedPrecision, int max_precision, int default_precision) {
159
    return addtype(type, subtype, name, defaultClass, coercion, iconName,
160
            fixedPrecision, max_precision, default_precision, NO_SUPPORT_SCALE
161
    );
162
  }
163

  
164
  @Override
165
  public final synchronized int addtype(int type, String subtype, String name,
166
          Class defaultClass, Coercion coercion, String iconName,
167
          boolean fixedPrecision, int max_precision, int default_precision, int default_scale) {
168
    if (type == INVALID) {
169
      type = getNewObjectIndexType();
159 170
    }
171
    if (type < 1 || type > MAX_TYPE_VALUE) {
172
      throw new IllegalArgumentException("Wrong type "
173
              + Integer.toHexString(type).toUpperCase() + ".");
174
    }
160 175

  
161
    private int getNewObjectIndexType() {
162
        for (int i = NEWINDEXES_AT; i <= MAX_TYPE_VALUE; i++) {
163
            if (types[i] == null) {
164
                return i;
165
            }
166
        }
167
        return DataTypes.INVALID;
176
    try {
177
      // Check if the type has been already registereds
178
      get(type);
179
      throw new IllegalArgumentException("type "
180
              + Integer.toHexString(type).toUpperCase() + ", name " + name
181
              + ", already registered as " + getTypeName(type) + ".");
182
    } catch (IllegalArgumentException e) {
183
      // OK, the type is still not registered.
168 184
    }
169 185

  
170
    @Override
171
    public DataType get(int type) {
172
        DataType dataType = null;
173
        if (type > 0 && type <= MAX_TYPE_VALUE) {
174
            dataType = types[type];
175
        }
186
    DataType dataType = new DefaultDataType(
187
            type, subtype, name, defaultClass, coercion, iconName,
188
            fixedPrecision, max_precision, default_precision, default_scale
189
    );
190
    types[type] = dataType;
191
    LOG.info("Registered data type {}.", dataType.toString());
192
    return type;
193
  }
176 194

  
177
        if (dataType == null) {
178
            throw new IllegalArgumentException("DataType " + type
179
                + " not registered");
180
        }
181

  
182
        return dataType;
195
  private int getNewObjectIndexType() {
196
    for (int i = NEWINDEXES_AT; i <= MAX_TYPE_VALUE; i++) {
197
      if (types[i] == null) {
198
        return i;
199
      }
183 200
    }
201
    return DataTypes.INVALID;
202
  }
184 203

  
185
    @Override
186
    public boolean isValidType(int type) {
187
        return type > 0 && type <= MAX_TYPE_VALUE && this.types[type] != null;
204
  @Override
205
  public DataType get(int type) {
206
    DataType dataType = null;
207
    if (type > 0 && type <= MAX_TYPE_VALUE) {
208
      dataType = types[type];
188 209
    }
189 210

  
190
    @Override
191
    public boolean isObject(int type) {
192
        return (type & DataTypes.OBJECT) == DataTypes.OBJECT;
211
    if (dataType == null) {
212
      throw new IllegalArgumentException("DataType " + type
213
              + " not registered");
193 214
    }
194 215

  
195
    @Override
196
    public boolean isContainer(int type) {
197
        return (type & DataTypes.CONTAINER) == DataTypes.CONTAINER;
198
    }
216
    return dataType;
217
  }
199 218

  
200
    @Override
201
    public int getType(String name) {
202
        if (name != null) {
203
            for (int i = 0; i < types.length; i++) {
204
                if (types[i] != null
205
                    && name.equalsIgnoreCase(types[i].getName())) {
206
                    return i;
207
                }
208
            }
209
        }
210
        return DataTypes.INVALID;
211
    }
219
  @Override
220
  public boolean isValidType(int type) {
221
    return type > 0 && type <= MAX_TYPE_VALUE && this.types[type] != null;
222
  }
212 223

  
213
    @Override
214
    public String getTypeName(int type) {
215
        DataType dataType = get(type);
216
        String name = dataType.getName();
217
        if (name == null) {
218
            return "unknow";
224
  @Override
225
  public boolean isObject(int type) {
226
    return (type & DataTypes.OBJECT) == DataTypes.OBJECT;
227
  }
228

  
229
  @Override
230
  public boolean isContainer(int type) {
231
    return (type & DataTypes.CONTAINER) == DataTypes.CONTAINER;
232
  }
233

  
234
  @Override
235
  public int getType(String name) {
236
    if (name != null) {
237
      for (int i = 0; i < types.length; i++) {
238
        if (types[i] != null
239
                && name.equalsIgnoreCase(types[i].getName())) {
240
          return i;
219 241
        }
220
        return name;
242
      }
221 243
    }
244
    return DataTypes.INVALID;
245
  }
222 246

  
223
    @Override
224
    public Class getDefaultClass(int type) {
225
        DataType dataType = get(type);
226
        return dataType.getDefaultClass();
247
  @Override
248
  public String getTypeName(int type) {
249
    DataType dataType = get(type);
250
    String name = dataType.getName();
251
    if (name == null) {
252
      return "unknow";
227 253
    }
254
    return name;
255
  }
228 256

  
229
    @Override
230
    public String getSubtype(int type) {
231
        DataType dataType = get(type);
232
        return dataType.getSubtype();
233
    }
257
  @Override
258
  public Class getDefaultClass(int type) {
259
    DataType dataType = get(type);
260
    return dataType.getDefaultClass();
261
  }
234 262

  
235
    @Override
236
    public Coercion getCoercion(int type) {
237
        DataType dataType = get(type);
238
        return dataType.getCoercion();
239
    }
263
  @Override
264
  public String getSubtype(int type) {
265
    DataType dataType = get(type);
266
    return dataType.getSubtype();
267
  }
240 268

  
269
  @Override
270
  public Coercion getCoercion(int type) {
271
    DataType dataType = get(type);
272
    return dataType.getCoercion();
273
  }
274

  
241 275
//    @Override
242 276
//    public void setCoercion(int type, Coercion coercion) {
243 277
//        DataType dataType = get(type);
244 278
//        dataType.setCoercion(coercion);
245 279
//    }
280
  @Override
281
  public void addCoercion(int type, Coercion coercion) {
282
    DataType dataType = get(type);
283
    dataType.addCoercion(coercion);
284
  }
246 285

  
247
    @Override
248
    public void addCoercion(int type, Coercion coercion) {
249
        DataType dataType = get(type);
250
        dataType.addCoercion(coercion);
251
    }
286
  @Override
287
  public Object coerce(int type, Object value) throws CoercionException {
288
    DataType dataType = get(type);
289
    return dataType.coerce(value);
290
  }
252 291

  
253
    @Override
254
    public Object coerce(int type, Object value) throws CoercionException {
255
        DataType dataType = get(type);
256
        return dataType.coerce(value);
292
  @Override
293
  public Iterator iterator() {
294
    List list = new ArrayList();
295
    DataType type;
296
    for (int i = 0; i < this.types.length; i++) {
297
      type = this.types[i];
298
      if (type != null) {
299
        list.add(this.types[i]);
300
      }
257 301
    }
302
    return list.iterator();
303
  }
258 304

  
259
    @Override
260
    public Iterator iterator() {
261
        List list = new ArrayList();
262
        DataType type;
263
        for (int i = 0; i < this.types.length; i++) {
264
            type = this.types[i];
265
            if (type != null)
266
                list.add(this.types[i]);
305
  @Override
306
  public DataType getDataType(Class defaultClass) {
307
    // First look for a class with exact match
308
    for (DataType type : types) {
309
      if (type != null) {
310
        Class typeClass = type.getDefaultClass();
311
        if (typeClass != null && typeClass.equals(defaultClass)) {
312
          return type;
267 313
        }
268
        return list.iterator();
314
      }
269 315
    }
270

  
271
    @Override
272
    public DataType getDataType(Class defaultClass) {
273
        // First look for a class with exact match
274
        for (int i = 0; i < types.length; i++) {
275
            if (types[i] != null) {
276
                Class typeClass = types[i].getDefaultClass();
277
                if (typeClass != null && typeClass.equals(defaultClass)) {
278
                    return types[i];
279
                }
280
            }
316
    // Then look for a class which is an interface or parent
317
    for (DataType type : types) {
318
      if (type != null) {
319
        Class typeClass = type.getDefaultClass();
320
        if (typeClass != null
321
                && typeClass.isAssignableFrom(defaultClass)) {
322
          return type;
281 323
        }
282
        // Then look for a class which is an interface or parent
283
        for (int i = 0; i < types.length; i++) {
284
            if (types[i] != null) {
285
                Class typeClass = types[i].getDefaultClass();
286
                if (typeClass != null
287
                    && typeClass.isAssignableFrom(defaultClass)) {
288
                    return types[i];
289
                }
290
            }
291
        }
292
        throw new IllegalArgumentException(
324
      }
325
    }
326
    throw new IllegalArgumentException(
293 327
            "There is not any registered data type with the class or a "
294
                + "parent of the class: " + defaultClass);
295
    }
296
    
328
            + "parent of the class: " + defaultClass);
329
  }
330

  
297 331
}
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/dataTypes/impl/DefaultDataType.java
66 66
    }
67 67
  }
68 68

  
69
  private static final NumberPrecisionAndScale BYTE_PRECISION_AND_SCALE = new DefaultNumberPrecisionAndScale(BYTE_MAX_PRECISION, 0);
70
  private static final NumberPrecisionAndScale INT_PRECISION_AND_SCALE = new DefaultNumberPrecisionAndScale(INT_MAX_PRECISION, 0);
71
  private static final NumberPrecisionAndScale LONG_PRECISION_AND_SCALE = new DefaultNumberPrecisionAndScale(LONG_MAX_PRECISION, 0);
69
  public static final int NO_SUPPORT_SCALE = -1;
70
  public static final int NO_SUPPORT_PRECISION = -1;
71
  
72 72
  private static final NumberPrecisionAndScale EMPTY_PRECISION_AND_SCALE = new DefaultNumberPrecisionAndScale(0, 0);
73 73

  
74 74
  private Coercion coercion;
......
80 80
  private int max_precision;
81 81
  private int default_precision;
82 82
  private int default_scale;
83
  private boolean fixedPrecision;
83 84

  
84 85
  DefaultDataType(int type, String subtype, String name, Class defaultClass, Coercion coercion) {
85 86
    this(type, subtype, name, defaultClass, coercion, "datatype-any");
86 87
  }
87 88

  
88 89
  DefaultDataType(int type, String subtype, String name, Class defaultClass, Coercion coercion, String iconName) {
89
    this(type, subtype, name, defaultClass, coercion, "datatype-any", 0, 0, 0);
90
    this(type, subtype, name, defaultClass, coercion, "datatype-any", false, NO_SUPPORT_PRECISION, NO_SUPPORT_PRECISION, NO_SUPPORT_SCALE);
90 91
  }
91 92

  
92
  DefaultDataType(int type, String subtype, String name, Class defaultClass, Coercion coercion, String iconName, int max_precision, int default_precision, int default_scale) {
93
  DefaultDataType(int type, String subtype, String name, Class defaultClass, Coercion coercion, String iconName, boolean isFixedPrecision, int max_precision, int default_precision) {
94
    this(type, subtype, name, defaultClass, coercion, "datatype-any", isFixedPrecision, max_precision, default_precision, NO_SUPPORT_SCALE);
95
  }
93 96

  
97
  DefaultDataType(int type, String subtype, String name, Class defaultClass, Coercion coercion, String iconName, boolean isFixedPrecision, int max_precision, int default_precision, int default_scale) {
98

  
94 99
    if (name == null) {
95 100
      LOG.trace("Can't register null type name for type {}.", new Object[]{Integer.toHexString(type).toUpperCase()});
96 101
      throw new IllegalArgumentException();
......
104 109
    this.max_precision = max_precision;
105 110
    this.default_precision = default_precision;
106 111
    this.default_scale = default_scale;
112
    this.fixedPrecision = isFixedPrecision;
107 113
  }
108 114

  
109 115
  @Override
......
265 271

  
266 272
  @Override
267 273
  public boolean supportPrecision() {
268
    if( this.max_precision<=0 ) {
269
      return false;
270
    }
271
    return true;
274
    return this.max_precision!=NO_SUPPORT_PRECISION;
272 275
  }
273 276

  
274 277
  @Override
275 278
  public boolean supportScale() {
276
    if( this.max_precision<=0 ) {
277
      return false;
278
    }
279
    switch (this.type) {
280
      case DataTypes.FLOAT:
281
      case DataTypes.DOUBLE:
282
      case DataTypes.DECIMAL:
283
        return true;
284
      default:
285
        return false;
286
    }
279
    return this.default_scale!=NO_SUPPORT_SCALE;
287 280
  }
288 281

  
289 282
  @Override
290 283
  public NumberPrecisionAndScale fixPrecisionAndScale(int precision, int scale) {
291
    if( this.max_precision > 0 ) {
292
      // Si el tipo tiene asignada una precision maxima asumimos que debemos
293
      // controlar la precision y la escala.
294
      DefaultNumberPrecisionAndScale r = new DefaultNumberPrecisionAndScale(
295
              precision, 
296
              scale
297
      );
284
    if( this.max_precision==NO_SUPPORT_PRECISION ) {
285
       return EMPTY_PRECISION_AND_SCALE;
286
    }
287
    DefaultNumberPrecisionAndScale r = new DefaultNumberPrecisionAndScale(
288
            precision, 
289
            scale
290
    );
291
    if( this.fixedPrecision ) {
292
      r.precision = max_precision;
293
    }
294
    if( this.default_scale==NO_SUPPORT_SCALE ) {
295
      // Soporta precision y no escala (byte, int, long... enteros)
296
      r.scale = 0;
297
      if( r.precision > max_precision ) {
298
        r.precision = max_precision;
299
      }
300
    } else {
301
      // Soporta precision y escala.
298 302
      if (r.precision < 1) {
299 303
        // Sin precision
300 304
        if (r.scale < 1) {
......
363 367
          }
364 368
        }
365 369
      }
366
      return r;
367 370
    }
368
    // Para los tipos enteros basicos, ya tienen una precision y escala fijas.
369
    switch(this.type) {
370
      case DataTypes.BYTE:
371
        return BYTE_PRECISION_AND_SCALE;
372
        
373
      case DataTypes.INT:
374
        return INT_PRECISION_AND_SCALE;
375
        
376
      case DataTypes.LONG:
377
        return LONG_PRECISION_AND_SCALE;
378
        
379
      default:
380
        return EMPTY_PRECISION_AND_SCALE;
381
    }
371
    return r;
382 372
  }
373

  
374
  @Override
375
  public int getMaxPrecision() {
376
    return this.max_precision;
377
  }
378

  
379
  @Override
380
  public int getDefaultPrecision() {
381
    return this.default_precision;
382
  }
383

  
384
  @Override
385
  public int getDefaultScale() {
386
    return this.default_scale;
387
  }
388

  
389
  public boolean isFixedPrecision() {
390
    return this.fixedPrecision;
391
  }
383 392
}
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.swing/org.gvsig.tools.swing.impl/src/main/java/org/gvsig/tools/swing/impl/ToolsSwingDefaultImplLibrary.java
98 98
            new String[] { "DataTypes", "datatype-any" },
99 99
            new String[] { "DataTypes", "datatype-binary" },
100 100
            new String[] { "DataTypes", "datatype-boolean" },
101
            new String[] { "DataTypes", "datatype-byte" },
101 102
            new String[] { "DataTypes", "datatype-bytearray" },
102 103
            new String[] { "DataTypes", "datatype-date" },
103 104
            new String[] { "DataTypes", "datatype-double" },

Also available in: Unified diff