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 @ 43246
History | View | Annotate | Download (6.27 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 |
package org.gvsig.fmap.dal.raster.spi; |
25 |
|
26 |
import org.gvsig.fmap.dal.DALLocator; |
27 |
import org.gvsig.fmap.dal.DataServerExplorer; |
28 |
import org.gvsig.fmap.dal.DataStoreParameters; |
29 |
import org.gvsig.fmap.dal.exception.CloseException; |
30 |
import org.gvsig.fmap.dal.exception.DataException; |
31 |
import org.gvsig.fmap.dal.exception.InitializeException; |
32 |
import org.gvsig.fmap.dal.exception.OpenException; |
33 |
import org.gvsig.fmap.dal.exception.ReadException; |
34 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
35 |
import org.gvsig.fmap.dal.raster.CoverageSelection; |
36 |
import org.gvsig.fmap.dal.resource.spi.ResourceManagerProviderServices; |
37 |
import org.gvsig.fmap.dal.resource.spi.ResourceProvider; |
38 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
39 |
import org.gvsig.fmap.geom.primitive.Envelope; |
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.DynObject_v2; |
45 |
import org.gvsig.tools.dynobject.exception.DynFieldNotFoundException; |
46 |
import org.gvsig.tools.dynobject.exception.DynMethodException; |
47 |
import org.gvsig.tools.exception.BaseException; |
48 |
|
49 |
|
50 |
/**
|
51 |
* @author jmvivo
|
52 |
*
|
53 |
*/
|
54 |
public abstract class AbstractCoverageStoreProvider extends AbstractDisposable |
55 |
implements CoverageStoreProvider {
|
56 |
protected CoverageStoreProviderServices store;
|
57 |
protected DelegatedDynObject metadata;
|
58 |
protected DataStoreParameters parameters;
|
59 |
|
60 |
|
61 |
protected AbstractCoverageStoreProvider(DataStoreParameters params,
|
62 |
DataStoreProviderServices storeServices, DynObject metadata) { |
63 |
init(params, storeServices, metadata); |
64 |
} |
65 |
|
66 |
protected AbstractCoverageStoreProvider(DataStoreParameters params,
|
67 |
DataStoreProviderServices storeServices) { |
68 |
init(params, storeServices, null);
|
69 |
} |
70 |
|
71 |
protected AbstractCoverageStoreProvider() {
|
72 |
} |
73 |
|
74 |
protected void init(DataStoreParameters params, |
75 |
DataStoreProviderServices storeServices, DynObject metadata) { |
76 |
this.store = (CoverageStoreProviderServices) storeServices;
|
77 |
this.metadata = (DelegatedDynObject) metadata;
|
78 |
this.parameters = params;
|
79 |
} |
80 |
|
81 |
/**
|
82 |
* Gets the DataStoreParameters
|
83 |
* @return DataStoreParameters
|
84 |
*/
|
85 |
public DataStoreParameters getDataStoreParameters() {
|
86 |
return parameters;
|
87 |
} |
88 |
|
89 |
/**
|
90 |
* Set metada container if this not set at construction time and only in one
|
91 |
* time. In other case an Exception will be throw
|
92 |
*
|
93 |
* @param metadata
|
94 |
*/
|
95 |
protected void setMetadata(DynObject metadata) { |
96 |
if (this.metadata != null) { |
97 |
// FIXME Exception
|
98 |
throw new IllegalStateException(); |
99 |
} |
100 |
this.metadata = (DelegatedDynObject) metadata;
|
101 |
} |
102 |
|
103 |
protected ResourceProvider createResource(String type, Object[] params) |
104 |
throws InitializeException {
|
105 |
ResourceManagerProviderServices manager = (ResourceManagerProviderServices) DALLocator |
106 |
.getResourceManager(); |
107 |
ResourceProvider resource = manager.createAddResource(type, params); |
108 |
return resource;
|
109 |
} |
110 |
|
111 |
public CoverageStoreProviderServices getStoreServices() {
|
112 |
return this.store; |
113 |
} |
114 |
|
115 |
public String getClassName() { |
116 |
return this.getClass().getName(); |
117 |
} |
118 |
|
119 |
public boolean allowWrite() { |
120 |
return false; |
121 |
} |
122 |
|
123 |
public CoverageSelection createCoverageSelection() throws DataException { |
124 |
return this.store.createDefaultCoverageSelection(); |
125 |
} |
126 |
|
127 |
public void refresh() throws OpenException { |
128 |
// Do nothing by default
|
129 |
} |
130 |
|
131 |
public void close() throws CloseException { |
132 |
// Do nothing by default
|
133 |
} |
134 |
|
135 |
protected void doDispose() throws BaseException { |
136 |
this.metadata = null; |
137 |
this.store = null; |
138 |
this.parameters = null; |
139 |
} |
140 |
|
141 |
public Envelope getEnvelope() throws DataException { |
142 |
return null; |
143 |
} |
144 |
|
145 |
public abstract DataServerExplorer getExplorer() throws ReadException, |
146 |
ValidateDataParametersException; |
147 |
|
148 |
public void delegate(DynObject dynObject) { |
149 |
if (this.metadata == null) { |
150 |
return;
|
151 |
} |
152 |
this.metadata.delegate(dynObject);
|
153 |
} |
154 |
|
155 |
public DynClass getDynClass() {
|
156 |
if (this.metadata == null) { |
157 |
return null; |
158 |
} |
159 |
return this.metadata.getDynClass(); |
160 |
} |
161 |
|
162 |
public Object getDynValue(String name) throws DynFieldNotFoundException { |
163 |
if (this.metadata == null) { |
164 |
return null; |
165 |
} |
166 |
// TODO this.open??
|
167 |
return this.metadata.getDynValue(name); |
168 |
} |
169 |
|
170 |
public boolean hasDynValue(String name) { |
171 |
if (this.metadata == null) { |
172 |
return false; |
173 |
} |
174 |
// TODO this.open??
|
175 |
return this.metadata.hasDynValue(name); |
176 |
} |
177 |
|
178 |
@Override
|
179 |
public boolean hasDynMethod(String name) { |
180 |
if( metadata instanceof DynObject_v2 ) { |
181 |
return ((DynObject_v2)this.metadata).hasDynMethod(name); |
182 |
} |
183 |
return false; |
184 |
} |
185 |
|
186 |
public void implement(DynClass dynClass) { |
187 |
if (this.metadata == null) { |
188 |
return;
|
189 |
} |
190 |
this.metadata.implement(dynClass);
|
191 |
|
192 |
} |
193 |
|
194 |
public Object invokeDynMethod(int code, Object[] args) |
195 |
throws DynMethodException {
|
196 |
if (this.metadata == null) { |
197 |
return null; |
198 |
} |
199 |
// TODO this.open??
|
200 |
return this.metadata.invokeDynMethod(this, code, args); |
201 |
} |
202 |
|
203 |
public Object invokeDynMethod(String name, Object[] args) |
204 |
throws DynMethodException {
|
205 |
if (this.metadata == null) { |
206 |
return null; |
207 |
} |
208 |
// TODO this.open??
|
209 |
return this.metadata.invokeDynMethod(this, name, args); |
210 |
} |
211 |
|
212 |
public void setDynValue(String name, Object value) |
213 |
throws DynFieldNotFoundException {
|
214 |
if (this.metadata == null) { |
215 |
return;
|
216 |
} |
217 |
// TODO this.open??
|
218 |
this.metadata.setDynValue(name, value);
|
219 |
} |
220 |
|
221 |
public void clear() { |
222 |
if (metadata != null) { |
223 |
metadata.clear(); |
224 |
} |
225 |
} |
226 |
} |