Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libFMap_dal / src / org / gvsig / fmap / dal / feature / spi / AbstractFeatureStoreProvider.java @ 29391

History | View | Annotate | Download (10.8 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
 * 2008 {{Company}}   {{Task}}
26
 */
27

    
28
package org.gvsig.fmap.dal.feature.spi;
29

    
30
import java.util.Iterator;
31

    
32
import org.gvsig.fmap.dal.DALLocator;
33
import org.gvsig.fmap.dal.DataServerExplorer;
34
import org.gvsig.fmap.dal.DataStoreParameters;
35
import org.gvsig.fmap.dal.exception.CloseException;
36
import org.gvsig.fmap.dal.exception.DataException;
37
import org.gvsig.fmap.dal.exception.InitializeException;
38
import org.gvsig.fmap.dal.exception.OpenException;
39
import org.gvsig.fmap.dal.exception.ReadException;
40
import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
41
import org.gvsig.fmap.dal.feature.FeatureLocks;
42
import org.gvsig.fmap.dal.feature.FeatureSelection;
43
import org.gvsig.fmap.dal.feature.FeatureStore;
44
import org.gvsig.fmap.dal.feature.FeatureType;
45
import org.gvsig.fmap.dal.resource.ResourceManager;
46
import org.gvsig.fmap.dal.resource.spi.ResourceManagerProviderServices;
47
import org.gvsig.fmap.dal.resource.spi.ResourceProvider;
48
import org.gvsig.fmap.dal.spi.DataStoreProviderServices;
49
import org.gvsig.fmap.geom.primitive.Envelope;
50
import org.gvsig.tools.dynobject.DelegatedDynObject;
51
import org.gvsig.tools.dynobject.DynClass;
52
import org.gvsig.tools.dynobject.DynObject;
53
import org.gvsig.tools.dynobject.exception.DynFieldNotFoundException;
54
import org.gvsig.tools.dynobject.exception.DynMethodException;
55

    
56
/**
57
 * Abstract implementation of {@link FeatureStoreProvider}
58
 *
59
 */
60
public abstract class AbstractFeatureStoreProvider implements
61
                FeatureStoreProvider {
62

    
63
        private FeatureStoreProviderServices store;
64
        private DelegatedDynObject metadata;
65
        private DataStoreParameters parameters;
66

    
67
        /**
68
         * Default Constructor.
69
         *
70
         * @param params
71
         * @param storeServices
72
         * @param metadata
73
         */
74
        protected AbstractFeatureStoreProvider(DataStoreParameters params,
75
                        DataStoreProviderServices storeServices, DynObject metadata) {
76
                this.store = (FeatureStoreProviderServices) storeServices;
77
                this.metadata = (DelegatedDynObject) metadata;
78
                this.parameters = params;
79
        }
80

    
81
        /**
82
         * Constructor when cannot create metada in constrution time. <br>
83
         * <br>
84
         * <strong>Note: </strong> Don't use it if not is necesary. Set metada
85
         * <strong>as soon as posible</strong> by
86
         * {@link AbstractFeatureStoreProvider#setMetadata(DynObject)}
87
         *
88
         * @param params
89
         * @param storeServices
90
         */
91
        protected AbstractFeatureStoreProvider(DataStoreParameters params,
92
                        DataStoreProviderServices storeServices) {
93
                this.store = (FeatureStoreProviderServices) storeServices;
94
                this.metadata = null;
95
                this.parameters = params;
96
        }
97

    
98
        /**
99
         * Set metada container if this not set at construction time and only in one
100
         * time. In other case an Exception will be throw
101
         *
102
         * @param metadata
103
         */
104
        protected void setMetadata(DynObject metadata) {
105
                if (this.metadata != null) {
106
                        // FIXME Exception
107
                        throw new IllegalStateException();
108
                }
109
                this.metadata = (DelegatedDynObject) metadata;
110
        }
111

    
112
        /**
113
         * @return the parameters
114
         */
115
        public DataStoreParameters getParameters() {
116
                return parameters;
117
        }
118

    
119
        /**
120
         * Create or get a resource of <code>type</code> for <code>params</code> in
121
         * {@link ResourceManager}
122
         *
123
         * @param type
124
         * @param params
125
         * @return
126
         * @throws InitializeException
127
         */
128
        protected ResourceProvider createResource(String type, Object[] params)
129
                        throws InitializeException {
130
                ResourceManagerProviderServices manager = (ResourceManagerProviderServices) DALLocator
131
                                .getResourceManager();
132
                ResourceProvider resource = manager.createResource(type, params);
133
                return resource;
134
        }
135

    
136
        /*
137
         * (non-Javadoc)
138
         *
139
         * @see
140
         * org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider#getStoreServices()
141
         */
142
        public FeatureStoreProviderServices getStoreServices() {
143
                return this.store;
144
        }
145

    
146
        public FeatureStore getFeatureStore() {
147
                return this.store.getFeatureStore();
148
        }
149

    
150
        /**
151
         * unsupported by default, override this otherwise
152
         *
153
         * @see org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider#allowWrite()
154
         */
155
        public boolean allowWrite() {
156
                return false;
157
        }
158

    
159

    
160
        /**
161
         * unsupported by default, override this otherwise
162
         *
163
         * @see org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider#performChanges(Iterator,
164
         *      Iterator, Iterator, Iterator)
165
         */
166

    
167
        public void performChanges(Iterator deleteds, Iterator inserteds,
168
                        Iterator updateds, Iterator featureTypesChanged)
169
                        throws DataException {
170
                // FIXME exception
171
                throw new UnsupportedOperationException();
172

    
173
        }
174

    
175
        /**
176
         * unsupported by default, override this otherwise
177
         *
178
         * @see org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider#isLocksSupported()
179
         */
180
        public boolean isLocksSupported() {
181
                return false;
182
        }
183

    
184
        /**
185
         * Default Factory of {@link FeatureProvider}. Create a new default
186
         * {@link FeatureProvider} instance.<br>
187
         *
188
         * Override this if you need an special implemtation of
189
         * {@link FeatureProvider}.
190
         *
191
         * @return
192
         * @throws DataException
193
         *
194
         * @see {@link org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider#createFeatureProvider(FeatureType)}
195
         */
196

    
197
        public FeatureProvider createFeatureProvider(FeatureType type)
198
                        throws DataException {
199
                return this.store.createDefaultFeatureProvider(type);
200
        }
201

    
202
        /**
203
         * unsupported by default (return <code>null</code>), override this
204
         * otherwise
205
         *
206
         * @see org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider#createFeatureLocks()
207
         */
208
        public FeatureLocks createFeatureLocks() throws DataException {
209
                return null;
210
        }
211

    
212
        /**
213
         * Default Factory of {@link FeatureSelection}. Create a new default
214
         * {@link FeatureSelection} instance.<br>
215
         *
216
         * Override this if you need an special implemtation of
217
         * {@link FeatureSelection}.
218
         *
219
         * @return
220
         * @throws DataException
221
         *
222
         * @see org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider#createFeatureSelection()
223
         */
224
        public FeatureSelection createFeatureSelection() throws DataException {
225
                return this.store.createDefaultFeatureSelection();
226
        }
227

    
228
        /**
229
         * do nothing by default, override this otherwise
230
         *
231
         * @see org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider#refresh()
232
         */
233
        public void refresh() throws OpenException {
234
                // Do nothing by default
235
        }
236

    
237
        /**
238
         * do nothing by default, override this otherwise
239
         *
240
         * @see org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider#close()
241
         */
242
        public void close() throws CloseException {
243
                // Do nothing by default
244
        }
245

    
246
        public void dispose() throws CloseException {
247
                this.metadata = null;
248
                this.store = null;
249
        }
250

    
251
        /**
252
         * unsupported geometry by default (return <code>null</code>), override this
253
         * otherwise
254
         *
255
         * @see org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider#getEnvelope()
256
         */
257
        public Envelope getEnvelope() throws DataException {
258
                return null;
259
        }
260

    
261
        /**
262
         * unsupported geometry write by default (return <code>false</code>),
263
         * override this otherwise
264
         *
265
         * @see org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider#canWriteGeometry(int,
266
         *      int)
267
         */
268
        public boolean canWriteGeometry(int geometryType, int geometrySubType)
269
                        throws DataException {
270
                return false;
271
        }
272

    
273
        // --- Metadata methods ---
274

    
275

    
276
        public void delegate(DynObject dynObject) {
277
                if (this.metadata == null) {
278
                        return;
279
                }
280
                this.metadata.delegate(dynObject);
281
        }
282

    
283
        public DynClass getDynClass() {
284
                if (this.metadata == null) {
285
                        return null;
286
                }
287
                return this.metadata.getDynClass();
288
        }
289

    
290
        public Object getDynValue(String name) throws DynFieldNotFoundException {
291
                if (this.metadata == null) {
292
                        return null;
293
                }
294
                // TODO this.open??
295
                return this.metadata.getDynValue(name);
296
        }
297

    
298
        public boolean hasDynValue(String name) {
299
                if (this.metadata == null) {
300
                        return false;
301
                }
302
                // TODO this.open??
303
                return this.metadata.hasDynValue(name);
304
        }
305

    
306
        public void implement(DynClass dynClass) {
307
                if (this.metadata == null) {
308
                        return;
309
                }
310
                this.metadata.implement(dynClass);
311

    
312
        }
313

    
314
        public Object invokeDynMethod(int code, DynObject context)
315
                        throws DynMethodException {
316
                if (this.metadata == null) {
317
                        return null;
318
                }
319
                // TODO this.open??
320
                return this.metadata.invokeDynMethod(this, code, context);
321
        }
322

    
323
        public Object invokeDynMethod(String name, DynObject context)
324
                        throws DynMethodException {
325
                if (this.metadata == null) {
326
                        return null;
327
                }
328
                // TODO this.open??
329
                return this.metadata.invokeDynMethod(this, name, context);
330
        }
331

    
332
        public void setDynValue(String name, Object value)
333
                        throws DynFieldNotFoundException {
334
                if (this.metadata == null) {
335
                        return;
336
                }
337
                // TODO this.open??
338
                this.metadata.setDynValue(name, value);
339
        }
340

    
341
        // --- end Metadata methods ---
342

    
343
        /**
344
         * unsupported by default, override this otherwise
345
         *
346
         * @see org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider#allowAutomaticValues()
347
         */
348
        public boolean allowAutomaticValues() {
349
                return false;
350

    
351
        }
352

    
353
        /**
354
         * unsupported by default, override this otherwise
355
         *
356
         * @see org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider#append(org.gvsig.
357
         *      fmap.dal.feature.spi.FeatureProvider)
358
         */
359
        public void append(FeatureProvider featureProvider) throws DataException {
360
                // FIXME exception
361
                throw new UnsupportedOperationException();
362
        }
363

    
364
        /**
365
         * unsupported by default, override this otherwise
366
         *
367
         * @see org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider#beginAppend()
368
         */
369
        public void beginAppend() throws DataException {
370
                // FIXME exception
371
                throw new UnsupportedOperationException();
372
        }
373

    
374
        /**
375
         * unsupported by default, override this otherwise
376
         *
377
         * @see org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider#endAppend()
378
         */
379
        public void endAppend() throws DataException {
380
                // FIXME exception
381
                throw new UnsupportedOperationException();
382
        }
383

    
384
        /**
385
         * unsupported by default, override this otherwise
386
         *
387
         * @see org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider#supportsAppendMode()
388
         */
389
        public boolean supportsAppendMode() {
390
                return false;
391
        }
392

    
393
        /**
394
         * unsupported by default (return null), override this otherwise
395
         *
396
         * @see org.gvsig.fmap.dal.spi.DataStoreProvider#getChilds()
397
         */
398
        public Iterator getChilds() {
399
                return null;
400
        }
401

    
402
        /**
403
         * unsupported by default (return null), override this otherwise
404
         *
405
         * @see org.gvsig.fmap.dal.spi.DataStoreProvider#getExplorer()
406
         */
407
        public DataServerExplorer getExplorer() throws ReadException,
408
                        ValidateDataParametersException {
409
                return null;
410
        }
411

    
412

    
413
}