gvsig-gdal / trunk / org.gvsig.gdal / org.gvsig.gdal.prov / org.gvsig.gdal.prov.gml / src / main / java / org / gvsig / gdal / prov / gml / GMLDataStoreProviderFactory.java @ 135
History | View | Annotate | Download (3.96 KB)
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.gml; |
25 |
|
26 |
import java.io.File; |
27 |
|
28 |
import org.gdal.ogr.DataSource; |
29 |
import org.gdal.ogr.Driver; |
30 |
import org.gdal.ogr.ogr; |
31 |
import org.gvsig.fmap.dal.DataParameters; |
32 |
import org.gvsig.fmap.dal.DataStoreParameters; |
33 |
import org.gvsig.fmap.dal.DataStoreProvider; |
34 |
import org.gvsig.fmap.dal.exception.InitializeException; |
35 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
36 |
import org.gvsig.gdal.prov.ogr.BasicOGRDataStoreProviderFactory; |
37 |
import org.gvsig.gdal.prov.ogr.OGRDataStoreProviderFactory; |
38 |
import org.gvsig.tools.dynobject.DynObject; |
39 |
|
40 |
/**
|
41 |
* @author <a href="mailto:lmarques@disid.com">Lluis Marques</a>
|
42 |
*
|
43 |
*/
|
44 |
public class GMLDataStoreProviderFactory extends BasicOGRDataStoreProviderFactory implements |
45 |
OGRDataStoreProviderFactory { |
46 |
|
47 |
private static final String DRIVER_NAME = "GML"; |
48 |
|
49 |
/**
|
50 |
* @param name
|
51 |
* Name of factory
|
52 |
* @param description
|
53 |
* Description of factory
|
54 |
*/
|
55 |
public GMLDataStoreProviderFactory(String name, String description) { |
56 |
super(name, description);
|
57 |
} |
58 |
|
59 |
@Override
|
60 |
public DataStoreProvider createProvider(DataParameters dataParameters,
|
61 |
DataStoreProviderServices providerServices) throws InitializeException {
|
62 |
return new GMLDataStoreProvider((DataStoreParameters) dataParameters, providerServices); |
63 |
} |
64 |
|
65 |
@Override
|
66 |
public DynObject createParameters() {
|
67 |
return new GMLDataStoreParameters(); |
68 |
} |
69 |
|
70 |
@Override
|
71 |
public DynObject createParameters(Object connectionObject) { |
72 |
if (canOpen(connectionObject)) {
|
73 |
return new GMLDataStoreParameters(); |
74 |
} |
75 |
return null; |
76 |
} |
77 |
|
78 |
@Override
|
79 |
public DynObject createDataExplorerParameters(Object connectionObject) { |
80 |
if (canOpen(connectionObject)) {
|
81 |
return new GMLDataExplorerParameters(); |
82 |
} |
83 |
return null; |
84 |
} |
85 |
|
86 |
private boolean canOpen(Object connectionObject) { |
87 |
|
88 |
if (connectionObject instanceof File) { |
89 |
File file = (File) connectionObject; |
90 |
if (file.isFile() && file.exists()) {
|
91 |
Driver driver = ogr.GetDriverByName(getDriver());
|
92 |
DataSource dataSource = driver.Open(file.getAbsolutePath());
|
93 |
if (dataSource != null) { |
94 |
dataSource.delete(); |
95 |
dataSource = null;
|
96 |
return true; |
97 |
} |
98 |
} |
99 |
} else if (connectionObject instanceof String) { |
100 |
String connectionString = (String) connectionObject; |
101 |
Driver driver = ogr.GetDriverByName(getDriver());
|
102 |
DataSource dataSource = driver.Open(connectionString);
|
103 |
if (dataSource != null) { |
104 |
dataSource.delete(); |
105 |
dataSource = null;
|
106 |
return true; |
107 |
} |
108 |
} else {
|
109 |
throw new IllegalArgumentException( |
110 |
"Connection object must be a file or a connection string");
|
111 |
} |
112 |
return false; |
113 |
} |
114 |
|
115 |
@Override
|
116 |
public String getDriver() { |
117 |
return DRIVER_NAME;
|
118 |
} |
119 |
} |