root / branches / v2_0_0_prep / libraries / org.gvsig.arcims / src / org / gvsig / remoteclient / arcims / ArcImsClient.java @ 32538
History | View | Annotate | Download (5.38 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.remoteclient.arcims; |
30 |
|
31 |
import java.net.URL; |
32 |
import java.util.TreeMap; |
33 |
|
34 |
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
35 |
import org.gvsig.remoteclient.RasterClient; |
36 |
import org.gvsig.remoteclient.arcims.exceptions.ArcImsException; |
37 |
import org.gvsig.remoteclient.arcims.utils.ServiceInformation; |
38 |
import org.gvsig.remoteclient.wms.ICancellable; |
39 |
|
40 |
import org.slf4j.Logger; |
41 |
import org.slf4j.LoggerFactory; |
42 |
|
43 |
/**
|
44 |
* Abstract class the with the necessary logic to connect to a ArcIms and
|
45 |
* interpretate the data.
|
46 |
*
|
47 |
* @author vsanjaime version 2.0
|
48 |
*
|
49 |
*/
|
50 |
public abstract class ArcImsClient extends RasterClient { |
51 |
|
52 |
private static Logger logger = LoggerFactory.getLogger(ArcImsProtocolHandler.class |
53 |
.getName()); |
54 |
|
55 |
/**
|
56 |
* Handler of the service used by the client to contact with ArcIMS
|
57 |
*
|
58 |
* @see ArcImsProtocolHandler#ArcImsProtocolHandler()
|
59 |
*/
|
60 |
protected ArcImsProtocolHandler handler = null; |
61 |
|
62 |
/**
|
63 |
* Layers of the service
|
64 |
*/
|
65 |
private TreeMap layers = new TreeMap(); |
66 |
|
67 |
/**
|
68 |
* Constructor
|
69 |
* @param serverURL
|
70 |
* @param serviceName
|
71 |
* @param serviceType
|
72 |
*/
|
73 |
public ArcImsClient(String serverURL, String serviceName, String serviceType) { |
74 |
|
75 |
// add server and service name
|
76 |
this.setHost(serverURL);
|
77 |
this.setServiceName(serviceName);
|
78 |
// instance ArcImsHandler
|
79 |
try {
|
80 |
this.handler = ArcImsProtocolHandlerFactory.negotiate(serviceType);
|
81 |
this.handler.setHost(serverURL);
|
82 |
this.handler.setService(serviceName);
|
83 |
this.handler.getServiceInformation().setType(serviceType);
|
84 |
} catch (Exception e) { |
85 |
logger.error(e.getMessage(), e); |
86 |
} |
87 |
} |
88 |
|
89 |
/**
|
90 |
* <p>
|
91 |
* One of the three interfaces defined by ArcIms, it gets the service
|
92 |
* capabilities
|
93 |
* </p>
|
94 |
*
|
95 |
*/
|
96 |
public void getCapabilities(ArcImsStatus status) throws ArcImsException { |
97 |
// get capabilities
|
98 |
this.handler.getCapabilities(status);
|
99 |
// layers availables
|
100 |
this.layers = this.handler.layers; |
101 |
} |
102 |
|
103 |
/**
|
104 |
* <p>
|
105 |
* One of the three interfaces defined by the ArcIms, it gets the
|
106 |
* information about a feature requested
|
107 |
* </p>
|
108 |
*
|
109 |
* @return Proper XML to build the Element Info GUI
|
110 |
*/
|
111 |
public String getFeatureInfo(ArcImsStatus status, int x, int y, |
112 |
int featureCount) throws ArcImsException { |
113 |
// get info of the one feature
|
114 |
return this.handler.getElementInfo(status, x, y, featureCount); |
115 |
} |
116 |
|
117 |
/**
|
118 |
* <p>
|
119 |
* Reads from the ArcIms Capabilities, the layers available in the service
|
120 |
* </p>
|
121 |
*
|
122 |
* @return a TreeMap with the available layers in the ArcIms
|
123 |
*/
|
124 |
public TreeMap getLayers() { |
125 |
return this.layers; |
126 |
} |
127 |
|
128 |
/**
|
129 |
* <p>
|
130 |
* Reads from the ArcIms Capabilities the number if layers available in the
|
131 |
* service
|
132 |
* </p>
|
133 |
*
|
134 |
* @return number of layers available
|
135 |
*/
|
136 |
public int getNumberOfLayers() { |
137 |
if (this.layers != null) { |
138 |
return this.layers.size(); |
139 |
} |
140 |
return 0; |
141 |
} |
142 |
|
143 |
/**
|
144 |
* <p>
|
145 |
* Gets the image formats available in the Service to retrieve the maps
|
146 |
* </p>
|
147 |
*
|
148 |
* @return a vector with all the available formats
|
149 |
*/
|
150 |
public boolean isQueryable() { |
151 |
return this.handler.getServiceInformation().isQueryable(); |
152 |
} |
153 |
|
154 |
/**
|
155 |
*
|
156 |
*/
|
157 |
public void close() { |
158 |
// nothing to do
|
159 |
} |
160 |
|
161 |
/**
|
162 |
* Gets the Service information included in the Capabilities
|
163 |
* */
|
164 |
public ServiceInformation getServiceInformation() {
|
165 |
// return info of the service from capabilities
|
166 |
return this.handler.getServiceInformation(); |
167 |
} |
168 |
|
169 |
/**
|
170 |
* <p>
|
171 |
* Checks the connection to de remote ArcIms and requests its capabilities.
|
172 |
* </p>
|
173 |
*
|
174 |
*/
|
175 |
public boolean connect(boolean override, ICancellable cancel) { |
176 |
try {
|
177 |
if (this.handler == null) { |
178 |
if (getHost().trim().length() > 0) { |
179 |
this.handler.setHost(getHost());
|
180 |
} else {
|
181 |
// must to specify host first!!!!
|
182 |
return false; |
183 |
} |
184 |
} |
185 |
|
186 |
this.getCapabilities(null); |
187 |
|
188 |
return true; |
189 |
} catch (Exception e) { |
190 |
logger.error("While connecting", e);
|
191 |
return false; |
192 |
} |
193 |
} |
194 |
|
195 |
public boolean connect(URL server, ICancellable cancel) { |
196 |
this.setHost(server.toString());
|
197 |
return connect(false, cancel); |
198 |
} |
199 |
|
200 |
/**
|
201 |
* Returns the handler.
|
202 |
*
|
203 |
* @return The handler
|
204 |
*/
|
205 |
public ArcImsProtocolHandler getHandler() {
|
206 |
return this.handler; |
207 |
} |
208 |
|
209 |
/**
|
210 |
* Method called to obtain the Legend for an ArcIMS layer ID
|
211 |
*
|
212 |
* @see es.prodevelop.cit.gvsig.arcims.fmap.layers.FFeatureLyrArcIMS#setInitialLegend()
|
213 |
* @param layerId
|
214 |
* @return
|
215 |
* @throws ArcImsException
|
216 |
*/
|
217 |
public ILegend getLegend(String layerId) throws ArcImsException { |
218 |
return this.handler.getLegend(layerId); |
219 |
} |
220 |
|
221 |
|
222 |
} |