gvsig-raster / org.gvsig.raster / branches / org.gvsig.raster.2.4 / org.gvsig.raster / org.gvsig.fmap.dal.raster / org.gvsig.fmap.dal.raster.spi / src / main / java / org / gvsig / fmap / dal / raster / spi / AbstractRasterStoreProvider.java @ 6500
History | View | Annotate | Download (6.62 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.util.Collection; |
26 |
import java.util.Iterator; |
27 |
|
28 |
import org.gvsig.fmap.dal.DALLocator; |
29 |
import org.gvsig.fmap.dal.DataStoreParameters; |
30 |
import org.gvsig.fmap.dal.exception.CloseException; |
31 |
import org.gvsig.fmap.dal.exception.InitializeException; |
32 |
import org.gvsig.fmap.dal.exception.OpenException; |
33 |
import org.gvsig.fmap.dal.resource.ResourceManager; |
34 |
import org.gvsig.fmap.dal.resource.spi.ResourceManagerProviderServices; |
35 |
import org.gvsig.fmap.dal.resource.spi.ResourceProvider; |
36 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
37 |
import org.gvsig.timesupport.Interval; |
38 |
import org.gvsig.tools.dispose.Disposable; |
39 |
import org.gvsig.tools.dispose.DisposeUtils; |
40 |
import org.gvsig.tools.dispose.impl.AbstractDisposable; |
41 |
import org.gvsig.tools.dynobject.DelegatedDynObject; |
42 |
import org.gvsig.tools.dynobject.DynClass; |
43 |
import org.gvsig.tools.dynobject.DynObject; |
44 |
import org.gvsig.tools.dynobject.exception.DynFieldNotFoundException; |
45 |
import org.gvsig.tools.dynobject.exception.DynMethodException; |
46 |
import org.gvsig.tools.exception.BaseException; |
47 |
|
48 |
/**
|
49 |
* Class to be extended by the providers to be implemented
|
50 |
* @author dmartinezizquierdo
|
51 |
*
|
52 |
*/
|
53 |
public abstract class AbstractRasterStoreProvider extends AbstractDisposable implements RasterStoreProvider{ |
54 |
|
55 |
private RasterStoreProviderServices store;
|
56 |
private DelegatedDynObject metadata;
|
57 |
private DataStoreParameters parameters;
|
58 |
|
59 |
protected AbstractRasterStoreProvider(DataStoreParameters params,
|
60 |
DataStoreProviderServices storeServices, DynObject metadata) { |
61 |
this.store=(RasterStoreProviderServices)storeServices;
|
62 |
this.metadata=(DelegatedDynObject)metadata;
|
63 |
this.parameters=params;
|
64 |
} |
65 |
|
66 |
/**
|
67 |
* @return the parameters
|
68 |
*/
|
69 |
public DataStoreParameters getParameters() {
|
70 |
return parameters;
|
71 |
} |
72 |
|
73 |
/**
|
74 |
* Create or get a resource of <code>type</code> for <code>params</code> in
|
75 |
* {@link ResourceManager}
|
76 |
*
|
77 |
* @param type
|
78 |
* @param params
|
79 |
* @return
|
80 |
* @throws InitializeException
|
81 |
*/
|
82 |
protected ResourceProvider createResource(String type, Object[] params) |
83 |
throws InitializeException {
|
84 |
ResourceManagerProviderServices manager = (ResourceManagerProviderServices) DALLocator |
85 |
.getResourceManager(); |
86 |
ResourceProvider resource = manager.createAddResource(type, params); |
87 |
return resource;
|
88 |
} |
89 |
|
90 |
/**
|
91 |
* unsupported by default (return null), override this otherwise
|
92 |
*
|
93 |
* @see org.gvsig.fmap.dal.spi.DataStoreProvider#getChilds()
|
94 |
*/
|
95 |
public Iterator<?> getChilds() { |
96 |
return null; |
97 |
} |
98 |
|
99 |
/**
|
100 |
* (non-Javadoc)
|
101 |
* @return RasterStoreProviderServices
|
102 |
*
|
103 |
* @see
|
104 |
* org.gvsig.fmap.dal.feature.spi.RasterStoreProvider#getStoreServices()
|
105 |
*/
|
106 |
public RasterStoreProviderServices getStoreServices() {
|
107 |
return this.store; |
108 |
} |
109 |
|
110 |
/**
|
111 |
* do nothing by default, override this otherwise
|
112 |
*
|
113 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider#close()
|
114 |
*/
|
115 |
public void close() throws CloseException { |
116 |
// Do nothing by default
|
117 |
} |
118 |
|
119 |
/**
|
120 |
* do nothing by default, override this otherwise
|
121 |
*
|
122 |
* @see org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider#refresh()
|
123 |
*/
|
124 |
public void refresh() throws OpenException { |
125 |
// Do nothing by default
|
126 |
} |
127 |
|
128 |
public Interval getInterval() {
|
129 |
// Do nothing
|
130 |
return null; |
131 |
} |
132 |
|
133 |
public Collection<?> getTimes() { |
134 |
// Do nothing
|
135 |
return null; |
136 |
} |
137 |
|
138 |
public Collection<?> getTimes(Interval interval) { |
139 |
// Do nothing
|
140 |
return null; |
141 |
} |
142 |
|
143 |
// --- Metadata methods ---
|
144 |
|
145 |
public void delegate(DynObject dynObject) { |
146 |
if (this.metadata == null) { |
147 |
return;
|
148 |
} |
149 |
this.metadata.delegate(dynObject);
|
150 |
} |
151 |
|
152 |
public DynClass getDynClass() {
|
153 |
if (this.metadata == null) { |
154 |
return null; |
155 |
} |
156 |
return this.metadata.getDynClass(); |
157 |
} |
158 |
|
159 |
public void implement(DynClass dynClass) { |
160 |
if (this.metadata == null) { |
161 |
return;
|
162 |
} |
163 |
this.metadata.implement(dynClass);
|
164 |
} |
165 |
|
166 |
public Object getDynValue(String name) throws DynFieldNotFoundException { |
167 |
if (this.metadata == null) { |
168 |
return null; |
169 |
} |
170 |
// TODO this.open??
|
171 |
return this.metadata.getDynValue(name); |
172 |
} |
173 |
|
174 |
public void setDynValue(String name, Object value) |
175 |
throws DynFieldNotFoundException {
|
176 |
if (this.metadata == null) { |
177 |
return;
|
178 |
} |
179 |
// TODO this.open??
|
180 |
this.metadata.setDynValue(name, value);
|
181 |
} |
182 |
|
183 |
public boolean hasDynValue(String name) { |
184 |
if (this.metadata == null) { |
185 |
return false; |
186 |
} |
187 |
// TODO this.open??
|
188 |
return this.metadata.hasDynValue(name); |
189 |
} |
190 |
|
191 |
public Object invokeDynMethod(int code, Object[] args) |
192 |
throws DynMethodException {
|
193 |
if (this.metadata == null) { |
194 |
return null; |
195 |
} |
196 |
// TODO this.open??
|
197 |
return this.metadata.invokeDynMethod(this, code, args); |
198 |
} |
199 |
|
200 |
public Object invokeDynMethod(String name, Object[] args) |
201 |
throws DynMethodException {
|
202 |
if (this.metadata == null) { |
203 |
return null; |
204 |
} |
205 |
// TODO this.open??
|
206 |
return this.metadata.invokeDynMethod(this, name, args); |
207 |
} |
208 |
|
209 |
public void clear() { |
210 |
if (metadata != null) { |
211 |
metadata.clear(); |
212 |
} |
213 |
} |
214 |
|
215 |
protected void doDispose() throws BaseException { |
216 |
if (this.store != null && this.store instanceof Disposable){ |
217 |
DisposeUtils.dispose((Disposable) this.store);
|
218 |
} |
219 |
this.store = null; |
220 |
this.metadata = null; |
221 |
this.parameters = null; |
222 |
} |
223 |
} |