svn-gvsig-desktop / branches / v2_0_0_prep / extensions / org.gvsig.arcims.image.extension / src / main / java / org / gvsig / arcims / image / fmap / drivers / ArcImsImageDriver.java @ 32573
History | View | Annotate | Download (7.23 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 |
* 2010 Prodevelop S.L. main development
|
26 |
* http://www.prodevelop.es
|
27 |
*/
|
28 |
|
29 |
package org.gvsig.arcims.image.fmap.drivers; |
30 |
|
31 |
import java.net.URL; |
32 |
import java.util.TreeMap; |
33 |
|
34 |
import org.slf4j.Logger; |
35 |
import org.slf4j.LoggerFactory; |
36 |
import org.gvsig.arcims.image.fmap.layers.ArcImsLayerNode; |
37 |
import org.gvsig.remoteclient.arcims.ArcImsClient; |
38 |
import org.gvsig.remoteclient.arcims.ArcImsImageClient; |
39 |
import org.gvsig.remoteclient.arcims.ArcImsStatus; |
40 |
import org.gvsig.remoteclient.arcims.exceptions.ArcImsException; |
41 |
import org.gvsig.remoteclient.exceptions.ServerErrorException; |
42 |
import org.gvsig.remoteclient.wms.ICancellable; |
43 |
|
44 |
|
45 |
/**
|
46 |
* ArcIMS driver implementation. Requests are passed to the <tt>ArcImsClientP</tt> object.
|
47 |
*
|
48 |
* @see org.gvsig.remoteClient.arcims.ArcImsImageClient ArcImsImageClient
|
49 |
* @author jldominguez
|
50 |
*/
|
51 |
public class ArcImsImageDriver { |
52 |
|
53 |
private static Logger logger = LoggerFactory.getLogger(ArcImsImageDriver.class.getName()); |
54 |
private ArcImsImageClient client;
|
55 |
private String server; |
56 |
private String service; |
57 |
private String serviceType; |
58 |
private boolean connectionDone = false; |
59 |
|
60 |
/**
|
61 |
* Constructor
|
62 |
*/
|
63 |
public ArcImsImageDriver() {
|
64 |
} |
65 |
|
66 |
/**
|
67 |
* The constructor needs the server's URL and the name of the service to be used.
|
68 |
*
|
69 |
* @param host server's URL
|
70 |
* @param service name of the service, chosen among the ones retrieved after a
|
71 |
* request with the parameter <tt>ServiceName=Catalog</tt>
|
72 |
*/
|
73 |
public ArcImsImageDriver(String host, String service, String svcType) { |
74 |
this.serviceType = svcType;
|
75 |
this.init(host, service);
|
76 |
} |
77 |
|
78 |
/**
|
79 |
* This method is called by the constructor and creates the
|
80 |
* <tt>client</tt> oject.
|
81 |
* @param host
|
82 |
* @param service
|
83 |
*/
|
84 |
public void init(String host, String service) { |
85 |
this.server = host;
|
86 |
this.service = service;
|
87 |
this.client = new ArcImsImageClient(host, service); |
88 |
} |
89 |
|
90 |
/**
|
91 |
* Gets available layers from the current server and service
|
92 |
*
|
93 |
* @return a TreeMap with available layers
|
94 |
*/
|
95 |
public TreeMap getLayers() { |
96 |
return this.client.getLayers(); |
97 |
} |
98 |
|
99 |
/**
|
100 |
* Gets the layers available on the server (the class that implements
|
101 |
* this interface will get the service name from the user)
|
102 |
*
|
103 |
* @param server ArcIMS server's URL
|
104 |
*/
|
105 |
public void getCapabilities(URL server, ICancellable cancel) |
106 |
throws ArcImsException {
|
107 |
if (connectionDone) {
|
108 |
return;
|
109 |
} |
110 |
else {
|
111 |
connectionDone = getClient().connect(server, cancel); |
112 |
} |
113 |
|
114 |
if (!connectionDone) {
|
115 |
throw new ArcImsException("connect_error"); |
116 |
} |
117 |
} |
118 |
|
119 |
/**
|
120 |
* Gets the visual information from the layers of
|
121 |
* the required service (that is, the map itself) depending
|
122 |
* on the graphic context (coord. system, view's size, etc)
|
123 |
*
|
124 |
* @param status the graphic context in which the request is performed
|
125 |
* @return the graphic data to be viewed, that is, the map. For the imageservice,
|
126 |
* it will be a <tt>File</tt> object.
|
127 |
*/
|
128 |
public Object getMap(ArcImsStatus status) throws ArcImsException { |
129 |
try {
|
130 |
return client.getMap(status);
|
131 |
} |
132 |
catch (ServerErrorException e) {
|
133 |
logger.error("While getting map ", e);
|
134 |
throw new ArcImsException("ArcIMS Unexpected server error." + |
135 |
e.getMessage()); |
136 |
} |
137 |
} |
138 |
|
139 |
/**
|
140 |
* Gets the layer's available information on a particular xy coordinates
|
141 |
* (usually derived from a mouse click). If it's a raster layer,
|
142 |
* a request will be sent to the server asking for the data associated
|
143 |
* to the elements (polygon, line or point) which cover the clicked
|
144 |
* pixel.
|
145 |
*
|
146 |
* @param status the graphic context in which the request is performed
|
147 |
* (ccord. system, view's dimension etc.)
|
148 |
* @param i x coordinate of the queried pixel
|
149 |
* @param j y coordinate of the queried pixel
|
150 |
* @param max_value maximun number of vector elements whose information
|
151 |
* will be retrieved.
|
152 |
* @return the available information at the given coordinates
|
153 |
*/
|
154 |
public String getFeatureInfo(ArcImsStatus status, int i, int j, |
155 |
int max_value) throws ArcImsException { |
156 |
String r = "No info available."; |
157 |
|
158 |
try {
|
159 |
r = client.getFeatureInfo(status, i, j, max_value); |
160 |
} |
161 |
catch (ArcImsException e) {
|
162 |
logger.error("ArcImsException. ", e);
|
163 |
throw e;
|
164 |
} |
165 |
|
166 |
return r;
|
167 |
} |
168 |
|
169 |
/**
|
170 |
* Given a layer name, gets a node that contains relevant information
|
171 |
* about the layer.
|
172 |
*
|
173 |
* @param layerName the name of the layer
|
174 |
* @return a node with layer's information
|
175 |
*/
|
176 |
public ArcImsLayerNode getLayer(String layerName) { |
177 |
ArcImsLayerNode node = new ArcImsLayerNode();
|
178 |
node.setName(layerName); |
179 |
|
180 |
return node;
|
181 |
} |
182 |
|
183 |
/**
|
184 |
* This method starts a connection with the server and sends
|
185 |
* a <tt>getCapabilities</tt> request.
|
186 |
* @return <b>true</b> if the connection was successful, <b>false</b>
|
187 |
* otherwise (bad or no server URL, for example)
|
188 |
*/
|
189 |
public boolean connect(ICancellable cancel) { |
190 |
if (connectionDone) {
|
191 |
return true; |
192 |
} |
193 |
else {
|
194 |
connectionDone = client.connect(false, cancel);
|
195 |
; |
196 |
|
197 |
return connectionDone;
|
198 |
} |
199 |
} |
200 |
|
201 |
/**
|
202 |
* Gets the <tt>ArcImsClientP</tt> object, onto which requests
|
203 |
* are passed.
|
204 |
*
|
205 |
* @return the object that actually performs requests.
|
206 |
*/
|
207 |
public ArcImsClient getClient() {
|
208 |
if (client == null) { |
209 |
init(server, service); |
210 |
} |
211 |
|
212 |
return client;
|
213 |
} |
214 |
|
215 |
/**
|
216 |
* This method tells whether this layer is queriable with a call to
|
217 |
* <tt>getFeatureInfo(...)</tt>
|
218 |
*
|
219 |
* @return <b>true</b> if method <tt>getFeatureInfo(...)</tt> can be invoqued,
|
220 |
* <b>false</b> otherwise
|
221 |
*/
|
222 |
public boolean isQueryable() { |
223 |
return client.isQueryable();
|
224 |
} |
225 |
|
226 |
/**
|
227 |
*
|
228 |
* @param status
|
229 |
* @param imgFormat
|
230 |
* @return
|
231 |
*/
|
232 |
public boolean testFormat(ArcImsStatus status, String imgFormat) { |
233 |
try {
|
234 |
return client.testFromat(status, imgFormat);
|
235 |
} |
236 |
catch (ArcImsException e) {
|
237 |
logger.error("While testing omage format ", e);
|
238 |
} |
239 |
|
240 |
return false; |
241 |
} |
242 |
} |