root / branches / v2_0_0_prep / extensions / extGPE-gvSIG / src / org / gvsig / fmap / dal / store / gpe / GPEStoreProvider.java @ 38564
History | View | Annotate | Download (11.2 KB)
1 | 27499 | jpiera | /* 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 | 28680 | jmvivo | *
|
6 | 27499 | jpiera | * 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 | 28680 | jmvivo | *
|
11 | 27499 | jpiera | * 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 | 28680 | jmvivo | *
|
16 | 27499 | jpiera | * 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 | 28680 | jmvivo | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 | 27499 | jpiera | * MA 02110-1301, USA.
|
20 | 28680 | jmvivo | *
|
21 | 27499 | jpiera | */
|
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 | 34133 | jpiera | import java.util.Map; |
32 | 27499 | jpiera | |
33 | 30752 | jpiera | import org.cresques.cts.IProjection; |
34 | 31838 | jpiera | import org.gvsig.fmap.dal.DALLocator; |
35 | import org.gvsig.fmap.dal.DataManager; |
||
36 | import org.gvsig.fmap.dal.DataServerExplorer; |
||
37 | 29326 | jmvivo | import org.gvsig.fmap.dal.DataStoreParameters; |
38 | 29187 | jpiera | import org.gvsig.fmap.dal.DataTypes; |
39 | 32953 | cordinyana | import org.gvsig.fmap.dal.FileHelper; |
40 | 28680 | jmvivo | import org.gvsig.fmap.dal.exception.DataException; |
41 | import org.gvsig.fmap.dal.exception.InitializeException; |
||
42 | import org.gvsig.fmap.dal.exception.OpenException; |
||
43 | 31838 | jpiera | import org.gvsig.fmap.dal.exception.ReadException; |
44 | import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
||
45 | 28680 | jmvivo | import org.gvsig.fmap.dal.feature.FeatureQuery; |
46 | import org.gvsig.fmap.dal.feature.FeatureType; |
||
47 | import org.gvsig.fmap.dal.feature.spi.AbstractFeatureStoreProvider; |
||
48 | 29292 | jmvivo | import org.gvsig.fmap.dal.feature.spi.FeatureProvider; |
49 | 28680 | jmvivo | import org.gvsig.fmap.dal.feature.spi.FeatureReferenceProviderServices; |
50 | import org.gvsig.fmap.dal.feature.spi.FeatureSetProvider; |
||
51 | 31022 | cordinyana | import org.gvsig.fmap.dal.resource.exception.ResourceExecuteException; |
52 | 27499 | jpiera | 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 | 31838 | jpiera | import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorer; |
56 | import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorerParameters; |
||
57 | 29326 | jmvivo | import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
58 | 27499 | jpiera | import org.gvsig.fmap.dal.store.gpe.handlers.FmapContentHandler; |
59 | import org.gvsig.fmap.dal.store.gpe.handlers.FmapErrorHandler; |
||
60 | 31838 | jpiera | import org.gvsig.fmap.geom.Geometry.TYPES; |
61 | 27499 | jpiera | import org.gvsig.fmap.geom.primitive.Envelope; |
62 | 32051 | jpiera | import org.gvsig.gpe.lib.api.GPELocator; |
63 | import org.gvsig.gpe.lib.api.GPEManager; |
||
64 | 29326 | jmvivo | import org.gvsig.tools.dynobject.DynObject; |
65 | 32051 | jpiera | import org.gvsig.xmlschema.lib.api.XMLSchemaLocator; |
66 | import org.gvsig.xmlschema.lib.api.XMLSchemaManager; |
||
67 | 27499 | jpiera | |
68 | /**
|
||
69 | * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
|
||
70 | */
|
||
71 | public class GPEStoreProvider extends AbstractFeatureStoreProvider implements |
||
72 | ResourceConsumer { |
||
73 | 34026 | jpiera | public static final String NAME = "GPE"; |
74 | public static final String DESCRIPTION = "GPE file"; |
||
75 | public static final String METADATA_DEFINITION_NAME = NAME; |
||
76 | 32953 | cordinyana | |
77 | 34026 | jpiera | protected File m_Fich; |
78 | protected boolean isOpen = false; |
||
79 | //private GPEStoreParameters gpeParams;
|
||
80 | private ResourceProvider gpeResource;
|
||
81 | 27499 | jpiera | |
82 | 34026 | jpiera | //Managers to manage the parsing process
|
83 | protected GPEManager gpeManager = null; |
||
84 | protected XMLSchemaManager xmlSchemaManager = null; |
||
85 | 27499 | jpiera | |
86 | 34026 | jpiera | //The content handler and the error handler
|
87 | protected FmapContentHandler contentHandler;
|
||
88 | protected FmapErrorHandler errorHandler;
|
||
89 | 27499 | jpiera | |
90 | 34026 | jpiera | public GPEStoreProvider(DataStoreParameters params,
|
91 | DataStoreProviderServices storeServices) |
||
92 | throws InitializeException {
|
||
93 | this(params, storeServices, FileHelper
|
||
94 | .newMetadataContainer(METADATA_DEFINITION_NAME)); |
||
95 | } |
||
96 | 27499 | jpiera | |
97 | 34026 | jpiera | protected GPEStoreProvider(DataStoreParameters params,
|
98 | DataStoreProviderServices storeServices, DynObject metadata) |
||
99 | throws InitializeException {
|
||
100 | 27499 | jpiera | |
101 | 34026 | jpiera | super(params, storeServices, metadata);
|
102 | 27499 | jpiera | |
103 | 34026 | jpiera | this.setDynValue("Envelope", params.getDynValue("Envelope")); |
104 | 27499 | jpiera | |
105 | 34026 | jpiera | gpeManager = GPELocator.getGPEManager(); |
106 | xmlSchemaManager = XMLSchemaLocator.getXMLSchemaManager(); |
||
107 | 27499 | jpiera | |
108 | 34026 | jpiera | retrieveFile(); |
109 | gpeResource = this.createResource(FileResource.NAME,
|
||
110 | new Object[] { m_Fich.getAbsolutePath() }); |
||
111 | gpeResource.addConsumer(this);
|
||
112 | this.initFeatureType();
|
||
113 | } |
||
114 | 27499 | jpiera | |
115 | 34026 | jpiera | protected void retrieveFile() throws InitializeException{ |
116 | m_Fich = getGPEParameters().getFile(); |
||
117 | } |
||
118 | 27499 | jpiera | |
119 | 34026 | jpiera | protected void initFeatureType() throws InitializeException { |
120 | try {
|
||
121 | 27499 | jpiera | |
122 | 34026 | jpiera | this.open();
|
123 | } catch (DataException e) {
|
||
124 | throw new InitializeException(this.getProviderName(), e); |
||
125 | } |
||
126 | } |
||
127 | 27499 | jpiera | |
128 | 34026 | jpiera | private GPEStoreParameters getGPEParameters() {
|
129 | return (GPEStoreParameters) this.getParameters(); |
||
130 | } |
||
131 | 27499 | jpiera | |
132 | 34026 | jpiera | /* (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 | 27499 | jpiera | |
140 | 34026 | jpiera | /* (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 | 27499 | jpiera | |
146 | 34026 | jpiera | } |
147 | 27499 | jpiera | |
148 | 34026 | jpiera | /* (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 | 31022 | cordinyana | |
157 | 34026 | jpiera | /* (non-Javadoc)
|
158 | * @see org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider#createNewOID()
|
||
159 | */
|
||
160 | public Object createNewOID() { |
||
161 | return contentHandler.createNewOID();
|
||
162 | } |
||
163 | 27499 | jpiera | |
164 | 34026 | jpiera | /* (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 | 27499 | jpiera | |
172 | 34026 | jpiera | protected FeatureProvider internalGetFeatureProviderByReference(
|
173 | FeatureReferenceProviderServices reference) throws DataException {
|
||
174 | return internalGetFeatureProviderByReference(reference,
|
||
175 | this
|
||
176 | .getFeatureStore() |
||
177 | .getDefaultFeatureType()); |
||
178 | } |
||
179 | 27499 | jpiera | |
180 | 34026 | jpiera | public FeatureProvider internalGetFeatureProviderByReference(
|
181 | FeatureReferenceProviderServices reference, FeatureType featureType) |
||
182 | throws DataException {
|
||
183 | 34133 | jpiera | Map featureSet = contentHandler.getFeatureSet();
|
184 | if (featureSet.containsKey(reference.getOID())){
|
||
185 | 34134 | jpiera | return (FeatureProvider)featureSet.get(reference.getOID());
|
186 | 34133 | jpiera | } |
187 | return null; |
||
188 | 34026 | jpiera | } |
189 | 27499 | jpiera | |
190 | 34026 | jpiera | FeatureProvider getFeatureProviderByIndex(Long index, FeatureType fType)
|
191 | throws DataException {
|
||
192 | 34134 | jpiera | Map featureSet = contentHandler.getFeatureSet();
|
193 | if (featureSet.containsKey(index)){
|
||
194 | return (FeatureProvider)featureSet.get(index);
|
||
195 | } |
||
196 | return null; |
||
197 | 34026 | jpiera | } |
198 | 27499 | jpiera | |
199 | 34026 | jpiera | public void resourcesBegin() throws ResourceExecuteException { |
200 | // Nothing to do
|
||
201 | } |
||
202 | 27499 | jpiera | |
203 | 34026 | jpiera | public void resourcesEnd() { |
204 | // Nothing to do
|
||
205 | } |
||
206 | 27499 | jpiera | |
207 | 34026 | jpiera | /* (non-Javadoc)
|
208 | * @see org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider#getFeatureReferenceOIDType()
|
||
209 | */
|
||
210 | public int getOIDType() { |
||
211 | return DataTypes.STRING;
|
||
212 | } |
||
213 | 28113 | jpiera | |
214 | 34026 | jpiera | /* (non-Javadoc)
|
215 | * @see org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider#getName()
|
||
216 | */
|
||
217 | public String getProviderName() { |
||
218 | return NAME;
|
||
219 | } |
||
220 | 28680 | jmvivo | |
221 | 34026 | jpiera | /* (non-Javadoc)
|
222 | * @see org.gvsig.fmap.dal.spi.DataStoreProvider#getSourceId()
|
||
223 | */
|
||
224 | public Object getSourceId() { |
||
225 | return getGPEParameters().getFile();
|
||
226 | } |
||
227 | 31838 | jpiera | |
228 | 34026 | jpiera | public String getName() { |
229 | String name = this.getGPEParameters().getFile().getName(); |
||
230 | int n = name.lastIndexOf("."); |
||
231 | if( n<1 ) { |
||
232 | return name;
|
||
233 | } |
||
234 | return name.substring(0, n); |
||
235 | } |
||
236 | 32051 | jpiera | |
237 | 34026 | jpiera | public String getFullName() { |
238 | return this.getGPEParameters().getFile().getAbsolutePath(); |
||
239 | } |
||
240 | 32051 | jpiera | |
241 | 34026 | jpiera | /* (non-Javadoc)
|
242 | * @see org.gvsig.fmap.dal.spi.DataStoreProvider#open()
|
||
243 | */
|
||
244 | public void open() throws OpenException { |
||
245 | if (isOpen) {
|
||
246 | return;
|
||
247 | } |
||
248 | try {
|
||
249 | errorHandler = new FmapErrorHandler();
|
||
250 | contentHandler = new FmapContentHandler(errorHandler,
|
||
251 | getStoreServices(), this, m_Fich,
|
||
252 | getSRS(), |
||
253 | getGeometryType()); |
||
254 | if (getStoreServices().getDefaultFeatureType() != null){ |
||
255 | contentHandler.setFeatureType(getStoreServices().getDefaultFeatureType().getEditable()); |
||
256 | } |
||
257 | contentHandler.setEnvelope((Envelope)getDynValue("Envelope"));
|
||
258 | isOpen = true;
|
||
259 | gpeManager.parse(contentHandler, errorHandler, m_Fich.toURI()); |
||
260 | } catch (Exception e) { |
||
261 | throw new OpenException("Imposible create a parser",e); |
||
262 | } |
||
263 | } |
||
264 | |||
265 | protected IProjection getSRS(){
|
||
266 | return getGPEParameters().getCRS();
|
||
267 | } |
||
268 | |||
269 | protected int getGeometryType() { |
||
270 | return TYPES.GEOMETRY;
|
||
271 | } |
||
272 | |||
273 | /* (non-Javadoc)
|
||
274 | * @see org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider#createSet(org.gvsig.fmap.dal.feature.FeatureQuery, org.gvsig.fmap.dal.feature.FeatureType)
|
||
275 | */
|
||
276 | public FeatureSetProvider createSet(FeatureQuery query,
|
||
277 | FeatureType featureType) throws DataException {
|
||
278 | return new GPESetProvider(this, query, featureType); |
||
279 | } |
||
280 | |||
281 | public long getFeatureCount() throws DataException { |
||
282 | return contentHandler.getFeaturesCount();
|
||
283 | } |
||
284 | |||
285 | /* (non-Javadoc)
|
||
286 | * @see org.gvsig.fmap.dal.feature.spi.AbstractFeatureStoreProvider#getEnvelope()
|
||
287 | */
|
||
288 | public Envelope getEnvelope() throws DataException { |
||
289 | this.open();
|
||
290 | return (Envelope) this.getDynValue("Envelope"); |
||
291 | } |
||
292 | |||
293 | public void setEnvelope(Envelope envelope) { |
||
294 | this.setDynValue("Envelope", envelope); |
||
295 | } |
||
296 | |||
297 | public ResourceProvider getResource() {
|
||
298 | return gpeResource;
|
||
299 | } |
||
300 | |||
301 | public DataServerExplorer getExplorer() throws ReadException, |
||
302 | ValidateDataParametersException { |
||
303 | DataManager manager = DALLocator.getDataManager(); |
||
304 | FilesystemServerExplorerParameters params; |
||
305 | try {
|
||
306 | params = (FilesystemServerExplorerParameters) manager |
||
307 | .createServerExplorerParameters(FilesystemServerExplorer.NAME); |
||
308 | params.setRoot(this.getGPEParameters().getFile().getParent());
|
||
309 | return manager.createServerExplorer(params);
|
||
310 | } catch (DataException e) {
|
||
311 | throw new ReadException(this.getProviderName(), e); |
||
312 | } catch (ValidateDataParametersException e) {
|
||
313 | // TODO Auto-generated catch block
|
||
314 | throw new ReadException(this.getProviderName(), e); |
||
315 | } |
||
316 | } |
||
317 | |||
318 | /**
|
||
319 | * @return the contentHandler
|
||
320 | */
|
||
321 | public FmapContentHandler getContentHandler() {
|
||
322 | return contentHandler;
|
||
323 | } |
||
324 | |||
325 | /**
|
||
326 | * @return the errorHandler
|
||
327 | */
|
||
328 | public FmapErrorHandler getErrorHandler() {
|
||
329 | return errorHandler;
|
||
330 | } |
||
331 | |||
332 | 31838 | jpiera | } |