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 @ 1860

History | View | Annotate | Download (11 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_COMPOSITION = 3;
59

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

    
65
    /**
66
     * Return the name of the field.
67
     *
68
     * @return name of the field
69
     */
70
    public String getName();
71

    
72
    /**
73
     * Return the type used in this field. The values of type is the same of
74
     * {@link DataTypes}
75
     *
76
     * @return
77
     */
78
    public int getType();
79

    
80
    public DataType getDataType();
81

    
82
    /**
83
     * Return the subtype associated to this field. The subtype is a string used
84
     * for the cliente of the field.
85
     *
86
     * When the field is of type #{@link DataTypes#DYNOBJECT}, the subtype are
87
     * the fullname of the DynClass.
88
     *
89
     * @return the subtype of the field.
90
     */
91
    public String getSubtype();
92

    
93
    /**
94
     * Return the descripcion associated to this field.
95
     *
96
     * @return the description of the field.
97
     */
98
    public String getDescription();
99

    
100
    /**
101
     * Return the default value used in creation of new objects with this field.
102
     *
103
     * @return defaulr value to use for this field.
104
     */
105
    public Object getDefaultValue();
106

    
107
    /**
108
     * Return a string that identify a group for this field. The groups are
109
     * defined by the client of the field.
110
     *
111
     * @return the group of the field
112
     */
113
    public String getGroup();
114

    
115
    /**
116
     * Return the ordinal that identify the order of this field in the
117
     * {@link DynObject}.
118
     *
119
     * @return the order of field in the {@link DynObject}
120
     */
121
    public int getOder();
122

    
123
    /**
124
     * Return true if this field is mandatory.
125
     *
126
     * @return
127
     */
128
    public boolean isMandatory();
129

    
130
    /**
131
     * Returns if the field is persistent or volatile. The meaning of being
132
     * persistent depends on how is persisted, but any persistence mechanism
133
     * must avoid persisting this field value.
134
     *
135
     * @return if the field is to be persisted or not
136
     */
137
    boolean isPersistent();
138

    
139
    /**
140
     * Inform if this field can be visible or not for the user. This value don't
141
     * affect the access through the API.
142
     *
143
     * @return true if the field is hidden for the user.
144
     */
145
    boolean isHidden();
146

    
147
    /**
148
     * Returns if the field is readOnly or not. The meaning of being readOnly
149
     * allows to know if the user input to any graphic component associated to
150
     * this field should be allowed or not.
151
     *
152
     * @return if the graphic component associated to this field should be
153
     * readOnly or not
154
     */
155
    public boolean isReadOnly();
156

    
157
    /**
158
     * Return true if the value of this field is a container. This method uses
159
     * the same criteria of the {@link DataType}
160
     *
161
     * @return true if the field type is a container
162
     */
163
    public boolean isContainer();
164

    
165
    /**
166
     * Return the available values for this field. When assign a value to the
167
     * field, this value need that exists in this list.
168
     *
169
     * @return an array of the available values for the field.
170
     */
171
    public DynObjectValueItem[] getAvailableValues();
172

    
173
    public Object getMinValue();
174

    
175
    public Object getMaxValue();
176

    
177
    /**
178
     * Return the java class of the value of the field.
179
     *
180
     * @return the class of the value
181
     */
182
    Class getClassOfValue();
183

    
184
    /**
185
     * If the field is a container (List, Map or Set) return the java class of
186
     * its items.
187
     *
188
     * @return the class of the items
189
     */
190
    Class getClassOfItems();
191

    
192
    /**
193
     * Sets the description asociated to this field.
194
     *
195
     * @param description
196
     *
197
     * @return this same {@link DynField} object
198
     */
199
    DynField setDescription(String description);
200

    
201
    /**
202
     * Sets the type of the field. The values used are the specified in
203
     * {@link DataTypes}.
204
     *
205
     * This method assign the default values of the type for "ClassOfValue" and
206
     * "subType".
207
     *
208
     * @param type
209
     *
210
     * @return this same {@link DynField} object
211
     */
212
    DynField setType(int type);
213

    
214
    DynField setType(DataType type);
215

    
216
    /**
217
     * Strings used as subtype for this field. This value is used by the client
218
     * of the object.
219
     *
220
     * When the field is a #{@link DataTypes#DYNOBJECT}, the subtype is the
221
     * fullname of the DynStruct.
222
     *
223
     * @param subtype
224
     *
225
     * @return this same {@link DynField} object
226
     */
227
    DynField setSubtype(String subtype);
228

    
229
    /**
230
     * Set the default value used for this field when a new object with this
231
     * field is created.
232
     *
233
     * @param defaultValue
234
     *
235
     * @return this same {@link DynField} object
236
     */
237
    DynField setDefaultFieldValue(Object defaultValue);
238

    
239
    DynField setGroup(String groupName);
240

    
241
    DynField setOrder(int order);
242

    
243
    DynField setMandatory(boolean mandatory);
244

    
245
    DynField setHidden(boolean hidden);
246

    
247
    /**
248
     * Sets if the field must be persisted or not.
249
     *
250
     * @see #isPersistent()
251
     * @param persistent if the field must be persisted or not
252
     * @return this same {@link DynField} object
253
     */
254
    DynField setPersistent(boolean persistent);
255

    
256
    DynField setAvailableValues(DynObjectValueItem[] values);
257

    
258
    DynField setAvailableValues(List values);
259

    
260
    DynField setMinValue(Object minValue);
261

    
262
    DynField setMaxValue(Object maxValue);
263

    
264
    /**
265
     * Sets the class used for the values of the field.
266
     *
267
     * @param theClass
268
     *
269
     * @return this same {@link DynField} object
270
     *
271
     * @throws DynFieldIsNotAContainerException
272
     */
273
    DynField setClassOfValue(Class theClass) throws DynFieldIsNotAContainerException;
274

    
275
    /**
276
     * If field type is List, Set or Map, this class is the class of items.
277
     *
278
     * @param theClass
279
     *
280
     * @return this same {@link DynField} object
281
     *
282
     * @throws DynFieldIsNotAContainerException
283
     */
284
    DynField setClassOfItems(Class theClass) throws DynFieldIsNotAContainerException;
285

    
286
    /**
287
     * Sets if the field is readOnly or not. The meaning of being readOnly
288
     * allows to know if the user input to any graphic component associated to
289
     * this field should be allowed or not.
290
     *
291
     * @param isReadOnly if the graphic component associated to this field
292
     * should be readOnly or not
293
     *
294
     * @return DynField that define the type of elements.
295
     */
296
    public DynField setReadOnly(boolean isReadOnly);
297

    
298
    /**
299
     * When a field is of type container, this method return a DynClass that
300
     * define the type of elements. When the type is DYNOBJECT return the
301
     * DynClass associated to this.
302
     *
303
     * Return null if the type not is a container.
304
     *
305
     * @return DynField that define the type of elements.
306
     */
307
    public DynField getElementsType();
308

    
309
    /**
310
     * Set the type of items when the field is a container.
311
     *
312
     * El tipo de los elementos de un container esta definido mediante un
313
     * DynField, que crea con el tipo pasado por parametro y lo devuelve este
314
     * metodo.
315
     *
316
     * @param type de los elementos
317
     * @return this same {@link DynField} object
318
     * @throws DynFieldIsNotAContainerException
319
     */
320
    public DynField setElementsType(int type) throws DynFieldIsNotAContainerException;
321

    
322
    /**
323
     * Set the type of items when the field is a container.
324
     *
325
     * Metodo de utilidad que establece el typo de DYNOBJECT y methe como
326
     * subtipo el DynStruct pasado como parametro.
327
     *
328
     * @param type de los elementos
329
     * @return this same {@link DynField} object
330
     * @throws DynFieldIsNotAContainerException
331
     */
332
    public DynField setElementsType(DynStruct type) throws DynFieldIsNotAContainerException;
333

    
334
    /**
335
     * Validate that the value match the properties of the field.
336
     *
337
     * @param value
338
     * @throws DynFieldValidateException
339
     */
340
    void validate(Object value) throws DynFieldValidateException;
341

    
342
    /**
343
     * Force the type of value to the type of the field.
344
     *
345
     * @param value
346
     * @return new value
347
     * @throws CoercionException
348
     */
349
    Object coerce(Object value) throws CoercionException;
350

    
351
    /**
352
     * If the field value can be any possible value, for its type.
353
     *
354
     * @deprecated now autodetect the mode of use
355
     */
356
    static final int ANY = 1;
357

    
358
    /**
359
     * If the field value must be one of a list of posible values.
360
     *
361
     * @deprecated usado automaticamente al asignar AvailableValues
362
     */
363
    static final int CHOICE = 2;
364

    
365
    /**
366
     * If the field value must pertain to a range of possible values.
367
     *
368
     * @deprecated usado automaticamente al asignar minValue/maxValue
369
     */
370
    static final int RANGE = 3;
371

    
372
    /**
373
     * @return 
374
     * @deprecated don't use, check minValue/maxValue and getAvailableValues
375
     * instead
376
     */
377
    int getTheTypeOfAvailableValues(); // SINGLE, CHOICE o RANGE
378

    
379
    /**
380
     * @param defaultValue
381
     * @return 
382
     * @deprecated use instead {@link #setDefaultFieldValue(Object)}
383
     */
384
    DynField setDefaultDynValue(Object defaultValue);
385

    
386
    /**
387
     * @param type
388
     * @return 
389
     * @deprecated don't use, set minValue/maxValue and availableValues instead
390
     */
391
    DynField setTheTypeOfAvailableValues(int type);
392

    
393
}