Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libFMap_dal / src / org / gvsig / fmap / dal / raster / impl / DefaultCoverageStore.java @ 31629

History | View | Annotate | Download (12.7 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
/**
29
 *
30
 */
31
package org.gvsig.fmap.dal.raster.impl;
32

    
33
import java.util.Iterator;
34
import java.util.Set;
35

    
36
import org.gvsig.fmap.dal.DataQuery;
37
import org.gvsig.fmap.dal.DataServerExplorer;
38
import org.gvsig.fmap.dal.DataSet;
39
import org.gvsig.fmap.dal.DataStore;
40
import org.gvsig.fmap.dal.DataStoreNotification;
41
import org.gvsig.fmap.dal.DataStoreParameters;
42
import org.gvsig.fmap.dal.exception.CloseException;
43
import org.gvsig.fmap.dal.exception.DataException;
44
import org.gvsig.fmap.dal.exception.InitializeException;
45
import org.gvsig.fmap.dal.exception.OpenException;
46
import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
47
import org.gvsig.fmap.dal.feature.FeatureStoreNotification;
48
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureStore;
49
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureStoreNotification;
50
import org.gvsig.fmap.dal.impl.DataStoreImplementation;
51
import org.gvsig.fmap.dal.impl.DefaultDataManager;
52
import org.gvsig.fmap.dal.raster.CoverageSelection;
53
import org.gvsig.fmap.dal.raster.CoverageStore;
54
import org.gvsig.fmap.dal.raster.spi.CoverageStoreProvider;
55
import org.gvsig.fmap.dal.raster.spi.CoverageStoreProviderServices;
56
import org.gvsig.fmap.dal.resource.Resource;
57
import org.gvsig.fmap.dal.spi.DataStoreProvider;
58
import org.gvsig.tools.ToolsLocator;
59
import org.gvsig.tools.dispose.impl.AbstractDisposable;
60
import org.gvsig.tools.dynobject.DelegatedDynObject;
61
import org.gvsig.tools.dynobject.DynClass;
62
import org.gvsig.tools.dynobject.DynObject;
63
import org.gvsig.tools.dynobject.DynObjectManager;
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.PersistenceException;
70
import org.gvsig.tools.persistence.PersistentState;
71
import org.gvsig.tools.undo.command.Command;
72
import org.gvsig.tools.visitor.Visitor;
73
import org.slf4j.Logger;
74
import org.slf4j.LoggerFactory;
75

    
76
/**
77
 * @author jmvivo
78
 *
79
 */
80
public class DefaultCoverageStore extends AbstractDisposable implements
81
                CoverageStore, CoverageStoreProviderServices, DataStoreImplementation {
82

    
83
        final static private Logger logger = LoggerFactory
84
                        .getLogger(DefaultFeatureStore.class);
85

    
86
        private DataStoreParameters parameters = null;
87
        private CoverageSelection selection;
88

    
89
        private long versionOfUpdate = 0;
90

    
91
        private DefaultDataManager dataManager = null;
92

    
93
        private CoverageStoreProvider provider = null;
94

    
95
        private DelegatedDynObject dynObject;
96

    
97
        private DelegateWeakReferencingObservable delegateObservable = new DelegateWeakReferencingObservable(
98
                        this);
99

    
100
        public DefaultCoverageStore() {
101

    
102
        }
103

    
104
        /*
105
         * (non-Javadoc)
106
         *
107
         * @see
108
         * org.gvsig.fmap.dal.impl.DataStoreImplementation#intializePhase1(org.gvsig
109
         * .fmap.dal.impl.DefaultDataManager,
110
         * org.gvsig.fmap.dal.DataStoreParameters)
111
         */
112
        public void intializePhase1(DefaultDataManager dataManager,
113
                        DataStoreParameters parameters) throws InitializeException {
114
                DynObjectManager dynManager = ToolsLocator.getDynObjectManager();
115

    
116
                this.dynObject = (DelegatedDynObject) dynManager
117
                                .createDynObject(dynManager.get(DataStore.DYNCLASS_NAME));
118
                this.dataManager = dataManager;
119
                this.parameters = parameters;
120

    
121
        }
122

    
123

    
124

    
125
        /*
126
         * (non-Javadoc)
127
         *
128
         * @see
129
         * org.gvsig.fmap.dal.impl.DataStoreImplementation#intializePhase2(org.gvsig
130
         * .fmap.dal.spi.DataStoreProvider)
131
         */
132
        public void intializePhase2(DataStoreProvider provider)
133
                        throws InitializeException {
134

    
135
                this.provider = (CoverageStoreProvider) provider;
136
                this.delegate(provider);
137

    
138
        }
139

    
140

    
141
        /* (non-Javadoc)
142
         * @see org.gvsig.fmap.dal.DataStore#createSelection()
143
         */
144
        public DataSet createSelection() throws DataException {
145
                // TODO Auto-generated method stub
146
                return null;
147
        }
148

    
149

    
150
        /* (non-Javadoc)
151
         * @see org.gvsig.fmap.dal.DataStore#getChildren()
152
         */
153
        public Iterator getChildren() {
154
                return this.provider.getChilds();
155
        }
156

    
157
        /* (non-Javadoc)
158
         * @see org.gvsig.fmap.dal.DataStore#getDataSet()
159
         */
160
        public DataSet getDataSet() throws DataException {
161
                // TODO Auto-generated method stub
162
                return null;
163
        }
164

    
165
        /* (non-Javadoc)
166
         * @see org.gvsig.fmap.dal.DataStore#getDataSet(org.gvsig.fmap.dal.DataQuery)
167
         */
168
        public DataSet getDataSet(DataQuery dataQuery) throws DataException {
169
                // TODO Auto-generated method stub
170
                return null;
171
        }
172

    
173
        public void accept(Visitor visitor) throws BaseException {
174
                // TODO Auto-generated method stub
175
        }
176

    
177
        public void accept(Visitor visitor, DataQuery dataQuery)
178
                        throws BaseException {
179
                // TODO Auto-generated method stub
180
        }
181

    
182
        /* (non-Javadoc)
183
         * @see org.gvsig.fmap.dal.DataStore#getDataSet(org.gvsig.tools.observer.Observer)
184
         */
185
        public void getDataSet(Observer observer) throws DataException {
186
                // TODO Auto-generated method stub
187

    
188
        }
189

    
190
        /* (non-Javadoc)
191
         * @see org.gvsig.fmap.dal.DataStore#getDataSet(org.gvsig.fmap.dal.DataQuery, org.gvsig.tools.observer.Observer)
192
         */
193
        public void getDataSet(DataQuery dataQuery, Observer observer)
194
                        throws DataException {
195
                // TODO Auto-generated method stub
196

    
197
        }
198

    
199
        /* (non-Javadoc)
200
         * @see org.gvsig.fmap.dal.DataStore#getExplorer()
201
         */
202
        public DataServerExplorer getExplorer() throws DataException,
203
                        ValidateDataParametersException {
204
                return provider.getExplorer();
205
        }
206

    
207
        /* (non-Javadoc)
208
         * @see org.gvsig.fmap.dal.DataStore#getName()
209
         */
210
        public String getName() {
211
                return provider.getName();
212
        }
213

    
214
        /* (non-Javadoc)
215
         * @see org.gvsig.fmap.dal.DataStore#getParameters()
216
         */
217
        public DataStoreParameters getParameters() {
218
                return this.parameters;
219
        }
220

    
221
        /* (non-Javadoc)
222
         * @see org.gvsig.fmap.dal.DataStore#getSelection()
223
         */
224
        public DataSet getSelection() throws DataException {
225
                // TODO Auto-generated method stub
226
                return null;
227
        }
228

    
229
        /* (non-Javadoc)
230
         * @see org.gvsig.fmap.dal.DataStore#refresh()
231
         */
232
        public void refresh() throws DataException {
233
                // TODO Auto-generated method stub
234

    
235
        }
236

    
237
        /* (non-Javadoc)
238
         * @see org.gvsig.fmap.dal.DataStore#setSelection(org.gvsig.fmap.dal.DataSet)
239
         */
240
        public void setSelection(DataSet selection) throws DataException {
241
                // TODO Auto-generated method stub
242

    
243
        }
244

    
245
        /* (non-Javadoc)
246
         * @see org.gvsig.tools.observer.ComplexObservable#beginComplexNotification()
247
         */
248
        public void beginComplexNotification() {
249
                // TODO Auto-generated method stub
250

    
251
        }
252

    
253
        /* (non-Javadoc)
254
         * @see org.gvsig.tools.observer.ComplexObservable#disableNotifications()
255
         */
256
        public void disableNotifications() {
257
                // TODO Auto-generated method stub
258

    
259
        }
260

    
261
        /* (non-Javadoc)
262
         * @see org.gvsig.tools.observer.ComplexObservable#enableNotifications()
263
         */
264
        public void enableNotifications() {
265
                // TODO Auto-generated method stub
266

    
267
        }
268

    
269
        /* (non-Javadoc)
270
         * @see org.gvsig.tools.observer.ComplexObservable#endComplexNotification()
271
         */
272
        public void endComplexNotification() {
273
                // TODO Auto-generated method stub
274

    
275
        }
276

    
277
        /* (non-Javadoc)
278
         * @see org.gvsig.tools.observer.Observable#addObserver(org.gvsig.tools.observer.Observer)
279
         */
280
        public void addObserver(Observer o) {
281
                // TODO Auto-generated method stub
282

    
283
        }
284

    
285
        /* (non-Javadoc)
286
         * @see org.gvsig.tools.observer.Observable#deleteObserver(org.gvsig.tools.observer.Observer)
287
         */
288
        public void deleteObserver(Observer o) {
289
                // TODO Auto-generated method stub
290

    
291
        }
292

    
293
        /* (non-Javadoc)
294
         * @see org.gvsig.tools.observer.Observable#deleteObservers()
295
         */
296
        public void deleteObservers() {
297
                // TODO Auto-generated method stub
298

    
299
        }
300

    
301
        /* (non-Javadoc)
302
         * @see org.gvsig.tools.persistence.Persistent#getState()
303
         */
304
        public PersistentState getState() throws PersistenceException {
305
                // TODO Auto-generated method stub
306
                return null;
307
        }
308

    
309
        /* (non-Javadoc)
310
         * @see org.gvsig.tools.persistence.Persistent#loadState(org.gvsig.tools.persistence.PersistentState)
311
         */
312
        public void saveToState(PersistentState state) throws PersistenceException {
313
                // TODO Auto-generated method stub
314

    
315
        }
316

    
317
        /* (non-Javadoc)
318
         * @see org.gvsig.tools.persistence.Persistent#setState(org.gvsig.tools.persistence.PersistentState)
319
         */
320
        public void loadFromState(PersistentState state) throws PersistenceException {
321
                // TODO Auto-generated method stub
322

    
323
        }
324

    
325
        //
326
        // ====================================================================
327
        // Metadata related methods
328
        //
329

    
330
        public Object getMetadataID() {
331
                return this.provider.getSourceId();
332
        }
333

    
334
        public void delegate(DynObject dynObject) {
335
                this.dynObject.delegate(dynObject);
336
        }
337

    
338
        public DynClass getDynClass() {
339
                return this.dynObject.getDynClass();
340
        }
341

    
342
        public Object getDynValue(String name) throws DynFieldNotFoundException {
343
                return this.dynObject.getDynValue(name);
344
        }
345

    
346
        public boolean hasDynValue(String name) {
347
                return this.dynObject.hasDynValue(name);
348
        }
349

    
350
        public void implement(DynClass dynClass) {
351
                this.dynObject.implement(dynClass);
352
        }
353

    
354
        public Object invokeDynMethod(String name, DynObject context)
355
                        throws DynMethodException {
356
                return this.dynObject.invokeDynMethod(this, name, context);
357
        }
358

    
359
        public Object invokeDynMethod(int code, DynObject context)
360
                        throws DynMethodException {
361
                return this.dynObject.invokeDynMethod(this, code, context);
362
        }
363

    
364
        public void setDynValue(String name, Object value)
365
                        throws DynFieldNotFoundException {
366
                this.dynObject.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.getName();
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 DefaultDataManager 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
}