Revision 398

View differences:

tags/org.gvsig.gdal-1.0.61/org.gvsig.gdal.prov/org.gvsig.gdal.prov.ogr/src/main/resources/org/gvsig/gdal/prov/ogr/OGRMetadata.xml
1
<?xml version="1.0"?>
2
<!--
3
Definitions of metadata fields of a shp file.  
4
 -->
5
<definitions>
6
  <version>1.0.0</version>
7
  <classes>
8
    
9
    <class name="OGRDataStoreProvider" namespace="Metadata">
10
      <extends>
11
      	<class namespace="Metadata" name="SpatialProvider"/>
12
      </extends>
13
      <description>Metadata of a OGR provider</description>
14
      <fields>
15
      </fields>
16
    </class>
17

  
18
  </classes>
19
</definitions>  
tags/org.gvsig.gdal-1.0.61/org.gvsig.gdal.prov/org.gvsig.gdal.prov.ogr/src/main/resources/org/gvsig/gdal/prov/ogr/OGRExplorerParameters.xml
1
<?xml version="1.0"?>
2
<definitions>
3
	<version>1.0.0</version>
4
	<classes>
5
		<class name="OGRDataExplorerParameters">
6
			<description>Store the parameters needed to create OGR data explorers
7
			</description>
8
			<fields>
9
				<field name="file" type="file" mandatory="false" group="Basic">
10
					<description>Resource file</description>
11
				</field>
12
				<field name="connectionString" type="string" mandatory="false"
13
					group="Basic">
14
					<description>Connection string to open data source</description>
15
				</field>
16
			</fields>
17
		</class>
18
	</classes>
19
</definitions>
tags/org.gvsig.gdal-1.0.61/org.gvsig.gdal.prov/org.gvsig.gdal.prov.ogr/src/main/resources/org/gvsig/gdal/prov/ogr/OGRNewDataStoreParameters.xml
1
<definitions>
2
	<version>1.0.0</version>
3
	<classes>
4
		<class name="OGRNewDataStoreParameters">
5
			<description>Store the parameters needed to create OGR data stores
6
			</description>
7
			<extends>
8
				<class namespace="dal" name="NewProviderParameters" />
9
				<class>OGRDataStoreParameters</class>
10
			</extends>
11
			<fields>
12
				<field name="driverName" type="string" mandatory="false" group="Basic">
13
					<description>Name of driver</description>
14
				</field>
15
				<field name="datasetCreationOptions" type="List" mandatory="false" group="Basic">
16
					<description>Name of driver</description>
17
				</field>
18
			</fields>
19
		</class>
20
	</classes>
21
</definitions>
tags/org.gvsig.gdal-1.0.61/org.gvsig.gdal.prov/org.gvsig.gdal.prov.ogr/src/main/resources/org/gvsig/gdal/prov/ogr/OGRDataStoreParameters.xml
1
<?xml version="1.0"?>
2
<definitions>
3
	<version>1.0.0</version>
4
	<classes>
5
		<class name="OGRDataStoreParameters">
6
			<extends>
7
				<class namespace="dal" name="ProviderParameters" />
8
			</extends>
9
			<description>Store the parameters needed to open OGR stores
10
			</description>
11
			<fields>
12
				<field name="CRS" type="crs" mandatory="false" group="Basic">
13
					<description>Coordinate reference system used</description>
14
				</field>
15
				<field name="file" type="file" mandatory="false" group="Basic">
16
					<description>Resource file</description>
17
				</field>
18
				<field name="connectionString" type="string" mandatory="false"
19
					group="Basic">
20
					<description>Connection string to open data source</description>
21
				</field>
22
				<field name="layerName" type="string" mandatory="false" group="Basic">
23
					<description>Layer name of data source</description>
24
				</field>
25
				<field name="defaultGeometryField" type="string" mandatory="false"
26
					group="Basic">
27
					<description>Name of default geometry field</description>
28
				</field>
29
        <field name="ignoreSpatialFilter" type="boolean" mandatory="false"
30
          group="Advanced" defaultValue="true">
31
          <description>Ignore spatial filter</description>
32
        </field>
33
			</fields>
34
		</class>
35
	</classes>
36
</definitions>
tags/org.gvsig.gdal-1.0.61/org.gvsig.gdal.prov/org.gvsig.gdal.prov.ogr/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.gdal.prov.ogr.OGRLibrary
tags/org.gvsig.gdal-1.0.61/org.gvsig.gdal.prov/org.gvsig.gdal.prov.ogr/src/main/java/org/gvsig/gdal/prov/ogr/OGRDataStoreProviderFactory.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright ? 2007-2016 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 2
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.gdal.prov.ogr;
25

  
26
import org.gvsig.fmap.dal.feature.FeatureStoreProviderFactory;
27
import org.gvsig.tools.dynobject.DynObject;
28

  
29
/**
30
 * OGR Provider factory to create parameters to create specific server data
31
 * explorers and specific data store providers.
32
 * 
33
 * @author <a href="mailto:lmarques@disid.com">Lluis Marques</a>
34
 *
35
 */
36
public interface OGRDataStoreProviderFactory extends FeatureStoreProviderFactory {
37

  
38
    /**
39
     * 
40
     * @return Name of driver used to open sources
41
     */
42
    public String getDriver();
43

  
44
    /**
45
     * Creates specific parameters if factory can open connection object. If it
46
     * can not open, it will be return null.
47
     * 
48
     * @param connectionObject
49
     *            File or connection string to be opened
50
     * @return Data explorer parameters If this factory can open connection
51
     *         object it will be return specific parameters, otherwise return
52
     *         null.
53
     */
54
    public DynObject createParameters(Object connectionObject);
55

  
56
    /**
57
     * Creates specific data explorer parameters if factory can open connection
58
     * object. If it
59
     * can not open, it will be return null.
60
     * 
61
     * @param connectionObject
62
     *            File or connection string to be opened
63
     * @return Data explorer parameters If this factory can open connection
64
     *         object it will be return specific data explrer parameters,
65
     *         otherwise return
66
     *         null.
67
     */
68
    public DynObject createDataExplorerParameters(Object connectionObject);
69

  
70
}
tags/org.gvsig.gdal-1.0.61/org.gvsig.gdal.prov/org.gvsig.gdal.prov.ogr/src/main/java/org/gvsig/gdal/prov/ogr/OGRDataExplorer.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright ? 2007-2016 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 2
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.gdal.prov.ogr;
25

  
26
import java.io.File;
27
import java.util.ArrayList;
28
import java.util.List;
29

  
30
import org.apache.commons.lang3.StringUtils;
31
import org.cresques.cts.ICRSFactory;
32
import org.cresques.cts.IProjection;
33
import org.gdal.ogr.DataSource;
34
import org.gdal.ogr.FieldDefn;
35
import org.gdal.ogr.GeomFieldDefn;
36
import org.gdal.ogr.Layer;
37
import org.gdal.ogr.ogr;
38
import org.gdal.ogr.ogrConstants;
39
import org.gdal.osr.SpatialReference;
40
import org.gvsig.fmap.dal.DALLocator;
41
import org.gvsig.fmap.dal.DataManager;
42
import org.gvsig.fmap.dal.DataServerExplorerParameters;
43
import org.gvsig.fmap.dal.DataStoreParameters;
44
import org.gvsig.fmap.dal.NewDataStoreParameters;
45
import org.gvsig.fmap.dal.exception.DataException;
46
import org.gvsig.fmap.dal.exception.InitializeException;
47
import org.gvsig.fmap.dal.exception.ReadRuntimeException;
48
import org.gvsig.fmap.dal.feature.EditableFeatureType;
49
import org.gvsig.fmap.dal.resource.ResourceAction;
50
import org.gvsig.fmap.dal.resource.file.FileResource;
51
import org.gvsig.fmap.dal.resource.spi.ResourceConsumer;
52
import org.gvsig.fmap.dal.resource.spi.ResourceManagerProviderServices;
53
import org.gvsig.fmap.dal.resource.spi.ResourceProvider;
54
import org.gvsig.fmap.dal.spi.AbstractDataServerExplorer;
55
import org.gvsig.fmap.dal.spi.DataServerExplorerProvider;
56
import org.gvsig.fmap.dal.spi.DataServerExplorerProviderServices;
57
import org.gvsig.tools.dynobject.DynField;
58
import org.slf4j.Logger;
59
import org.slf4j.LoggerFactory;
60

  
61
/**
62
 * 
63
 * @author <a href="mailto:lmarques@disid.com">Lluis Marques</a>
64
 *
65
 */
66
public class OGRDataExplorer extends AbstractDataServerExplorer implements DataServerExplorerProvider, ResourceConsumer {
67

  
68
    private static final Logger LOG = LoggerFactory.getLogger(OGRDataExplorer.class);
69

  
70
    /**
71
     * 
72
     */
73
    public static final String NAME = "OGRDataExplorer";
74

  
75
    private DataServerExplorerProviderServices providerServives;
76
    protected OGRDataExplorerParameters parameters;
77

  
78
    private ResourceProvider resourceProvider;
79

  
80
    protected DataSource dataSource;
81

  
82
    protected Boolean updateSupport;
83

  
84
    private List<Layer> layerList;
85

  
86
    /**
87
     * @param parameters
88
     *            Parameters to open data explorer.
89
     * @param providerServices
90
     *            Available services
91
     * @throws InitializeException
92
     *             If there is some error initializing this store provider
93
     */
94
    public OGRDataExplorer(OGRDataExplorerParameters parameters,
95
        DataServerExplorerProviderServices providerServices) throws InitializeException {
96
        super(parameters, providerServices);
97
        this.providerServives = providerServices;
98
        this.parameters = parameters;
99

  
100
        getResourceProvider().addConsumer(this);
101
    }
102

  
103
    private ResourceProvider getResourceProvider() {
104
        if (this.resourceProvider == null) {
105
            ResourceManagerProviderServices manager =
106
                (ResourceManagerProviderServices) DALLocator.getResourceManager();
107

  
108
            if (StringUtils.isBlank(parameters.getConnectionString())) {
109
                try {
110
                    this.resourceProvider =
111
                        (FileResource) manager.createAddResource(FileResource.NAME,
112
                            new Object[] { this.parameters.getFile().getAbsolutePath() });
113
                } catch (InitializeException e) {
114
                    throw new ReadRuntimeException(getProviderName(), e);
115
                }
116
            } else {
117
                try {
118
                    this.resourceProvider =
119
                        (OGRResource) manager.createAddResource(OGRResource.NAME,
120
                            new Object[] { this.parameters.getConnectionString() });
121
                } catch (InitializeException e) {
122
                    throw new ReadRuntimeException(getProviderName(), e);
123
                }
124
            }
125
        }
126
        return this.resourceProvider;
127
    }
128

  
129
    protected synchronized DataSource getDataSource() throws OGRUnsupportedFormatException {
130
        if (this.dataSource == null) {
131
            // Prioritize connection string over file
132
            if (StringUtils.isNotBlank(this.parameters.getConnectionString())) {
133
                // Trying to open in update mode
134
                this.dataSource = ogr.Open(this.parameters.getConnectionString(), 1);
135

  
136
                if (this.dataSource == null) {
137
                    this.dataSource = ogr.Open(this.parameters.getConnectionString());
138
                    updateSupport = false;
139
                } else {
140
                    updateSupport = true;
141
                }
142

  
143
            } else if (this.parameters.getFile() != null && this.parameters.getFile().exists()) {
144

  
145
                // Trying to open in update mode
146
                this.dataSource = ogr.Open(this.parameters.getFile().getAbsolutePath(), 1);
147

  
148
                if (this.dataSource == null) {
149
                    this.dataSource = ogr.Open(this.parameters.getFile().getAbsolutePath());
150
                    updateSupport = false;
151
                } else {
152
                    updateSupport = true;
153
                }
154

  
155
            } else {
156
                throw new IllegalStateException(
157
                    "Invalid parameters. Connection string must not be blank or file must exists");
158
            }
159
        }
160

  
161
        if (this.dataSource == null) {
162

  
163
            if (StringUtils.isNotBlank(this.parameters.getConnectionString())) {
164
                throw new OGRUnsupportedFormatException(this.parameters.getConnectionString());
165
            }
166
        }
167

  
168
        return this.dataSource;
169
    }
170

  
171
    @SuppressWarnings("unchecked")
172
    protected List<Layer> getLayerList() {
173
        if (this.layerList == null) {
174
            this.layerList = (List<Layer>) getResourceProvider().execute(new ResourceAction() {
175

  
176
                @Override
177
                public Object run() throws Exception {
178
                    List<Layer> layers = new ArrayList<Layer>();
179

  
180
                    for (int i = 0; i < getDataSource().GetLayerCount(); i++) {
181
                        layers.add(getDataSource().GetLayer(i));
182
                    }
183

  
184
                    return layers;
185
                }
186
            });
187
        }
188
        return this.layerList;
189
    }
190

  
191
    private Boolean hasUpdateSupport() throws OGRUnsupportedFormatException {
192
        if (this.updateSupport == null) {
193
            // Open data source to check update support of driver
194
            getDataSource();
195
        }
196
        return this.updateSupport;
197
    }
198

  
199
    @Override
200
    public String getProviderName() {
201
        return NAME;
202
    }
203

  
204
    @Override
205
    public boolean canAdd() {
206

  
207
        return (boolean) getResourceProvider().execute(new ResourceAction() {
208

  
209
            @Override
210
            public Object run() throws Exception {
211
                return getDataSource().TestCapability(ogrConstants.ODsCCreateLayer)
212
                    && getDataSource().TestCapability(ogrConstants.ODsCDeleteLayer)
213
                    && hasUpdateSupport();
214
            }
215
        });
216
    }
217

  
218
    @Override
219
    public boolean canAdd(String storeName) throws DataException {
220
        return getDataStoreProviderNames().contains(storeName) && canAdd();
221
    }
222

  
223
    @SuppressWarnings("rawtypes")
224
    @Override
225
    public List list() throws DataException {
226
        return list(MODE_ALL);
227
    }
228

  
229
    @SuppressWarnings("rawtypes")
230
    @Override
231
    public List list(int mode) throws DataException {
232
        List<Layer> layerList = getLayerList();
233
        DataManager dataManager = DALLocator.getDataManager();
234
        
235
        List<OGRDataStoreParameters> parametersList = new ArrayList<OGRDataStoreParameters>();
236
        for (Layer layer : layerList) {
237
            
238
            OGRDataStoreParameters storeParameters =
239
                (OGRDataStoreParameters) dataManager.createStoreParameters(OGRDataStoreProvider.NAME);
240
            String connectionString = this.parameters.getConnectionString();
241
            File file = this.parameters.getFile();
242
            storeParameters.setConnectionString(connectionString);
243
            storeParameters.setFile(file);
244
            storeParameters.setLayerName(layer.GetName());
245
            parametersList.add(storeParameters);
246
        }
247
        return parametersList;
248
    }
249

  
250
    @Override
251
    public boolean add(String provider, final NewDataStoreParameters parameters,
252
        final boolean overwrite) throws DataException {
253

  
254
        if (canAdd()) {
255

  
256
            return (boolean) getResourceProvider().execute(new ResourceAction() {
257

  
258
                @Override
259
                public Object run() throws Exception {
260

  
261
                    if (parameters instanceof OGRNewDataStoreParameters) {
262
                        OGRNewDataStoreParameters ogrParameters =
263
                            (OGRNewDataStoreParameters) parameters;
264

  
265
                        String layerName = ogrParameters.getLayerName();
266
                        if (overwrite) {
267
                            for (int i = 0; i < getLayerList().size(); i++) {
268
                                if (getLayerList().get(i).GetName().equals(layerName)) {
269
                                    getDataSource().DeleteLayer(i);
270
                                }
271
                            }
272
                        } else {
273
                            for (Layer layer : getLayerList()) {
274
                                if (layer.GetName().equals(layerName)) {
275
                                    return false;
276
                                }
277
                            }
278
                        }
279

  
280
                        EditableFeatureType editableFeatureType =
281
                            ogrParameters.getDefaultFeatureType();
282

  
283
                        OGRConverter converter = new OGRConverter();
284

  
285
                        // If SRS is defined convert it to spatial reference
286
                        IProjection projection = editableFeatureType.getDefaultSRS();
287
                        SpatialReference srs = null;
288
                        if (projection != null) {
289
                            srs = new SpatialReference(projection.export(ICRSFactory.FORMAT_PROJ4));
290
                        }
291

  
292
                        // Convert to geometry type to OGR Geometry type
293
                        Integer ogrGeometryType = null;
294
                        if (editableFeatureType.getDefaultGeometryAttribute() != null) {
295
                            int geomType =
296
                                editableFeatureType.getDefaultGeometryAttribute().getGeomType()
297
                                    .getType();
298
                            ogrGeometryType = converter.convertToOGRGeomType(geomType);
299
                        }
300

  
301
                        // Create layer
302
                        Layer newlayer = null;
303
                        if (srs == null) {
304
                            newlayer = getDataSource().CreateLayer(layerName);
305
                        } else if (ogrGeometryType == null && srs != null) {
306
                            newlayer = getDataSource().CreateLayer(layerName, srs);
307
                        } else if (ogrGeometryType != null && srs != null) {
308
                            newlayer = getDataSource().CreateLayer(layerName, srs, ogrGeometryType);
309
                        }
310

  
311
                        List<FieldDefn> fields =
312
                            converter.convertFields(editableFeatureType.getNotEditableCopy());
313
                        for (FieldDefn fieldDefn : fields) {
314
                            newlayer.CreateField(fieldDefn);
315
                        }
316

  
317
                        List<GeomFieldDefn> geometryFields =
318
                            converter.convertGeometryFields(
319
                                editableFeatureType.getNotEditableCopy(), false);
320
                        for (GeomFieldDefn geomFieldDefn : geometryFields) {
321
                            newlayer.CreateGeomField(geomFieldDefn);
322
                        }
323
                        return true;
324
                    }
325
                    return false;
326
                }
327
            });
328
        }
329
        return false;
330
    }
331

  
332
    @Override
333
    public void remove(final DataStoreParameters parameters) throws DataException {
334

  
335
        if (canAdd()) {
336

  
337
            getResourceProvider().execute(new ResourceAction() {
338

  
339
                @Override
340
                public Object run() throws Exception {
341
                    if (parameters instanceof OGRNewDataStoreParameters) {
342
                        OGRNewDataStoreParameters ogrParameters =
343
                            (OGRNewDataStoreParameters) parameters;
344

  
345
                        String layerName = ogrParameters.getLayerName();
346
                        for (int i = 0; i < getLayerList().size(); i++) {
347
                            if (getLayerList().get(i).GetName().equals(layerName)) {
348
                                getDataSource().DeleteLayer(i);
349
                                return true;
350
                            }
351
                        }
352
                    }
353
                    return false;
354
                }
355
            });
356
        }
357
    }
358

  
359
    @Override
360
    public NewDataStoreParameters getAddParameters(String storeName) throws DataException {
361

  
362
        if (getDataStoreProviderNames().contains(storeName)) {
363
            OGRNewDataStoreParameters newParameters = new OGRNewDataStoreParameters();
364
            newParameters.setFile(this.parameters.getFile());
365
            newParameters.setConnectionString(this.parameters.getConnectionString());
366
            return newParameters;
367
        }
368

  
369
        return null;
370
    }
371

  
372
    @Override
373
    public DataServerExplorerParameters getParameters() {
374
        return parameters;
375
    }
376

  
377
    @SuppressWarnings("rawtypes")
378
    @Override
379
    public List getDataStoreProviderNames() {
380
        List<String> providerNames = new ArrayList<String>();
381
        providerNames.add(OGRDataStoreProvider.NAME);
382
        return providerNames;
383
    }
384

  
385
    @Override
386
    public void doDispose() {
387

  
388
        try {
389
            getDataSource().SyncToDisk();
390
            getDataSource().delete();
391
        } catch (OGRUnsupportedFormatException e) {
392
            LOG.warn("Can not dispose OGRDataExplorer", e);
393
        }
394

  
395
        this.dataSource = null;
396
        this.layerList = null;
397

  
398
        getResourceProvider().removeConsumer(this);
399
        this.resourceProvider = null;
400
    }
401

  
402
    @Override
403
    public DataServerExplorerProviderServices getServerExplorerProviderServices() {
404
        return providerServives;
405
    }
406

  
407
    @Override
408
    public boolean closeResourceRequested(ResourceProvider resource) {
409

  
410
        try {
411
            getDataSource().SyncToDisk();
412
            getDataSource().delete();
413
        } catch (OGRUnsupportedFormatException e) {
414
            LOG.warn(String.format("Can not close requested resource %1s", resource), e);
415
        }
416

  
417
        this.dataSource = null;
418
        this.layerList = null;
419
        return true;
420
    }
421

  
422
    @Override
423
    public void resourceChanged(ResourceProvider resource) {
424

  
425
        try {
426
            getDataSource().SyncToDisk();
427
            getDataSource().delete();
428
        } catch (OGRUnsupportedFormatException e) {
429
            LOG.warn("Can not sync to disk or release native resources to reopen data source", e);
430
        }
431

  
432
        this.dataSource = null;
433
        this.layerList = null;
434
    }
435

  
436
    @Override
437
    public DataStoreParameters get(String name) throws DataException {
438
        // "name" es un nombre de fichero sin path.
439
        
440
        // No tengo nada clara esta implementacion
441
        OGRDataStoreParameters params = new OGRDataStoreParameters();
442
        //
443
        // Copiamos los paramametros que se llamen igual entre el explorer y
444
        // el DataStoreParametes
445
        for( DynField field : params.getDynClass().getDynFields() ) {
446
            String fieldName = field.getName();
447
            if( parameters.hasDynValue(fieldName) ) {
448
                params.setDynValue(fieldName, parameters.getDynValue(fieldName));
449
            }
450
        }
451
        // Si el file es una carpeta asignamos como file el fichero name que haya
452
        // en ella
453
        // Si el file es un fichero cogemos el fichero name que se encuentre en
454
        // su misma carpeta.
455
        if( parameters.getFile().isDirectory() ) {
456
            params.setFile(new File(parameters.getFile(),name));
457
        } else {
458
            params.setFile(new File(parameters.getFile().getParentFile(),name));
459
        }
460
        // Usamos como layer el nombre del fichero pasado como parametro.
461
        params.setLayerName(name);
462
        return params;
463
    }
464
}
tags/org.gvsig.gdal-1.0.61/org.gvsig.gdal.prov/org.gvsig.gdal.prov.ogr/src/main/java/org/gvsig/gdal/prov/ogr/OGRDataStoreParameters.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright ? 2007-2016 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 2
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.gdal.prov.ogr;
25

  
26
import java.io.File;
27

  
28
import org.apache.commons.lang3.StringUtils;
29
import org.cresques.cts.IProjection;
30
import org.gvsig.fmap.dal.DataStoreParameters;
31
import org.gvsig.fmap.dal.feature.OpenFeatureStoreParameters;
32
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters;
33
import org.gvsig.fmap.dal.spi.AbstractDataParameters;
34
import org.gvsig.fmap.dal.spi.DataStoreProviderServices;
35
import org.gvsig.tools.ToolsLocator;
36
import org.gvsig.tools.dynobject.DelegatedDynObject;
37

  
38
/**
39
 *
40
 * @author <a href="mailto:lmarques@disid.com">Lluis Marques</a>
41
 *
42
 */
43
public class OGRDataStoreParameters extends AbstractDataParameters implements OpenFeatureStoreParameters,
44
    FilesystemStoreParameters {
45

  
46
    /**
47
     *
48
     */
49
    public static final String PARAMETERS_DEFINITION_NAME = "OGRDataStoreParameters";
50

  
51
    /**
52
     *
53
     */
54
    public static final String FILE_PARAMTER_NAME = "file";
55

  
56
    /**
57
     *
58
     */
59
    public static final String LAYER_NAME_PARAMTER_NAME = "layerName";
60

  
61
    /**
62
     *
63
     */
64
    public static final String CONNECTION_STRING_PARAMETER_NAME = "connectionString";
65

  
66
    /**
67
     *
68
     */
69
    public static final String DEFAULT_GEOMETRY_PARAMETER_NAME = "defaultGeometryField";
70

  
71
    /**
72
     *
73
     */
74
    public static final String CRS_PARAMETER_NAME = "crs";
75

  
76
    /**
77
     *
78
     */
79
    public static final String IGNORE_SPATIAL_FILTER = "ignoreSpatialFilter";
80

  
81

  
82
    protected DelegatedDynObject parameters;
83

  
84
    /**
85
     *
86
     */
87
    public OGRDataStoreParameters() {
88
        this.parameters =
89
            (DelegatedDynObject) ToolsLocator.getDynObjectManager().createDynObject(
90
                ToolsLocator.getPersistenceManager().getDefinition(PARAMETERS_DEFINITION_NAME));
91
        this.setDynValue(DataStoreProviderServices.PROVIDER_PARAMTER_NAME,
92
            OGRDataStoreProvider.NAME);
93
    }
94

  
95
    @Override
96
    public String getDataStoreName() {
97
        return OGRDataStoreProvider.NAME;
98
    }
99

  
100
    @Override
101
    public String getDescription() {
102
        return OGRDataStoreProvider.DESCRIPTION;
103
    }
104

  
105
    /**
106
     * @return File
107
     */
108
    public File getFile() {
109
        return (File) this.getDynValue(FILE_PARAMTER_NAME);
110
    }
111

  
112
    /**
113
     * @return String
114
     */
115
    public String getLayerName() {
116
        return (String) this.getDynValue(LAYER_NAME_PARAMTER_NAME);
117
    }
118

  
119
    /**
120
     * @return String
121
     */
122
    public String getConnectionString() {
123
        return (String) this.getDynValue(CONNECTION_STRING_PARAMETER_NAME);
124
    }
125

  
126
    /**
127
     * @return String
128
     */
129
    public String getDefaultGeometryField() {
130
        return (String) this.getDynValue(DEFAULT_GEOMETRY_PARAMETER_NAME);
131
    }
132

  
133
    /**
134
     *
135
     * @return String
136
     */
137
    public IProjection getCRS() {
138
        return (IProjection) this.getDynValue(CRS_PARAMETER_NAME);
139
    }
140

  
141
    /**
142
     * @param file
143
     *            File
144
     */
145
    public void setFile(File file) {
146
        this.setDynValue(FILE_PARAMTER_NAME, file);
147
    }
148

  
149
    /**
150
     * @param layerName
151
     *            Name of layer
152
     */
153
    public void setLayerName(String layerName) {
154
        this.setDynValue(LAYER_NAME_PARAMTER_NAME, layerName);
155
    }
156

  
157
    /**
158
     * @param connectionString
159
     *            Connection string
160
     */
161
    public void setConnectionString(String connectionString) {
162
        this.setDynValue(CONNECTION_STRING_PARAMETER_NAME, connectionString);
163
    }
164

  
165
    /**
166
     * @param defaultGeoemtryField
167
     *            Name of defualt geometry field.
168
     */
169
    public void setDefaultGeometryField(String defaultGeoemtryField) {
170
        this.setDynValue(DEFAULT_GEOMETRY_PARAMETER_NAME, defaultGeoemtryField);
171
    }
172

  
173
    /**
174
     *
175
     * @param crs
176
     */
177
    public void setCRS(IProjection crs) {
178
        this.setDynValue(CRS_PARAMETER_NAME, crs);
179
    }
180

  
181
    @Override
182
    public boolean isValid() {
183
        if ((this.getFile() != null && this.getFile().exists())
184
            || StringUtils.isNotBlank(this.getConnectionString())) {
185
            return true;
186
        }
187
        return false;
188
    }
189

  
190
    @Override
191
    protected DelegatedDynObject getDelegatedDynObject() {
192
        return parameters;
193
    }
194

  
195
}
tags/org.gvsig.gdal-1.0.61/org.gvsig.gdal.prov/org.gvsig.gdal.prov.ogr/src/main/java/org/gvsig/gdal/prov/ogr/BasicOGRDataStoreProviderFactory.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright ? 2007-2016 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 2
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.gdal.prov.ogr;
25

  
26
import java.util.ArrayList;
27
import java.util.List;
28

  
29
import org.gvsig.fmap.dal.DataParameters;
30
import org.gvsig.fmap.dal.DataStoreParameters;
31
import org.gvsig.fmap.dal.DataStoreProvider;
32
import org.gvsig.fmap.dal.DataTypes;
33
import org.gvsig.fmap.dal.exception.InitializeException;
34
import org.gvsig.fmap.dal.feature.spi.AbstractFeatureStoreProviderFactory;
35
import org.gvsig.fmap.dal.spi.DataStoreProviderServices;
36
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
37
import org.gvsig.tools.dynobject.DynObject;
38

  
39
/**
40
 * 
41
 * @author <a href="mailto:lmarques@disid.com">Lluis Marques</a>
42
 *
43
 */
44
public class BasicOGRDataStoreProviderFactory extends AbstractFeatureStoreProviderFactory implements
45
    OGRDataStoreProviderFactory {
46

  
47
    /**
48
     * @param name
49
     *            Name of factory
50
     * @param description
51
     *            Description of factory
52
     */
53
    public BasicOGRDataStoreProviderFactory(String name, String description) {
54
        super(name, description);
55
    }
56

  
57
    @Override
58
    public DataStoreProvider createProvider(DataParameters dataParameters,
59
        DataStoreProviderServices providerServices) throws InitializeException {
60
        return new OGRDataStoreProvider((DataStoreParameters) dataParameters, providerServices);
61
    }
62

  
63
    @Override
64
    public DynObject createParameters() {
65
        return new OGRDataStoreParameters();
66
    }
67

  
68
    public int allowMultipleGeometryTypes() {
69
        return UNKNOWN;
70
    }
71

  
72
    public int allowEditableFeatureType() {
73
        return UNKNOWN;
74
    }
75

  
76
    /**
77
     * See {@link OGRConverter#convertToDataType(int)} method. The list of data
78
     * type of OGR. If the list of OGR types changes update this method.
79
     */
80
    @SuppressWarnings("rawtypes")
81
    public List getSupportedDataTypes() {
82

  
83
        List<Integer> supportedDataTypes = new ArrayList<Integer>();
84

  
85
        supportedDataTypes.add(DataTypes.BOOLEAN);
86
        supportedDataTypes.add(DataTypes.DATE);
87
        supportedDataTypes.add(DataTypes.FLOAT);
88
        supportedDataTypes.add(DataTypes.DOUBLE);
89
        supportedDataTypes.add(DataTypes.STRING);
90
        supportedDataTypes.add(DataTypes.INT);
91
        supportedDataTypes.add(DataTypes.LONG);
92
        supportedDataTypes.add(DataTypes.TIME);
93

  
94
        return supportedDataTypes;
95
    }
96

  
97
    @SuppressWarnings("rawtypes")
98
    public List getSupportedGeometryTypesSubtypes() {
99
        List<Integer> supportedSubtypes = new ArrayList<Integer>();
100
        supportedSubtypes.add(SUBTYPES.GEOM2D);
101
        return supportedSubtypes;
102
    }
103

  
104
    public boolean allowsMandatoryAttributes() {
105
        return false;
106
    }
107

  
108
    public boolean allowsPrimaryKeyAttributes() {
109
        return false;
110
    }
111

  
112
    public int useLocalIndexesCanImprovePerformance() {
113
        return UNKNOWN;
114
    }
115

  
116
    @Override
117
    public DynObject createDataExplorerParameters(Object connectionString) {
118
        return new OGRDataExplorerParameters();
119
    }
120

  
121
    @Override
122
    public DynObject createParameters(Object connectionObject) {
123
        return createParameters();
124
    }
125

  
126
    @Override
127
    public String getDriver() {
128
        return null;
129
    }
130

  
131
}
tags/org.gvsig.gdal-1.0.61/org.gvsig.gdal.prov/org.gvsig.gdal.prov.ogr/src/main/java/org/gvsig/gdal/prov/ogr/OGRResourceParameters.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2016 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.gdal.prov.ogr;
25

  
26
import org.gvsig.fmap.dal.resource.spi.AbstractResourceParameters;
27
import org.gvsig.tools.ToolsLocator;
28
import org.gvsig.tools.dataTypes.DataTypes;
29
import org.gvsig.tools.dynobject.DelegatedDynObject;
30
import org.gvsig.tools.dynobject.DynClass;
31
import org.gvsig.tools.persistence.PersistenceManager;
32

  
33
/**
34
 * 
35
 * @author <a href="mailto:lmarques@disid.com">Lluis Marques</a>
36
 *
37
 */
38
public class OGRResourceParameters extends AbstractResourceParameters {
39

  
40
    /**
41
     * 
42
     */
43
    public static final String DYNCLASS_NAME = "OGRResourceParameters";
44

  
45
    /**
46
     * 
47
     */
48
    private static final String DYNFIELDNAME_NAME = "name";
49

  
50
    /**
51
     * 
52
     */
53
    private static final String DYNFIELDNAME_CONNECTION_STRING = "connectionString";
54

  
55
    private DelegatedDynObject delegatedDynObject;
56

  
57
    /**
58
     * 
59
     */
60
    public OGRResourceParameters() {
61
        super();
62
        PersistenceManager manager = ToolsLocator.getPersistenceManager();
63
        DynClass definition = (DynClass) manager.getDefinition(DYNCLASS_NAME);
64
        this.delegatedDynObject =
65
            (DelegatedDynObject) ToolsLocator.getDynObjectManager().createDynObject(definition);
66
    }
67

  
68
    /**
69
     * 
70
     * @param connectionString
71
     *            Connection string
72
     */
73
    public OGRResourceParameters(String connectionString) {
74
        this();
75
        setDynValue(DYNFIELDNAME_NAME,
76
            String.valueOf(connectionString.hashCode()).concat("@OGResource"));
77
        setDynValue(DYNFIELDNAME_CONNECTION_STRING, connectionString);
78
    }
79

  
80
    /**
81
     * 
82
     * @param params
83
     *            Array with parameter values
84
     */
85
    public OGRResourceParameters(Object[] params) {
86
        this((String) params[0]);
87
    }
88

  
89
    @Override
90
    public String getTypeName() {
91
        return OGRResource.NAME;
92
    }
93

  
94
    @Override
95
    protected DelegatedDynObject getDelegatedDynObject() {
96
        return delegatedDynObject;
97
    }
98

  
99
    /**
100
     * @return String
101
     */
102
    public String getName() {
103
        return (String) this.getDynValue(DYNFIELDNAME_NAME);
104
    }
105

  
106
    /**
107
     * @return String
108
     */
109
    public String getConnectionString() {
110
        return (String) this.getDynValue(DYNFIELDNAME_CONNECTION_STRING);
111
    }
112

  
113
    protected static void registerPersistenceDefinition() {
114
        PersistenceManager manager = ToolsLocator.getPersistenceManager();
115
        DynClass definition = (DynClass) manager.getDefinition(DYNCLASS_NAME);
116
        if (definition == null) {
117
            definition = (DynClass) manager.addDefinition(OGRResourceParameters.class,
118
                DYNCLASS_NAME, DYNCLASS_NAME + " persistence definition", null, null);
119

  
120
            definition.addDynField(DYNFIELDNAME_NAME).setType(DataTypes.STRING)
121
                .setDescription("Name of resource");
122
            definition.addDynField(DYNFIELDNAME_CONNECTION_STRING).setType(DataTypes.STRING)
123
                .setDescription("Connection string");
124
        }
125
    }
126
}
tags/org.gvsig.gdal-1.0.61/org.gvsig.gdal.prov/org.gvsig.gdal.prov.ogr/src/main/java/org/gvsig/gdal/prov/ogr/OGRDataExplorerParameters.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright ? 2007-2016 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 2
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.gdal.prov.ogr;
25

  
26
import java.io.File;
27

  
28
import org.gvsig.fmap.dal.DataServerExplorerParameters;
29
import org.gvsig.fmap.dal.spi.AbstractDataParameters;
30
import org.gvsig.tools.ToolsLocator;
31
import org.gvsig.tools.dynobject.DelegatedDynObject;
32

  
33
/**
34
 * 
35
 * @author <a href="mailto:lmarques@disid.com">Lluis Marques</a>
36
 *
37
 */
38
public class OGRDataExplorerParameters extends AbstractDataParameters
39
    implements DataServerExplorerParameters {
40

  
41
    /**
42
     * 
43
     */
44
    public static final String PARAMETERS_DEFINITION_NAME = "OGRDataExplorerParameters";
45

  
46
    /**
47
     * 
48
     */
49
    public static final String FILE_PARAMETER_NAME = "file";
50

  
51
    /**
52
     * 
53
     */
54
    public static final String CONNECTION_STRING_PARAMETER_NAME = "connectionString";
55

  
56
    private DelegatedDynObject parameters;
57

  
58
    /**
59
     * 
60
     */
61
    public OGRDataExplorerParameters() {
62
        this.parameters = (DelegatedDynObject) ToolsLocator.getDynObjectManager().createDynObject(
63
            ToolsLocator.getPersistenceManager().getDefinition(PARAMETERS_DEFINITION_NAME));
64
    }
65

  
66
    @Override
67
    public String getExplorerName() {
68
        return OGRDataExplorer.NAME;
69
    }
70

  
71
    @Override
72
    protected DelegatedDynObject getDelegatedDynObject() {
73
        return this.parameters;
74
    }
75

  
76
    /**
77
     * 
78
     * @return File
79
     */
80
    public File getFile() {
81
        return (File) this.getDynValue(FILE_PARAMETER_NAME);
82
    }
83

  
84
    /**
85
     * 
86
     * @return String
87
     */
88
    public String getConnectionString() {
89
        return (String) this.getDynValue(CONNECTION_STRING_PARAMETER_NAME);
90
    }
91

  
92
    /**
93
     * 
94
     * @param file
95
     *            File
96
     */
97
    public void setFile(File file) {
98
        this.setDynValue(FILE_PARAMETER_NAME, file);
99
    }
100

  
101
    /**
102
     * 
103
     * @param connection
104
     *            Connection string
105
     */
106
    public void setConnectionString(String connection) {
107
        this.setDynValue(CONNECTION_STRING_PARAMETER_NAME, connection);
108
    }
109
}
tags/org.gvsig.gdal-1.0.61/org.gvsig.gdal.prov/org.gvsig.gdal.prov.ogr/src/main/java/org/gvsig/gdal/prov/ogr/OGRUnsupportedFormatException.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright ? 2007-2016 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 2
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.gdal.prov.ogr;
25

  
26
import java.util.Map;
27

  
28
import org.gvsig.fmap.dal.exception.DataException;
29

  
30
/**
31
 * 
32
 * @author <a href="mailto:lmarques@disid.com">Lluis Marques</a>
33
 *
34
 */
35
@SuppressWarnings("unchecked")
36
public class OGRUnsupportedFormatException extends DataException {
37

  
38
    private static final long serialVersionUID = -2670314598211236837L;
39

  
40
    private final static String MESSAGE =
41
        "Unsupported vectorial format. There are not any OGR driver registered to open %(connectionString)";
42

  
43
    private final static String KEY = "_UnsupportedVectorialFormatException";
44

  
45
    /**
46
     * @param messageFormat
47
     *            Message format
48
     * @param cause
49
     *            Cause
50
     * @param messageKey
51
     *            Message key
52
     * @param code
53
     *            code
54
     * @param values
55
     *            Values
56
     */
57
    public OGRUnsupportedFormatException(String messageFormat, Throwable cause, String messageKey,
58
        long code, Map<Object, Object> values) {
59
        super(messageFormat, cause, messageKey, code);
60
        this.values.putAll(values);
61
    }
62

  
63
    /**
64
     * @param messageFormat
65
     *            Message format
66
     * @param cause
67
     *            Cause
68
     * @param values
69
     *            Values
70
     */
71
    public OGRUnsupportedFormatException(String messageFormat, Throwable cause,
72
        Map<Object, Object> values) {
73
        super(messageFormat, cause, KEY, serialVersionUID);
74
        this.values.putAll(values);
75
    }
76

  
77
    /**
78
     * @param connectionString
79
     *            Conenction string
80
     */
81
    public OGRUnsupportedFormatException(String connectionString) {
82
        super(MESSAGE, KEY, serialVersionUID);
83
        this.values.put("connectionString", connectionString);
84
    }
85

  
86
}
tags/org.gvsig.gdal-1.0.61/org.gvsig.gdal.prov/org.gvsig.gdal.prov.ogr/src/main/java/org/gvsig/gdal/prov/ogr/OGRDataStoreProvider.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright ? 2007-2016 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 2
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.gdal.prov.ogr;
25

  
26
import java.util.ArrayList;
27
import java.util.Iterator;
28
import java.util.List;
29

  
30
import org.apache.commons.lang3.StringUtils;
31
import org.gdal.ogr.DataSource;
32
import org.gdal.ogr.Feature;
33
import org.gdal.ogr.FeatureDefn;
34
import org.gdal.ogr.FieldDefn;
35
import org.gdal.ogr.GeomFieldDefn;
36
import org.gdal.ogr.Geometry;
37
import org.gdal.ogr.Layer;
38
import org.gdal.ogr.ogr;
39
import org.gdal.ogr.ogrConstants;
40

  
41
import org.gvsig.fmap.dal.DataStore;
42
import org.gvsig.fmap.dal.DataStoreParameters;
43
import org.gvsig.fmap.dal.DataTypes;
44
import org.gvsig.fmap.dal.FileHelper;
45
import org.gvsig.fmap.dal.exception.DataException;
46
import org.gvsig.fmap.dal.exception.InitializeException;
47
import org.gvsig.fmap.dal.exception.OpenException;
48
import org.gvsig.fmap.dal.exception.ReadRuntimeException;
49
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor;
50
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
51
import org.gvsig.fmap.dal.feature.FeatureQuery;
52
import org.gvsig.fmap.dal.feature.FeatureQueryOrder;
53
import org.gvsig.fmap.dal.feature.FeatureQueryOrder.FeatureQueryOrderMember;
54
import org.gvsig.fmap.dal.feature.FeatureType;
55
import org.gvsig.fmap.dal.feature.spi.AbstractFeatureStoreProvider;
56
import org.gvsig.fmap.dal.feature.spi.DefaultFeatureProvider;
57
import org.gvsig.fmap.dal.feature.spi.FeatureProvider;
58
import org.gvsig.fmap.dal.feature.spi.FeatureReferenceProviderServices;
59
import org.gvsig.fmap.dal.feature.spi.FeatureSetProvider;
60
import org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider;
61
import org.gvsig.fmap.dal.resource.ResourceAction;
62
import org.gvsig.fmap.dal.resource.file.FileResource;
63
import org.gvsig.fmap.dal.resource.spi.ResourceConsumer;
64
import org.gvsig.fmap.dal.resource.spi.ResourceProvider;
65
import org.gvsig.fmap.dal.spi.DataStoreProviderServices;
66
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
67
import org.gvsig.fmap.geom.GeometryLocator;
68
import org.gvsig.fmap.geom.primitive.Envelope;
69
import org.gvsig.fmap.geom.type.GeometryTypeNotSupportedException;
70
import org.gvsig.fmap.geom.type.GeometryTypeNotValidException;
71
import org.gvsig.tools.dynobject.DynObject;
72
import org.gvsig.tools.evaluator.Evaluator;
73
import org.gvsig.tools.exception.BaseException;
74

  
75
import org.slf4j.Logger;
76
import org.slf4j.LoggerFactory;
77

  
78
/**
79
 *
80
 * @author <a href="mailto:lmarques@disid.com">Lluis Marques</a>
81
 *
82
 */
83
public class OGRDataStoreProvider extends AbstractFeatureStoreProvider implements
84
    FeatureStoreProvider, ResourceConsumer {
85

  
86
    private static final Logger LOG = LoggerFactory.getLogger(OGRDataStoreProvider.class);
87

  
88
    /**
89
     *
90
     */
91
    public static final String METADATA_DEFINITION_NAME = "OGRDataStoreProvider";
92

  
93
    /**
94
     *
95
     */
96
    public static final String NAME = "OGRDataStoreProvider";
97

  
98
    /**
99
     *
100
     */
101
    public static final String DESCRIPTION = "OGR provider to open vectorial resources";
102

  
103
    protected DataSource dataSource;
104

  
105
    private Envelope envelope;
106

  
107
    private Layer newLayer;
108

  
109
    protected ResourceProvider resourceProvider;
110

  
111
    private Boolean updateSupport;
112

  
113
    private boolean opened = false;
114

  
115
    protected OGRDataStoreProvider(DataStoreParameters dataParameters,
116
        DataStoreProviderServices storeServices, DynObject metadata) throws InitializeException {
117
        super(dataParameters, storeServices, metadata);
118

  
119
        // Set CRS parameter to metadata
120
        this.setDynValue(DataStore.METADATA_CRS, dataParameters.getDynValue(DataStore.METADATA_CRS));
121

  
122
        getResource().addConsumer(this);
123

  
124
        try {
125
            this.open();
126
        } catch (OpenException e) {
127
            throw new InitializeException(NAME, e);
128
        }
129
    }
130

  
131
    protected OGRDataStoreProvider(DataStoreParameters dataParameters,
132
        DataStoreProviderServices storeServices) throws InitializeException {
133
        this(dataParameters, storeServices, FileHelper
134
            .newMetadataContainer(METADATA_DEFINITION_NAME));
135
    }
136

  
137
    /*
138
     * Lazy initialization of data source
139
     */
140
    protected synchronized DataSource getDataSource() throws OGRUnsupportedFormatException {
141
        if (this.dataSource == null) {
142

  
143
            // Prioritize connection string over file
144
            if (StringUtils.isNotBlank(getOGRParameters().getConnectionString())) {
145

  
146
                // Trying to open in update mode
147
                this.dataSource = ogr.Open(getOGRParameters().getConnectionString(), 1);
148

  
149
                if (this.dataSource == null) {
150
                    this.dataSource = ogr.Open(getOGRParameters().getConnectionString());
151
                    updateSupport = false;
152
                } else {
153
                    updateSupport = true;
154
                }
155

  
156
            } else if (getOGRParameters().getFile() != null
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff