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