Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.spi / src / main / java / org / gvsig / fmap / dal / raster / spi / AbstractCoverageStoreProvider.java @ 40559

History | View | Annotate | Download (6.97 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
/* gvSIG. Geographic Information System of the Valencian Government
25
*
26
* Copyright (C) 2007-2008 Infrastructures and Transports Department
27
* of the Valencian Government (CIT)
28
*
29
* This program is free software; you can redistribute it and/or
30
* modify it under the terms of the GNU General Public License
31
* as published by the Free Software Foundation; either version 2
32
* of the License, or (at your option) any later version.
33
*
34
* This program is distributed in the hope that it will be useful,
35
* but WITHOUT ANY WARRANTY; without even the implied warranty of
36
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
37
* GNU General Public License for more details.
38
*
39
* You should have received a copy of the GNU General Public License
40
* along with this program; if not, write to the Free Software
41
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
42
* MA  02110-1301, USA.
43
*
44
*/
45

    
46
/*
47
* AUTHORS (In addition to CIT):
48
* 2009 IVER T.I   {{Task}}
49
*/
50

    
51
/**
52
 *
53
 */
54
package org.gvsig.fmap.dal.raster.spi;
55

    
56
import org.gvsig.fmap.dal.DALLocator;
57
import org.gvsig.fmap.dal.DataServerExplorer;
58
import org.gvsig.fmap.dal.DataStoreParameters;
59
import org.gvsig.fmap.dal.exception.CloseException;
60
import org.gvsig.fmap.dal.exception.DataException;
61
import org.gvsig.fmap.dal.exception.InitializeException;
62
import org.gvsig.fmap.dal.exception.OpenException;
63
import org.gvsig.fmap.dal.exception.ReadException;
64
import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
65
import org.gvsig.fmap.dal.raster.CoverageSelection;
66
import org.gvsig.fmap.dal.resource.spi.ResourceManagerProviderServices;
67
import org.gvsig.fmap.dal.resource.spi.ResourceProvider;
68
import org.gvsig.fmap.dal.spi.DataStoreProviderServices;
69
import org.gvsig.fmap.geom.primitive.Envelope;
70
import org.gvsig.tools.dispose.impl.AbstractDisposable;
71
import org.gvsig.tools.dynobject.DelegatedDynObject;
72
import org.gvsig.tools.dynobject.DynClass;
73
import org.gvsig.tools.dynobject.DynObject;
74
import org.gvsig.tools.dynobject.exception.DynFieldNotFoundException;
75
import org.gvsig.tools.dynobject.exception.DynMethodException;
76
import org.gvsig.tools.exception.BaseException;
77

    
78

    
79
/**
80
 * @author jmvivo
81
 *
82
 */
83
public abstract class AbstractCoverageStoreProvider extends AbstractDisposable
84
                implements CoverageStoreProvider {
85
        protected CoverageStoreProviderServices store;
86
        protected DelegatedDynObject metadata;
87
        protected DataStoreParameters parameters;
88

    
89

    
90
        protected AbstractCoverageStoreProvider(DataStoreParameters params,
91
                        DataStoreProviderServices storeServices, DynObject metadata) {
92
                init(params, storeServices, metadata);
93
        }
94

    
95
        protected AbstractCoverageStoreProvider(DataStoreParameters params,
96
                        DataStoreProviderServices storeServices) {
97
                init(params, storeServices, null);
98
        }
99
        
100
        protected AbstractCoverageStoreProvider() {
101
        }
102
        
103
        protected void init(DataStoreParameters params,
104
                        DataStoreProviderServices storeServices, DynObject metadata) {
105
                this.store = (CoverageStoreProviderServices) storeServices;
106
                this.metadata = (DelegatedDynObject) metadata;
107
                this.parameters = params;
108
        }
109
        
110
        /**
111
         * Gets the DataStoreParameters
112
         * @return DataStoreParameters
113
         */
114
        public DataStoreParameters getDataStoreParameters() {
115
                return parameters;
116
        }
117

    
118
        /**
119
         * Set metada container if this not set at construction time and only in one
120
         * time. In other case an Exception will be throw
121
         *
122
         * @param metadata
123
         */
124
        protected void setMetadata(DynObject metadata) {
125
                if (this.metadata != null) {
126
                        // FIXME Exception
127
                        throw new IllegalStateException();
128
                }
129
                this.metadata = (DelegatedDynObject) metadata;
130
        }
131

    
132
        protected ResourceProvider createResource(String type, Object[] params)
133
                        throws InitializeException {
134
                ResourceManagerProviderServices manager = (ResourceManagerProviderServices) DALLocator
135
                                .getResourceManager();
136
                ResourceProvider resource = manager.createAddResource(type, params);
137
                return resource;
138
        }
139

    
140
        public CoverageStoreProviderServices getStoreServices() {
141
                return this.store;
142
        }
143

    
144
        public String getClassName() {
145
                return this.getClass().getName();
146
        }
147

    
148
        public boolean allowWrite() {
149
                return false;
150
        }
151

    
152
        public CoverageSelection createCoverageSelection() throws DataException {
153
                return this.store.createDefaultCoverageSelection();
154
        }
155

    
156
        public void refresh() throws OpenException {
157
                // Do nothing by default
158
        }
159

    
160
        public void close() throws CloseException {
161
                // Do nothing by default
162
        }
163

    
164
        protected void doDispose() throws BaseException {
165
                this.metadata = null;
166
                this.store = null;
167
                this.parameters = null;
168
        }
169

    
170
        public Envelope getEnvelope() throws DataException {
171
                return null;
172
        }
173

    
174
        public abstract DataServerExplorer getExplorer() throws ReadException,
175
                        ValidateDataParametersException;
176

    
177
        public void delegate(DynObject dynObject) {
178
                if (this.metadata == null) {
179
                        return;
180
                }
181
                this.metadata.delegate(dynObject);
182
        }
183

    
184
        public DynClass getDynClass() {
185
                if (this.metadata == null) {
186
                        return null;
187
                }
188
                return this.metadata.getDynClass();
189
        }
190

    
191
        public Object getDynValue(String name) throws DynFieldNotFoundException {
192
                if (this.metadata == null) {
193
                        return null;
194
                }
195
                // TODO this.open??
196
                return this.metadata.getDynValue(name);
197
        }
198

    
199
        public boolean hasDynValue(String name) {
200
                if (this.metadata == null) {
201
                        return false;
202
                }
203
                // TODO this.open??
204
                return this.metadata.hasDynValue(name);
205
        }
206

    
207
        public void implement(DynClass dynClass) {
208
                if (this.metadata == null) {
209
                        return;
210
                }
211
                this.metadata.implement(dynClass);
212

    
213
        }
214

    
215
        public Object invokeDynMethod(int code, DynObject context)
216
                        throws DynMethodException {
217
                if (this.metadata == null) {
218
                        return null;
219
                }
220
                // TODO this.open??
221
                return this.metadata.invokeDynMethod(this, code, context);
222
        }
223

    
224
        public Object invokeDynMethod(String name, DynObject context)
225
                        throws DynMethodException {
226
                if (this.metadata == null) {
227
                        return null;
228
                }
229
                // TODO this.open??
230
                return this.metadata.invokeDynMethod(this, name, context);
231
        }
232

    
233
        public void setDynValue(String name, Object value)
234
                        throws DynFieldNotFoundException {
235
                if (this.metadata == null) {
236
                        return;
237
                }
238
                // TODO this.open??
239
                this.metadata.setDynValue(name, value);
240
        }
241

    
242
        public void clear() {
243
                if (metadata != null) {
244
                        metadata.clear();
245
                }
246
        }
247
}