svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.impl / src / main / java / org / gvsig / fmap / dal / raster / impl / DefaultCoverageStore.java @ 44304
History | View | Annotate | Download (16 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 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 3
|
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.fmap.dal.raster.impl; |
25 |
|
26 |
import java.util.Collection; |
27 |
import java.util.Set; |
28 |
import org.gvsig.fmap.dal.BaseStoresRepository; |
29 |
|
30 |
import org.gvsig.fmap.dal.DataCache; |
31 |
import org.gvsig.fmap.dal.DataManager; |
32 |
import org.gvsig.fmap.dal.DataQuery; |
33 |
import org.gvsig.fmap.dal.DataServerExplorer; |
34 |
import org.gvsig.fmap.dal.DataSet; |
35 |
import org.gvsig.fmap.dal.DataStore; |
36 |
import org.gvsig.fmap.dal.DataStoreNotification; |
37 |
import org.gvsig.fmap.dal.DataStoreParameters; |
38 |
import org.gvsig.fmap.dal.DataStoreProviderFactory; |
39 |
import org.gvsig.fmap.dal.StoresRepository; |
40 |
import org.gvsig.fmap.dal.exception.CloseException; |
41 |
import org.gvsig.fmap.dal.exception.DataException; |
42 |
import org.gvsig.fmap.dal.exception.InitializeException; |
43 |
import org.gvsig.fmap.dal.exception.OpenException; |
44 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
45 |
import org.gvsig.fmap.dal.feature.FeatureStoreNotification; |
46 |
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureStoreNotification; |
47 |
import org.gvsig.fmap.dal.impl.DefaultDataManager; |
48 |
import org.gvsig.fmap.dal.raster.CoverageSelection; |
49 |
import org.gvsig.fmap.dal.raster.CoverageStore; |
50 |
import org.gvsig.fmap.dal.raster.spi.CoverageStoreProvider; |
51 |
import org.gvsig.fmap.dal.raster.spi.CoverageStoreProviderServices; |
52 |
import org.gvsig.fmap.dal.resource.Resource; |
53 |
import org.gvsig.fmap.dal.spi.DataStoreInitializer; |
54 |
import org.gvsig.fmap.dal.spi.DataStoreProvider; |
55 |
import org.gvsig.metadata.MetadataLocator; |
56 |
import org.gvsig.timesupport.Interval; |
57 |
import org.gvsig.tools.ToolsLocator; |
58 |
import org.gvsig.tools.dispose.impl.AbstractDisposable; |
59 |
import org.gvsig.tools.dynobject.DelegatedDynObject; |
60 |
import org.gvsig.tools.dynobject.DynClass; |
61 |
import org.gvsig.tools.dynobject.DynObject; |
62 |
import org.gvsig.tools.dynobject.DynObjectManager; |
63 |
import org.gvsig.tools.dynobject.DynObject_v2; |
64 |
import org.gvsig.tools.dynobject.exception.DynFieldNotFoundException; |
65 |
import org.gvsig.tools.dynobject.exception.DynMethodException; |
66 |
import org.gvsig.tools.exception.BaseException; |
67 |
import org.gvsig.tools.observer.Observer; |
68 |
import org.gvsig.tools.observer.impl.DelegateWeakReferencingObservable; |
69 |
import org.gvsig.tools.persistence.PersistentState; |
70 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
71 |
import org.gvsig.tools.resourcesstorage.ResourcesStorage; |
72 |
import org.gvsig.tools.undo.command.Command; |
73 |
import org.gvsig.tools.util.UnmodifiableBasicMap; |
74 |
import org.gvsig.tools.visitor.Visitor; |
75 |
import org.slf4j.Logger; |
76 |
import org.slf4j.LoggerFactory; |
77 |
|
78 |
/**
|
79 |
* @author jmvivo
|
80 |
*
|
81 |
*/
|
82 |
public class DefaultCoverageStore extends AbstractDisposable implements |
83 |
CoverageStore, CoverageStoreProviderServices, DataStoreInitializer { |
84 |
|
85 |
private static final Logger LOG = LoggerFactory.getLogger(DefaultCoverageStore.class); |
86 |
|
87 |
|
88 |
private DataStoreParameters parameters = null; |
89 |
private CoverageSelection selection;
|
90 |
|
91 |
// private long versionOfUpdate = 0;
|
92 |
|
93 |
private DefaultDataManager dataManager = null; |
94 |
|
95 |
private CoverageStoreProvider provider = null; |
96 |
|
97 |
private DelegatedDynObject metadata;
|
98 |
|
99 |
private DelegateWeakReferencingObservable delegateObservable = new DelegateWeakReferencingObservable( |
100 |
this);
|
101 |
|
102 |
public DefaultCoverageStore() {
|
103 |
|
104 |
} |
105 |
|
106 |
/*
|
107 |
* (non-Javadoc)
|
108 |
*
|
109 |
* @see
|
110 |
* org.gvsig.fmap.dal.impl.DataStoreImplementation#intializePhase1(org.gvsig
|
111 |
* .fmap.dal.impl.DefaultDataManager,
|
112 |
* org.gvsig.fmap.dal.DataStoreParameters)
|
113 |
*/
|
114 |
public void intializePhase1(DataManager dataManager, |
115 |
DataStoreParameters parameters) throws InitializeException {
|
116 |
DynObjectManager dynManager = ToolsLocator.getDynObjectManager(); |
117 |
|
118 |
this.metadata = (DelegatedDynObject) dynManager
|
119 |
.createDynObject( |
120 |
MetadataLocator.getMetadataManager().getDefinition(DataStore.SPATIAL_METADATA_DEFINITION_NAME) |
121 |
); |
122 |
this.dataManager = (DefaultDataManager)dataManager;
|
123 |
this.parameters = parameters;
|
124 |
|
125 |
} |
126 |
|
127 |
|
128 |
|
129 |
/*
|
130 |
* (non-Javadoc)
|
131 |
*
|
132 |
* @see
|
133 |
* org.gvsig.fmap.dal.impl.DataStoreImplementation#intializePhase2(org.gvsig
|
134 |
* .fmap.dal.spi.DataStoreProvider)
|
135 |
*/
|
136 |
public void intializePhase2(DataStoreProvider provider) |
137 |
throws InitializeException {
|
138 |
|
139 |
this.provider = (CoverageStoreProvider) provider;
|
140 |
this.delegate((DynObject) provider);
|
141 |
|
142 |
} |
143 |
|
144 |
|
145 |
/* (non-Javadoc)
|
146 |
* @see org.gvsig.fmap.dal.DataStore#createSelection()
|
147 |
*/
|
148 |
public DataSet createSelection() throws DataException { |
149 |
// TODO Auto-generated method stub
|
150 |
return null; |
151 |
} |
152 |
|
153 |
|
154 |
@Override
|
155 |
public UnmodifiableBasicMap<String,DataStore> getChildren() { |
156 |
return UnmodifiableBasicMap.EMPTY_UNMODIFIABLEBASICMAP;
|
157 |
} |
158 |
|
159 |
/* (non-Javadoc)
|
160 |
* @see org.gvsig.fmap.dal.DataStore#getDataSet()
|
161 |
*/
|
162 |
public DataSet getDataSet() throws DataException { |
163 |
// TODO Auto-generated method stub
|
164 |
return null; |
165 |
} |
166 |
|
167 |
/* (non-Javadoc)
|
168 |
* @see org.gvsig.fmap.dal.DataStore#getDataSet(org.gvsig.fmap.dal.DataQuery)
|
169 |
*/
|
170 |
public DataSet getDataSet(DataQuery dataQuery) throws DataException { |
171 |
// TODO Auto-generated method stub
|
172 |
return null; |
173 |
} |
174 |
|
175 |
public void accept(Visitor visitor) throws BaseException { |
176 |
// TODO Auto-generated method stub
|
177 |
} |
178 |
|
179 |
public void accept(Visitor visitor, DataQuery dataQuery) |
180 |
throws BaseException {
|
181 |
// TODO Auto-generated method stub
|
182 |
} |
183 |
|
184 |
/* (non-Javadoc)
|
185 |
* @see org.gvsig.fmap.dal.DataStore#getDataSet(org.gvsig.tools.observer.Observer)
|
186 |
*/
|
187 |
public void getDataSet(Observer observer) throws DataException { |
188 |
// TODO Auto-generated method stub
|
189 |
|
190 |
} |
191 |
|
192 |
/* (non-Javadoc)
|
193 |
* @see org.gvsig.fmap.dal.DataStore#getDataSet(org.gvsig.fmap.dal.DataQuery, org.gvsig.tools.observer.Observer)
|
194 |
*/
|
195 |
public void getDataSet(DataQuery dataQuery, Observer observer) |
196 |
throws DataException {
|
197 |
// TODO Auto-generated method stub
|
198 |
|
199 |
} |
200 |
|
201 |
/* (non-Javadoc)
|
202 |
* @see org.gvsig.fmap.dal.DataStore#getExplorer()
|
203 |
*/
|
204 |
public DataServerExplorer getExplorer() throws DataException, |
205 |
ValidateDataParametersException { |
206 |
return provider.getExplorer();
|
207 |
} |
208 |
|
209 |
/* (non-Javadoc)
|
210 |
* @see org.gvsig.fmap.dal.DataStore#getParameters()
|
211 |
*/
|
212 |
public DataStoreParameters getParameters() {
|
213 |
return this.parameters; |
214 |
} |
215 |
|
216 |
/* (non-Javadoc)
|
217 |
* @see org.gvsig.fmap.dal.DataStore#getSelection()
|
218 |
*/
|
219 |
public DataSet getSelection() throws DataException { |
220 |
// TODO Auto-generated method stub
|
221 |
return null; |
222 |
} |
223 |
|
224 |
/* (non-Javadoc)
|
225 |
* @see org.gvsig.fmap.dal.DataStore#refresh()
|
226 |
*/
|
227 |
public void refresh() throws DataException { |
228 |
// TODO Auto-generated method stub
|
229 |
|
230 |
} |
231 |
|
232 |
/* (non-Javadoc)
|
233 |
* @see org.gvsig.fmap.dal.DataStore#setSelection(org.gvsig.fmap.dal.DataSet)
|
234 |
*/
|
235 |
public void setSelection(DataSet selection) throws DataException { |
236 |
// TODO Auto-generated method stub
|
237 |
|
238 |
} |
239 |
|
240 |
/* (non-Javadoc)
|
241 |
* @see org.gvsig.tools.observer.ComplexObservable#beginComplexNotification()
|
242 |
*/
|
243 |
public void beginComplexNotification() { |
244 |
// TODO Auto-generated method stub
|
245 |
|
246 |
} |
247 |
|
248 |
/* (non-Javadoc)
|
249 |
* @see org.gvsig.tools.observer.ComplexObservable#disableNotifications()
|
250 |
*/
|
251 |
public void disableNotifications() { |
252 |
// TODO Auto-generated method stub
|
253 |
|
254 |
} |
255 |
|
256 |
/* (non-Javadoc)
|
257 |
* @see org.gvsig.tools.observer.ComplexObservable#enableNotifications()
|
258 |
*/
|
259 |
public void enableNotifications() { |
260 |
// TODO Auto-generated method stub
|
261 |
|
262 |
} |
263 |
|
264 |
/* (non-Javadoc)
|
265 |
* @see org.gvsig.tools.observer.ComplexObservable#endComplexNotification()
|
266 |
*/
|
267 |
public void endComplexNotification() { |
268 |
// TODO Auto-generated method stub
|
269 |
|
270 |
} |
271 |
|
272 |
/* (non-Javadoc)
|
273 |
* @see org.gvsig.tools.observer.Observable#addObserver(org.gvsig.tools.observer.Observer)
|
274 |
*/
|
275 |
public void addObserver(Observer o) { |
276 |
// TODO Auto-generated method stub
|
277 |
|
278 |
} |
279 |
|
280 |
/* (non-Javadoc)
|
281 |
* @see org.gvsig.tools.observer.Observable#deleteObserver(org.gvsig.tools.observer.Observer)
|
282 |
*/
|
283 |
public void deleteObserver(Observer o) { |
284 |
// TODO Auto-generated method stub
|
285 |
|
286 |
} |
287 |
|
288 |
/* (non-Javadoc)
|
289 |
* @see org.gvsig.tools.observer.Observable#deleteObservers()
|
290 |
*/
|
291 |
public void deleteObservers() { |
292 |
// TODO Auto-generated method stub
|
293 |
|
294 |
} |
295 |
|
296 |
/* (non-Javadoc)
|
297 |
* @see org.gvsig.tools.persistence.Persistent#getState()
|
298 |
*/
|
299 |
public PersistentState getState() throws PersistenceException { |
300 |
// TODO Auto-generated method stub
|
301 |
return null; |
302 |
} |
303 |
|
304 |
/* (non-Javadoc)
|
305 |
* @see org.gvsig.tools.persistence.Persistent#loadState(org.gvsig.tools.persistence.PersistentState)
|
306 |
*/
|
307 |
public void saveToState(PersistentState state) throws PersistenceException { |
308 |
// TODO Auto-generated method stub
|
309 |
|
310 |
} |
311 |
|
312 |
/* (non-Javadoc)
|
313 |
* @see org.gvsig.tools.persistence.Persistent#setState(org.gvsig.tools.persistence.PersistentState)
|
314 |
*/
|
315 |
public void loadFromState(PersistentState state) throws PersistenceException { |
316 |
// TODO Auto-generated method stub
|
317 |
|
318 |
} |
319 |
|
320 |
//
|
321 |
// ====================================================================
|
322 |
// Metadata related methods
|
323 |
//
|
324 |
|
325 |
public Object getMetadataID() { |
326 |
return this.provider.getSourceId(); |
327 |
} |
328 |
|
329 |
public void delegate(DynObject dynObject) { |
330 |
this.metadata.delegate(dynObject);
|
331 |
} |
332 |
|
333 |
public DynClass getDynClass() {
|
334 |
return this.metadata.getDynClass(); |
335 |
} |
336 |
|
337 |
public Object getDynValue(String name) throws DynFieldNotFoundException { |
338 |
return this.metadata.getDynValue(name); |
339 |
} |
340 |
|
341 |
public boolean hasDynValue(String name) { |
342 |
return this.metadata.hasDynValue(name); |
343 |
} |
344 |
|
345 |
@Override
|
346 |
public boolean hasDynMethod(String name) { |
347 |
return ((DynObject_v2)this.metadata).hasDynMethod(name); |
348 |
} |
349 |
|
350 |
public void implement(DynClass dynClass) { |
351 |
this.metadata.implement(dynClass);
|
352 |
} |
353 |
|
354 |
public Object invokeDynMethod(String name, Object[] args) |
355 |
throws DynMethodException {
|
356 |
return this.metadata.invokeDynMethod(this, name, args); |
357 |
} |
358 |
|
359 |
public Object invokeDynMethod(int code, Object[] args) |
360 |
throws DynMethodException {
|
361 |
return this.metadata.invokeDynMethod(this, code, args); |
362 |
} |
363 |
|
364 |
public void setDynValue(String name, Object value) |
365 |
throws DynFieldNotFoundException {
|
366 |
this.metadata.setDynValue(name, value);
|
367 |
|
368 |
} |
369 |
|
370 |
/*
|
371 |
* (non-Javadoc)
|
372 |
*
|
373 |
* @see org.gvsig.metadata.Metadata#getMetadataChildren()
|
374 |
*/
|
375 |
public Set getMetadataChildren() { |
376 |
return null; |
377 |
} |
378 |
|
379 |
/*
|
380 |
* (non-Javadoc)
|
381 |
*
|
382 |
* @see org.gvsig.metadata.Metadata#getMetadataName()
|
383 |
*/
|
384 |
public String getMetadataName() { |
385 |
return this.provider.getProviderName(); |
386 |
} |
387 |
|
388 |
|
389 |
/* (non-Javadoc)
|
390 |
* @see org.gvsig.fmap.dal.raster.spi.CoverageStoreProviderServices#createDefaultCoverageSelection()
|
391 |
*/
|
392 |
public CoverageSelection createDefaultCoverageSelection()
|
393 |
throws DataException {
|
394 |
// TODO Auto-generated method stub
|
395 |
return null; |
396 |
} |
397 |
|
398 |
|
399 |
/* (non-Javadoc)
|
400 |
* @see org.gvsig.fmap.dal.raster.spi.CoverageStoreProviderServices#getManager()
|
401 |
*/
|
402 |
public DataManager getManager() {
|
403 |
return this.dataManager; |
404 |
} |
405 |
|
406 |
/* (non-Javadoc)
|
407 |
* @see org.gvsig.fmap.dal.raster.spi.CoverageStoreProviderServices#getProvider()
|
408 |
*/
|
409 |
public CoverageStoreProvider getProvider() {
|
410 |
return this.provider; |
411 |
} |
412 |
|
413 |
public void notifyChange(String notification) { |
414 |
delegateObservable |
415 |
.notifyObservers(new DefaultCoverageStoreNotification(
|
416 |
this, notification));
|
417 |
|
418 |
} |
419 |
|
420 |
|
421 |
public void notifyChange(String notification, Command command) { |
422 |
delegateObservable |
423 |
.notifyObservers(new DefaultCoverageStoreNotification(
|
424 |
this, notification, command));
|
425 |
} |
426 |
|
427 |
|
428 |
/*
|
429 |
* (non-Javadoc)
|
430 |
*
|
431 |
* @see
|
432 |
* org.gvsig.fmap.dal.feature.spi.FeatureStoreProviderServices#notifyChange
|
433 |
* (java.lang.String, org.gvsig.fmap.dal.resource.Resource)
|
434 |
*/
|
435 |
public void notifyChange(String notification, Resource resource) { |
436 |
delegateObservable.notifyObservers(new DefaultFeatureStoreNotification(
|
437 |
this, FeatureStoreNotification.RESOURCE_CHANGED));
|
438 |
} |
439 |
|
440 |
public void open() throws OpenException { |
441 |
// TODO: Se puede hacer un open estando en edicion ?
|
442 |
this.notifyChange(DataStoreNotification.BEFORE_OPEN);
|
443 |
this.provider.open();
|
444 |
this.notifyChange(DataStoreNotification.AFTER_OPEN);
|
445 |
} |
446 |
|
447 |
public void close() throws CloseException { |
448 |
// TODO: Se puede hacer un close estando en edicion ?
|
449 |
this.notifyChange(DataStoreNotification.BEFORE_CLOSE);
|
450 |
this.provider.close();
|
451 |
this.notifyChange(DataStoreNotification.AFTER_CLOSE);
|
452 |
} |
453 |
|
454 |
protected void doDispose() throws BaseException { |
455 |
this.notifyChange(DataStoreNotification.BEFORE_DISPOSE);
|
456 |
this.provider.dispose();
|
457 |
if (this.selection != null) { |
458 |
this.selection.dispose();
|
459 |
this.selection = null; |
460 |
} |
461 |
|
462 |
this.parameters = null; |
463 |
this.notifyChange(DataStoreNotification.AFTER_DISPOSE);
|
464 |
this.delegateObservable.deleteObservers();
|
465 |
this.delegateObservable = null; |
466 |
} |
467 |
|
468 |
public boolean allowWrite() { |
469 |
return this.provider.allowWrite(); |
470 |
} |
471 |
|
472 |
public DataQuery createQuery() {
|
473 |
// TODO Auto-generated method stub
|
474 |
return null; |
475 |
} |
476 |
|
477 |
public DataStore getStore() {
|
478 |
return this; |
479 |
} |
480 |
|
481 |
public CoverageStore getCoverageStore() {
|
482 |
return this; |
483 |
} |
484 |
|
485 |
public void clear() { |
486 |
if (metadata != null) { |
487 |
metadata.clear(); |
488 |
} |
489 |
} |
490 |
|
491 |
public String getProviderName() { |
492 |
return this.provider.getProviderName(); |
493 |
} |
494 |
|
495 |
public String getName() { |
496 |
return this.provider.getName(); |
497 |
} |
498 |
|
499 |
public String getFullName() { |
500 |
return this.provider.getFullName(); |
501 |
} |
502 |
|
503 |
public Interval getInterval() {
|
504 |
// TODO Auto-generated method stub
|
505 |
return null; |
506 |
} |
507 |
|
508 |
public Collection getTimes() { |
509 |
// TODO Auto-generated method stub
|
510 |
return null; |
511 |
} |
512 |
|
513 |
public Collection getTimes(Interval interval) { |
514 |
// TODO Auto-generated method stub
|
515 |
return null; |
516 |
} |
517 |
|
518 |
@Override
|
519 |
public void useCache(String providerName, DynObject parameters) throws DataException { |
520 |
throw new UnsupportedOperationException(); |
521 |
} |
522 |
|
523 |
@Override
|
524 |
public DataStoreProviderFactory getProviderFactory() {
|
525 |
DataStoreProviderFactory factory = dataManager.getStoreProviderFactory(parameters.getDataStoreName()); |
526 |
return factory;
|
527 |
} |
528 |
|
529 |
@Override
|
530 |
public DataCache getCache() {
|
531 |
// TODO Auto-generated method stub
|
532 |
return null; |
533 |
} |
534 |
|
535 |
@Override
|
536 |
public ResourcesStorage getResourcesStorage() {
|
537 |
try {
|
538 |
return this.getExplorer().getResourcesStorage(this); |
539 |
} catch (Exception ex) { |
540 |
LOG.warn("Can't create resources storage",ex);
|
541 |
return null; |
542 |
} |
543 |
} |
544 |
|
545 |
@Override
|
546 |
public StoresRepository getStoresRepository() {
|
547 |
final StoresRepository mainRepository = this.dataManager.getStoresRepository(); |
548 |
StoresRepository repository = new BaseStoresRepository(this.getName()) { |
549 |
|
550 |
@Override
|
551 |
protected DataStoreParameters getMyParameters(String name) { |
552 |
// Uff, esta implementacion no es nada buena
|
553 |
DataStore store = getChildren().get(name); |
554 |
if( store==null ) { |
555 |
return null; |
556 |
} |
557 |
return store.getParameters();
|
558 |
} |
559 |
|
560 |
@Override
|
561 |
protected boolean isEmptyMyRepository() { |
562 |
UnmodifiableBasicMap<String, DataStore> children = getChildren();
|
563 |
return children==null || children.isEmpty(); |
564 |
} |
565 |
|
566 |
@Override
|
567 |
protected int getMySize() { |
568 |
UnmodifiableBasicMap<String, DataStore> children = getChildren();
|
569 |
if( children==null ) { |
570 |
return 0; |
571 |
} |
572 |
return children.size();
|
573 |
} |
574 |
|
575 |
@Override
|
576 |
public void add(String name, DataStoreParameters parameters) { |
577 |
mainRepository.add(name, parameters); |
578 |
} |
579 |
|
580 |
@Override
|
581 |
public void remove(String name) { |
582 |
mainRepository.remove(name); |
583 |
} |
584 |
|
585 |
}; |
586 |
return repository;
|
587 |
} |
588 |
|
589 |
} |