svn-gvsig-desktop / tags / v2_0_0_Build_2020 / extensions / extGPE-gvSIG / src / org / gvsig / fmap / dal / store / gpe / GPEStoreProvider.java @ 33934
History | View | Annotate | Download (9.82 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
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 |
*/
|
22 |
|
23 |
/*
|
24 |
* AUTHORS (In addition to CIT):
|
25 |
* 2009 {Iver T.I.} {Task}
|
26 |
*/
|
27 |
|
28 |
package org.gvsig.fmap.dal.store.gpe; |
29 |
|
30 |
import java.io.File; |
31 |
|
32 |
import org.cresques.cts.IProjection; |
33 |
import org.gvsig.fmap.dal.DALLocator; |
34 |
import org.gvsig.fmap.dal.DataManager; |
35 |
import org.gvsig.fmap.dal.DataServerExplorer; |
36 |
import org.gvsig.fmap.dal.DataStoreParameters; |
37 |
import org.gvsig.fmap.dal.DataTypes; |
38 |
import org.gvsig.fmap.dal.FileHelper; |
39 |
import org.gvsig.fmap.dal.exception.DataException; |
40 |
import org.gvsig.fmap.dal.exception.InitializeException; |
41 |
import org.gvsig.fmap.dal.exception.OpenException; |
42 |
import org.gvsig.fmap.dal.exception.ReadException; |
43 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
44 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
45 |
import org.gvsig.fmap.dal.feature.FeatureType; |
46 |
import org.gvsig.fmap.dal.feature.impl.DefaultFeature; |
47 |
import org.gvsig.fmap.dal.feature.spi.AbstractFeatureStoreProvider; |
48 |
import org.gvsig.fmap.dal.feature.spi.FeatureProvider; |
49 |
import org.gvsig.fmap.dal.feature.spi.FeatureReferenceProviderServices; |
50 |
import org.gvsig.fmap.dal.feature.spi.FeatureSetProvider; |
51 |
import org.gvsig.fmap.dal.resource.exception.ResourceExecuteException; |
52 |
import org.gvsig.fmap.dal.resource.file.FileResource; |
53 |
import org.gvsig.fmap.dal.resource.spi.ResourceConsumer; |
54 |
import org.gvsig.fmap.dal.resource.spi.ResourceProvider; |
55 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorer; |
56 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorerParameters; |
57 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
58 |
import org.gvsig.fmap.dal.store.gpe.handlers.FmapContentHandler; |
59 |
import org.gvsig.fmap.dal.store.gpe.handlers.FmapErrorHandler; |
60 |
import org.gvsig.fmap.geom.Geometry.TYPES; |
61 |
import org.gvsig.fmap.geom.primitive.Envelope; |
62 |
import org.gvsig.gpe.lib.api.GPELocator; |
63 |
import org.gvsig.gpe.lib.api.GPEManager; |
64 |
import org.gvsig.tools.dynobject.DynObject; |
65 |
import org.gvsig.xmlschema.lib.api.XMLSchemaLocator; |
66 |
import org.gvsig.xmlschema.lib.api.XMLSchemaManager; |
67 |
|
68 |
/**
|
69 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
|
70 |
*/
|
71 |
public class GPEStoreProvider extends AbstractFeatureStoreProvider implements |
72 |
ResourceConsumer { |
73 |
public static final String NAME = "GPE"; |
74 |
public static final String DESCRIPTION = "GPE file"; |
75 |
public static final String METADATA_DEFINITION_NAME = NAME; |
76 |
|
77 |
protected File m_Fich; |
78 |
protected boolean isOpen = false; |
79 |
//private GPEStoreParameters gpeParams;
|
80 |
private ResourceProvider gpeResource;
|
81 |
|
82 |
//Managers to manage the parsing process
|
83 |
protected GPEManager gpeManager = null; |
84 |
protected XMLSchemaManager xmlSchemaManager = null; |
85 |
|
86 |
//The content handler and the error handler
|
87 |
protected FmapContentHandler contentHandler;
|
88 |
protected FmapErrorHandler errorHandler;
|
89 |
|
90 |
public GPEStoreProvider(DataStoreParameters params,
|
91 |
DataStoreProviderServices storeServices) |
92 |
throws InitializeException {
|
93 |
this(params, storeServices, FileHelper
|
94 |
.newMetadataContainer(METADATA_DEFINITION_NAME)); |
95 |
} |
96 |
|
97 |
protected GPEStoreProvider(DataStoreParameters params,
|
98 |
DataStoreProviderServices storeServices, DynObject metadata) |
99 |
throws InitializeException {
|
100 |
|
101 |
super(params, storeServices, metadata);
|
102 |
|
103 |
this.setDynValue("Envelope", null); |
104 |
|
105 |
gpeManager = GPELocator.getGPEManager(); |
106 |
xmlSchemaManager = XMLSchemaLocator.getXMLSchemaManager(); |
107 |
|
108 |
retrieveFile(); |
109 |
gpeResource = this.createResource(FileResource.NAME,
|
110 |
new Object[] { m_Fich.getAbsolutePath() }); |
111 |
gpeResource.addConsumer(this);
|
112 |
this.initFeatureType();
|
113 |
} |
114 |
|
115 |
protected void retrieveFile() throws InitializeException{ |
116 |
m_Fich = getGPEParameters().getFile(); |
117 |
} |
118 |
|
119 |
protected void initFeatureType() throws InitializeException { |
120 |
try {
|
121 |
|
122 |
this.open();
|
123 |
} catch (DataException e) {
|
124 |
throw new InitializeException(this.getProviderName(), e); |
125 |
} |
126 |
} |
127 |
|
128 |
private GPEStoreParameters getGPEParameters() {
|
129 |
return (GPEStoreParameters) this.getParameters(); |
130 |
} |
131 |
|
132 |
/* (non-Javadoc)
|
133 |
* @see org.gvsig.fmap.dal.resource.spi.ResourceConsumer#closeResourceRequested(org.gvsig.fmap.dal.resource.spi.ResourceProvider)
|
134 |
*/
|
135 |
public boolean closeResourceRequested(ResourceProvider resource) { |
136 |
// TODO Auto-generated method stub
|
137 |
return false; |
138 |
} |
139 |
|
140 |
/* (non-Javadoc)
|
141 |
* @see org.gvsig.fmap.dal.resource.spi.ResourceConsumer#resourceChanged(org.gvsig.fmap.dal.resource.spi.ResourceProvider)
|
142 |
*/
|
143 |
public void resourceChanged(ResourceProvider resource) { |
144 |
// TODO Auto-generated method stub
|
145 |
|
146 |
} |
147 |
|
148 |
/* (non-Javadoc)
|
149 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider#canWriteGeometry(int)
|
150 |
*/
|
151 |
public boolean canWriteGeometry(int geometryType, int geometrySubtype) |
152 |
throws DataException {
|
153 |
// TODO Auto-generated method stub
|
154 |
return false; |
155 |
} |
156 |
|
157 |
/* (non-Javadoc)
|
158 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider#createNewOID()
|
159 |
*/
|
160 |
public Object createNewOID() { |
161 |
return contentHandler.createNewOID();
|
162 |
} |
163 |
|
164 |
/* (non-Javadoc)
|
165 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider#createSet(org.gvsig.fmap.dal.feature.FeatureQuery)
|
166 |
*/
|
167 |
public FeatureSetProvider createSet(FeatureQuery query)
|
168 |
throws DataException {
|
169 |
return new GPESetProvider(this, query); |
170 |
} |
171 |
|
172 |
protected FeatureProvider internalGetFeatureProviderByReference(
|
173 |
FeatureReferenceProviderServices reference) throws DataException {
|
174 |
return internalGetFeatureProviderByReference(reference,
|
175 |
this
|
176 |
.getFeatureStore() |
177 |
.getDefaultFeatureType()); |
178 |
} |
179 |
|
180 |
protected FeatureProvider internalGetFeatureProviderByReference(
|
181 |
FeatureReferenceProviderServices reference, FeatureType featureType) |
182 |
throws DataException {
|
183 |
return this.getFeatureProviderByIndex((Long) reference.getOID(), |
184 |
featureType); |
185 |
} |
186 |
|
187 |
FeatureProvider getFeatureProviderByIndex(Long index, FeatureType fType)
|
188 |
throws DataException {
|
189 |
return ((DefaultFeature)contentHandler.
|
190 |
getFeatureSet().get(index)).getData(); |
191 |
} |
192 |
|
193 |
public void resourcesBegin() throws ResourceExecuteException { |
194 |
// Nothing to do
|
195 |
} |
196 |
|
197 |
public void resourcesEnd() { |
198 |
// Nothing to do
|
199 |
} |
200 |
|
201 |
/* (non-Javadoc)
|
202 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider#getFeatureReferenceOIDType()
|
203 |
*/
|
204 |
public int getOIDType() { |
205 |
return DataTypes.STRING;
|
206 |
} |
207 |
|
208 |
/* (non-Javadoc)
|
209 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider#getName()
|
210 |
*/
|
211 |
public String getProviderName() { |
212 |
return NAME;
|
213 |
} |
214 |
|
215 |
/* (non-Javadoc)
|
216 |
* @see org.gvsig.fmap.dal.spi.DataStoreProvider#getSourceId()
|
217 |
*/
|
218 |
public Object getSourceId() { |
219 |
return getGPEParameters().getFile();
|
220 |
} |
221 |
|
222 |
public String getName() { |
223 |
String name = this.getGPEParameters().getFile().getName(); |
224 |
int n = name.lastIndexOf("."); |
225 |
if( n<1 ) { |
226 |
return name;
|
227 |
} |
228 |
return name.substring(0, n); |
229 |
} |
230 |
|
231 |
public String getFullName() { |
232 |
return this.getGPEParameters().getFile().getAbsolutePath(); |
233 |
} |
234 |
|
235 |
/* (non-Javadoc)
|
236 |
* @see org.gvsig.fmap.dal.spi.DataStoreProvider#open()
|
237 |
*/
|
238 |
public void open() throws OpenException { |
239 |
if (isOpen) {
|
240 |
return;
|
241 |
} |
242 |
try {
|
243 |
errorHandler = new FmapErrorHandler();
|
244 |
contentHandler = new FmapContentHandler(errorHandler,
|
245 |
getStoreServices(), this, m_Fich,
|
246 |
getSRS(), |
247 |
getGeometryType()); |
248 |
isOpen = true;
|
249 |
gpeManager.parse(contentHandler, errorHandler, m_Fich.toURI()); |
250 |
} catch (Exception e) { |
251 |
throw new OpenException("Imposible create a parser",e); |
252 |
} |
253 |
} |
254 |
|
255 |
protected IProjection getSRS(){
|
256 |
return getGPEParameters().getCRS();
|
257 |
} |
258 |
|
259 |
protected int getGeometryType() { |
260 |
return TYPES.GEOMETRY;
|
261 |
} |
262 |
|
263 |
/* (non-Javadoc)
|
264 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider#createSet(org.gvsig.fmap.dal.feature.FeatureQuery, org.gvsig.fmap.dal.feature.FeatureType)
|
265 |
*/
|
266 |
public FeatureSetProvider createSet(FeatureQuery query,
|
267 |
FeatureType featureType) throws DataException {
|
268 |
return new GPESetProvider(this, query, featureType); |
269 |
} |
270 |
|
271 |
public long getFeatureCount() throws DataException { |
272 |
return contentHandler.getFeaturesCount();
|
273 |
} |
274 |
|
275 |
/* (non-Javadoc)
|
276 |
* @see org.gvsig.fmap.dal.feature.spi.AbstractFeatureStoreProvider#getEnvelope()
|
277 |
*/
|
278 |
public Envelope getEnvelope() throws DataException { |
279 |
this.open();
|
280 |
return (Envelope) this.getDynValue("Envelope"); |
281 |
} |
282 |
|
283 |
public void setEnvelope(Envelope envelope) { |
284 |
this.setDynValue("Envelope", envelope); |
285 |
} |
286 |
|
287 |
public ResourceProvider getResource() {
|
288 |
return gpeResource;
|
289 |
} |
290 |
|
291 |
public DataServerExplorer getExplorer() throws ReadException, |
292 |
ValidateDataParametersException { |
293 |
DataManager manager = DALLocator.getDataManager(); |
294 |
FilesystemServerExplorerParameters params; |
295 |
try {
|
296 |
params = (FilesystemServerExplorerParameters) manager |
297 |
.createServerExplorerParameters(FilesystemServerExplorer.NAME); |
298 |
params.setRoot(this.getGPEParameters().getFile().getParent());
|
299 |
return manager.createServerExplorer(params);
|
300 |
} catch (DataException e) {
|
301 |
throw new ReadException(this.getProviderName(), e); |
302 |
} catch (ValidateDataParametersException e) {
|
303 |
// TODO Auto-generated catch block
|
304 |
throw new ReadException(this.getProviderName(), e); |
305 |
} |
306 |
} |
307 |
|
308 |
/**
|
309 |
* @return the contentHandler
|
310 |
*/
|
311 |
public FmapContentHandler getContentHandler() {
|
312 |
return contentHandler;
|
313 |
} |
314 |
|
315 |
/**
|
316 |
* @return the errorHandler
|
317 |
*/
|
318 |
public FmapErrorHandler getErrorHandler() {
|
319 |
return errorHandler;
|
320 |
} |
321 |
|
322 |
} |