Revision 40597 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.dbf/src/main/java/org/gvsig/fmap/dal/store/dbf/DBFStoreProvider.java

View differences:

DBFStoreProvider.java
60 60
import org.gvsig.fmap.dal.feature.FeatureSet;
61 61
import org.gvsig.fmap.dal.feature.FeatureStore;
62 62
import org.gvsig.fmap.dal.feature.FeatureType;
63
import org.gvsig.fmap.dal.feature.exception.AttributeNameException;
64
import org.gvsig.fmap.dal.feature.exception.AttributeNameTooLongException;
63 65
import org.gvsig.fmap.dal.feature.exception.PerformEditingException;
64 66
import org.gvsig.fmap.dal.feature.exception.UnknownDataTypeException;
65 67
import org.gvsig.fmap.dal.feature.spi.AbstractFeatureStoreProvider;
66 68
import org.gvsig.fmap.dal.feature.spi.FeatureProvider;
67 69
import org.gvsig.fmap.dal.feature.spi.FeatureReferenceProviderServices;
68 70
import org.gvsig.fmap.dal.feature.spi.FeatureSetProvider;
71
import org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider.FeatureTypeChanged;
69 72
import org.gvsig.fmap.dal.resource.ResourceAction;
70 73
import org.gvsig.fmap.dal.resource.exception.AccessResourceException;
71 74
import org.gvsig.fmap.dal.resource.exception.ResourceException;
......
93 96

  
94 97
    private static final Logger LOG = LoggerFactory.getLogger(DBFStoreProvider.class);
95 98

  
99
    public static final int MAX_FIELD_NAME_LENGTH = 11;
100
    
96 101
	public static String NAME = "DBF";
97 102
	public static String DESCRIPTION = "DBF file";
98 103
	private static final Locale ukLocale = new Locale("en", "UK");
......
217 222
	public void performChanges(Iterator deleteds, Iterator inserteds,
218 223
			Iterator updateds, Iterator originalFeatureTypesUpdated)
219 224
			throws PerformEditingException {
225
		
226
		/*
227
		 * This will throw an exception if there are new fields
228
		 * with names too long
229
		 */
230
		checkNewFieldsNameSize(originalFeatureTypesUpdated);
220 231

  
221 232
		try {
222 233
			final FeatureStore store =
......
290 301

  
291 302
		this.counterNewsOIDs = -1;
292 303
	}
304
	
305
	protected void checkNewFieldsNameSize(Iterator ft_upd) throws PerformEditingException {
293 306

  
307
		String long_fields = getNewFieldsWithNameTooLong(ft_upd);
308
		if (long_fields != null) {
309
			AttributeNameException ane = new AttributeNameTooLongException(
310
					long_fields,
311
					getProviderName(),
312
					MAX_FIELD_NAME_LENGTH);
313
			throw new PerformEditingException(getProviderName(), ane);
314
		}
315
	}
316
	
317
	/**
318
	 * Returns null or a string which is a comma-separated list
319
	 * 
320
	 * @param ft_updated
321
	 * @return
322
	 */
323
	protected String getNewFieldsWithNameTooLong(Iterator ft_updated) {
324
		
325
		String resp = "";
326
		FeatureTypeChanged item = null;
327
		FeatureType ft = null;
328
		FeatureAttributeDescriptor[] atts = null;
329
		while (ft_updated.hasNext()) {
330
			item = (FeatureTypeChanged) ft_updated.next();
331
			ft = item.getTarget();
332
			atts = ft.getAttributeDescriptors();
333
			for (int i=0; i<atts.length; i++) {
334
				if (atts[i].getName().length() > MAX_FIELD_NAME_LENGTH) {
335
					if (resp.length() == 0) {
336
						resp = atts[i].getName(); 
337
					} else {
338
						resp = resp + ", " + atts[i].getName(); 
339
					}
340
				}
341
			}
342
		}
343
		
344
		if (resp.length() == 0) {
345
			return null;
346
		} else {
347
			return "(" + resp + ")";
348
		}
349
	}
294 350
	/*
295 351
	 * ==================================================
296 352
	 */

Also available in: Unified diff