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

History | View | Annotate | Download (10.6 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.Iterator;
27
import java.util.List;
28
import java.util.function.Predicate;
29

    
30
import org.cresques.cts.IProjection;
31

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

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

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

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

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

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

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

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

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

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

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

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

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

    
191
    public boolean isEmpty();
192

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
318
    /**
319
     * Return the store associated to this type.
320
     *
321
     * @return the FeatureStore of the type.
322
     */
323
    public FeatureStore getStore();
324

    
325
    public List<FeatureAttributeDescriptor> getFilteredAttributes(
326
            Predicate<FeatureAttributeDescriptor> filter,
327
            int max
328
    );
329

    
330
    public List<FeatureAttributeDescriptor> getRecentUseds();
331

    
332
    FeatureStore getAsFeatureStore();
333
    
334
    public String getNewFieldName();
335
     /**
336
     * Return the store associated to this type.
337
     * It will return Null when it's in not editing mode
338
     * or the featureType has not been change
339
     * 
340
     * @return the original FeatureStore of the type.
341
     */
342
    public FeatureType getOriginalFeatureType();
343
}