Revision 41342 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/feature/impl/DefaultFeatureType.java

View differences:

DefaultFeatureType.java
25 25

  
26 26
import java.lang.ref.WeakReference;
27 27
import java.util.ArrayList;
28
import java.util.Arrays;
28 29
import java.util.Collections;
30
import java.util.HashSet;
29 31
import java.util.Iterator;
30 32
import java.util.List;
33
import java.util.Set;
31 34

  
32 35
import org.cresques.cts.IProjection;
33 36

  
......
36 39
import org.gvsig.fmap.dal.feature.EditableFeatureType;
37 40
import org.gvsig.fmap.dal.feature.Feature;
38 41
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
39
import org.gvsig.fmap.dal.feature.FeatureRule;
42
import org.gvsig.fmap.dal.feature.FeatureAttributeEmulator;
40 43
import org.gvsig.fmap.dal.feature.FeatureRules;
41 44
import org.gvsig.fmap.dal.feature.FeatureType;
42
import org.gvsig.fmap.dal.feature.exception.ValidateFeaturesException;
43 45
import org.gvsig.tools.dynobject.DynClass;
44 46
import org.gvsig.tools.dynobject.DynField;
45 47
import org.gvsig.tools.dynobject.DynMethod;
......
59 61

  
60 62
	private DefaultFeatureRules rules;
61 63
	protected boolean hasEvaluators;
64
	protected boolean hasEmulators;
62 65
	protected String defaultGeometryAttributeName;
63 66
	protected int defaultGeometryAttributeIndex;
64 67
	protected int defaultTimeAttributeIndex;
......
75 78
		this.id = id;
76 79
		this.rules = new DefaultFeatureRules();
77 80
		this.hasEvaluators = false;
81
		this.hasEmulators = false;
78 82
		this.defaultGeometryAttributeName = null;
79 83
		this.defaultGeometryAttributeIndex = -1;
80 84
		this.defaultTimeAttributeIndex = -1;
......
108 112
		}
109 113
		this.defaultGeometryAttributeName = other.defaultGeometryAttributeName;
110 114
		this.hasEvaluators = other.hasEvaluators;
115
		this.hasEmulators = other.hasEmulators;
111 116
		this.rules = (DefaultFeatureRules) other.rules.getCopy();
112 117
		this.defaultGeometryAttributeIndex = other.defaultGeometryAttributeIndex;
113 118
		this.defaultTimeAttributeIndex = other.defaultTimeAttributeIndex;
......
187 192
		return this.hasEvaluators;
188 193
	}
189 194

  
195
	public boolean hasEmulators() {
196
		return this.hasEmulators;
197
	}
198

  
190 199
	public List getSRSs() {
191 200
		if (this.srsList == null) {
192 201
			ArrayList tmp = new ArrayList();
......
258 267
		private static final long serialVersionUID = 6913732960073922540L;
259 268
		WeakReference parent;
260 269

  
261
		SubtypeFeatureType(DefaultFeatureType parent, String[] names, String[] constantsNames)
262
				throws DataException {
263
			super(parent, false);
264
			DefaultFeatureAttributeDescriptor attrcopy;
265
			DefaultFeatureAttributeDescriptor attr;
270
                SubtypeFeatureType(DefaultFeatureType parent, String[] names, String[] constantsNames)
271
                        throws DataException {
272
                    super(parent, false);
273
                    DefaultFeatureAttributeDescriptor attrcopy;
274
                    DefaultFeatureAttributeDescriptor attr;
275
                    Set attrnames = null;
266 276

  
267
                        // Copy attributes
268
                        if (names != null && names.length > 0) {
269
                            for (int i = 0; i < names.length; i++) {
270
                                attr = (DefaultFeatureAttributeDescriptor) parent
271
                                        .getAttributeDescriptor(names[i]);
272
                                if (attr == null) {
273
                                    throw new SubtypeFeatureTypeNameException(names[i], parent
274
                                            .getId());
277
                    // Copy attributes
278
                    if ( names != null && names.length > 0 ) {
279
                        attrnames = new HashSet();
280
                        attrnames.addAll(Arrays.asList(names));
281
                        if ( parent.hasEmulators ) {
282
                            for ( int i = 0; i < parent.size(); i++ ) {
283
                                attr = (DefaultFeatureAttributeDescriptor) parent.getAttributeDescriptor(i);
284
                                FeatureAttributeEmulator emulator = attr.getFeatureAttributeEmulator();
285
                                if ( emulator != null ) {
286
                                    String ss[] = emulator.getRequiredFieldNames();
287
                                    if ( ss != null ) {
288
                                        attrnames.addAll(Arrays.asList(ss));
289
                                    }
275 290
                                }
276
                                attrcopy = new DefaultFeatureAttributeDescriptor(attr);
277
                                this.add(attrcopy);
278
                                attrcopy.index = i;
279 291
                            }
280
                        } else {
281
                           for( int i=0; i<parent.size(); i++ ) {
282
                                attr = (DefaultFeatureAttributeDescriptor) parent.getAttributeDescriptor(i);
283
                                attrcopy = new DefaultFeatureAttributeDescriptor(attr);
284
                                this.add(attrcopy);
285
                                attrcopy.index = i;
286
                           }
287 292
                        }
293
                        Iterator it = attrnames.iterator();
294
                        int i = 0;
295
                        while ( it.hasNext() ) {
296
                            String name = (String) it.next();
297
                            attr = (DefaultFeatureAttributeDescriptor) parent
298
                                    .getAttributeDescriptor(name);
299
                            if ( attr == null ) {
300
                                throw new SubtypeFeatureTypeNameException(name, parent
301
                                        .getId());
302
                            }
303
                            attrcopy = new DefaultFeatureAttributeDescriptor(attr);
304
                            this.add(attrcopy);
305
                            attrcopy.index = i++;
306
                        }
288 307

  
289
                        // Set the consttants attributes.
290
                        if (constantsNames != null && constantsNames.length > 0) {
291
                            for (int i = 0; i < constantsNames.length; i++) {
292
                                attr = (DefaultFeatureAttributeDescriptor) this.getAttributeDescriptor(constantsNames[i]);
293
                                attr.setConstantValue(true);
308
                    } else {
309
                        for ( int i = 0; i < parent.size(); i++ ) {
310
                            attr = (DefaultFeatureAttributeDescriptor) parent.getAttributeDescriptor(i);
311
                            attrcopy = new DefaultFeatureAttributeDescriptor(attr);
312
                            this.add(attrcopy);
313
                            attrcopy.index = i;
314
                        }
315
                    }
316

  
317
                    // Set the consttants attributes.
318
                    if ( constantsNames != null && constantsNames.length > 0 ) {
319
                        for ( int i = 0; i < constantsNames.length; i++ ) {
320
                            if ( attrnames != null && attrnames.contains(constantsNames[i]) ) {
321
                                continue;
294 322
                            }
323
                            attr = (DefaultFeatureAttributeDescriptor) this.getAttributeDescriptor(constantsNames[i]);
324
                            attr.setConstantValue(true);
295 325
                        }
326
                    }
296 327

  
297
			// Add missing pk fiels if any
298
			if (!parent.hasOID()) {
299
				Iterator iter = parent.iterator();
300
				while (iter.hasNext()) {
301
					attr = (DefaultFeatureAttributeDescriptor) iter.next();
302
					if (attr.isPrimaryKey()
303
							&& this.getIndex(attr.getName()) < 0) {
304
						attrcopy = new DefaultFeatureAttributeDescriptor(attr);
305
						this.add(attrcopy);
306
						attrcopy.index = this.size() - 1;
307
					}
308
				}
309
			}
328
                    // Add missing pk fiels if any
329
                    if ( !parent.hasOID() ) {
330
                        Iterator iter = parent.iterator();
331
                        while ( iter.hasNext() ) {
332
                            attr = (DefaultFeatureAttributeDescriptor) iter.next();
333
                            if ( attr.isPrimaryKey() && this.getIndex(attr.getName()) < 0 ) {
334
                                attrcopy = new DefaultFeatureAttributeDescriptor(attr);
335
                                this.add(attrcopy);
336
                                attrcopy.index = this.size() - 1;
337
                            }
338
                        }
339
                    }
310 340

  
311
			this.defaultGeometryAttributeIndex = this
312
					.getIndex(this.defaultGeometryAttributeName);
313
			if (this.defaultGeometryAttributeIndex < 0) {
314
				this.defaultGeometryAttributeName = null;
315
			}
316
			this.parent = new WeakReference(parent);
317
		}
341
                    this.defaultGeometryAttributeIndex = this
342
                            .getIndex(this.defaultGeometryAttributeName);
343
                    if ( this.defaultGeometryAttributeIndex < 0 ) {
344
                        this.defaultGeometryAttributeName = null;
345
                    }
346
                    this.parent = new WeakReference(parent);
347
                }
318 348

  
319 349
		public FeatureType getSubtype(String[] names) throws DataException {
320 350
			return new SubtypeFeatureType((DefaultFeatureType) this.parent

Also available in: Unified diff