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

History | View | Annotate | Download (10.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.util.Comparator;
27
import java.util.Iterator;
28
import java.util.List;
29
import java.util.function.Predicate;
30
import org.apache.commons.lang3.StringUtils;
31

    
32
import org.cresques.cts.IProjection;
33

    
34
import org.gvsig.fmap.geom.Geometry;
35
import org.gvsig.tools.dataTypes.DataType;
36
import org.gvsig.tools.dataTypes.DataTypes;
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 static final Predicate<FeatureAttributeDescriptor> BASIC_TYPES_FILTER = new Predicate<FeatureAttributeDescriptor>() {
87
        @Override
88
        public boolean test(FeatureAttributeDescriptor attrdesc) {
89
            DataType t = attrdesc.getDataType();
90
            boolean r = !(t.isContainer() || t.isDynObject() || t.isObject());
91
            return r;
92
        }
93
    };
94

    
95
    public static Predicate<FeatureAttributeDescriptor> ALL_FILTER = new Predicate<FeatureAttributeDescriptor>() {
96
        @Override
97
        public boolean test(FeatureAttributeDescriptor t) {
98
            return true;
99
        }
100
    };
101
    /**
102
     * Returns a new copy of this FeatureType
103
     *
104
     * @return a new copy of this FeatureType
105
     */
106
    public FeatureType getCopy();
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 an iterator over this FeatureType's attributes. Elements returned
175
     * by this iterator are of type {@link FeatureAttributeDescriptor}.
176
     *
177
     * @return An iterator over this FeatureType's
178
     * {@link FeatureAttributeDescriptor}s.
179
     */
180
    public Iterator iterator();
181

    
182
    /**
183
     * Returns this FeatureType size. The size of a FeatureType is determined by
184
     * its number of attributes.
185
     *
186
     * @return this FeatureType size, defined as the number of attributes it is
187
     * composed of.
188
     *
189
     */
190
    public int size();
191

    
192
    public boolean isEmpty();
193

    
194
    /**
195
     * Returns this FeatureType identifier. This identifier must always be equal
196
     * to a store.
197
     *
198
     * @return the identifier.
199
     */
200
    public String getId();
201

    
202
    /**
203
     * Returns the name of the attribute that will be used as default geometry
204
     * attribute for those processes that require a geometry (for instance
205
     * rendering).
206
     *
207
     * @return name of the default geometry attribute.
208
     */
209
    public String getDefaultGeometryAttributeName();
210

    
211
    /**
212
     * Returns the index of the attribute that will be used as default geometry
213
     * attribute.
214
     *
215
     * @return index of the default geometry attribute.
216
     */
217
    public int getDefaultGeometryAttributeIndex();
218

    
219
    /**
220
     * Returns a list with the SRSs in which this FeatureType geometries are
221
     * expressed. Normally there may be one SRS for each attribute of type
222
     * {@link Geometry}.
223
     *
224
     * @return a list with the SRS in which this FeatureType geometries are
225
     * expressed.
226
     */
227
    public List getSRSs();
228

    
229
    /**
230
     * Returns the SRS in which the default geometry attribute is expressed.
231
     *
232
     * @return the SRS in which the default geometry attribute is expressed,
233
     * null if not has a default geometry attribute.
234
     */
235
    public IProjection getDefaultSRS();
236

    
237
    /**
238
     * Indicates whether this FeatureType has any assigned {@link Evaluator}(s).
239
     * Evaluators are used to obtain the values for calculated attributes.
240
     *
241
     * @return true if this FeatureType has any assigned {@link Evaluator}(s).
242
     */
243
    public boolean hasEvaluators(); // FIXME: Quitar del interface y dejar en DefaultFeatureType
244

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

    
260
    /**
261
     * Incicates if attibutes with automatic values are allowed in the source
262
     *
263
     * @return true if source supports this feature, false otherwise
264
     */
265
    public boolean allowAutomaticValues();
266

    
267
    /**
268
     * Returns an Array of the FeatureAttributeDescriptor
269
     *
270
     * @return
271
     */
272
    public FeatureAttributeDescriptor[] getAttributeDescriptors();
273

    
274
    /**
275
     * Returns an Array of the FeatureAttributeDescriptor that compounds the
276
     * primary key. If not have primary keys return a empty array.
277
     *
278
     * @return
279
     */
280
    public FeatureAttributeDescriptor[] getPrimaryKey();
281

    
282
    /**
283
     * Returns the default geometry FeatureAttributeDescriptor. Return null if
284
     * it's not set
285
     *
286
     * @return
287
     */
288
    public FeatureAttributeDescriptor getDefaultGeometryAttribute();
289

    
290
    /**
291
     * Returns the default time FeatureAttributeDescriptor. Return null if it's
292
     * not set.
293
     *
294
     * @return the default time attribute
295
     */
296
    public FeatureAttributeDescriptor getDefaultTimeAttribute();
297

    
298
    /**
299
     * Returns the name of the attribute that will be used as default geometry
300
     * attribute for those processes that require a geometry (for instance
301
     * rendering).
302
     *
303
     * @return name of the default geometry attribute.
304
     */
305
    public String getDefaultTimeAttributeName();
306

    
307
    /**
308
     * Returns the index of the attribute that will be used as default geometry
309
     * attribute.
310
     *
311
     * @return index of the default geometry attribute.
312
     */
313
    public int getDefaultTimeAttributeIndex();
314

    
315
    /**
316
     * Return the store associated to this type.
317
     *
318
     * @return the FeatureStore of the type.
319
     */
320
    public FeatureStore getStore();
321

    
322
    public List<FeatureAttributeDescriptor> getFilteredAttributes(
323
            Predicate<FeatureAttributeDescriptor> filter,
324
            int max
325
    );
326

    
327
    public List<FeatureAttributeDescriptor> getRecentUseds();
328

    
329
}