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

History | View | Annotate | Download (11.3 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 interface FeatureTypeChanged {
85
      FeatureType getSource();
86

    
87
      FeatureType getTarget();
88
    }
89

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

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

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

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

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

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

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

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

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

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

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

    
209
    public boolean isEmpty();
210

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
348
    public List<FeatureAttributeDescriptor> getRecentUseds();
349

    
350
    FeatureStore getAsFeatureStore();
351
    
352
    public String getNewFieldName();
353

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

    
365
    public void writeAsDALFile(File file);
366
    
367
    public FeatureExtraColumns getExtraColumns();
368

    
369
}