Revision 41483 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
3 3
 *
4 4
 * Copyright (C) 2007-2013 gvSIG Association.
5 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.
6
 * This program is free software; you can redistribute it and/or modify it under
7
 * the terms of the GNU General Public License as published by the Free Software
8
 * Foundation; either version 3 of the License, or (at your option) any later
9
 * version.
10 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.
11
 * This program is distributed in the hope that it will be useful, but WITHOUT
12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14
 * details.
15 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.
16
 * You should have received a copy of the GNU General Public License along with
17
 * this program; if not, write to the Free Software Foundation, Inc., 51
18
 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 19
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
20
 * For any additional information, do not hesitate to contact us at info AT
21
 * gvsig.com, or visit our website www.gvsig.com.
23 22
 */
24 23
package org.gvsig.fmap.dal.store.dbf;
25 24

  
......
28 27
import java.nio.charset.Charset;
29 28
import java.text.DateFormat;
30 29
import java.text.ParseException;
30
import java.text.SimpleDateFormat;
31 31
import java.util.ArrayList;
32 32
import java.util.Date;
33 33
import java.util.Iterator;
......
35 35
import java.util.Locale;
36 36

  
37 37
import org.apache.commons.io.FileUtils;
38
import org.apache.commons.lang3.StringUtils;
38 39
import org.slf4j.Logger;
39 40
import org.slf4j.LoggerFactory;
40 41

  
......
92 93
import org.gvsig.tools.exception.BaseException;
93 94

  
94 95
public class DBFStoreProvider extends AbstractFeatureStoreProvider implements
95
		ResourceConsumer {
96
        ResourceConsumer {
96 97

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

  
99 100
    public static final int MAX_FIELD_NAME_LENGTH = 11;
100
    
101
	public static String NAME = "DBF";
102
	public static String DESCRIPTION = "DBF file";
103
	private static final Locale ukLocale = new Locale("en", "UK");
104
	
105
	public static final String METADATA_DEFINITION_NAME = NAME;
106
	private static final String METADATA_ENCODING = "Encoding";
107
	private static final String METADATA_CODEPAGE = "CodePage";
108
		
109
	private DbaseFile dbfFile = null;
110
	private ResourceProvider dbfResource;
111
	private long counterNewsOIDs = -1;
112
	private DBFFeatureWriter writer;
113
	
114
	private static long lastLogTime = 0;
115 101

  
102
    public static String NAME = "DBF";
103
    public static String DESCRIPTION = "DBF file";
104
    private static final Locale ukLocale = new Locale("en", "UK");
116 105

  
117
	protected static void registerMetadataDefinition() throws MetadataException {
118
		MetadataManager manager = MetadataLocator.getMetadataManager();
119
		if( manager.getDefinition(METADATA_DEFINITION_NAME)==null ) {
120
			manager.addDefinition(
121
					METADATA_DEFINITION_NAME, 
122
					DBFStoreParameters.class.getResourceAsStream("DBFStoreMetadata.xml"),
123
					DBFStoreParameters.class.getClassLoader()
124
			);
125
		}
126
	}
106
    public static final String METADATA_DEFINITION_NAME = NAME;
107
    private static final String METADATA_ENCODING = "Encoding";
108
    private static final String METADATA_CODEPAGE = "CodePage";
127 109

  
128
	public DBFStoreProvider(DBFStoreParameters params,
129
			DataStoreProviderServices storeServices)
130
			throws InitializeException {
131
		super(
132
				params, 
133
				storeServices,
134
				FileHelper.newMetadataContainer(METADATA_DEFINITION_NAME)
135
		);
136
		this.init(params, storeServices);
137
	}
110
    private DbaseFile dbfFile = null;
111
    private ResourceProvider dbfResource;
112
    private long counterNewsOIDs = -1;
113
    private DBFFeatureWriter writer;
138 114

  
139
	protected DBFStoreProvider(DBFStoreParameters params,
140
			DataStoreProviderServices storeServices, DynObject metadata)
141
			throws InitializeException {
142
		super(params, storeServices, metadata);
143
		this.init(params, storeServices);
144
	}
115
    private static long lastLogTime = 0;
145 116

  
146
	protected void init(DBFStoreParameters params,
147
			DataStoreProviderServices storeServices) throws InitializeException {
148
		if( params == null ) {
149
			throw new InitializeException( new NullPointerException("params is null") );
150
		}
151
		File theFile = getDBFParameters().getDBFFile();
152
		if( theFile == null ) {
153
			throw new InitializeException( new NullPointerException("dbf file is null") );
154
		}
155
		initResource(params, storeServices);
117
    protected static void registerMetadataDefinition() throws MetadataException {
118
        MetadataManager manager = MetadataLocator.getMetadataManager();
119
        if (manager.getDefinition(METADATA_DEFINITION_NAME) == null) {
120
            manager.addDefinition(
121
                    METADATA_DEFINITION_NAME,
122
                    DBFStoreParameters.class.getResourceAsStream("DBFStoreMetadata.xml"),
123
                    DBFStoreParameters.class.getClassLoader()
124
            );
125
        }
126
    }
156 127

  
157
		Charset charset = params.getEncoding();
158
		this.dbfFile = new DbaseFile(theFile, charset);
128
    public DBFStoreProvider(DBFStoreParameters params,
129
            DataStoreProviderServices storeServices)
130
            throws InitializeException {
131
        super(
132
                params,
133
                storeServices,
134
                FileHelper.newMetadataContainer(METADATA_DEFINITION_NAME)
135
        );
136
        this.init(params, storeServices);
137
    }
159 138

  
160
		writer = new DBFFeatureWriter(this.getProviderName());
139
    protected DBFStoreProvider(DBFStoreParameters params,
140
            DataStoreProviderServices storeServices, DynObject metadata)
141
            throws InitializeException {
142
        super(params, storeServices, metadata);
143
        this.init(params, storeServices);
144
    }
161 145

  
162
		this.initFeatureType();
146
    protected void init(DBFStoreParameters params,
147
            DataStoreProviderServices storeServices) throws InitializeException {
148
        if (params == null) {
149
            throw new InitializeException(new NullPointerException("params is null"));
150
        }
151
        File theFile = getDBFParameters().getDBFFile();
152
        if (theFile == null) {
153
            throw new InitializeException(new NullPointerException("dbf file is null"));
154
        }
155
        initResource(params, storeServices);
163 156

  
164
	}
157
        Charset charset = params.getEncoding();
158
        this.dbfFile = new DbaseFile(theFile, charset);
165 159

  
166
	public Object getDynValue(String name) throws DynFieldNotFoundException {
167
		try {
168
			this.open();
169
		} catch (OpenException e) {
170
			throw new RuntimeException(e);
171
		}
172
		if( METADATA_ENCODING.equalsIgnoreCase(name) ) {
173
			return this.dbfFile.getOriginalCharset();
174
		} else if( METADATA_CODEPAGE.equalsIgnoreCase(name) ) {
175
			return new Byte(this.dbfFile.getCodePage());
176
		}
177
		return super.getDynValue(name);
178
	}
160
        writer = new DBFFeatureWriter(this.getProviderName());
179 161

  
180
	protected void initResource(DBFStoreParameters params,
181
			DataStoreProviderServices storeServices) throws InitializeException {
162
        this.initFeatureType();
182 163

  
183
		File theFile = getDBFParameters().getDBFFile();
184
		dbfResource =
185
				this.createResource(FileResource.NAME,
186
						new Object[] { theFile.getAbsolutePath() });
187
		dbfResource.addConsumer(this);
188
	}
164
    }
189 165

  
190
	public String getProviderName() {
191
		return NAME;
192
	}
166
    public Object getDynValue(String name) throws DynFieldNotFoundException {
167
        try {
168
            this.open();
169
        } catch (OpenException e) {
170
            throw new RuntimeException(e);
171
        }
172
        if (METADATA_ENCODING.equalsIgnoreCase(name)) {
173
            return this.dbfFile.getOriginalCharset();
174
        } else if (METADATA_CODEPAGE.equalsIgnoreCase(name)) {
175
            return new Byte(this.dbfFile.getCodePage());
176
        }
177
        return super.getDynValue(name);
178
    }
193 179

  
194
	protected DBFStoreParameters getDBFParameters() {
195
		return (DBFStoreParameters) super.getParameters();
196
	}
180
    protected void initResource(DBFStoreParameters params,
181
            DataStoreProviderServices storeServices) throws InitializeException {
197 182

  
183
        File theFile = getDBFParameters().getDBFFile();
184
        dbfResource
185
                = this.createResource(FileResource.NAME,
186
                        new Object[]{theFile.getAbsolutePath()});
187
        dbfResource.addConsumer(this);
188
    }
198 189

  
199
	public DataServerExplorer getExplorer() throws ReadException {
200
		DataManager manager = DALLocator.getDataManager();
201
		FilesystemServerExplorerParameters params;
202
		try {
203
			params = (FilesystemServerExplorerParameters) manager
204
					.createServerExplorerParameters(FilesystemServerExplorer.NAME);
205
			params.setRoot(this.getDBFParameters().getDBFFile().getParent());
206
			return manager.openServerExplorer(FilesystemServerExplorer.NAME,params);
207
		} catch (DataException e) {
208
			throw new ReadException(this.getProviderName(), e);
209
		} catch (ValidateDataParametersException e) {
210
			// TODO Auto-generated catch block
211
			throw new ReadException(this.getProviderName(), e);
212
		}
213
	}
190
    public String getProviderName() {
191
        return NAME;
192
    }
214 193

  
215
	protected FeatureProvider internalGetFeatureProviderByReference(
216
			FeatureReferenceProviderServices reference, FeatureType featureType)
217
			throws DataException {
218
		return this.getFeatureProviderByIndex(
219
				((Long) reference.getOID()).longValue(), featureType);
220
	}
194
    protected DBFStoreParameters getDBFParameters() {
195
        return (DBFStoreParameters) super.getParameters();
196
    }
221 197

  
222
	public void performChanges(Iterator deleteds, Iterator inserteds,
223
			Iterator updateds, Iterator originalFeatureTypesUpdated)
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);
198
    public DataServerExplorer getExplorer() throws ReadException {
199
        DataManager manager = DALLocator.getDataManager();
200
        FilesystemServerExplorerParameters params;
201
        try {
202
            params = (FilesystemServerExplorerParameters) manager
203
                    .createServerExplorerParameters(FilesystemServerExplorer.NAME);
204
            params.setRoot(this.getDBFParameters().getDBFFile().getParent());
205
            return manager.openServerExplorer(FilesystemServerExplorer.NAME, params);
206
        } catch (DataException e) {
207
            throw new ReadException(this.getProviderName(), e);
208
        } catch (ValidateDataParametersException e) {
209
            // TODO Auto-generated catch block
210
            throw new ReadException(this.getProviderName(), e);
211
        }
212
    }
231 213

  
232
		try {
233
			final FeatureStore store =
234
					this.getStoreServices().getFeatureStore();
235
			getResource().execute(new ResourceAction() {
214
    protected FeatureProvider internalGetFeatureProviderByReference(
215
            FeatureReferenceProviderServices reference, FeatureType featureType)
216
            throws DataException {
217
        return this.getFeatureProviderByIndex(
218
                ((Long) reference.getOID()).longValue(), featureType);
219
    }
236 220

  
237
				public Object run() throws Exception {
238
					FeatureSet set = null;
239
					DisposableIterator iter = null;
240
					try {
241
						set = store.getFeatureSet();
242
						DBFStoreParameters tmpParams =
243
								(DBFStoreParameters) getDBFParameters().getCopy();
221
    public void performChanges(Iterator deleteds, Iterator inserteds,
222
            Iterator updateds, Iterator originalFeatureTypesUpdated)
223
            throws PerformEditingException {
244 224

  
245
						File tmp_file = File.createTempFile(
246
						    "tmp_" + System.currentTimeMillis(), ".dbf");
247
						tmp_file.deleteOnExit();
248
						
249
						tmpParams.setDBFFile(tmp_file);
225
        /*
226
         * This will throw an exception if there are new fields
227
         * with names too long
228
         */
229
        checkNewFieldsNameSize(originalFeatureTypesUpdated);
250 230

  
251
						writer.begin(tmpParams, store.getDefaultFeatureType(),
252
								set.getSize());
231
        try {
232
            final FeatureStore store
233
                    = this.getStoreServices().getFeatureStore();
234
            getResource().execute(new ResourceAction() {
253 235

  
254
						iter = set.fastIterator();
255
						while (iter.hasNext()) {
256
							Feature feature = (Feature) iter.next();
257
							writer.append(feature);
258
						}
236
                public Object run() throws Exception {
237
                    FeatureSet set = null;
238
                    DisposableIterator iter = null;
239
                    try {
240
                        set = store.getFeatureSet();
241
                        DBFStoreParameters tmpParams
242
                                = (DBFStoreParameters) getDBFParameters().getCopy();
259 243

  
260
						writer.end();
244
                        File tmp_file = File.createTempFile(
245
                                "tmp_" + System.currentTimeMillis(), ".dbf");
246
                        tmp_file.deleteOnExit();
261 247

  
262
						try {
263
							close();
264
						} catch (CloseException e1) {
265
							throw new PerformEditingException(getProviderName(), e1);
266
						}
267
						getDBFParameters().getDBFFile().delete();
268
						
269
						File target_file = getDBFParameters().getDBFFile();
270
						if (target_file.exists()) {
271
						    target_file.delete();
272
						}
273
						tmp_file.renameTo(target_file);
274
						
275
						if (tmp_file.exists() && !target_file.exists()) {
276
						    // Renaming failed, let's simply copy.
277
						    // We assume we cannot delete it, but we
278
						    // used deleteOnExit and it's
279
						    // temporary, so no problem
280
						    LOG.info("Warning: copying tmp file instead of renaming: "
281
	                                + target_file.getName());
282
						    FileUtils.copyFile(tmp_file, target_file);
283
						}
248
                        tmpParams.setDBFFile(tmp_file);
284 249

  
285
						resourcesNotifyChanges();
286
						initFeatureType();
287
					} finally {
288
						if (set != null) {
289
							set.dispose();
290
						}
291
						if (iter != null) {
292
							iter.dispose();
293
						}
294
					}
295
					return null;
296
				}
297
			});
298
		} catch (ResourceExecuteException e) {
299
			throw new PerformEditingException(this.getProviderName(), e);
300
		}
250
                        writer.begin(tmpParams, store.getDefaultFeatureType(),
251
                                set.getSize());
301 252

  
302
		this.counterNewsOIDs = -1;
303
	}
304
	
305
	protected void checkNewFieldsNameSize(Iterator ft_upd) throws PerformEditingException {
253
                        iter = set.fastIterator();
254
                        while (iter.hasNext()) {
255
                            Feature feature = (Feature) iter.next();
256
                            writer.append(feature);
257
                        }
306 258

  
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
	}
350
	/*
351
	 * ==================================================
352
	 */
259
                        writer.end();
353 260

  
354
	public FeatureProvider createFeatureProvider(FeatureType type) throws DataException {
355
		return new DBFFeatureProvider(this, type);
356
	}
261
                        try {
262
                            close();
263
                        } catch (CloseException e1) {
264
                            throw new PerformEditingException(getProviderName(), e1);
265
                        }
266
                        getDBFParameters().getDBFFile().delete();
357 267

  
268
                        File target_file = getDBFParameters().getDBFFile();
269
                        if (target_file.exists()) {
270
                            target_file.delete();
271
                        }
272
                        tmp_file.renameTo(target_file);
358 273

  
359
	/*
360
	 * ===================================================
361
	 */
274
                        if (tmp_file.exists() && !target_file.exists()) {
275
                            // Renaming failed, let's simply copy.
276
                            // We assume we cannot delete it, but we
277
                            // used deleteOnExit and it's
278
                            // temporary, so no problem
279
                            LOG.info("Warning: copying tmp file instead of renaming: "
280
                                    + target_file.getName());
281
                            FileUtils.copyFile(tmp_file, target_file);
282
                        }
362 283

  
284
                        resourcesNotifyChanges();
285
                        initFeatureType();
286
                    } finally {
287
                        if (set != null) {
288
                            set.dispose();
289
                        }
290
                        if (iter != null) {
291
                            iter.dispose();
292
                        }
293
                    }
294
                    return null;
295
                }
296
            });
297
        } catch (ResourceExecuteException e) {
298
            throw new PerformEditingException(this.getProviderName(), e);
299
        }
363 300

  
301
        this.counterNewsOIDs = -1;
302
    }
364 303

  
365
	protected void initFeatureType() throws InitializeException {
366
		try {
367
			FeatureType defaultType =
368
					this.getTheFeatureType().getNotEditableCopy();
369
			List types = new ArrayList(1);
370
			types.add(defaultType);
371
			this.getStoreServices().setFeatureTypes(types, defaultType);
372
		} catch (OpenException e) {
373
			throw new InitializeException(getResource().toString(), e);
374
		}
375
	}
304
    protected void checkNewFieldsNameSize(Iterator ft_upd) throws PerformEditingException {
376 305

  
377
	protected EditableFeatureType getTheFeatureType()
378
			throws InitializeException, OpenException {
379
		try {
380
			this.open();
381
		} catch (DataException e) {
382
			throw new InitializeException(this.getProviderName(), e);
383
		}
384
		return (EditableFeatureType) getResource().execute(
385
				new ResourceAction() {
306
        String long_fields = getNewFieldsWithNameTooLong(ft_upd);
307
        if (long_fields != null) {
308
            AttributeNameException ane = new AttributeNameTooLongException(
309
                    long_fields,
310
                    getProviderName(),
311
                    MAX_FIELD_NAME_LENGTH);
312
            throw new PerformEditingException(getProviderName(), ane);
313
        }
314
    }
386 315

  
387
					public Object run() throws Exception {
388
						int fieldCount = -1;
389
						fieldCount = dbfFile.getFieldCount();
316
    /**
317
     * Returns null or a string which is a comma-separated list
318
     *
319
     * @param ft_updated
320
     * @return
321
     */
322
    protected String getNewFieldsWithNameTooLong(Iterator ft_updated) {
390 323

  
391
						EditableFeatureType fType =
392
								getStoreServices().createFeatureType(getName());
324
        String resp = "";
325
        FeatureTypeChanged item = null;
326
        FeatureType ft = null;
327
        FeatureAttributeDescriptor[] atts = null;
328
        while (ft_updated.hasNext()) {
329
            item = (FeatureTypeChanged) ft_updated.next();
330
            ft = item.getTarget();
331
            atts = ft.getAttributeDescriptors();
332
            for (int i = 0; i < atts.length; i++) {
333
                if (atts[i].getName().length() > MAX_FIELD_NAME_LENGTH) {
334
                    if (resp.length() == 0) {
335
                        resp = atts[i].getName();
336
                    } else {
337
                        resp = resp + ", " + atts[i].getName();
338
                    }
339
                }
340
            }
341
        }
393 342

  
394
						fType.setHasOID(true);
395
						int precision;
396
						for (int i = 0; i < fieldCount; i++) {
397
							char fieldType = dbfFile.getFieldType(i);
398
							EditableFeatureAttributeDescriptor attr;
343
        if (resp.length() == 0) {
344
            return null;
345
        } else {
346
            return "(" + resp + ")";
347
        }
348
    }
349
    /*
350
     * ==================================================
351
     */
399 352

  
400
							if (fieldType == 'L') {
401
								attr =
402
										fType.add(dbfFile.getFieldName(i),
403
												DataTypes.BOOLEAN);
404
								attr.setDefaultValue(new Boolean(false));
405
								attr.setAllowNull(false);
353
    public FeatureProvider createFeatureProvider(FeatureType type) throws DataException {
354
        return new DBFFeatureProvider(this, type);
355
    }
406 356

  
407
							} else if ((fieldType == 'F') || (fieldType == 'N')) {
408
								precision = dbfFile.getFieldDecimalLength(i);
409
								if (precision > 0) {
410
									attr =
411
											fType.add(dbfFile.getFieldName(i),
412
													DataTypes.DOUBLE,
413
													dbfFile.getFieldLength(i));
414
									attr.setPrecision(precision);
415
									attr.setDefaultValue(new Double(0));
416 357

  
417
								} else {
418
								    int length = dbfFile.getFieldLength(i);
419
								    int type = DataTypes.INT;
420
								    if (length > 9){
421
								        type = DataTypes.LONG;
422
								    }
423
									attr =
424
											fType.add(dbfFile.getFieldName(i),
425
											        type,
426
													length);
427
									attr.setDefaultValue(new Integer(0));
428
								}
429
								attr.setAllowNull(false);
358
    /*
359
     * ===================================================
360
     */
361
    protected void initFeatureType() throws InitializeException {
362
        try {
363
            FeatureType defaultType
364
                    = this.getTheFeatureType().getNotEditableCopy();
365
            List types = new ArrayList(1);
366
            types.add(defaultType);
367
            this.getStoreServices().setFeatureTypes(types, defaultType);
368
        } catch (OpenException e) {
369
            throw new InitializeException(getResource().toString(), e);
370
        }
371
    }
430 372

  
431
							} else if (fieldType == 'C') {
432
								attr =
433
										fType.add(dbfFile.getFieldName(i),
434
												DataTypes.STRING);
435
								attr.setSize(dbfFile.getFieldLength(i));
436
								attr.setDefaultValue("");
437
								
438
								
439
								attr.setAllowNull(false);
373
    protected EditableFeatureType getTheFeatureType()
374
            throws InitializeException, OpenException {
375
        try {
376
            this.open();
377
        } catch (DataException e) {
378
            throw new InitializeException(this.getProviderName(), e);
379
        }
380
        return (EditableFeatureType) getResource().execute(
381
                new ResourceAction() {
440 382

  
441
							} else if (fieldType == 'D') {
442
								attr =
443
										fType.add(dbfFile.getFieldName(i),
444
												DataTypes.DATE);
445
								/*
446
								 * def value 1-1-1970
447
								 */
448
								attr.setDefaultValue(new Date(0));
449
								attr.setAllowNull(false);
450
							} else {
451
								throw new InitializeException(getProviderName(),
452
										new UnknownDataTypeException(
453
												dbfFile.getFieldName(i), ""
454
														+ fieldType, getProviderName()));
455
							}
456
						}
457
						
458
						// FeatureRules rules = fType.getRules();
459
						// rules.add(new DBFRowValidator());
460
						return fType;
461
					}
462
				});
463
	}
383
                    public Object run() throws Exception {
384
                        int fieldCount = -1;
385
                        fieldCount = dbfFile.getFieldCount();
464 386

  
387
                        EditableFeatureType fType = getStoreServices().createFeatureType(getName());
465 388

  
466
	protected void loadValue(FeatureProvider featureProvider, int rowIndex,
467
			FeatureAttributeDescriptor descriptor) throws ReadException {
468
	    
469
		if (descriptor.getEvaluator() != null) {
470
			// Nothing to do
471
			return;
472
		}
389
                        fType.setHasOID(true);
390
                        int precision;
391
                        for (int i = 0; i < fieldCount; i++) {
392
                            char fieldType = dbfFile.getFieldType(i);
393
                            EditableFeatureAttributeDescriptor attr;
473 394

  
474
		int dbfIndex = this.dbfFile.getFieldIndex(descriptor.getName());
475
		
476
		if (dbfIndex < 0) {
477
		    // Someone asked to load a field
478
		    // which does not exist in the DBF file. This can happen 
479
		    // in editing process when a field has been added
480
		    // in the current editing session, so we simply do nothing.
481
		    // The expansion manager is expected to manage those new fields
482
		    // and their values.
483
		    long curr_time = System.currentTimeMillis();
484
		    // This ensures not more than one log every 2 seconds
485
		    if (curr_time - lastLogTime > 2000) {
486
		        LOG.info("Warning: The requested field does not exist in the DBF file. Assumed it's a new field in editing mode.");
487
		        lastLogTime = curr_time;
488
		    }
489
		    return;
490
		}
491
		
492
		String value = null;
493
		try {
494
			value = this.dbfFile.getStringFieldValue(rowIndex, dbfIndex);
495
		} catch (DataException e) {
496
			throw new ReadException(this.getProviderName(), e);
497
		}
498
		value = value.trim();
499
		int fieldType = descriptor.getType();
500
		switch (fieldType) {
501
		case DataTypes.STRING:
502
			featureProvider.set(descriptor.getIndex(), value);
503
			break;
395
                            if (fieldType == 'L') {
396
                                attr = fType.add(dbfFile.getFieldName(i), DataTypes.BOOLEAN);
397
                                attr.setDefaultValue(new Boolean(false));
398
                                attr.setAllowNull(false);
504 399

  
505
		case DataTypes.DOUBLE:
506
			try {
507
				featureProvider.set(descriptor.getIndex(), new Double(value));
508
			} catch (NumberFormatException e) {
509
				featureProvider.set(descriptor.getIndex(), null);
510
			}
511
			break;
400
                            } else if ((fieldType == 'F') || (fieldType == 'N')) {
401
                                precision = dbfFile.getFieldDecimalLength(i);
402
                                if (precision > 0) {
403
                                    attr = fType.add(dbfFile.getFieldName(i),
404
                                            DataTypes.DOUBLE,
405
                                            dbfFile.getFieldLength(i));
406
                                    attr.setPrecision(precision);
407
                                    attr.setDefaultValue(new Double(0));
512 408

  
513
		case DataTypes.INT:
514
			try {
515
				featureProvider.set(descriptor.getIndex(), new Integer(value));
516
			} catch (NumberFormatException e) {
517
				featureProvider.set(descriptor.getIndex(), null);
518
			}
519
			break;
409
                                } else {
410
                                    int length = dbfFile.getFieldLength(i);
411
                                    int type = DataTypes.INT;
412
                                    if (length > 9) {
413
                                        type = DataTypes.LONG;
414
                                    }
415
                                    attr = fType.add(dbfFile.getFieldName(i),
416
                                            type,
417
                                            length);
418
                                    attr.setDefaultValue(new Integer(0));
419
                                }
420
                                attr.setAllowNull(false);
520 421

  
521
		case DataTypes.FLOAT:
522
			try {
523
				featureProvider.set(descriptor.getIndex(), new Float(value));
524
			} catch (NumberFormatException e) {
525
				featureProvider.set(descriptor.getIndex(), null);
526
			}
527
			break;
422
                            } else if (fieldType == 'C' || getDBFParameters().handleDatesAsStrings()) {
423
                                attr = fType.add(dbfFile.getFieldName(i), DataTypes.STRING);
424
                                attr.setSize(dbfFile.getFieldLength(i));
425
                                attr.setDefaultValue("");
426
                                attr.setAllowNull(false);
528 427

  
529
		case DataTypes.LONG:
530
			try {
531
				featureProvider.set(descriptor.getIndex(), new Long(value));
532
			} catch (NumberFormatException e) {
533
				featureProvider.set(descriptor.getIndex(), null);
534
			}
535
			break;
428
                            } else if (fieldType == 'D') {
429
                                attr = fType.add(dbfFile.getFieldName(i), DataTypes.DATE);
430
                                attr.setDefaultValue(new Date(0)); // def value 1-1-1970
431
                                attr.setAllowNull(true);
432
                                String sfmt = getDBFParameters().getDateFormat();
433
                                if (!StringUtils.isBlank(sfmt)) {
434
                                    try {
435
                                        SimpleDateFormat datefmt = new SimpleDateFormat(sfmt, getDBFParameters().getLocale());
436
                                        attr.setDateFormat(datefmt);
437
                                    } catch (Exception ex) {
438
                                        LOG.warn("Invalid date format ("+sfmt+") specified in DBF parameters.",ex);
439
                                    }
440
                                }
441
                            } else {
442
                                throw new InitializeException(getProviderName(),
443
                                        new UnknownDataTypeException(
444
                                                dbfFile.getFieldName(i), ""
445
                                                + fieldType, getProviderName()));
446
                            }
447
                        }
536 448

  
537
		case DataTypes.BOOLEAN:
538
			if (value.equalsIgnoreCase("T")){
539
				featureProvider.set(descriptor.getIndex(), Boolean.TRUE);
540
			} else {
541
				featureProvider.set(descriptor.getIndex(), Boolean.FALSE);
542
				
543
			}
544
			break;
449
                        // FeatureRules rules = fType.getRules();
450
                        // rules.add(new DBFRowValidator());
451
                        return fType;
452
                    }
453
                }
454
        );
455
    }
545 456

  
546
		case DataTypes.BYTE:
547
			try {
548
				featureProvider.set(descriptor.getIndex(), new Byte(value));
549
			} catch (NumberFormatException e) {
550
				featureProvider.set(descriptor.getIndex(), null);
551
			}
552
			break;
457
    protected void loadValue(FeatureProvider featureProvider, int rowIndex,
458
            FeatureAttributeDescriptor descriptor) throws ReadException {
553 459

  
554
		case DataTypes.DATE:
555
			if (value.equals("")){
556
				value=null;
557
				return;
558
			}
559
			String year = value.substring(0, 4);
560
			String month = value.substring(4, 6);
561
			String day = value.substring(6, 8);
562
			DateFormat df;
563
			if (descriptor.getDateFormat() == null){
564
				df = DateFormat.getDateInstance(DateFormat.SHORT,
565
						ukLocale);
566
			} else{
567
				df = descriptor.getDateFormat();
568
			}
569
			/*
570
			 * Calendar c = Calendar.getInstance(); c.clear();
571
			 * c.set(Integer.parseInt(year), Integer.parseInt(month),
572
			 * Integer.parseInt(day)); c.set(Calendar.MILLISECOND, 0);
573
			 */
574
			String strAux = month + "/" + day + "/" + year;
575
			Date dat = null;
576
			try {
577
				dat = df.parse(strAux);
578
			} catch (ParseException e) {
579
				throw new ReadException(this.getProviderName(), e);
580
			}
581
			featureProvider.set(descriptor.getIndex(), dat);
582
			break;
460
        if (descriptor.getEvaluator() != null) {
461
            // Nothing to do
462
            return;
463
        }
583 464

  
465
        int dbfIndex = this.dbfFile.getFieldIndex(descriptor.getName());
584 466

  
585
		default:
586
			featureProvider
587
					.set(descriptor.getIndex(), descriptor.getDefaultValue());
588
			break;
589
		}
590
	}
467
        if (dbfIndex < 0) {
468
            // Someone asked to load a field
469
            // which does not exist in the DBF file. This can happen 
470
            // in editing process when a field has been added
471
            // in the current editing session, so we simply do nothing.
472
            // The expansion manager is expected to manage those new fields
473
            // and their values.
474
            long curr_time = System.currentTimeMillis();
475
            // This ensures not more than one log every 2 seconds
476
            if (curr_time - lastLogTime > 2000) {
477
                LOG.info("Warning: The requested field does not exist in the DBF file. Assumed it's a new field in editing mode.");
478
                lastLogTime = curr_time;
479
            }
480
            return;
481
        }
591 482

  
483
        String value = null;
484
        try {
485
            value = this.dbfFile.getStringFieldValue(rowIndex, dbfIndex);
486
        } catch (DataException e) {
487
            throw new ReadException(this.getProviderName(), e);
488
        }
489
        value = value.trim();
490
        int fieldType = descriptor.getType();
491
        switch (fieldType) {
492
            case DataTypes.STRING:
493
                featureProvider.set(descriptor.getIndex(), value);
494
                break;
592 495

  
593
	/***
594
	 * NOT supported in Alter Mode
595
	 *
596
	 * @param index
597
	 * @return
598
	 * @throws ReadException
599
	 */
600
	protected FeatureProvider getFeatureProviderByIndex(long index) throws DataException {
601
		return this
602
				.getFeatureProviderByIndex(index, this.getStoreServices()
603
				.getDefaultFeatureType());
604
	}
496
            case DataTypes.DOUBLE:
497
                try {
498
                    featureProvider.set(descriptor.getIndex(), new Double(value));
499
                } catch (NumberFormatException e) {
500
                    featureProvider.set(descriptor.getIndex(), null);
501
                }
502
                break;
605 503

  
606
	public long getFeatureCount() throws ReadException, OpenException,
607
			ResourceNotifyChangesException {
608
		this.open();
609
		return ((Long) getResource().execute(new ResourceAction() {
610
			public Object run() throws Exception {
611
				return Long.valueOf(dbfFile.getRecordCount());
612
			}
613
		})).longValue();
614
	}
504
            case DataTypes.INT:
505
                try {
506
                    featureProvider.set(descriptor.getIndex(), new Integer(value));
507
                } catch (NumberFormatException e) {
508
                    featureProvider.set(descriptor.getIndex(), null);
509
                }
510
                break;
615 511

  
616
	public FeatureSetProvider createSet(FeatureQuery query, FeatureType featureType)
617
			throws DataException {
618
		return new DBFSetProvider(this, query, featureType);
619
	}
512
            case DataTypes.FLOAT:
513
                try {
514
                    featureProvider.set(descriptor.getIndex(), new Float(value));
515
                } catch (NumberFormatException e) {
516
                    featureProvider.set(descriptor.getIndex(), null);
517
                }
518
                break;
620 519

  
621
	public boolean canCreate() {
622
		return true;
623
	}
520
            case DataTypes.LONG:
521
                try {
522
                    featureProvider.set(descriptor.getIndex(), new Long(value));
523
                } catch (NumberFormatException e) {
524
                    featureProvider.set(descriptor.getIndex(), null);
525
                }
526
                break;
624 527

  
625
	public boolean canWriteGeometry(int geometryType, int geometrySubType) throws DataException {
626
		return false;
627
	}
528
            case DataTypes.BOOLEAN:
529
                if (value.equalsIgnoreCase("T")) {
530
                    featureProvider.set(descriptor.getIndex(), Boolean.TRUE);
531
                } else {
532
                    featureProvider.set(descriptor.getIndex(), Boolean.FALSE);
628 533

  
629
	public void open() throws OpenException {
630
		if (this.dbfFile.isOpen()) {
631
			return;
632
		}
633
		try {
634
			getResource().execute(new ResourceAction() {
635
				public Object run() throws Exception {
636
					openFile();
637
					resourcesOpen();
638
					return null;
639
				}
640
			});
534
                }
535
                break;
641 536

  
642
		} catch (ResourceExecuteException e) {
643
			throw new OpenException(this.getProviderName(), e);
644
		}
645
	}
537
            case DataTypes.BYTE:
538
                try {
539
                    featureProvider.set(descriptor.getIndex(), new Byte(value));
540
                } catch (NumberFormatException e) {
541
                    featureProvider.set(descriptor.getIndex(), null);
542
                }
543
                break;
646 544

  
647
	protected void openFile() throws FileNotFoundException,
648
			UnsupportedVersionException, IOException, DataException {
649
		this.dbfFile.open();
650
	}
545
            case DataTypes.DATE:
546
                if (value.equals("")) {
547
                    value = null;
548
                    return;
549
                }
550
                Date dat = null;
551
                DateFormat df = new SimpleDateFormat("yyyyMMdd");
552
                try {
553
                    dat = df.parse(value);
554
                } catch (ParseException e) {
555
                    throw new InvalidDateException(df.toString(), value, this.getProviderName(), e);
556
                }
557
                featureProvider.set(descriptor.getIndex(), dat);
558
                break;
651 559

  
652
	public void close() throws CloseException {
653
		if (dbfFile == null || !this.dbfFile.isOpen()) {
654
			return;
655
		}
656
		super.close();
657
		//Cerrar recurso
658
		try {
659
			getResource().execute(new ResourceAction() {
660
				public Object run() throws Exception {
661
					closeFile();
662
					resourcesNotifyClose();
663
					return null;
664
				}
665
			});
666
		} catch (ResourceExecuteException e) {
667
			throw new CloseException(this.getProviderName(), e);
668
		}
669
	}
560
            default:
561
                featureProvider
562
                        .set(descriptor.getIndex(), descriptor.getDefaultValue());
563
                break;
564
        }
565
    }
670 566

  
671
	protected void closeFile() throws CloseException {
672
		this.dbfFile.close();
673
	}
567
    private static class InvalidDateException extends ReadException {
568
        public InvalidDateException(String dateFormat, String value, String store, Throwable cause) {
569
            super(
570
                    "Can't parse date value '%(value)' with format '%(dateFormat)' in dbf '%(store)'.",
571
                    cause,
572
                    "Cant_parse_date_value_XvalueX_with_format_XdateFormatX_in_dbf_XstoreX",
573
                    0
574
            );
575
            setValue("dateFormat",dateFormat);
576
            setValue("value", value);
577
            setValue("store",store);   
578
        }
579
    }
580
    
581
    /**
582
     * *
583
     * NOT supported in Alter Mode
584
     *
585
     * @param index
586
     * @return
587
     * @throws ReadException
588
     */
589
    protected FeatureProvider getFeatureProviderByIndex(long index) throws DataException {
590
        return this
591
                .getFeatureProviderByIndex(index, this.getStoreServices()
592
                        .getDefaultFeatureType());
593
    }
674 594

  
675
	@Override
676
	protected void doDispose() throws BaseException {
677
		this.close();
678
		dbfFile = null;
679
		disposeResource();
680
		super.doDispose();
681
	}
595
    public long getFeatureCount() throws ReadException, OpenException,
596
            ResourceNotifyChangesException {
597
        this.open();
598
        return ((Long) getResource().execute(new ResourceAction() {
599
            public Object run() throws Exception {
600
                return Long.valueOf(dbfFile.getRecordCount());
601
            }
602
        })).longValue();
603
    }
682 604

  
683
	protected void disposeResource() {
684
		this.dbfResource.removeConsumer(this);
685
		dbfResource = null;
686
	}
605
    public FeatureSetProvider createSet(FeatureQuery query, FeatureType featureType)
606
            throws DataException {
607
        return new DBFSetProvider(this, query, featureType);
608
    }
687 609

  
688
	public boolean closeResourceRequested(ResourceProvider resource) {
689
		try {
690
			this.close();
691
		} catch (CloseException e) {
692
			return false;
693
		}
694
		return true;
695
	}
610
    public boolean canCreate() {
611
        return true;
612
    }
696 613

  
697
	public boolean allowWrite() {
698
		File file;
699
		try {
700
			file = ((File) this.dbfResource.get());
701
		} catch (AccessResourceException e) {
702
			return false;
703
		}
704
		return file.canWrite();
705
	}
614
    public boolean canWriteGeometry(int geometryType, int geometrySubType) throws DataException {
615
        return false;
616
    }
706 617

  
707
	public void refresh() throws OpenException {
708
		try {
709
			this.close();
710
		} catch (CloseException e) {
711
			throw new OpenException(this.getProviderName(), e);
712
		}
713
		this.open();
714
		try {
715
			this.initFeatureType();
716
		} catch (InitializeException e) {
717
			throw new OpenException(this.getProviderName(), e);
718
		}
719
	}
618
    public void open() throws OpenException {
619
        if (this.dbfFile.isOpen()) {
620
            return;
621
        }
622
        try {
623
            getResource().execute(new ResourceAction() {
624
                public Object run() throws Exception {
625
                    openFile();
626
                    resourcesOpen();
627
                    return null;
628
                }
629
            });
720 630

  
721
	/**
722
	 *
723
	 * @param index
724
	 * @param featureType
725
	 * @return
726
	 * @throws ReadException
727
	 */
728
	protected FeatureProvider getFeatureProviderByIndex(long index,
729
			FeatureType featureType) throws DataException {
730
		FeatureProvider featureProvider = this.createFeatureProvider(featureType);
731
		featureProvider.setOID(new Long(index));
732
		return featureProvider;
733
	}
631
        } catch (ResourceExecuteException e) {
632
            throw new OpenException(this.getProviderName(), e);
633
        }
634
    }
734 635

  
735
	protected void initFeatureProviderByIndex(FeatureProvider featureProvider,
736
			long index, FeatureType featureType) throws DataException {
737
		featureProvider.setOID(new Long(index));
738
	}
636
    protected void openFile() throws FileNotFoundException,
637
            UnsupportedVersionException, IOException, DataException {
638
        this.dbfFile.open();
639
    }
739 640

  
740
	/**
741
	 *
742
	 * @param featureProvider
743
	 * @throws DataException
744
	 */
745
	protected void loadFeatureProviderByIndex(FeatureProvider featureProvider)
746
			throws DataException {
747
	    
748
		long index = ((Long) featureProvider.getOID()).longValue();
641
    public void close() throws CloseException {
642
        if (dbfFile == null || !this.dbfFile.isOpen()) {
643
            return;
644
        }
645
        super.close();
646
        //Cerrar recurso
647
        try {
648
            getResource().execute(new ResourceAction() {
649
                public Object run() throws Exception {
650
                    closeFile();
651
                    resourcesNotifyClose();
652
                    return null;
653
                }
654
            });
655
        } catch (ResourceExecuteException e) {
656
            throw new CloseException(this.getProviderName(), e);
657
        }
658
    }
659

  
660
    protected void closeFile() throws CloseException {
661
        this.dbfFile.close();
662
    }
663

  
664
    @Override
665
    protected void doDispose() throws BaseException {
666
        this.close();
667
        dbfFile = null;
668
        disposeResource();
669
        super.doDispose();
670
    }
671

  
672
    protected void disposeResource() {
673
        this.dbfResource.removeConsumer(this);
674
        dbfResource = null;
675
    }
676

  
677
    public boolean closeResourceRequested(ResourceProvider resource) {
678
        try {
679
            this.close();
680
        } catch (CloseException e) {
681
            return false;
682
        }
683
        return true;
684
    }
685

  
686
    public boolean allowWrite() {
687
        File file;
688
        try {
689
            file = ((File) this.dbfResource.get());
690
        } catch (AccessResourceException e) {
691
            return false;
692
        }
693
        return file.canWrite();
694
    }
695

  
696
    public void refresh() throws OpenException {
697
        try {
698
            this.close();
699
        } catch (CloseException e) {
700
            throw new OpenException(this.getProviderName(), e);
701
        }
702
        this.open();
703
        try {
704
            this.initFeatureType();
705
        } catch (InitializeException e) {
706
            throw new OpenException(this.getProviderName(), e);
707
        }
708
    }
709

  
710
    /**
711
     *
712
     * @param index
713
     * @param featureType
714
     * @return
715
     * @throws ReadException
716
     */
717
    protected FeatureProvider getFeatureProviderByIndex(long index,
718
            FeatureType featureType) throws DataException {
719
        FeatureProvider featureProvider = this.createFeatureProvider(featureType);
720
        featureProvider.setOID(new Long(index));
721
        return featureProvider;
722
    }
723

  
724
    protected void initFeatureProviderByIndex(FeatureProvider featureProvider,
725
            long index, FeatureType featureType) throws DataException {
726
        featureProvider.setOID(new Long(index));
727
    }
728

  
729
    /**
730
     *
731
     * @param featureProvider
732
     * @throws DataException
733
     */
734
    protected void loadFeatureProviderByIndex(FeatureProvider featureProvider)
735
            throws DataException {
736

  
737
        long index = ((Long) featureProvider.getOID()).longValue();
749 738
        int rec_count = this.dbfFile.getRecordCount();
750
        
739

  
751 740
        if (index >= rec_count) {
752 741

  
753 742
            ReadException rex = new ReadException(NAME,
754
                new ArrayIndexOutOfBoundsException(
755
                "Index of requested feature (" +
756
                index + ") is >= record count (" + rec_count + ")"));
757
            
743
                    new ArrayIndexOutOfBoundsException(
744
                            "Index of requested feature ("
745
                            + index + ") is >= record count (" + rec_count + ")"));
746

  
758 747
            LOG.info("Error while loading feature. ", rex);
759 748
            throw rex;
760
        }		
761
		
762
		Iterator iterator = featureProvider.getType().iterator();
763
		while (iterator.hasNext()) {
764
			FeatureAttributeDescriptor descriptor =
765
					(FeatureAttributeDescriptor) iterator.next();
766
			this.loadValue(featureProvider, (int) index, descriptor);
767
		}
768
	}
749
        }
769 750

  
770
	public int getOIDType() {
771
		return DataTypes.LONG;
772
	}
751
        Iterator iterator = featureProvider.getType().iterator();
752
        while (iterator.hasNext()) {
753
            FeatureAttributeDescriptor descriptor
754
                    = (FeatureAttributeDescriptor) iterator.next();
755
            this.loadValue(featureProvider, (int) index, descriptor);
756
        }
757
    }
773 758

  
774
	public Object createNewOID() {
775
		if (this.counterNewsOIDs < 0) {
776
			try {
777
				this.counterNewsOIDs = this.getFeatureCount();
778
			} catch (DataException e) {
779
				e.printStackTrace();
780
			}
759
    public int getOIDType() {
760
        return DataTypes.LONG;
761
    }
781 762

  
782
		}else{
783
			this.counterNewsOIDs++;
784
		}
785
		return new Long(counterNewsOIDs);
786
	}
763
    public Object createNewOID() {
764
        if (this.counterNewsOIDs < 0) {
765
            try {
766
                this.counterNewsOIDs = this.getFeatureCount();
767
            } catch (DataException e) {
768
                e.printStackTrace();
769
            }
787 770

  
788
	public boolean supportsAppendMode() {
789
		return true;
790
	}
771
        } else {
772
            this.counterNewsOIDs++;
773
        }
774
        return new Long(counterNewsOIDs);
775
    }
791 776

  
777
    public boolean supportsAppendMode() {
778
        return true;
779
    }
792 780

  
793
	public void append(final FeatureProvider featureProvider)
794
			throws DataException {
795
		getResource().execute(new ResourceAction() {
796
			public Object run() throws Exception {
797
				writer.append(getStoreServices().createFeature(featureProvider));
798
				return null;
799
			}
800
		});
801
	}
781
    public void append(final FeatureProvider featureProvider)
782
            throws DataException {
783
        getResource().execute(new ResourceAction() {
784
            public Object run() throws Exception {
785
                writer.append(getStoreServices().createFeature(featureProvider));
786
                return null;
787
            }
788
        });
789
    }
802 790

  
803
	public void beginAppend() throws DataException {
804
		this.close();
805
		getResource().execute(new ResourceAction() {
806
			public Object run() throws Exception {
807
				writer.begin(getDBFParameters(),
808
						getStoreServices().getDefaultFeatureType(),
809
						getStoreServices().getFeatureStore().getFeatureCount());
810
				return null;
811
			}
812
		});
813
	}
791
    public void beginAppend() throws DataException {
792
        this.close();
793
        getResource().execute(new ResourceAction() {
794
            public Object run() throws Exception {
795
                writer.begin(getDBFParameters(),
796
                        getStoreServices().getDefaultFeatureType(),
797
                        getStoreServices().getFeatureStore().getFeatureCount());
798
                return null;
799
            }
800
        });
801
    }
814 802

  
815
	public void endAppend() throws DataException {
816
		getResource().execute(new ResourceAction() {
817
			public Object run() throws Exception {
818
				writer.end();
819
			    resourcesNotifyChanges();
820
				counterNewsOIDs = -1;
821
				return null;
822
			}
823
		});
824
	}
803
    public void endAppend() throws DataException {
804
        getResource().execute(new ResourceAction() {
805
            public Object run() throws Exception {
806
                writer.end();
807
                resourcesNotifyChanges();
808
                counterNewsOIDs = -1;
809
                return null;
810
            }
811
        });
812
    }
825 813

  
826
	/*
827
	 * (non-Javadoc)
828
	 *
829
	 * @see
830
	 * org.gvsig.fmap.dal.resource.spi.ResourceConsumer#resourceChanged(org.
831
	 * gvsig.fmap.dal.resource.spi.ResourceProvider)
832
	 */
833
	public void resourceChanged(ResourceProvider resource) {
834
		this.getStoreServices().notifyChange(
835
				DataStoreNotification.RESOURCE_CHANGED,
836
				resource);
837
	}
814
    /*
815
     * (non-Javadoc)
816
     *
817
     * @see
818
     * org.gvsig.fmap.dal.resource.spi.ResourceConsumer#resourceChanged(org.
819
     * gvsig.fmap.dal.resource.spi.ResourceProvider)
820
     */
821
    public void resourceChanged(ResourceProvider resource) {
822
        this.getStoreServices().notifyChange(
823
                DataStoreNotification.RESOURCE_CHANGED,
824
                resource);
825
    }
838 826

  
839
	/**
840
	 *
841
	 * @throws ResourceNotifyChangesException
842
	 */
843
	protected void resourcesNotifyChanges()
844
			throws ResourceNotifyChangesException {
845
		this.dbfResource.notifyChanges();
846
	}
827
    /**
828
     *
829
     * @throws ResourceNotifyChangesException
830
     */
831
    protected void resourcesNotifyChanges()
832
            throws ResourceNotifyChangesException {
833
        this.dbfResource.notifyChanges();
834
    }
847 835

  
848
	/**
849
	 * @throws ResourceNotifyCloseException
850
	 *
851
	 */
852
	protected void resourcesNotifyClose() throws ResourceNotifyCloseException {
853
		this.dbfResource.notifyClose();
854
	}
836
    /**
837
     * @throws ResourceNotifyCloseException
838
     *
839
     */
840
    protected void resourcesNotifyClose() throws ResourceNotifyCloseException {
841
        this.dbfResource.notifyClose();
842
    }
855 843

  
856
	/**
857
	 * @throws ResourceNotifyOpenException
858
	 *
859
	 */
860
	protected void resourcesOpen() throws ResourceNotifyOpenException {
861
		this.dbfResource.notifyOpen();
862
	}
844
    /**
845
     * @throws ResourceNotifyOpenException
846
     *
847
     */
848
    protected void resourcesOpen() throws ResourceNotifyOpenException {
849
        this.dbfResource.notifyOpen();
850
    }
863 851

  
864
	public Object getSourceId() {
865
		return this.getDBFParameters().getFile();
866
	}
867
	
868
	public String getName() {
869
		String name = this.getDBFParameters().getFile().getName();
870
		int n = name.lastIndexOf(".");
871
		if( n<1 ) {
872
			return name;
873
		}
874
		return name.substring(0, n);
875
	}
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff