gvsig-raster / org.gvsig.raster.wmts / trunk / org.gvsig.raster.wmts / org.gvsig.raster.wmts.io / src / main / java / org / gvsig / raster / wmts / io / WMTSServerExplorer.java @ 9641
History | View | Annotate | Download (6.69 KB)
1 |
/* 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 |
package org.gvsig.raster.wmts.io; |
29 |
|
30 |
import java.io.IOException; |
31 |
import java.io.InputStream; |
32 |
import java.net.MalformedURLException; |
33 |
import java.net.URI; |
34 |
import java.net.URISyntaxException; |
35 |
import java.net.URL; |
36 |
import java.net.URLConnection; |
37 |
import java.util.List; |
38 |
|
39 |
import org.slf4j.Logger; |
40 |
import org.slf4j.LoggerFactory; |
41 |
|
42 |
import org.gvsig.compat.net.ICancellable; |
43 |
import org.gvsig.fmap.dal.DALLocator; |
44 |
import org.gvsig.fmap.dal.DataManager; |
45 |
import org.gvsig.fmap.dal.DataServerExplorerParameters; |
46 |
import org.gvsig.fmap.dal.DataStoreParameters; |
47 |
import org.gvsig.fmap.dal.NewDataStoreParameters; |
48 |
import org.gvsig.fmap.dal.coverage.exception.ConnectException; |
49 |
import org.gvsig.fmap.dal.coverage.store.RasterDataServerExplorer; |
50 |
import org.gvsig.fmap.dal.coverage.store.parameter.TileDataParameters; |
51 |
import org.gvsig.fmap.dal.exception.DataException; |
52 |
import org.gvsig.fmap.dal.exception.InitializeException; |
53 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
54 |
import org.gvsig.fmap.dal.spi.AbstractDataServerExplorer; |
55 |
import org.gvsig.fmap.dal.spi.DataServerExplorerProvider; |
56 |
import org.gvsig.fmap.dal.spi.DataServerExplorerProviderServices; |
57 |
import org.gvsig.raster.wmts.ogc.WMTSClient; |
58 |
import org.gvsig.raster.wmts.ogc.WMTSOGCLocator; |
59 |
|
60 |
/**
|
61 |
* Explorer for a WMTS server
|
62 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
63 |
*/
|
64 |
public class WMTSServerExplorer extends AbstractDataServerExplorer implements RasterDataServerExplorer, DataServerExplorerProvider { |
65 |
public static final String NAME = WMTSProvider.NAME; |
66 |
private WMTSClient ogcClient = null; |
67 |
// private WMTSServerExplorerParameters parameters = null;
|
68 |
private static final Logger logger = LoggerFactory.getLogger(WMTSServerExplorer.class); |
69 |
|
70 |
public WMTSServerExplorer(
|
71 |
WMTSServerExplorerParameters parameters, |
72 |
DataServerExplorerProviderServices services) |
73 |
throws InitializeException {
|
74 |
super(parameters, services);
|
75 |
// this.parameters = parameters;
|
76 |
} |
77 |
|
78 |
public String getDataStoreProviderName() { |
79 |
return WMTSProvider.NAME;
|
80 |
} |
81 |
|
82 |
public String getDescription() { |
83 |
return WMTSProvider.DESCRIPTION;
|
84 |
} |
85 |
|
86 |
public boolean add(String provider, NewDataStoreParameters parameters, |
87 |
boolean overwrite) throws DataException { |
88 |
return false; |
89 |
} |
90 |
|
91 |
public boolean canAdd() { |
92 |
return false; |
93 |
} |
94 |
|
95 |
public boolean canAdd(String storeName) throws DataException { |
96 |
return false; |
97 |
} |
98 |
|
99 |
public NewDataStoreParameters getAddParameters(String storeName) |
100 |
throws DataException {
|
101 |
return null; |
102 |
} |
103 |
|
104 |
public List<String> getDataStoreProviderNames() { |
105 |
return null; |
106 |
} |
107 |
|
108 |
public WMTSServerExplorerParameters getParameters() {
|
109 |
return (WMTSServerExplorerParameters) super.getParameters(); |
110 |
} |
111 |
|
112 |
public List<DataStoreParameters> list() throws DataException { |
113 |
return null; |
114 |
} |
115 |
|
116 |
public List<DataStoreParameters> list(int mode) throws DataException { |
117 |
return null; |
118 |
} |
119 |
|
120 |
public void remove(DataStoreParameters parameters) throws DataException { |
121 |
|
122 |
} |
123 |
|
124 |
public String getProviderName() { |
125 |
return WMTSProvider.NAME;
|
126 |
} |
127 |
|
128 |
//**********************************************
|
129 |
//Connector
|
130 |
//**********************************************
|
131 |
|
132 |
public DataStoreParameters getStoredParameters() {
|
133 |
DataManager manager = DALLocator.getDataManager(); |
134 |
WMTSDataParameters wmtsParams = null;
|
135 |
try {
|
136 |
wmtsParams = (WMTSDataParameters) manager.createStoreParameters(this.getDataStoreProviderName());
|
137 |
String host = getParameters().getHost();
|
138 |
try {
|
139 |
wmtsParams.setURI(new URI(host)); |
140 |
} catch (URISyntaxException e) { |
141 |
logger.warn("Can't create URI from "+host, e);
|
142 |
} |
143 |
wmtsParams.setOGCClient(getOGCClient()); |
144 |
|
145 |
if(WMTSProvider.TILED) {
|
146 |
TileDataParameters tileParams = (TileDataParameters) manager.createStoreParameters("Tile Store");
|
147 |
tileParams.setDataParameters(wmtsParams); |
148 |
return tileParams;
|
149 |
} |
150 |
} catch (InitializeException e) {
|
151 |
logger.warn("Can't get DataStoreParameters from WMTSServerExplorer", e);
|
152 |
} catch (ProviderNotRegisteredException e) {
|
153 |
logger.warn("Can't get DataStoreParameters from WMTSServerExplorer", e);
|
154 |
} |
155 |
return wmtsParams;
|
156 |
} |
157 |
|
158 |
public void connect(ICancellable cancellable) throws ConnectException { |
159 |
URL url = null; |
160 |
boolean override = false; |
161 |
|
162 |
try {
|
163 |
url = new URL(getParameters().getHost()); |
164 |
} catch (Exception e) { |
165 |
throw new ConnectException("Malformed URL",e); |
166 |
} |
167 |
try {
|
168 |
ogcClient = WMTSOGCLocator.getManager().createWMTSClient(url.toString()); |
169 |
ogcClient.setForceChangeAxisOrder(getParameters().isLongitudeFirst()); |
170 |
if (!ogcClient.connect(override, cancellable))
|
171 |
throw new ConnectException("Error connecting"); |
172 |
} catch (IOException e) { |
173 |
throw new ConnectException(e.getMessage(), e); |
174 |
} |
175 |
} |
176 |
|
177 |
public boolean isHostReachable(int timeout) { |
178 |
URL url = null; |
179 |
URLConnection con = null; |
180 |
try {
|
181 |
url = new URL(getParameters().getHost()); |
182 |
con = url.openConnection(); |
183 |
if(con == null) |
184 |
return false; |
185 |
con.connect(); |
186 |
} catch (MalformedURLException e) { |
187 |
return false; |
188 |
} catch (IOException e) { |
189 |
return false; |
190 |
} |
191 |
|
192 |
InputStream stream = null; |
193 |
try {
|
194 |
stream = con.getInputStream(); |
195 |
if(stream == null) |
196 |
return false; |
197 |
} catch (IOException e) { |
198 |
} |
199 |
|
200 |
return true; |
201 |
} |
202 |
|
203 |
/**
|
204 |
* Checks if the network and host are reachable
|
205 |
* @return true if both are reachable and false if they are not
|
206 |
*/
|
207 |
public boolean isHostReachable() { |
208 |
return isHostReachable(RasterDataServerExplorer.TIME);
|
209 |
} |
210 |
|
211 |
public boolean isConnected() { |
212 |
if(ogcClient != null) |
213 |
return true; |
214 |
return false; |
215 |
} |
216 |
|
217 |
public WMTSClient getOGCClient() {
|
218 |
return ogcClient;
|
219 |
} |
220 |
|
221 |
public String getHost() { |
222 |
return getParameters().getHost();
|
223 |
} |
224 |
|
225 |
public DataServerExplorerProviderServices getServerExplorerProviderServices() {
|
226 |
return null; |
227 |
} |
228 |
} |