Revision 41212 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
231 231
	}
232 232

  
233 233
	public FeatureType getSubtype(String[] names) throws DataException {
234
		return new SubtypeFeatureType(this, names);
234
                if( names==null || names.length <1) {
235
                    return (FeatureType) this.clone();
236
                }
237
		return new SubtypeFeatureType(this, names, null);
235 238
	}
236 239

  
240
	public FeatureType getSubtype(String[] names, String[] constantsNames) throws DataException {
241
                if( (names==null || names.length <1) && (constantsNames==null || constantsNames.length <1) ) {
242
                    return (FeatureType) this.clone();
243
                }
244
		return new SubtypeFeatureType(this, names,constantsNames);
245
	}
246

  
237 247
	public boolean isSubtypeOf(FeatureType featureType) {
238 248
		return false;
239 249
	}
......
247 257
		private static final long serialVersionUID = 6913732960073922540L;
248 258
		WeakReference parent;
249 259

  
250
		SubtypeFeatureType(DefaultFeatureType parent, String[] names)
260
		SubtypeFeatureType(DefaultFeatureType parent, String[] names, String[] constantsNames)
251 261
				throws DataException {
252 262
			super(parent, false);
253 263
			DefaultFeatureAttributeDescriptor attrcopy;
254 264
			DefaultFeatureAttributeDescriptor attr;
255
			// Copy attributes
256
			for (int i = 0; i < names.length; i++) {
257
				attr = (DefaultFeatureAttributeDescriptor) parent
258
						.getAttributeDescriptor(names[i]);
259
				if (attr == null) {
260
					throw new SubtypeFeatureTypeNameException(names[i], parent
261
							.getId());
262
				}
263
				attrcopy = new DefaultFeatureAttributeDescriptor(attr);
264
				this.add(attrcopy);
265
				attrcopy.index = i;
266
			}
267 265

  
266
                        // Copy attributes
267
                        if (names != null && names.length > 0) {
268
                            for (int i = 0; i < names.length; i++) {
269
                                attr = (DefaultFeatureAttributeDescriptor) parent
270
                                        .getAttributeDescriptor(names[i]);
271
                                if (attr == null) {
272
                                    throw new SubtypeFeatureTypeNameException(names[i], parent
273
                                            .getId());
274
                                }
275
                                attrcopy = new DefaultFeatureAttributeDescriptor(attr);
276
                                this.add(attrcopy);
277
                                attrcopy.index = i;
278
                            }
279
                        } else {
280
                           for( int i=0; i<parent.size(); i++ ) {
281
                                attr = (DefaultFeatureAttributeDescriptor) parent.getAttributeDescriptor(i);
282
                                attrcopy = new DefaultFeatureAttributeDescriptor(attr);
283
                                this.add(attrcopy);
284
                                attrcopy.index = i;
285
                           }
286
                        }
287

  
288
                        // Set the consttants attributes.
289
                        if (constantsNames != null && constantsNames.length > 0) {
290
                            for (int i = 0; i < constantsNames.length; i++) {
291
                                attr = (DefaultFeatureAttributeDescriptor) this.getAttributeDescriptor(constantsNames[i]);
292
                                attr.setConstantValue(true);
293
                            }
294
                        }
295

  
268 296
			// Add missing pk fiels if any
269 297
			if (!parent.hasOID()) {
270 298
				Iterator iter = parent.iterator();
......
289 317

  
290 318
		public FeatureType getSubtype(String[] names) throws DataException {
291 319
			return new SubtypeFeatureType((DefaultFeatureType) this.parent
292
					.get(), names);
320
					.get(), names, null);
293 321
		}
294 322

  
295 323
		public boolean isSubtypeOf(FeatureType featureType) {

Also available in: Unified diff