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