Statistics
| Revision:

gvsig-tools / org.gvsig.tools / library / trunk / org.gvsig.tools / org.gvsig.tools.lib / src / main / java / org / gvsig / tools / dynobject / DynField.java @ 2123

History | View | Annotate | Download (11.2 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or modify it under
7
 * the terms of the GNU General Public License as published by the Free Software
8
 * Foundation; either version 2 of the License, or (at your option) any later
9
 * version.
10
 *
11
 * This program is distributed in the hope that it will be useful, but WITHOUT
12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14
 * details.
15
 *
16
 * You should have received a copy of the GNU General Public License along with
17
 * this program; if not, write to the Free Software Foundation, Inc., 51
18
 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us at info AT
21
 * gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.tools.dynobject;
24

    
25
import java.util.List;
26

    
27
import org.gvsig.tools.dataTypes.CoercionException;
28
import org.gvsig.tools.dataTypes.DataType;
29
import org.gvsig.tools.dataTypes.DataTypes;
30
import org.gvsig.tools.dynobject.exception.DynFieldIsNotAContainerException;
31
import org.gvsig.tools.dynobject.exception.DynFieldValidateException;
32

    
33
/**
34
 * A field of a {@link DynObject}.
35
 * <p>
36
 * A field will be persisted only if it is set as persistent (@see
37
 * {@link DynField#isPersistent()}, which is the default value.
38
 * </p>
39
 *
40
 */
41
public interface DynField extends org.gvsig.tools.lang.Cloneable{
42

    
43
    public static final int RELATION_TYPE_NONE = 0;
44

    
45
    /**
46
     * Relation of colaboration 1:1 Two separate entities that are related
47
     */
48
    public static final int RELATION_TYPE_COLLABORATION = 1;
49

    
50
    /**
51
     * Relation of composition 1:1 both elements make the same entity
52
     */
53
    public static final int RELATION_TYPE_IDENTITY = 2;
54

    
55
    /**
56
     * Relation of composition 1:N
57
     */
58
    public static final int RELATION_TYPE_MASTER_COMPOSITION = 3;
59

    
60
    /**
61
     * Relation of aggregation 1:N
62
     */
63
    public static final int RELATION_TYPE_MASTER_AGGREGATE = 4;
64

    
65
    /**
66
     * Relation of composition N:1
67
     */
68
    public static final int RELATION_TYPE_DETAIL_COMPOSITION = 5;
69

    
70
    /**
71
     * Relation of aggregation N:1
72
     */
73
    public static final int RELATION_TYPE_DETAIL_AGGREGATE = 6;
74

    
75
    /**
76
     * Return the name of the field.
77
     *
78
     * @return name of the field
79
     */
80
    public String getName();
81

    
82
    /**
83
     * Return the type used in this field. The values of type is the same of
84
     * {@link DataTypes}
85
     *
86
     * @return
87
     */
88
    public int getType();
89

    
90
    public DataType getDataType();
91

    
92
    /**
93
     * Return the subtype associated to this field. The subtype is a string used
94
     * for the cliente of the field.
95
     *
96
     * When the field is of type #{@link DataTypes#DYNOBJECT}, the subtype are
97
     * the fullname of the DynClass.
98
     *
99
     * @return the subtype of the field.
100
     */
101
    public String getSubtype();
102

    
103
    /**
104
     * Return the descripcion associated to this field.
105
     *
106
     * @return the description of the field.
107
     */
108
    public String getDescription();
109

    
110
    /**
111
     * Return the default value used in creation of new objects with this field.
112
     *
113
     * @return defaulr value to use for this field.
114
     */
115
    public Object getDefaultValue();
116

    
117
    /**
118
     * Return a string that identify a group for this field. The groups are
119
     * defined by the client of the field.
120
     *
121
     * @return the group of the field
122
     */
123
    public String getGroup();
124

    
125
    /**
126
     * Return the ordinal that identify the order of this field in the
127
     * {@link DynObject}.
128
     *
129
     * @return the order of field in the {@link DynObject}
130
     */
131
    public int getOder();
132

    
133
    /**
134
     * Return true if this field is mandatory.
135
     *
136
     * @return
137
     */
138
    public boolean isMandatory();
139

    
140
    /**
141
     * Returns if the field is persistent or volatile. The meaning of being
142
     * persistent depends on how is persisted, but any persistence mechanism
143
     * must avoid persisting this field value.
144
     *
145
     * @return if the field is to be persisted or not
146
     */
147
    boolean isPersistent();
148

    
149
    /**
150
     * Inform if this field can be visible or not for the user. This value don't
151
     * affect the access through the API.
152
     *
153
     * @return true if the field is hidden for the user.
154
     */
155
    boolean isHidden();
156

    
157
    /**
158
     * Returns if the field is readOnly or not. The meaning of being readOnly
159
     * allows to know if the user input to any graphic component associated to
160
     * this field should be allowed or not.
161
     *
162
     * @return if the graphic component associated to this field should be
163
     * readOnly or not
164
     */
165
    public boolean isReadOnly();
166

    
167
    /**
168
     * Return true if the value of this field is a container. This method uses
169
     * the same criteria of the {@link DataType}
170
     *
171
     * @return true if the field type is a container
172
     */
173
    public boolean isContainer();
174

    
175
    /**
176
     * Return the available values for this field. When assign a value to the
177
     * field, this value need that exists in this list.
178
     *
179
     * @return an array of the available values for the field.
180
     */
181
    public DynObjectValueItem[] getAvailableValues();
182

    
183
    public Object getMinValue();
184

    
185
    public Object getMaxValue();
186

    
187
    /**
188
     * Return the java class of the value of the field.
189
     *
190
     * @return the class of the value
191
     */
192
    Class getClassOfValue();
193

    
194
    /**
195
     * If the field is a container (List, Map or Set) return the java class of
196
     * its items.
197
     *
198
     * @return the class of the items
199
     */
200
    Class getClassOfItems();
201

    
202
    /**
203
     * Sets the description asociated to this field.
204
     *
205
     * @param description
206
     *
207
     * @return this same {@link DynField} object
208
     */
209
    DynField setDescription(String description);
210

    
211
    /**
212
     * Sets the type of the field. The values used are the specified in
213
     * {@link DataTypes}.
214
     *
215
     * This method assign the default values of the type for "ClassOfValue" and
216
     * "subType".
217
     *
218
     * @param type
219
     *
220
     * @return this same {@link DynField} object
221
     */
222
    DynField setType(int type);
223

    
224
    DynField setType(DataType type);
225

    
226
    /**
227
     * Strings used as subtype for this field. This value is used by the client
228
     * of the object.
229
     *
230
     * When the field is a #{@link DataTypes#DYNOBJECT}, the subtype is the
231
     * fullname of the DynStruct.
232
     *
233
     * @param subtype
234
     *
235
     * @return this same {@link DynField} object
236
     */
237
    DynField setSubtype(String subtype);
238

    
239
    /**
240
     * Set the default value used for this field when a new object with this
241
     * field is created.
242
     *
243
     * @param defaultValue
244
     *
245
     * @return this same {@link DynField} object
246
     */
247
    DynField setDefaultFieldValue(Object defaultValue);
248

    
249
    DynField setGroup(String groupName);
250

    
251
    DynField setOrder(int order);
252

    
253
    DynField setMandatory(boolean mandatory);
254

    
255
    DynField setHidden(boolean hidden);
256

    
257
    /**
258
     * Sets if the field must be persisted or not.
259
     *
260
     * @see #isPersistent()
261
     * @param persistent if the field must be persisted or not
262
     * @return this same {@link DynField} object
263
     */
264
    DynField setPersistent(boolean persistent);
265

    
266
    DynField setAvailableValues(DynObjectValueItem[] values);
267

    
268
    DynField setAvailableValues(List values);
269

    
270
    DynField setMinValue(Object minValue);
271

    
272
    DynField setMaxValue(Object maxValue);
273

    
274
    /**
275
     * Sets the class used for the values of the field.
276
     *
277
     * @param theClass
278
     *
279
     * @return this same {@link DynField} object
280
     *
281
     * @throws DynFieldIsNotAContainerException
282
     */
283
    DynField setClassOfValue(Class theClass) throws DynFieldIsNotAContainerException;
284

    
285
    /**
286
     * If field type is List, Set or Map, this class is the class of items.
287
     *
288
     * @param theClass
289
     *
290
     * @return this same {@link DynField} object
291
     *
292
     * @throws DynFieldIsNotAContainerException
293
     */
294
    DynField setClassOfItems(Class theClass) throws DynFieldIsNotAContainerException;
295

    
296
    /**
297
     * Sets if the field is readOnly or not. The meaning of being readOnly
298
     * allows to know if the user input to any graphic component associated to
299
     * this field should be allowed or not.
300
     *
301
     * @param isReadOnly if the graphic component associated to this field
302
     * should be readOnly or not
303
     *
304
     * @return DynField that define the type of elements.
305
     */
306
    public DynField setReadOnly(boolean isReadOnly);
307

    
308
    /**
309
     * When a field is of type container, this method return a DynClass that
310
     * define the type of elements. When the type is DYNOBJECT return the
311
     * DynClass associated to this.
312
     *
313
     * Return null if the type not is a container.
314
     *
315
     * @return DynField that define the type of elements.
316
     */
317
    public DynField getElementsType();
318

    
319
    /**
320
     * Set the type of items when the field is a container.
321
     *
322
     * El tipo de los elementos de un container esta definido mediante un
323
     * DynField, que crea con el tipo pasado por parametro y lo devuelve este
324
     * metodo.
325
     *
326
     * @param type de los elementos
327
     * @return this same {@link DynField} object
328
     * @throws DynFieldIsNotAContainerException
329
     */
330
    public DynField setElementsType(int type) throws DynFieldIsNotAContainerException;
331

    
332
    /**
333
     * Set the type of items when the field is a container.
334
     *
335
     * Metodo de utilidad que establece el typo de DYNOBJECT y methe como
336
     * subtipo el DynStruct pasado como parametro.
337
     *
338
     * @param type de los elementos
339
     * @return this same {@link DynField} object
340
     * @throws DynFieldIsNotAContainerException
341
     */
342
    public DynField setElementsType(DynStruct type) throws DynFieldIsNotAContainerException;
343

    
344
    /**
345
     * Validate that the value match the properties of the field.
346
     *
347
     * @param value
348
     * @throws DynFieldValidateException
349
     */
350
    void validate(Object value) throws DynFieldValidateException;
351

    
352
    /**
353
     * Force the type of value to the type of the field.
354
     *
355
     * @param value
356
     * @return new value
357
     * @throws CoercionException
358
     */
359
    Object coerce(Object value) throws CoercionException;
360

    
361
    /**
362
     * If the field value can be any possible value, for its type.
363
     *
364
     * @deprecated now autodetect the mode of use
365
     */
366
    static final int ANY = 1;
367

    
368
    /**
369
     * If the field value must be one of a list of posible values.
370
     *
371
     * @deprecated usado automaticamente al asignar AvailableValues
372
     */
373
    static final int CHOICE = 2;
374

    
375
    /**
376
     * If the field value must pertain to a range of possible values.
377
     *
378
     * @deprecated usado automaticamente al asignar minValue/maxValue
379
     */
380
    static final int RANGE = 3;
381

    
382
    /**
383
     * @return 
384
     * @deprecated don't use, check minValue/maxValue and getAvailableValues
385
     * instead
386
     */
387
    int getTheTypeOfAvailableValues(); // SINGLE, CHOICE o RANGE
388

    
389
    /**
390
     * @param defaultValue
391
     * @return 
392
     * @deprecated use instead {@link #setDefaultFieldValue(Object)}
393
     */
394
    DynField setDefaultDynValue(Object defaultValue);
395

    
396
    /**
397
     * @param type
398
     * @return 
399
     * @deprecated don't use, set minValue/maxValue and availableValues instead
400
     */
401
    DynField setTheTypeOfAvailableValues(int type);
402

    
403
}