gvsig-raster / org.gvsig.raster / branches / org.gvsig.raster.2.4 / org.gvsig.wcs / org.gvsig.wcs.provider / src / main / java / org / gvsig / wcs / provider / DefaultWCSRasterServerExplorer.java @ 8786
History | View | Annotate | Download (9.84 KB)
1 | 6549 | fdiaz | package org.gvsig.wcs.provider; |
---|---|---|---|
2 | /* gvSIG. Desktop Geographic Information System.
|
||
3 | *
|
||
4 | * Copyright ? 2007-2016 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 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 | * 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 | |||
25 | |||
26 | import java.io.IOException; |
||
27 | 8786 | fdiaz | import java.net.ConnectException; |
28 | 6549 | fdiaz | import java.net.URL; |
29 | import java.util.ArrayList; |
||
30 | import java.util.Collection; |
||
31 | 8786 | fdiaz | import java.util.Enumeration; |
32 | 6549 | fdiaz | import java.util.Hashtable; |
33 | import java.util.List; |
||
34 | |||
35 | import org.cresques.cts.IProjection; |
||
36 | import org.slf4j.Logger; |
||
37 | import org.slf4j.LoggerFactory; |
||
38 | |||
39 | import org.gvsig.fmap.crs.CRSFactory; |
||
40 | import org.gvsig.fmap.dal.DataServerExplorer; |
||
41 | import org.gvsig.fmap.dal.DataServerExplorerParameters; |
||
42 | import org.gvsig.fmap.dal.DataStoreParameters; |
||
43 | import org.gvsig.fmap.dal.NewDataStoreParameters; |
||
44 | import org.gvsig.fmap.dal.exception.DataException; |
||
45 | import org.gvsig.fmap.dal.exception.InitializeException; |
||
46 | import org.gvsig.fmap.dal.spi.AbstractDataServerExplorer; |
||
47 | import org.gvsig.fmap.dal.spi.DataServerExplorerProvider; |
||
48 | import org.gvsig.fmap.dal.spi.DataServerExplorerProviderServices; |
||
49 | import org.gvsig.remoteclient.wcs.WCSClient; |
||
50 | import org.gvsig.remoteclient.wcs.WCSCoverage; |
||
51 | 6666 | fdiaz | import org.gvsig.remoteclient.wcs.WCSCoverage.AxisDescription; |
52 | 8786 | fdiaz | import org.gvsig.tools.ToolsLocator; |
53 | import org.gvsig.tools.i18n.I18nManager; |
||
54 | import org.gvsig.tools.util.InformationBuilder; |
||
55 | import org.gvsig.tools.util.ToolsUtilLocator; |
||
56 | 6549 | fdiaz | |
57 | |||
58 | /**
|
||
59 | * @author fdiaz
|
||
60 | *
|
||
61 | */
|
||
62 | 8786 | fdiaz | public class DefaultWCSRasterServerExplorer extends AbstractDataServerExplorer implements DataServerExplorerProvider, WCSRasterServerExplorer { |
63 | 6549 | fdiaz | |
64 | private static final Logger logger = |
||
65 | 8786 | fdiaz | LoggerFactory.getLogger(DefaultWCSRasterServerExplorer.class); |
66 | 6549 | fdiaz | |
67 | 6666 | fdiaz | /**
|
68 | *
|
||
69 | */
|
||
70 | 6549 | fdiaz | public static String DESCRIPTION = "WCS Raster Server Explorer"; |
71 | |||
72 | private URL service = null; |
||
73 | |||
74 | //WCS Parameters
|
||
75 | // private WCSStatus status = null;
|
||
76 | private WCSClient wcsClient = null; |
||
77 | |||
78 | 8786 | fdiaz | private Boolean override; |
79 | |||
80 | protected DefaultWCSRasterServerExplorer(DataServerExplorerParameters parameters,
|
||
81 | 6549 | fdiaz | DataServerExplorerProviderServices providerServices) throws InitializeException {
|
82 | super(parameters, providerServices);
|
||
83 | // TODO Auto-generated constructor stub
|
||
84 | |||
85 | this.service = (URL)(parameters.getDynValue(WCSRasterServerExplorerParameters.WCS_SERVICE_PARAMETER_NAME)); |
||
86 | 8786 | fdiaz | this.override = (Boolean)(parameters.getDynValue(WCSRasterServerExplorerParameters.WCS_OVERRIDE_CAPABILITIES_PARAMETER_NAME)); |
87 | |||
88 | 6549 | fdiaz | if (wcsClient == null){ |
89 | try {
|
||
90 | wcsClient = new WCSClient(service.toString());
|
||
91 | 8786 | fdiaz | if (!wcsClient.connect(override, null)) { |
92 | throw new ConnectException("Error connecting"); |
||
93 | } |
||
94 | 6549 | fdiaz | // if (status == null){
|
95 | // status = new WCSStatus();
|
||
96 | // }
|
||
97 | // Rectangle2D extent = wcsClient.getExtent(
|
||
98 | // (String)parameters.getDynValue(WCSRasterProviderParameters.WCS_COVERAGENAME_PARAMETER_NAME),
|
||
99 | // (String)parameters.getDynValue(WCSRasterProviderParameters.WCS_CRS_PARAMETER_NAME));
|
||
100 | // status.setExtent(extent);
|
||
101 | //
|
||
102 | // wcsClient.getCoverage(status, null); //.getCapabilities(status, true, null);
|
||
103 | } catch (IOException e) { |
||
104 | throw new InitializeException("Not possible to connect with " + service, e); |
||
105 | } |
||
106 | } |
||
107 | } |
||
108 | |||
109 | @Override
|
||
110 | public String getProviderName() { |
||
111 | return WCSRasterProvider.NAME;
|
||
112 | } |
||
113 | |||
114 | @Override
|
||
115 | public boolean canAdd() { |
||
116 | return false; |
||
117 | } |
||
118 | |||
119 | @Override
|
||
120 | public boolean canAdd(String storeName) throws DataException { |
||
121 | return false; |
||
122 | } |
||
123 | |||
124 | @Override
|
||
125 | public List<WCSRasterProviderParameters> list() throws DataException { |
||
126 | List<WCSRasterProviderParameters> result = new ArrayList<WCSRasterProviderParameters>(); |
||
127 | @SuppressWarnings("unchecked") |
||
128 | 6666 | fdiaz | Hashtable<?, WCSCoverage> wcsCoverageList = wcsClient.getCoverageList();
|
129 | 6549 | fdiaz | |
130 | Collection<WCSCoverage> values = wcsCoverageList.values();
|
||
131 | |||
132 | 6666 | fdiaz | for (WCSCoverage wcsCoverage : values) {
|
133 | 6549 | fdiaz | |
134 | WCSRasterProviderParameters params = new WCSRasterProviderParameters();
|
||
135 | params.setService(this.service);
|
||
136 | String paramCoverage = wcsCoverage.getName();
|
||
137 | params.setCoverageName(paramCoverage); |
||
138 | |||
139 | @SuppressWarnings("unchecked") |
||
140 | 6666 | fdiaz | List<String> formats = wcsCoverage.getFormats(); |
141 | 6549 | fdiaz | if(formats!=null && formats.size()>0){ |
142 | 6666 | fdiaz | params.setFormat(formats.get(0));
|
143 | 6549 | fdiaz | } |
144 | |||
145 | @SuppressWarnings("unchecked") |
||
146 | 6666 | fdiaz | List<String> allSrs = wcsCoverage.getAllSrs(); |
147 | 6549 | fdiaz | if(allSrs!=null && allSrs.size()>0){ |
148 | 6666 | fdiaz | boolean foundValidSrs = false; |
149 | for (String srs : allSrs) { |
||
150 | 6549 | fdiaz | if(isValidSrs(srs)){
|
151 | params.setCRS(srs); |
||
152 | 6666 | fdiaz | foundValidSrs = true;
|
153 | 6549 | fdiaz | break;
|
154 | } |
||
155 | } |
||
156 | 6666 | fdiaz | |
157 | if(!foundValidSrs){
|
||
158 | 6549 | fdiaz | throw new IllegalArgumentException(this.getProviderName() |
159 | 6666 | fdiaz | + ": The server does not provide any valid srs.'");
|
160 | 6549 | fdiaz | } |
161 | } |
||
162 | result.add(params); |
||
163 | } |
||
164 | return result;
|
||
165 | } |
||
166 | |||
167 | @Override
|
||
168 | public List<WCSRasterProviderParameters> list(int mode) throws DataException { |
||
169 | if(mode!=DataServerExplorer.MODE_RASTER){
|
||
170 | return null; |
||
171 | } |
||
172 | return list();
|
||
173 | } |
||
174 | |||
175 | @Override
|
||
176 | public boolean add(String provider, NewDataStoreParameters parameters, boolean overwrite) throws DataException { |
||
177 | return false; |
||
178 | } |
||
179 | |||
180 | @Override
|
||
181 | public void remove(DataStoreParameters parameters) throws DataException { |
||
182 | throw new UnsupportedOperationException("Can't remove a WCS provider."); |
||
183 | |||
184 | } |
||
185 | |||
186 | @Override
|
||
187 | public NewDataStoreParameters getAddParameters(String storeName) throws DataException { |
||
188 | return null; |
||
189 | } |
||
190 | |||
191 | @Override
|
||
192 | public List<String> getDataStoreProviderNames() { |
||
193 | List<String> x = new ArrayList<String>(); |
||
194 | x.add(WCSRasterProvider.NAME); |
||
195 | return x;
|
||
196 | } |
||
197 | |||
198 | 8786 | fdiaz | @Override
|
199 | 6549 | fdiaz | @SuppressWarnings("unchecked") |
200 | public List<String> getFormats(){ |
||
201 | return new ArrayList<String>(wcsClient.getFormats()); |
||
202 | } |
||
203 | |||
204 | private boolean isValidSrs(String srs){ |
||
205 | try{
|
||
206 | IProjection crs=CRSFactory.getCRS(srs); |
||
207 | if(crs!=null){ |
||
208 | return true; |
||
209 | } |
||
210 | }catch(Exception e){ |
||
211 | logger.info("Can't get crs from: '"+srs+"' code", e); |
||
212 | return false; |
||
213 | } |
||
214 | return false; |
||
215 | } |
||
216 | 6666 | fdiaz | |
217 | 8786 | fdiaz | @Override
|
218 | 6666 | fdiaz | public String getDescription() { |
219 | return wcsClient.getDescription();
|
||
220 | } |
||
221 | |||
222 | 8786 | fdiaz | @Override
|
223 | 6666 | fdiaz | @SuppressWarnings("unchecked") |
224 | public List<String> getCoverageNames() { |
||
225 | return new ArrayList<String>(wcsClient.getCoverageList().keySet()); |
||
226 | } |
||
227 | |||
228 | 8786 | fdiaz | @Override
|
229 | public List<WCSCoverageData> getCoverageList() { |
||
230 | Hashtable<?, WCSCoverage> coverages = wcsClient.getCoverageList();
|
||
231 | Enumeration<WCSCoverage> elements = coverages.elements();
|
||
232 | List<WCSCoverageData> result = new ArrayList<WCSCoverageData>(coverages.size()); |
||
233 | while (elements.hasMoreElements()) {
|
||
234 | WCSCoverage coverage = (WCSCoverage) elements.nextElement(); |
||
235 | DefaultWCSCoverageData wcsCoverageData = new DefaultWCSCoverageData(coverage, wcsClient, service);
|
||
236 | result.add(wcsCoverageData); |
||
237 | } |
||
238 | return result;
|
||
239 | } |
||
240 | |||
241 | @Override
|
||
242 | 6666 | fdiaz | @SuppressWarnings("unchecked") |
243 | public List<String> getFormats(WCSRasterProviderParameters params){ |
||
244 | |||
245 | String coverageName = params.getCoverageName();
|
||
246 | return ((WCSCoverage)wcsClient.getCoverageList().get(coverageName)).getFormats();
|
||
247 | } |
||
248 | |||
249 | 8786 | fdiaz | @Override
|
250 | 6666 | fdiaz | @SuppressWarnings("unchecked") |
251 | public List<String> getBands(WCSRasterProviderParameters params){ |
||
252 | ArrayList<String> bands = new ArrayList<String>(); |
||
253 | String coverageName = params.getCoverageName();
|
||
254 | WCSCoverage wcsCoverage = ((WCSCoverage)wcsClient.getCoverageList().get(coverageName)); |
||
255 | String rangeSetName = wcsCoverage.getRangeSetName();
|
||
256 | |||
257 | if (rangeSetName!=null && !rangeSetName.isEmpty()) { |
||
258 | Hashtable<?, ?> axisPool = wcsCoverage.axisPool;
|
||
259 | AxisDescription axisDescription = (AxisDescription) axisPool.get(rangeSetName); |
||
260 | if (axisDescription != null) { |
||
261 | bands = axisDescription.getSingleValues(); |
||
262 | } |
||
263 | } |
||
264 | return bands;
|
||
265 | } |
||
266 | |||
267 | 8786 | fdiaz | @Override
|
268 | public String getInfoString() { |
||
269 | I18nManager i18nManager = ToolsLocator.getI18nManager(); |
||
270 | |||
271 | InformationBuilder builder = ToolsUtilLocator.getToolsUtilManager().createInformationBuilder(); |
||
272 | |||
273 | builder.title().labelkey(i18nManager.getTranslation("_service_information"));
|
||
274 | |||
275 | builder.property().labelkey("_server").value(service.toString());
|
||
276 | |||
277 | builder.property().labelkey("_server_title").value(wcsClient.getServiceTitle());
|
||
278 | builder.property().labelkey("_server_type").value("WCS "+ wcsClient.getVersion()); |
||
279 | builder.property().labelkey("_server_description").value(wcsClient.getDescription());
|
||
280 | |||
281 | return builder.toString();
|
||
282 | } |
||
283 | |||
284 | 6549 | fdiaz | } |