gvsig-gdal / trunk / org.gvsig.gdal / org.gvsig.gdal.prov / org.gvsig.gdal.prov.gml / src / main / java / org / gvsig / gdal / prov / gml / GMLDataExplorer.java @ 135
History | View | Annotate | Download (5.32 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 |
import java.util.ArrayList; |
28 |
import java.util.List; |
29 |
|
30 |
import org.gdal.gdal.gdal; |
31 |
import org.gdal.ogr.DataSource; |
32 |
import org.gdal.ogr.Layer; |
33 |
import org.gvsig.fmap.dal.DALLocator; |
34 |
import org.gvsig.fmap.dal.DataManager; |
35 |
import org.gvsig.fmap.dal.NewDataStoreParameters; |
36 |
import org.gvsig.fmap.dal.exception.DataException; |
37 |
import org.gvsig.fmap.dal.exception.InitializeException; |
38 |
import org.gvsig.fmap.dal.spi.DataServerExplorerProviderServices; |
39 |
import org.gvsig.gdal.prov.ogr.OGRDataExplorer; |
40 |
import org.gvsig.gdal.prov.ogr.OGRDataExplorerParameters; |
41 |
import org.gvsig.gdal.prov.ogr.OGRDataStoreProvider; |
42 |
import org.gvsig.gdal.prov.ogr.OGRNewDataStoreParameters; |
43 |
import org.gvsig.gdal.prov.ogr.OGRUnsupportedFormatException; |
44 |
|
45 |
/**
|
46 |
* @author <a href="mailto:lmarques@disid.com">Lluis Marques</a>
|
47 |
*
|
48 |
*/
|
49 |
public class GMLDataExplorer extends OGRDataExplorer { |
50 |
|
51 |
/**
|
52 |
*
|
53 |
*/
|
54 |
public static final String NAME = "GMLDataExplorer"; |
55 |
|
56 |
/**
|
57 |
* @param parameters
|
58 |
* Parameters to open data explorer.
|
59 |
* @param providerServices
|
60 |
* Available services
|
61 |
* @throws InitializeException
|
62 |
* If there is some error initializating this store provider
|
63 |
*/
|
64 |
public GMLDataExplorer(OGRDataExplorerParameters parameters,
|
65 |
DataServerExplorerProviderServices providerServices) throws InitializeException {
|
66 |
super(parameters, providerServices);
|
67 |
} |
68 |
|
69 |
@Override
|
70 |
protected synchronized DataSource getDataSource() throws OGRUnsupportedFormatException { |
71 |
try {
|
72 |
if (this.parameters instanceof GMLDataExplorerParameters) { |
73 |
GMLDataExplorerParameters gmlDataExplorerParameters = |
74 |
(GMLDataExplorerParameters) this.parameters;
|
75 |
|
76 |
if (gmlDataExplorerParameters.getGfsSchema() != null) { |
77 |
gdal.SetConfigOption("GML_GFS_TEMPLATE", gmlDataExplorerParameters
|
78 |
.getGfsSchema().getAbsolutePath()); |
79 |
} |
80 |
|
81 |
return super.getDataSource(); |
82 |
} else {
|
83 |
throw new IllegalStateException( |
84 |
"Parameters of GML Data explorer is not instance of GMLDataExplorerParameters");
|
85 |
} |
86 |
} finally {
|
87 |
gdal.SetConfigOption("GML_GFS_TEMPLATE", null); |
88 |
} |
89 |
} |
90 |
|
91 |
@Override
|
92 |
public NewDataStoreParameters getAddParameters(String storeName) throws DataException { |
93 |
if (getDataStoreProviderNames().contains(storeName)) {
|
94 |
|
95 |
NewDataStoreParameters newDataStoreParameters = super.getAddParameters(storeName);
|
96 |
if (OGRDataStoreProvider.NAME.equals(storeName)) {
|
97 |
|
98 |
return newDataStoreParameters;
|
99 |
} else if (GMLDataStoreProvider.NAME.equals(storeName) |
100 |
&& newDataStoreParameters instanceof OGRNewDataStoreParameters) {
|
101 |
|
102 |
((OGRNewDataStoreParameters) newDataStoreParameters).setDriverName("GML");
|
103 |
return newDataStoreParameters;
|
104 |
} |
105 |
} |
106 |
|
107 |
return null; |
108 |
} |
109 |
|
110 |
@SuppressWarnings("unchecked") |
111 |
@Override
|
112 |
public List getDataStoreProviderNames() { |
113 |
List<String> providerNames = super.getDataStoreProviderNames(); |
114 |
providerNames.add(GMLDataStoreProvider.NAME); |
115 |
return providerNames;
|
116 |
} |
117 |
|
118 |
@Override
|
119 |
public List list(int mode) throws DataException { |
120 |
|
121 |
List<Layer> layerList = getLayerList();
|
122 |
List<GMLDataStoreParameters> parametersList = new ArrayList<GMLDataStoreParameters>(); |
123 |
DataManager dataManager = DALLocator.getDataManager(); |
124 |
GMLDataExplorerParameters gmlDataExplorerParameters = |
125 |
(GMLDataExplorerParameters) this.parameters;
|
126 |
|
127 |
for (Layer layer : layerList) {
|
128 |
|
129 |
GMLDataStoreParameters storeParameters = |
130 |
(GMLDataStoreParameters) dataManager |
131 |
.createStoreParameters(GMLDataStoreProvider.NAME); |
132 |
String connectionString = gmlDataExplorerParameters.getConnectionString();
|
133 |
File file = gmlDataExplorerParameters.getFile();
|
134 |
File gfsSchema = gmlDataExplorerParameters.getGfsSchema();
|
135 |
storeParameters.setConnectionString(connectionString); |
136 |
storeParameters.setFile(file); |
137 |
storeParameters.setGfsSchema(gfsSchema); |
138 |
storeParameters.setLayerName(layer.GetName()); |
139 |
parametersList.add(storeParameters); |
140 |
} |
141 |
|
142 |
return parametersList;
|
143 |
} |
144 |
} |