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

History | View | Annotate | Download (11.1 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

    
31
import org.cresques.cts.IProjection;
32

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

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

    
84
    public static final Predicate<FeatureAttributeDescriptor> BASIC_TYPES_FILTER = new Predicate<FeatureAttributeDescriptor>() {
85
        @Override
86
        public boolean test(FeatureAttributeDescriptor attrdesc) {
87
            DataType t = attrdesc.getDataType();
88
            boolean r = !(t.isContainer() || t.isDynObject() || t.isObject());
89
            return r;
90
        }
91
    };
92

    
93
    public static Predicate<FeatureAttributeDescriptor> ALL_FILTER = new Predicate<FeatureAttributeDescriptor>() {
94
        @Override
95
        public boolean test(FeatureAttributeDescriptor t) {
96
            return true;
97
        }
98
    };
99
    /**
100
     * Returns a new copy of this FeatureType
101
     *
102
     * @return a new copy of this FeatureType
103
     */
104
    public FeatureType getCopy();
105

    
106
    public void copyFrom(FeatureType other);
107
    
108
    /**
109
     * Returns a {@link FeatureRules} containing all rules applicable to
110
     * features of this type.
111
     *
112
     * @return a {@link FeatureRules} containing all rules applicable to
113
     * features of this type.
114
     */
115
    public FeatureRules getRules();
116

    
117
    /**
118
     * Returns an editable instance of this FeatureType. Any modifications on a
119
     * FeatureType must be done through its editable instance.
120
     *
121
     * @return the editable instance of this FeatureType.
122
     *
123
     * @see EditableFeatureType
124
     */
125
    public EditableFeatureType getEditable();
126

    
127
    /**
128
     * Given the name of an attribute, this method returns its position in this
129
     * FeatureType.
130
     *
131
     * @param name of the attribute
132
     * @return position of the attribute
133
     */
134
    public int getIndex(String name);
135

    
136
    /**
137
     * Returns an attribute descriptor given its name.
138
     *
139
     * @param name of the attribute
140
     * @return descriptor of the attribute, a
141
     * {@link FeatureAttributeDescriptor}.
142
     */
143
    public Object get(String name);
144

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

    
154
    /**
155
     * Returns a {@link FeatureAttributeDescriptor} given the attribute name, or
156
     * null if an attribute with the given name does not exist.
157
     *
158
     * @param name of the attribute
159
     *
160
     * @return a {@link FeatureAttributeDescriptor}
161
     */
162
    public FeatureAttributeDescriptor getAttributeDescriptor(String name);
163

    
164
    /**
165
     * Returns a {@link FeatureAttributeDescriptor} given the attribute index.
166
     *
167
     * @param index of the attribute
168
     *
169
     * @return a {@link FeatureAttributeDescriptor}
170
     */
171
    public FeatureAttributeDescriptor getAttributeDescriptor(int index);
172

    
173
    /**
174
     * Returns the name of the given the attribute index.
175
     * If the index is incorrect, return null.
176
     * 
177
     * @param index of the attribute
178
     *
179
     * @return a String with the name of attribute
180
     */
181
    public String getAttributeName(int index);
182
   
183
    /**
184
     * Returns an iterator over this FeatureType's attributes. Elements returned
185
     * by this iterator are of type {@link FeatureAttributeDescriptor}.
186
     *
187
     * @return An iterator over this FeatureType's
188
     * {@link FeatureAttributeDescriptor}s.
189
     */
190
    public Iterator iterator();
191

    
192
    /**
193
     * Returns this FeatureType size. The size of a FeatureType is determined by
194
     * its number of attributes.
195
     *
196
     * @return this FeatureType size, defined as the number of attributes it is
197
     * composed of.
198
     *
199
     */
200
    public int size();
201

    
202
    public boolean isEmpty();
203

    
204
    /**
205
     * Returns this FeatureType identifier. This identifier must always be equal
206
     * to a store.
207
     *
208
     * @return the identifier.
209
     */
210
    public String getId();
211

    
212
    /**
213
     * Returns the name of the attribute that will be used as default geometry
214
     * attribute for those processes that require a geometry (for instance
215
     * rendering).
216
     *
217
     * @return name of the default geometry attribute.
218
     */
219
    public String getDefaultGeometryAttributeName();
220

    
221
    /**
222
     * Returns the index of the attribute that will be used as default geometry
223
     * attribute.
224
     *
225
     * @return index of the default geometry attribute.
226
     */
227
    public int getDefaultGeometryAttributeIndex();
228

    
229
    /**
230
     * Returns a list with the SRSs in which this FeatureType geometries are
231
     * expressed. Normally there may be one SRS for each attribute of type
232
     * {@link Geometry}.
233
     *
234
     * @return a list with the SRS in which this FeatureType geometries are
235
     * expressed.
236
     */
237
    public List getSRSs();
238

    
239
    /**
240
     * Returns the SRS in which the default geometry attribute is expressed.
241
     *
242
     * @return the SRS in which the default geometry attribute is expressed,
243
     * null if not has a default geometry attribute.
244
     */
245
    public IProjection getDefaultSRS();
246

    
247
    /**
248
     * Indicates whether this FeatureType has any assigned {@link Evaluator}(s).
249
     * Evaluators are used to obtain the values for calculated attributes.
250
     *
251
     * @return true if this FeatureType has any assigned {@link Evaluator}(s).
252
     */
253
    public boolean hasEvaluators(); // FIXME: Quitar del interface y dejar en DefaultFeatureType
254

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

    
270
    /**
271
     * Incicates if attibutes with automatic values are allowed in the source
272
     *
273
     * @return true if source supports this feature, false otherwise
274
     */
275
    public boolean allowAutomaticValues();
276

    
277
    /**
278
     * Returns an Array of the FeatureAttributeDescriptor
279
     *
280
     * @return
281
     */
282
    public FeatureAttributeDescriptor[] getAttributeDescriptors();
283

    
284
    /**
285
     * Returns an Array of the FeatureAttributeDescriptor that compounds the
286
     * primary key. If not have primary keys return a empty array.
287
     *
288
     * @return
289
     */
290
    public FeatureAttributeDescriptor[] getPrimaryKey();
291

    
292
    public boolean hasPrimaryKey();
293
    
294
    public boolean supportReferences();
295
    
296
    /**
297
     * Returns the default geometry FeatureAttributeDescriptor. Return null if
298
     * it's not set
299
     *
300
     * @return
301
     */
302
    public FeatureAttributeDescriptor getDefaultGeometryAttribute();
303

    
304
    /**
305
     * Returns the default time FeatureAttributeDescriptor. Return null if it's
306
     * not set.
307
     *
308
     * @return the default time attribute
309
     */
310
    public FeatureAttributeDescriptor getDefaultTimeAttribute();
311

    
312
    /**
313
     * Returns the name of the attribute that will be used as default geometry
314
     * attribute for those processes that require a geometry (for instance
315
     * rendering).
316
     *
317
     * @return name of the default geometry attribute.
318
     */
319
    public String getDefaultTimeAttributeName();
320

    
321
    /**
322
     * Returns the index of the attribute that will be used as default geometry
323
     * attribute.
324
     *
325
     * @return index of the default geometry attribute.
326
     */
327
    public int getDefaultTimeAttributeIndex();
328

    
329
    /**
330
     * Return the store associated to this type.
331
     *
332
     * @return the FeatureStore of the type.
333
     */
334
    public FeatureStore getStore();
335

    
336
    public List<FeatureAttributeDescriptor> getFilteredAttributes(
337
            Predicate<FeatureAttributeDescriptor> filter,
338
            int max
339
    );
340

    
341
    public List<FeatureAttributeDescriptor> getRecentUseds();
342

    
343
    FeatureStore getAsFeatureStore();
344
    
345
    public String getNewFieldName();
346

    
347
    /**
348
     * Return the original feature type of this type.
349
     * It will return Null when the store it's in not editing mode
350
     * or the featureType has not been change
351
     * 
352
     * @return the original FeatureType of the type.
353
     */
354
    public FeatureType getOriginalFeatureType();
355
    
356
    public boolean hasOnlyMetadataChanges(FeatureType other);
357

    
358
    public void writeAsDALFile(File file);
359
    
360
    public FeatureExtraColumn getExtraColumn();
361

    
362
}