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

History | View | Annotate | Download (10.4 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
    public void copyFrom(FeatureType other);
109
    
110
    /**
111
     * Returns a {@link FeatureRules} containing all rules applicable to
112
     * features of this type.
113
     *
114
     * @return a {@link FeatureRules} containing all rules applicable to
115
     * features of this type.
116
     */
117
    public FeatureRules getRules();
118

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

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

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

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

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

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

    
175
    /**
176
     * Returns an iterator over this FeatureType's attributes. Elements returned
177
     * by this iterator are of type {@link FeatureAttributeDescriptor}.
178
     *
179
     * @return An iterator over this FeatureType's
180
     * {@link FeatureAttributeDescriptor}s.
181
     */
182
    public Iterator iterator();
183

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

    
194
    public boolean isEmpty();
195

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

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

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

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

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

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

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

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

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

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

    
284
    public boolean hasPrimaryKey();
285
    
286
    public boolean supportReferences();
287
    
288
    /**
289
     * Returns the default geometry FeatureAttributeDescriptor. Return null if
290
     * it's not set
291
     *
292
     * @return
293
     */
294
    public FeatureAttributeDescriptor getDefaultGeometryAttribute();
295

    
296
    /**
297
     * Returns the default time FeatureAttributeDescriptor. Return null if it's
298
     * not set.
299
     *
300
     * @return the default time attribute
301
     */
302
    public FeatureAttributeDescriptor getDefaultTimeAttribute();
303

    
304
    /**
305
     * Returns the name of the attribute that will be used as default geometry
306
     * attribute for those processes that require a geometry (for instance
307
     * rendering).
308
     *
309
     * @return name of the default geometry attribute.
310
     */
311
    public String getDefaultTimeAttributeName();
312

    
313
    /**
314
     * Returns the index of the attribute that will be used as default geometry
315
     * attribute.
316
     *
317
     * @return index of the default geometry attribute.
318
     */
319
    public int getDefaultTimeAttributeIndex();
320

    
321
    /**
322
     * Return the store associated to this type.
323
     *
324
     * @return the FeatureStore of the type.
325
     */
326
    public FeatureStore getStore();
327

    
328
    public List<FeatureAttributeDescriptor> getFilteredAttributes(
329
            Predicate<FeatureAttributeDescriptor> filter,
330
            int max
331
    );
332

    
333
    public List<FeatureAttributeDescriptor> getRecentUseds();
334

    
335
}