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