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 / AbstractRasterStoreProvider.java @ 44831
History | View | Annotate | Download (10.1 KB)
1 |
/* gvSIG. Desktop Geographic Information System.
|
---|---|
2 |
*
|
3 |
* Copyright ? 2007-2016 gvSIG Association
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
18 |
* MA 02110-1301, USA.
|
19 |
*
|
20 |
* For any additional information, do not hesitate to contact us
|
21 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
22 |
*/
|
23 |
package org.gvsig.fmap.dal.raster.spi; |
24 |
|
25 |
import java.awt.Image; |
26 |
import java.util.ArrayList; |
27 |
import java.util.Collection; |
28 |
import java.util.Iterator; |
29 |
import java.util.List; |
30 |
|
31 |
import org.slf4j.Logger; |
32 |
import org.slf4j.LoggerFactory; |
33 |
|
34 |
import org.gvsig.fmap.dal.DALLocator; |
35 |
import org.gvsig.fmap.dal.DataStoreParameters; |
36 |
import org.gvsig.fmap.dal.exception.CloseException; |
37 |
import org.gvsig.fmap.dal.exception.InitializeException; |
38 |
import org.gvsig.fmap.dal.exception.OpenException; |
39 |
import org.gvsig.fmap.dal.raster.BandAttributeDescriptor; |
40 |
import org.gvsig.fmap.dal.raster.BandDescriptor; |
41 |
import org.gvsig.fmap.dal.raster.BandQuery; |
42 |
import org.gvsig.fmap.dal.raster.RasterQuery; |
43 |
import org.gvsig.fmap.dal.resource.ResourceManager; |
44 |
import org.gvsig.fmap.dal.resource.spi.ResourceManagerProviderServices; |
45 |
import org.gvsig.fmap.dal.resource.spi.ResourceProvider; |
46 |
import org.gvsig.fmap.dal.spi.AbstractDataStoreProvider; |
47 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
48 |
import org.gvsig.raster.lib.buffer.api.BufferDimensions; |
49 |
import org.gvsig.raster.lib.buffer.api.NoData; |
50 |
import org.gvsig.raster.lib.buffer.api.TileStruct; |
51 |
import org.gvsig.timesupport.Interval; |
52 |
import org.gvsig.tools.dispose.Disposable; |
53 |
import org.gvsig.tools.dispose.DisposeUtils; |
54 |
import org.gvsig.tools.dispose.impl.AbstractDisposable; |
55 |
import org.gvsig.tools.dynobject.DelegatedDynObject; |
56 |
import org.gvsig.tools.dynobject.DynClass; |
57 |
import org.gvsig.tools.dynobject.DynObject; |
58 |
import org.gvsig.tools.dynobject.DynObject_v2; |
59 |
import org.gvsig.tools.dynobject.exception.DynFieldNotFoundException; |
60 |
import org.gvsig.tools.dynobject.exception.DynMethodException; |
61 |
import org.gvsig.tools.exception.BaseException; |
62 |
|
63 |
/**
|
64 |
* Class to be extended by the providers to be implemented
|
65 |
* @author dmartinezizquierdo
|
66 |
*
|
67 |
*/
|
68 |
public abstract class AbstractRasterStoreProvider |
69 |
extends AbstractDataStoreProvider
|
70 |
implements RasterStoreProvider
|
71 |
{ |
72 |
|
73 |
protected static final Logger LOG = |
74 |
LoggerFactory.getLogger(AbstractRasterStoreProvider.class); |
75 |
|
76 |
private RasterStoreProviderServices store;
|
77 |
private DelegatedDynObject metadata;
|
78 |
private DataStoreParameters parameters;
|
79 |
private ArrayList<BandDescriptor> bandDescriptors; |
80 |
protected BufferDimensions dimensions;
|
81 |
|
82 |
protected AbstractRasterStoreProvider(DataStoreParameters params,
|
83 |
DataStoreProviderServices storeServices, DynObject metadata) { |
84 |
this.store=(RasterStoreProviderServices)storeServices;
|
85 |
this.metadata=(DelegatedDynObject)metadata;
|
86 |
this.parameters=params;
|
87 |
} |
88 |
|
89 |
/**
|
90 |
* @return the parameters
|
91 |
*/
|
92 |
public DataStoreParameters getParameters() {
|
93 |
return parameters;
|
94 |
} |
95 |
|
96 |
/**
|
97 |
* Create or get a resource of <code>type</code> for <code>params</code> in
|
98 |
* {@link ResourceManager}
|
99 |
*
|
100 |
* @param type
|
101 |
* @param params
|
102 |
* @return
|
103 |
* @throws InitializeException
|
104 |
*/
|
105 |
protected ResourceProvider createResource(String type, Object[] params) |
106 |
throws InitializeException {
|
107 |
ResourceManagerProviderServices manager = (ResourceManagerProviderServices) DALLocator |
108 |
.getResourceManager(); |
109 |
ResourceProvider resource = manager.createAddResource(type, params); |
110 |
return resource;
|
111 |
} |
112 |
|
113 |
/**
|
114 |
* unsupported by default (return null), override this otherwise
|
115 |
*
|
116 |
* @see org.gvsig.fmap.dal.spi.DataStoreProvider#getChilds()
|
117 |
*/
|
118 |
public Iterator<?> getChilds() { |
119 |
return null; |
120 |
} |
121 |
|
122 |
/**
|
123 |
* (non-Javadoc)
|
124 |
* @return RasterStoreProviderServices
|
125 |
*
|
126 |
* @see
|
127 |
* org.gvsig.fmap.dal.feature.spi.RasterStoreProvider#getStoreServices()
|
128 |
*/
|
129 |
public RasterStoreProviderServices getStoreServices() {
|
130 |
return this.store; |
131 |
} |
132 |
|
133 |
/**
|
134 |
* do nothing by default, override this otherwise
|
135 |
*
|
136 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider#close()
|
137 |
*/
|
138 |
public void close() throws CloseException { |
139 |
// Do nothing by default
|
140 |
} |
141 |
|
142 |
/**
|
143 |
* do nothing by default, override this otherwise
|
144 |
*
|
145 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider#refresh()
|
146 |
*/
|
147 |
public void refresh() throws OpenException { |
148 |
// Do nothing by default
|
149 |
} |
150 |
|
151 |
public Interval getInterval() {
|
152 |
// Do nothing
|
153 |
return null; |
154 |
} |
155 |
|
156 |
public Collection<?> getTimes() { |
157 |
// Do nothing
|
158 |
return null; |
159 |
} |
160 |
|
161 |
public Collection<?> getTimes(Interval interval) { |
162 |
// Do nothing
|
163 |
return null; |
164 |
} |
165 |
|
166 |
// --- Metadata methods ---
|
167 |
|
168 |
public void delegate(DynObject dynObject) { |
169 |
if (this.metadata == null) { |
170 |
return;
|
171 |
} |
172 |
this.metadata.delegate(dynObject);
|
173 |
} |
174 |
|
175 |
public DynClass getDynClass() {
|
176 |
if (this.metadata == null) { |
177 |
return null; |
178 |
} |
179 |
return this.metadata.getDynClass(); |
180 |
} |
181 |
|
182 |
public void implement(DynClass dynClass) { |
183 |
if (this.metadata == null) { |
184 |
return;
|
185 |
} |
186 |
this.metadata.implement(dynClass);
|
187 |
} |
188 |
|
189 |
public Object getDynValue(String name) throws DynFieldNotFoundException { |
190 |
if (this.metadata == null) { |
191 |
return null; |
192 |
} |
193 |
// TODO this.open??
|
194 |
return this.metadata.getDynValue(name); |
195 |
} |
196 |
|
197 |
public void setDynValue(String name, Object value) |
198 |
throws DynFieldNotFoundException {
|
199 |
if (this.metadata == null) { |
200 |
return;
|
201 |
} |
202 |
// TODO this.open??
|
203 |
this.metadata.setDynValue(name, value);
|
204 |
} |
205 |
|
206 |
public boolean hasDynValue(String name) { |
207 |
if (this.metadata == null) { |
208 |
return false; |
209 |
} |
210 |
// TODO this.open??
|
211 |
return this.metadata.hasDynValue(name); |
212 |
} |
213 |
|
214 |
public Object invokeDynMethod(int code, Object[] args) |
215 |
throws DynMethodException {
|
216 |
if (this.metadata == null) { |
217 |
return null; |
218 |
} |
219 |
// TODO this.open??
|
220 |
return this.metadata.invokeDynMethod(this, code, args); |
221 |
} |
222 |
|
223 |
public Object invokeDynMethod(String name, Object[] args) |
224 |
throws DynMethodException {
|
225 |
if (this.metadata == null) { |
226 |
return null; |
227 |
} |
228 |
// TODO this.open??
|
229 |
return this.metadata.invokeDynMethod(this, name, args); |
230 |
} |
231 |
|
232 |
public void clear() { |
233 |
if (metadata != null) { |
234 |
metadata.clear(); |
235 |
} |
236 |
} |
237 |
|
238 |
protected void doDispose() throws BaseException { |
239 |
LOG.debug("Dispose AbstractRasterStoreProvider '"+this.getFullName()+"'"); |
240 |
|
241 |
this.metadata = null; |
242 |
this.parameters = null; |
243 |
if (bandDescriptors != null) { |
244 |
for (Iterator iterator = bandDescriptors.iterator(); iterator.hasNext();) { |
245 |
BandDescriptor bandDescriptor = (BandDescriptor) iterator.next(); |
246 |
DisposeUtils.dispose(bandDescriptor); |
247 |
iterator.remove(); |
248 |
} |
249 |
this.bandDescriptors = null; |
250 |
} |
251 |
|
252 |
} |
253 |
|
254 |
|
255 |
@Override
|
256 |
public TileStruct getTileStruct() {
|
257 |
//Subclasses should implement this method
|
258 |
throw new UnsupportedOperationException(); |
259 |
} |
260 |
|
261 |
protected void autoOpen(){ |
262 |
try {
|
263 |
open(); |
264 |
} catch (Exception e) { |
265 |
throw new RuntimeException(e); |
266 |
} |
267 |
} |
268 |
|
269 |
@Override
|
270 |
public Image getImageLegend() { |
271 |
return null; |
272 |
} |
273 |
|
274 |
/**
|
275 |
* @return
|
276 |
*/
|
277 |
public List<BandDescriptor> getBandsDescriptor() { |
278 |
if(bandDescriptors==null){ |
279 |
bandDescriptors = new ArrayList<BandDescriptor>(); |
280 |
} |
281 |
if(bandDescriptors.isEmpty()){
|
282 |
for (int i = 0; i < this.getBands(); i++) { |
283 |
bandDescriptors.add(getStoreServices().createBandDescriptor(i, |
284 |
new ArrayList<BandAttributeDescriptor>())); |
285 |
|
286 |
} |
287 |
} |
288 |
return this.bandDescriptors; |
289 |
} |
290 |
|
291 |
|
292 |
@Override
|
293 |
public BandDescriptorServices getBandDescriptor(int band) { |
294 |
if(band > this.getBands()){ |
295 |
throw new IllegalArgumentException("Invalid band"); |
296 |
} |
297 |
return (BandDescriptorServices) this.getBandsDescriptor().get(band); |
298 |
} |
299 |
|
300 |
|
301 |
public NoData getNoData(RasterQuery rasterQuery, int band){ |
302 |
List<BandQuery> bands = rasterQuery.getBands();
|
303 |
for (BandQuery bandQuery : bands) {
|
304 |
if(bandQuery.getDescriptor().getBand()==band){
|
305 |
NoData noData = bandQuery.getDescriptor().getNoData(); |
306 |
if(noData == null) { |
307 |
break;
|
308 |
} |
309 |
return noData;
|
310 |
} |
311 |
} |
312 |
return this.getBandDescriptor(band).getNoData(); |
313 |
} |
314 |
|
315 |
public NoData[] getNoDatas(){ |
316 |
NoData[] noDatas = new NoData[this.getBands()]; |
317 |
for (int i = 0; i < this.getBands(); i++) { |
318 |
noDatas[i] = this.getBandDescriptor(i).getNoData();
|
319 |
} |
320 |
return noDatas;
|
321 |
} |
322 |
|
323 |
public int[] getDataTypes(){ |
324 |
int[] dataTypes = new int[this.getBands()]; |
325 |
for (int i = 0; i < this.getBands(); i++) { |
326 |
dataTypes[i] = this.getBandDescriptor(i).getDataType();
|
327 |
} |
328 |
return dataTypes;
|
329 |
} |
330 |
|
331 |
@Override
|
332 |
public boolean isTiled() { |
333 |
return false; |
334 |
} |
335 |
|
336 |
@Override
|
337 |
public boolean hasDynMethod(String name) { |
338 |
if( metadata instanceof DynObject_v2 ) { |
339 |
return ((DynObject_v2)this.metadata).hasDynMethod(name); |
340 |
} |
341 |
return false; |
342 |
} |
343 |
|
344 |
} |