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