Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.api / src / main / java / org / gvsig / fmap / dal / feature / FeatureType.java @ 45220

History | View | Annotate | Download (11.5 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
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.fmap.dal.feature;
25

    
26
import java.io.File;
27
import java.util.Iterator;
28
import java.util.List;
29
import java.util.function.Predicate;
30
import javax.json.JsonObject;
31
import javax.json.JsonObjectBuilder;
32

    
33
import org.cresques.cts.IProjection;
34

    
35
import org.gvsig.fmap.geom.Geometry;
36
import org.gvsig.tools.dataTypes.DataType;
37
import org.gvsig.tools.dynobject.DynClass;
38
import org.gvsig.tools.dynobject.DynStruct_v2;
39
import org.gvsig.tools.evaluator.Evaluator;
40
import org.gvsig.tools.util.UnmodifiableBasicList;
41

    
42
/**
43
 * <p>
44
 * This interface provides all the information that describes the structure of a
45
 * type of feature, methods for managing it and also offers a variety of utility
46
 * methods for simplicity's sake.
47
 * </p>
48
 *
49
 * <p>
50
 * The relevant information that compounds a FeatureType includes:
51
 * </p>
52
 *
53
 * <ul>
54
 * <li> {@link FeatureAttributeDescriptor}(s)
55
 * <li> {@link FeatureRule}(s)
56
 * <li> Its size
57
 * <li> Its SRS(s)
58
 * <li> Its identifier
59
 * <li> Whether features of this type have an OID or not (identifier assigned by
60
 * the store).
61
 * </ul>
62
 *
63
 * <p>
64
 * Methods for management include:
65
 * </p>
66
 *
67
 * <ul>
68
 * <li>Obtaining its editable instance.
69
 * <li>Obtaining an iterator over its attributes.
70
 * <li>Knowing whether this FeatureType has any associated evaluator for
71
 * calculated attributes.
72
 * </ul>
73
 *
74
 * <p>
75
 * Utility methods include:
76
 * </p>
77
 *
78
 * <ul>
79
 * <li>Getting a copy of the FeatureType.
80
 * <li>Getting the default geometry attribute.
81
 * <li>Getting the default spatial reference system.
82
 * </ul>
83
 */
84
public interface FeatureType extends DynClass, DynStruct_v2, UnmodifiableBasicList<FeatureAttributeDescriptor> {
85
        
86
    public interface FeatureTypeChanged {
87
      FeatureType getSource();
88

    
89
      FeatureType getTarget();
90
    }
91

    
92
    public static final Predicate<FeatureAttributeDescriptor> BASIC_TYPES_FILTER = new Predicate<FeatureAttributeDescriptor>() {
93
        @Override
94
        public boolean test(FeatureAttributeDescriptor attrdesc) {
95
            DataType t = attrdesc.getDataType();
96
            boolean r = !(t.isContainer() || t.isDynObject() || t.isObject());
97
            return r;
98
        }
99
    };
100

    
101
    public static Predicate<FeatureAttributeDescriptor> ALL_FILTER = new Predicate<FeatureAttributeDescriptor>() {
102
        @Override
103
        public boolean test(FeatureAttributeDescriptor t) {
104
            return true;
105
        }
106
    };
107
    
108
    /**
109
     * Returns a new copy of this FeatureType
110
     *
111
     * @return a new copy of this FeatureType
112
     */
113
    public FeatureType getCopy();
114

    
115
    public void copyFrom(FeatureType other);
116
    
117
    /**
118
     * Returns a {@link FeatureRules} containing all rules applicable to
119
     * features of this type.
120
     *
121
     * @return a {@link FeatureRules} containing all rules applicable to
122
     * features of this type.
123
     */
124
    public FeatureRules getRules();
125

    
126
    /**
127
     * Returns an editable instance of this FeatureType. Any modifications on a
128
     * FeatureType must be done through its editable instance.
129
     *
130
     * @return the editable instance of this FeatureType.
131
     *
132
     * @see EditableFeatureType
133
     */
134
    public EditableFeatureType getEditable();
135

    
136
    /**
137
     * Given the name of an attribute, this method returns its position in this
138
     * FeatureType.
139
     *
140
     * @param name of the attribute
141
     * @return position of the attribute
142
     */
143
    public int getIndex(String name);
144

    
145
    /**
146
     * Returns an attribute descriptor given its name.
147
     *
148
     * @param name of the attribute
149
     * @return descriptor of the attribute, a
150
     * {@link FeatureAttributeDescriptor}.
151
     */
152
    public Object get(String name);
153

    
154
    /**
155
     * Returns an attribute descriptor given its index
156
     *
157
     * @param index of the attribute
158
     *
159
     * @return descriptor of the attribute, a {@link FeatureAttributeDescriptor}
160
     */
161
    public FeatureAttributeDescriptor get(int index);
162

    
163
    /**
164
     * Returns a {@link FeatureAttributeDescriptor} given the attribute name, or
165
     * null if an attribute with the given name does not exist.
166
     *
167
     * @param name of the attribute
168
     *
169
     * @return a {@link FeatureAttributeDescriptor}
170
     */
171
    public FeatureAttributeDescriptor getAttributeDescriptor(String name);
172

    
173
    /**
174
     * Returns a {@link FeatureAttributeDescriptor} given the attribute index.
175
     *
176
     * @param index of the attribute
177
     *
178
     * @return a {@link FeatureAttributeDescriptor}
179
     */
180
    public FeatureAttributeDescriptor getAttributeDescriptor(int index);
181

    
182
    /**
183
     * Returns the name of the given the attribute index.
184
     * If the index is incorrect, return null.
185
     * 
186
     * @param index of the attribute
187
     *
188
     * @return a String with the name of attribute
189
     */
190
    public String getAttributeName(int index);
191
   
192
    /**
193
     * Returns an iterator over this FeatureType's attributes. Elements returned
194
     * by this iterator are of type {@link FeatureAttributeDescriptor}.
195
     *
196
     * @return An iterator over this FeatureType's
197
     * {@link FeatureAttributeDescriptor}s.
198
     */
199
    public Iterator iterator();
200

    
201
    /**
202
     * Returns this FeatureType size. The size of a FeatureType is determined by
203
     * its number of attributes.
204
     *
205
     * @return this FeatureType size, defined as the number of attributes it is
206
     * composed of.
207
     *
208
     */
209
    public int size();
210

    
211
    public boolean isEmpty();
212

    
213
    /**
214
     * Returns this FeatureType identifier. This identifier must always be equal
215
     * to a store.
216
     *
217
     * @return the identifier.
218
     */
219
    public String getId();
220

    
221
    /**
222
     * Returns the name of the attribute that will be used as default geometry
223
     * attribute for those processes that require a geometry (for instance
224
     * rendering).
225
     *
226
     * @return name of the default geometry attribute.
227
     */
228
    public String getDefaultGeometryAttributeName();
229

    
230
    /**
231
     * Returns the index of the attribute that will be used as default geometry
232
     * attribute.
233
     *
234
     * @return index of the default geometry attribute.
235
     */
236
    public int getDefaultGeometryAttributeIndex();
237

    
238
    /**
239
     * Returns a list with the SRSs in which this FeatureType geometries are
240
     * expressed. Normally there may be one SRS for each attribute of type
241
     * {@link Geometry}.
242
     *
243
     * @return a list with the SRS in which this FeatureType geometries are
244
     * expressed.
245
     */
246
    public List getSRSs();
247

    
248
    /**
249
     * Returns the SRS in which the default geometry attribute is expressed.
250
     *
251
     * @return the SRS in which the default geometry attribute is expressed,
252
     * null if not has a default geometry attribute.
253
     */
254
    public IProjection getDefaultSRS();
255

    
256
    /**
257
     * Indicates whether this FeatureType has any assigned {@link Evaluator}(s).
258
     * Evaluators are used to obtain the values for calculated attributes.
259
     *
260
     * @return true if this FeatureType has any assigned {@link Evaluator}(s).
261
     */
262
    public boolean hasEvaluators(); // FIXME: Quitar del interface y dejar en DefaultFeatureType
263

    
264
    /**
265
     * Indicates whether {@link Feature}(s) of this FeatureType have an OID
266
     * defined. An OID is the Feature unique identifier.
267
     *
268
     * Some stores provide their own OIDs which are always unique (such as
269
     * Postgre) while others don't support this concept and then it is the
270
     * library who creates runtime ad-hoc OIDs as it see fits, but then
271
     * integrity of this OIDs among different work sessions cannot be guaranteed
272
     * (this is the case for shape files).
273
     *
274
     * @return true if this FeatureType has an OID defined, false otherwise.
275
     *
276
     */
277
    public boolean hasOID();
278

    
279
    /**
280
     * Incicates if attibutes with automatic values are allowed in the source
281
     *
282
     * @return true if source supports this feature, false otherwise
283
     */
284
    public boolean allowAutomaticValues();
285

    
286
    /**
287
     * Returns an Array of the FeatureAttributeDescriptor
288
     *
289
     * @return
290
     */
291
    public FeatureAttributeDescriptor[] getAttributeDescriptors();
292

    
293
    /**
294
     * Returns an Array of the FeatureAttributeDescriptor that compounds the
295
     * primary key. If not have primary keys return a empty array.
296
     *
297
     * @return
298
     */
299
    public FeatureAttributeDescriptor[] getPrimaryKey();
300

    
301
    public boolean hasPrimaryKey();
302
    
303
    public boolean supportReferences();
304
    
305
    /**
306
     * Returns the default geometry FeatureAttributeDescriptor. Return null if
307
     * it's not set
308
     *
309
     * @return
310
     */
311
    public FeatureAttributeDescriptor getDefaultGeometryAttribute();
312

    
313
    /**
314
     * Returns the default time FeatureAttributeDescriptor. Return null if it's
315
     * not set.
316
     *
317
     * @return the default time attribute
318
     */
319
    public FeatureAttributeDescriptor getDefaultTimeAttribute();
320

    
321
    /**
322
     * Returns the name of the attribute that will be used as default geometry
323
     * attribute for those processes that require a geometry (for instance
324
     * rendering).
325
     *
326
     * @return name of the default geometry attribute.
327
     */
328
    public String getDefaultTimeAttributeName();
329

    
330
    /**
331
     * Returns the index of the attribute that will be used as default geometry
332
     * attribute.
333
     *
334
     * @return index of the default geometry attribute.
335
     */
336
    public int getDefaultTimeAttributeIndex();
337

    
338
    /**
339
     * Return the store associated to this type.
340
     *
341
     * @return the FeatureStore of the type.
342
     */
343
    public FeatureStore getStore();
344

    
345
    public List<FeatureAttributeDescriptor> getFilteredAttributes(
346
            Predicate<FeatureAttributeDescriptor> filter,
347
            int max
348
    );
349

    
350
    public List<FeatureAttributeDescriptor> getRecentUseds();
351

    
352
    FeatureStore getAsFeatureStore();
353
    
354
    public String getNewFieldName();
355

    
356
    /**
357
     * Return the original feature type of this type.
358
     * It will return Null when the store it's in not editing mode
359
     * or the featureType has not been change
360
     * 
361
     * @return the original FeatureType of the type.
362
     */
363
    public FeatureType getOriginalFeatureType();
364
    
365
    public boolean hasOnlyMetadataChanges(FeatureType other);
366

    
367
    public void writeAsDALFile(File file);
368
    
369
    public FeatureExtraColumns getExtraColumns();
370

    
371
    public JsonObject toJson();
372

    
373
    public JsonObjectBuilder toJsonBuilder();
374
    
375
    public Iterable<FeatureAttributeDescriptor> getAllAttributeDescriptors();
376

    
377
}