Revision 130

View differences:

org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.lib/src/test/java/org/gvsig/tools/persistence/BasicListTest.java
137 137
				null, 
138 138
				null
139 139
		);
140
		definition.addDynFieldList("values").setMandatory(true).addElementsType().setType(DataTypes.STRING);
140
		definition.addDynFieldList("values").setMandatory(true).setElementsType(DataTypes.STRING);
141 141
		definition.addDynFieldList("persistentValues").setMandatory(true).setElementsType(definition2);
142 142
	}
143 143

  
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.lib/src/test/java/org/gvsig/tools/persistence/BasicSetTest.java
116 116
				null, 
117 117
				null
118 118
		);
119
		definition.addDynFieldSet("values").setMandatory(true).addElementsType().setType(DataTypes.STRING);
119
		definition.addDynFieldSet("values").setMandatory(true).setElementsType(DataTypes.STRING);
120 120
		definition.addDynFieldSet("persistentValues").setMandatory(true).setElementsType(definition2);
121 121
	}
122 122

  
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.lib/src/test/java/org/gvsig/tools/persistence/BasicMapTest.java
99 99
				null, 
100 100
				null
101 101
		);
102
		definition.addDynFieldMap("values").setMandatory(true).addElementsType().setType(DataTypes.STRING);
102
		definition.addDynFieldMap("values").setMandatory(true).setElementsType(DataTypes.STRING);
103 103
		definition.addDynFieldMap("persistentValues").setMandatory(true).setElementsType(definition2);
104 104
	}
105 105

  
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.lib/src/test/java/org/gvsig/tools/persistence/BasicTypesArrayTest.java
88 88
				null, 
89 89
				null
90 90
		);
91
		definition.addDynFieldArray("a").setMandatory(true).addElementsType().setType(DataTypes.INT);
92
		definition.addDynFieldArray("b").setMandatory(true).addElementsType().setType(DataTypes.LONG);
93
		definition.addDynFieldArray("c").setMandatory(true).addElementsType().setType(DataTypes.DOUBLE);
94
		definition.addDynFieldArray("d").setMandatory(true).addElementsType().setType(DataTypes.FLOAT);
95
		definition.addDynFieldArray("e").setMandatory(true).addElementsType().setType(DataTypes.BOOLEAN);
96
		definition.addDynFieldArray("f").setMandatory(true).addElementsType().setType(DataTypes.STRING);
97
		definition.addDynFieldArray("g").setMandatory(true).addElementsType().setType(DataTypes.DATE);
91
		definition.addDynFieldArray("a").setMandatory(true).setElementsType(DataTypes.INT);
92
		definition.addDynFieldArray("b").setMandatory(true).setElementsType(DataTypes.LONG);
93
		definition.addDynFieldArray("c").setMandatory(true).setElementsType(DataTypes.DOUBLE);
94
		definition.addDynFieldArray("d").setMandatory(true).setElementsType(DataTypes.FLOAT);
95
		definition.addDynFieldArray("e").setMandatory(true).setElementsType(DataTypes.BOOLEAN);
96
		definition.addDynFieldArray("f").setMandatory(true).setElementsType(DataTypes.STRING);
97
		definition.addDynFieldArray("g").setMandatory(true).setElementsType(DataTypes.DATE);
98 98
	}
99 99

  
100 100
	protected void unregister() throws PersistenceClassNotRegistered {
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/dynobject/DynObjectManager.java
148 148
	public void remove(DynStruct dynClass);
149 149
	
150 150
	/**
151
	 * Obtiene  la clase asociado al nombre indicado del namespace
152
	 * por defecto..
151
	 * Obtiene  la clase asociado al nombre indicado.
152
	 * 
153
	 * Si se indica un nombre con namespace la buscara en
154
	 * ese namespace. if not se usara el namespace por
155
	 * defecto.
153 156
	 *
154 157
	 * @param name
155 158
	 *            , nombre de la clase que queremos obtener.
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/dynobject/DynField.java
3 3
import java.util.List;
4 4

  
5 5
import org.gvsig.tools.dataTypes.CoercionException;
6
import org.gvsig.tools.dataTypes.DataTypes;
6 7
import org.gvsig.tools.dynobject.exception.DynFieldIsNotAContainerException;
7 8
import org.gvsig.tools.dynobject.exception.DynFieldValidateException;
8 9

  
......
80 81

  
81 82
	DynField setType(int type);
82 83

  
84
	/**
85
	 * Cuando el tipo sea  #{@link DataTypes#DYNOBJECT}, el
86
	 * subtype sera el fullname de la DynStruct.
87
	 *  
88
	 * @param subtype
89
	 * @return
90
	 */
83 91
	DynField setSubtype(String subtype);
84 92
	
85 93
	DynField setDefaultDynValue(Object defaultValue);
......
147 155
	 * 
148 156
	 * Return null if the type not is a container.
149 157
	 * 
150
	 * @return DynClass that define the type of elements.
158
	 * @return DynField that define the type of elements.
151 159
	 */
152
	public DynStruct getElementsType();
160
	public DynField getElementsType();
153 161

  
154 162
	/**
155 163
 	 * Set the type of items when the field is a container.
156
 	 * When the type is DYNOBJECT is the DynClass associated
157
 	 * to this.
158 164
 	 * 
159
	 * @param definition
165
 	 * El  tipo de los elementos de un container esta definido
166
 	 * mediante un DynField, que crea con el tipo pasado por
167
 	 * parametro y lo devuelve este metodo.
168
 	 * 
169
	 * @param tipo de los elementos
160 170
	 * @return this same {@link DynField} object
161 171
	 * @throws DynFieldIsNotAContainerException
162 172
	 */
163
	public DynField setElementsType(DynStruct definition) throws DynFieldIsNotAContainerException ;
173
	public DynField setElementsType(int type) throws DynFieldIsNotAContainerException ;
164 174

  
165
	
166 175
	/**
167
	 * Create a DynClass and asociate to the elements of this
168
	 * container field and return the unique field defined in this
169
	 * DynClass.
170
	 *  
171
	 *  This method is a utility method for define the type
172
	 *  of elements of a container when this elements are
173
	 *  basic types and not compound objects.
174
	 *  
175
	 *  The name of the DynField and DynClass created are
176
	 *  the same as this field.
177
	 *  
178
	 * @return DynField that define the type of elements.
176
 	 * Set the type of items when the field is a container.
177
 	 * 
178
 	 * Metodo de utilidad que establece el typo de DYNOBJECT y
179
 	 * methe como subtipo el DynStruct pasado como parametro.
180
 	 *  
181
	 * @param tipo de los elementos
182
	 * @return this same {@link DynField} object
179 183
	 * @throws DynFieldIsNotAContainerException
180 184
	 */
181
	public DynField addElementsType() throws DynFieldIsNotAContainerException ;
185
	public DynField setElementsType(DynStruct type) throws DynFieldIsNotAContainerException ;
182 186
	
183 187
}
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/dynobject/impl/DynClassImportHelper.java
52 52
	private static final String FIELD_AVALILABLEVALUES_TAG = "availableValues";
53 53
	private static final String FIELD_GROUP_TAG = "group";
54 54
	private static final String FIELD_ORDER_TAG = "order";
55
	private static final String FIELD_HIDDEN_TAG = "hidden";
55 56

  
56 57
	private static final String VALUEITEM_TAG = "valueItem";
57 58
	private static final String VALUEITEM_LABEL_TAG = "label";
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/dynobject/impl/DefaultDynObjectManager.java
313 313
	public void remove(DynStruct dynClass)  {
314 314
		this.classes.remove(dynClass);
315 315
	}
316

  
317
	public static String  getFullName(String namespace, String name) {
318
    	if( namespace == null ) {
319
    		return name;
320
    	}
321
    	return namespace + ":" + name;
322
    }
323

  
324
	public static String[] splitFullName(String fullname) {
325
		String[] name = new String[] { null, fullname };
326
		int x=fullname.indexOf(':');
327
		if( x>-1 ) {
328
			name[0] = fullname.substring(0, x);
329
			name[1] = fullname.substring(x+1);
330
		}
331
		return name;
332
		
333
	}
316 334
	
317
	public DynClass get(String name) {
318
		return this.get(name,null);
335
	public DynClass get(String theName) {
336
		String[] name = splitFullName(theName);
337
		return this.get(name[0],name[1]);
319 338
	}
320 339

  
321 340
	public DynClass get(String namespace, String name ) {
......
357 376
		return this.classes.iterator();
358 377
	}
359 378
	public DynObject createDynObject(String dynClassName) {
360
		return this.createDynObject(dynClassName, null);
379
		String[] name = splitFullName(dynClassName); 
380
		return this.createDynObject(name[1], name[0]);
361 381
	}
362 382

  
363 383
	public DynObject createDynObject(String dynClassName, String namespace) {
......
525 545
		return new DynClassImportHelper().importDefinitions(resource, loader, defaultNamespace);
526 546
	}
527 547
	
528
	public static String  getFullName(String namespace, String name) {
529
    	if( namespace == null ) {
530
    		return name;
531
    	}
532
    	return namespace + ":" + name;
533
    }
534

  
535 548
}
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/dynobject/impl/DefaultDynField.java
12 12
import org.gvsig.tools.dataTypes.DataTypesManager;
13 13
import org.gvsig.tools.dynobject.DynClass;
14 14
import org.gvsig.tools.dynobject.DynField;
15
import org.gvsig.tools.dynobject.DynMethod;
16 15
import org.gvsig.tools.dynobject.DynObject;
17 16
import org.gvsig.tools.dynobject.DynObjectValueItem;
18 17
import org.gvsig.tools.dynobject.DynStruct;
19 18
import org.gvsig.tools.dynobject.exception.DynFieldIsNotAContainerException;
20 19
import org.gvsig.tools.dynobject.exception.DynFieldValidateException;
21
import org.gvsig.tools.dynobject.exception.DynMethodException;
22 20
import org.gvsig.tools.dynobject.exception.DynObjectValidateException;
23 21

  
24 22
public class DefaultDynField implements DynField {
......
27 25

  
28 26
	private int dataType;
29 27
	private String subtype;
30
	
31 28

  
32 29
	private Object defaultValue;
33 30

  
34 31
	private int order;
35 32
	private boolean hidden;
36
	private String groupName; 
33
	private String groupName;
37 34
	private DynObjectValueItem[] availableValues;
38 35
	private Object minValue;
39 36
	private Object maxValue;
40 37
	private boolean mandatory;
41 38
	private boolean persistent;
42 39
	private Class theClass;
43
	private DynStruct elementsType;
44
	private boolean validateElements; 
40
	private DynField elementsType;
41
	private boolean validateElements;
45 42

  
46 43
	public DefaultDynField(String name) {
47 44
		this(name, // field name
48
				DataTypes.UNKNOWN, // data type
45
				DataTypes.STRING, // data type
49 46
				null, // default value
50 47
				true, // persistent
51 48
				false // mandatory
52 49
		);
53 50
	}
54
	
51

  
55 52
	public DefaultDynField(String name, int dataType, Object defaultValue,
56 53
			boolean persistent, boolean mandatory) {
57 54
		this.name = name;
......
67 64
		this.hidden = false;
68 65
	}
69 66

  
67
	public String toString() {
68
		StringBuffer buffer = new StringBuffer();
70 69

  
71
    public String toString() {
72
    	StringBuffer buffer = new StringBuffer();
73
    	
74
    	buffer.append("DynField").append("[").append(this.hashCode()).append("]").append("( ")
75
    		.append("name='").append(this.name).append("', ")
76
    		.append("description='").append(this.description).append("', ")
77
    		.append("dataType='").append(this.dataType).append(", ")
78
    		.append("minValue='").append(this.minValue).append(", ")
79
    		.append("maxValue='").append(this.maxValue).append(", ")
80
    		.append("mandatory='").append(this.isMandatory()).append(", ")
81
    		.append("persistent='").append(this.isPersistent()).append(", ")
82
    		.append("defaultValue='").append(this.getDefaultValue())
83
    		.append(" )");
84
    	return buffer.toString();
85
    }
70
		buffer.append("DynField").append("[").append(this.hashCode()).append(
71
				"]").append("( ").append("name='").append(this.name).append(
72
				"', ").append("description='").append(this.description).append(
73
				"', ").append("dataType='").append(this.dataType).append(", ")
74
				.append("minValue='").append(this.minValue).append(", ")
75
				.append("maxValue='").append(this.maxValue).append(", ")
76
				.append("mandatory='").append(this.isMandatory()).append(", ")
77
				.append("persistent='").append(this.isPersistent())
78
				.append(", ").append("defaultValue='").append(
79
						this.getDefaultValue()).append(" )");
80
		return buffer.toString();
81
	}
86 82

  
87

  
88 83
	public String getName() {
89 84
		return name;
90 85
	}
......
112 107

  
113 108
	public DynField setSubtype(String subtype) {
114 109
		this.subtype = subtype;
110
		if( subtype!=null && this.dataType == DataTypes.DYNOBJECT ) {
111
			if( ToolsLocator.getDynObjectManager().get(subtype) == null ) {
112
				throw new IllegalArgumentException("DynClass '"+subtype+"' does not exist.");
113
			}
114
		}
115 115
		return this;
116 116
	}
117 117

  
......
134 134
	}
135 135

  
136 136
	public DynField setAvailableValues(List availableValues) {
137
		this.availableValues = (DynObjectValueItem[]) availableValues.toArray(new DynObjectValueItem[availableValues.size()]) ;
137
		this.availableValues = (DynObjectValueItem[]) availableValues
138
				.toArray(new DynObjectValueItem[availableValues.size()]);
138 139
		return this;
139 140
	}
140 141

  
......
179 180
	}
180 181

  
181 182
	public DynField setTheTypeOfAvailableValues(int type) {
182
		return this;  // FIXME: this method is @deprecated
183
		return this; // FIXME: this method is @deprecated
183 184
	}
184 185

  
185 186
	public int getTheTypeOfAvailableValues() {
186 187
		return 1; // FIXME: this method is @deprecated
187 188
	}
188 189

  
190
	public boolean equals(Object obj) {
191
		if (this == obj) {
192
			return true;
193
		}
194
		if (obj instanceof DynField) {
195
			// FIXME: No esta claro que esto sea correcto.
196
			return name.equals(((DynField) obj).getName());
197
		}
198
		return false;
199
	}
189 200

  
190
    public boolean equals(Object obj) {
191
        if (this == obj) {
192
            return true;
193
        }
194
        if (obj instanceof DynField) {
195
        	// FIXME: No esta claro que esto sea correcto.
196
            return name.equals(((DynField) obj).getName());
197
        }
198
        return false;
199
    }
200

  
201

  
202

  
203 201
	public Class getClassOfValue() {
204 202
		return theClass;
205 203
	}
206 204

  
207 205
	public DynField setValidateElements(boolean validate) {
208
		switch(this.dataType) {
206
		switch (this.dataType) {
209 207
		case DataTypes.ARRAY:
210 208
		case DataTypes.LIST:
211 209
		case DataTypes.MAP:
......
217 215
		this.validateElements = validate;
218 216
		return this;
219 217
	}
220
	
218

  
221 219
	public boolean getValidateElements() {
222 220
		return this.validateElements;
223 221
	}
224
	
225
	public DynField setClassOfValue(Class theClass) throws DynFieldIsNotAContainerException{
226
		switch(this.dataType) {
222

  
223
	public DynField setClassOfValue(Class theClass)
224
			throws DynFieldIsNotAContainerException {
225
		switch (this.dataType) {
227 226
		case DataTypes.OBJECT:
228 227
		case DataTypes.ARRAY:
229 228
		case DataTypes.LIST:
......
237 236
		return this;
238 237
	}
239 238

  
240
	public DynField setElementsType(DynStruct dynClass)  throws DynFieldIsNotAContainerException{
241
		switch(this.dataType) {
242
		case DataTypes.OBJECT:
243
		case DataTypes.ARRAY:
244
		case DataTypes.LIST:
245
		case DataTypes.MAP:
246
		case DataTypes.SET:
247
			break;
248
		default:
239
	public DynField setElementsType(int type)
240
			throws DynFieldIsNotAContainerException {
241
		if (!ToolsLocator.getDataTypesManager().isContainer(this.dataType)) {
249 242
			throw new DynFieldIsNotAContainerException(this.name);
250 243
		}
251
		this.elementsType = dynClass;
244
		this.elementsType = new DefaultDynField(this.name + "-"
245
				+ ToolsLocator.getDataTypesManager().getTypeName(this.dataType)
246
				+ "-item");
252 247
		return this;
253 248
	}
254
	
255
	public DynField addElementsType()  throws DynFieldIsNotAContainerException{
256
		switch(this.dataType) {
257
		case DataTypes.ARRAY:
258
		case DataTypes.LIST:
259
		case DataTypes.MAP:
260
		case DataTypes.SET:
261
			break;
262
		default:
263
			throw new DynFieldIsNotAContainerException(this.name);
264
		}
265
		DynField dynField = new DefaultDynField(this.name+"-"+ToolsLocator.getDataTypesManager().getTypeName(this.dataType)+"-item");
266
		this.elementsType = new ElementTypeWrapper(this.name, this.description, dynField);
267
		return dynField;
249

  
250

  
251
	public DynField setElementsType(DynStruct type)
252
			throws DynFieldIsNotAContainerException {
253
		this.setElementsType(DataTypes.DYNOBJECT).getElementsType().setSubtype(type.getFullName());
254
		return this;
268 255
	}
269
	
270
	public DynStruct getElementsType() {
256

  
257

  
258
	public DynField getElementsType() {
271 259
		return this.elementsType;
272 260
	}
273
	
261

  
274 262
	public void validate(Object value) throws DynFieldValidateException {
275 263
		Comparable v;
276
		if( value == null ) {
277
			if( this.mandatory ) {
278
				throw new DynFieldValidateException(value,this);
264
		if (value == null) {
265
			if (this.mandatory) {
266
				throw new DynFieldValidateException(value, this);
279 267
			}
280 268
			return;
281 269
		}
282
		
283
		switch( this.dataType ) {
270

  
271
		switch (this.dataType) {
284 272
		case DataTypes.BOOLEAN:
285
			if( ! (value instanceof Boolean) ) {
286
				throw new DynFieldValidateException(value,this);
273
			if (!(value instanceof Boolean)) {
274
				throw new DynFieldValidateException(value, this);
287 275
			}
288 276
			break;
289
			
277

  
290 278
		case DataTypes.DOUBLE:
291
			if( ! (value instanceof Double) ) {
292
				throw new DynFieldValidateException(value,this);
279
			if (!(value instanceof Double)) {
280
				throw new DynFieldValidateException(value, this);
293 281
			}
294 282
			break;
295
			
283

  
296 284
		case DataTypes.FLOAT:
297
			if( ! (value instanceof Float) ) {
298
				throw new DynFieldValidateException(value,this);
285
			if (!(value instanceof Float)) {
286
				throw new DynFieldValidateException(value, this);
299 287
			}
300 288
			break;
301
			
289

  
302 290
		case DataTypes.INT:
303
			if( ! (value instanceof Integer) ) {
304
				throw new DynFieldValidateException(value,this);
291
			if (!(value instanceof Integer)) {
292
				throw new DynFieldValidateException(value, this);
305 293
			}
306 294
			break;
307
		
295

  
308 296
		case DataTypes.LONG:
309
			if( ! (value instanceof Long) ) {
310
				throw new DynFieldValidateException(value,this);
297
			if (!(value instanceof Long)) {
298
				throw new DynFieldValidateException(value, this);
311 299
			}
312 300
			break;
313
		
301

  
314 302
		case DataTypes.STRING:
315
			if( ! (value instanceof String) ) {
316
				throw new DynFieldValidateException(value,this);
303
			if (!(value instanceof String)) {
304
				throw new DynFieldValidateException(value, this);
317 305
			}
318 306
			break;
319 307

  
320 308
		case DataTypes.DATE:
321
			if( ! (value instanceof Date) ) {
322
				throw new DynFieldValidateException(value,this);
309
			if (!(value instanceof Date)) {
310
				throw new DynFieldValidateException(value, this);
323 311
			}
324 312
			break;
325 313

  
326 314
		case DataTypes.LIST:
327
			if( ! (value instanceof List) ) {
328
				throw new DynFieldValidateException(value,this);
315
			if (!(value instanceof List)) {
316
				throw new DynFieldValidateException(value, this);
329 317
			}
330
			if ( this.validateElements && this.elementsType != null) {
331
				if( this.elementsType instanceof ElementTypeWrapper) {
332
					DynField field = ((ElementTypeWrapper)this.elementsType).getDynField();
333
					Iterator it = ((List)value).iterator();
334
					while( it.hasNext() ) {
335
						field.validate( it.next() );
336
					}
337
				} else {
338
					DynStruct dynClass = this.elementsType;
339
					Iterator it = ((List)value).iterator();
340
					while( it.hasNext() ) {
341
						try {
342
							Object obj = it.next();
343
							dynClass.validate((DynObject) obj);
344
						} catch (DynObjectValidateException e) {
345
							throw new DynFieldValidateException(value,this,e);
346
						}
347
					}
348
					
318
			if (this.validateElements && this.elementsType != null) {
319
				Iterator it = ((List) value).iterator();
320
				while (it.hasNext()) {
321
					this.elementsType.validate(it.next());
349 322
				}
350 323
			}
351 324
			break;
352
			
325

  
353 326
		case DataTypes.MAP:
354
			if( ! (value instanceof Map) ) {
355
				throw new DynFieldValidateException(value,this);
327
			if (!(value instanceof Map)) {
328
				throw new DynFieldValidateException(value, this);
356 329
			}
357 330
			break;
358 331
		case DataTypes.SET:
359
			if( ! (value instanceof Set) ) {
360
				throw new DynFieldValidateException(value,this);
332
			if (!(value instanceof Set)) {
333
				throw new DynFieldValidateException(value, this);
361 334
			}
362 335
			break;
363
		
336

  
364 337
		case DataTypes.OBJECT:
365
			if( this.theClass != null ) {
366
				if(! this.theClass.isInstance(value)) {
367
					throw new DynFieldValidateException(value,this);
338
			if (this.theClass != null) {
339
				if (!this.theClass.isInstance(value)) {
340
					throw new DynFieldValidateException(value, this);
368 341
				}
369
			} else if( this.elementsType!= null ) {
370
				if( ! (value instanceof DynObject) ) {
371
					throw new DynFieldValidateException(value,this);
372
				}
373
				if( !this.elementsType.getFullName().equals(((DynObject)value).getDynClass().getFullName()) )  {
374
					throw new DynFieldValidateException(value,this);
375
				}
376
				try {
377
					((DynObject)value).getDynClass().validate((DynObject)value);
378
				} catch (DynObjectValidateException e) {
379
					throw new DynFieldValidateException(value,this, e);
380
				}
381 342
			}
382 343
			break;
383
			
344

  
345
		case DataTypes.DYNOBJECT:
346
			if (!(value instanceof DynObject)) {
347
				throw new DynFieldValidateException(value, this);
348
			}
349
			DynClass dynClass = ToolsLocator.getDynObjectManager().get(
350
					this.getSubtype());
351
			if ( dynClass==null || !dynClass.isInstance((DynObject) value)) {
352
				throw new DynFieldValidateException(value, this);
353
			}
354
			try {
355
				dynClass.validate((DynObject) value);
356
			} catch (DynObjectValidateException e) {
357
				throw new DynFieldValidateException(value, this, e);
358
			}
359
			break;
360

  
384 361
		case DataTypes.ARRAY:
385 362
			// TODO: falta verificar que es un array del tipo que toca.
386 363
			break;
387
		
364

  
388 365
		default:
389
			throw new DynFieldValidateException(value,this);
366
			throw new DynFieldValidateException(value, this);
390 367
		}
391 368

  
392
		if( this.mandatory && value==null ) {
393
			throw new DynFieldValidateException(value,this);
369
		if (this.mandatory && value == null) {
370
			throw new DynFieldValidateException(value, this);
394 371
		}
395 372

  
396
		if( this.getAvailableValues() != null ) {
397
			if( !(value instanceof Comparable) ) {
398
				throw new DynFieldValidateException(value,this);
373
		if (this.getAvailableValues() != null) {
374
			if (!(value instanceof Comparable)) {
375
				throw new DynFieldValidateException(value, this);
399 376
			}
400
			v = (Comparable)value;
377
			v = (Comparable) value;
401 378
			boolean ok = false;
402
			for( int i=0; i<this.availableValues.length; i++ ) {
403
				if( v.compareTo(this.availableValues[i].getValue())==0) {
379
			for (int i = 0; i < this.availableValues.length; i++) {
380
				if (v.compareTo(this.availableValues[i].getValue()) == 0) {
404 381
					ok = true;
405 382
					break;
406 383
				}
407 384
			}
408
			if( !ok ) {
409
				throw new DynFieldValidateException(value,this);
385
			if (!ok) {
386
				throw new DynFieldValidateException(value, this);
410 387
			}
411
		} else if( this.getMaxValue()!=null && this.getMinValue()!=null ) {
412
			if( !(value instanceof Comparable) ) {
413
				throw new DynFieldValidateException(value,this);
388
		} else if (this.getMaxValue() != null && this.getMinValue() != null) {
389
			if (!(value instanceof Comparable)) {
390
				throw new DynFieldValidateException(value, this);
414 391
			}
415
			v = (Comparable)value;
416
			if( v.compareTo(this.minValue)<0 || v.compareTo(this.maxValue)>0 ) {
417
				throw new DynFieldValidateException(value,this);
392
			v = (Comparable) value;
393
			if (v.compareTo(this.minValue) < 0
394
					|| v.compareTo(this.maxValue) > 0) {
395
				throw new DynFieldValidateException(value, this);
418 396
			}
419 397
		}
420 398
	}
421 399

  
422 400
	public Object coerce(Object value) throws CoercionException {
423
		if( value == null ) {
424
			return value; // O debe retorna this.defaultValue 
425
		} 
401
		if (value == null) {
402
			return value; // O debe retorna this.defaultValue
403
		}
426 404
		DataTypesManager manager = ToolsLocator.getDataTypesManager();
427 405
		return manager.coerce(this.dataType, value);
428 406
	}
429 407

  
430 408

  
431
	
432
	class ElementTypeWrapper implements DynClass {
433

  
434
	    private DynField[] declaredFields;
435
		private String name;
436
		private String description;
437
		
438
		ElementTypeWrapper(String name, String description, DynField dynField) {
439
			this.declaredFields =  new DynField[] { dynField };
440
			this.name = name;
441
			this.description = description;
442
		}
443

  
444
		public DynField getDynField() {
445
			return this.declaredFields[0];
446
		}
447
		
448
		public DynField getDeclaredDynField(String name) {
449
			if( this.name.equals(name) ) {
450
				return this.declaredFields[0];
451
			}
452
			return null;
453
		}
454

  
455
		public DynField[] getDeclaredDynFields() {
456
			return this.declaredFields;
457
		}
458

  
459
		public String getDescription() {
460
			return this.description;
461
		}
462

  
463
		public DynField getDynField(String name) {
464
			if( this.name.equals(name) ) {
465
				return this.declaredFields[0];
466
			}
467
			return null;
468
		}
469

  
470
		public DynField[] getDynFields() {
471
			return this.declaredFields;
472
		}
473

  
474
		public String getFullName() {
475
			return this.name;
476
		}
477

  
478
		public String getName() {
479
			return this.name;
480
		}
481

  
482
		public String getNamespace() {
483
			return null;
484
		}
485

  
486
		public DynClass[] getSuperDynClasses() {
487
			return null;
488
		}
489

  
490
		public boolean isInstance(DynObject dynObject) {
491
			return false;
492
		}
493

  
494
		public DynObject newInstance() {
495
			return null;
496
		}
497

  
498
		public void addDynMethod(DynMethod dynMethod) {
499
			throw new UnsupportedOperationException();
500
		}
501

  
502
		public void extend(String dynClassName) {
503
			throw new UnsupportedOperationException();
504
		}
505

  
506
		public void extend(String namespace, String dynClassName) {
507
			throw new UnsupportedOperationException();
508
		}
509

  
510
		public DynMethod getDeclaredDynMethod(String name)
511
				throws DynMethodException {
512
			throw new UnsupportedOperationException();
513
		}
514

  
515
		public DynMethod[] getDeclaredDynMethods() throws DynMethodException {
516
			throw new UnsupportedOperationException();
517
		}
518

  
519
		public DynMethod getDynMethod(String name) throws DynMethodException {
520
			throw new UnsupportedOperationException();
521
		}
522

  
523
		public DynMethod getDynMethod(int code) throws DynMethodException {
524
			throw new UnsupportedOperationException();
525
		}
526

  
527
		public DynMethod[] getDynMethods() throws DynMethodException {
528
			throw new UnsupportedOperationException();
529
		}
530

  
531
		public void removeDynMethod(String name) {
532
			throw new UnsupportedOperationException();
533
		}
534

  
535
		public DynField addDynField(String name) {
536
			throw new UnsupportedOperationException();
537
		}
538

  
539
		public DynField addDynFieldArray(String name) {
540
			throw new UnsupportedOperationException();
541
		}
542

  
543
		public DynField addDynFieldBoolean(String name) {
544
			throw new UnsupportedOperationException();
545
		}
546

  
547
		public DynField addDynFieldChoice(String name, int type,
548
				Object defaultValue, DynObjectValueItem[] values,
549
				boolean mandatory, boolean persistent) {
550
			throw new UnsupportedOperationException();
551
		}
552

  
553
		public DynField addDynFieldChoice(String name, int type,
554
				Object defaultValue, DynObjectValueItem[] values) {
555
			throw new UnsupportedOperationException();
556
		}
557

  
558
		public DynField addDynFieldDouble(String name) {
559
			throw new UnsupportedOperationException();
560
		}
561

  
562
		public DynField addDynFieldFloat(String name) {
563
			throw new UnsupportedOperationException();
564
		}
565

  
566
		public DynField addDynFieldInt(String name) {
567
			throw new UnsupportedOperationException();
568
		}
569

  
570
		public DynField addDynFieldList(String name) {
571
			throw new UnsupportedOperationException();
572
		}
573

  
574
		public DynField addDynFieldLong(String name) {
575
			throw new UnsupportedOperationException();
576
		}
577

  
578
		public DynField addDynFieldMap(String name) {
579
			throw new UnsupportedOperationException();
580
		}
581

  
582
		public DynField addDynFieldObject(String name) {
583
			throw new UnsupportedOperationException();
584
		}
585

  
586
		public DynField addDynFieldRange(String name, int type,
587
				Object defaultValue, Object min, Object max, boolean mandatory,
588
				boolean persistent) {
589
			throw new UnsupportedOperationException();
590
		}
591

  
592
		public DynField addDynFieldRange(String name, int type,
593
				Object defaultValue, Object min, Object max) {
594
			throw new UnsupportedOperationException();
595
		}
596

  
597
		public DynField addDynFieldSet(String name) {
598
			throw new UnsupportedOperationException();
599
		}
600

  
601
		public DynField addDynFieldSingle(String name, int type,
602
				Object defaultValue, boolean mandatory, boolean persistent) {
603
			throw new UnsupportedOperationException();
604
		}
605

  
606
		public DynField addDynFieldSingle(String name, int type,
607
				Object defaultValue) {
608
			throw new UnsupportedOperationException();
609
		}
610

  
611
		public DynField addDynFieldString(String name) {
612
			throw new UnsupportedOperationException();
613
		}
614

  
615
		public void removeDynField(String name) {
616
			throw new UnsupportedOperationException();
617
		}
618

  
619
		public void validate(DynObject object)
620
				throws DynObjectValidateException {
621
			throw new UnsupportedOperationException();
622
		}
623

  
624
		public DynField addDynFieldDate(String name) {
625
			throw new UnsupportedOperationException();
626
		}
627

  
628
		public void extend(DynStruct struct) {
629
			throw new UnsupportedOperationException();
630
		}
631

  
632
		public DynStruct[] getSuperDynStructs() {
633
			throw new UnsupportedOperationException();
634
		}
635

  
636
		public void setDescription(String description) {
637
			throw new UnsupportedOperationException();
638
		}
639

  
640
		public void setNamespace(String namespace) {
641
			throw new UnsupportedOperationException();
642
		}
643
	}
644

  
645

  
646

  
647 409
	public String getGroup() {
648 410
		return this.groupName;
649 411
	}
......
670 432
		this.hidden = hidden;
671 433
		return this;
672 434
	}
673

  
674 435
}
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/dataTypes/DataTypes.java
7 7
 */
8 8
public interface DataTypes {
9 9
	
10
	public static final int INVALID = -1;
10
	public static final int INVALID = 0x00;
11 11
	
12 12
	public static final int UNKNOWN = 0x00;
13 13
	public static final int BOOLEAN = 0x01;
......
24 24
	public static final int BYTEARRAY = 0x0C;
25 25
	public static final int FILE = 0x0D;
26 26
	public static final int FOLDER = 0x0E;
27
	public static final int DYNOBJECT = 0x0F;
27 28
	
28 29
	public static final int CONTAINER = 0x10;
29 30
	public static final int ARRAY = 0x11;
30 31
	public static final int LIST = 0x12;
31 32
	public static final int SET = 0x13;
32 33
	public static final int MAP = 0x14;
33
	public static final int DYNOBJECT = 0x15;
34 34

  
35 35
	public static final int OBJECT = 0x20;
36 36

  
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/dataTypes/impl/DefaultDataTypesManager.java
48 48
	}
49 49
	
50 50
	public  String getTypeName(int type) {
51
		if( type<0 || type>0x40 ) {
51
		if( type<1 || type>0x40 ) {
52 52
			return "unknow";
53 53
		}
54 54
		String name = TYPE_NAMES[type];
......
70 70
	}
71 71

  
72 72
	public  Class getDefaultClass(int type) {
73
		if( type<0 || type>0x40 ) {
73
		if( type<1 || type>0x40 ) {
74 74
			return null;
75 75
		}
76 76
		return DEFAULT_CLASSES[type];
77 77
	}
78 78

  
79 79
	public String getSubtype(int type) {
80
		if( type<0 || type>0x40 ) {
80
		if( type<1 || type>0x40 ) {
81 81
			return null;
82 82
		}
83 83
		return SUBTYPES[type];

Also available in: Unified diff