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

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
    /**
67
     * Return the name of the field.
68
     *
69
     * @return name of the field
70
     */
71
    public String getName();
72

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

    
81
    public DataType getDataType();
82

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

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

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

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

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

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

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

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

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

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

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

    
174
    public Object getMinValue();
175

    
176
    public Object getMaxValue();
177

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

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

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

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

    
215
    DynField setType(DataType type);
216

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

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

    
240
    DynField setGroup(String groupName);
241

    
242
    DynField setOrder(int order);
243

    
244
    DynField setMandatory(boolean mandatory);
245

    
246
    DynField setHidden(boolean hidden);
247

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

    
257
    DynField setAvailableValues(DynObjectValueItem[] values);
258

    
259
    DynField setAvailableValues(List values);
260

    
261
    DynField setMinValue(Object minValue);
262

    
263
    DynField setMaxValue(Object maxValue);
264

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
394
}