Revision 41125 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.remoteclient/src/main/java/org/gvsig/remoteclient/wcs/WCSClient.java

View differences:

WCSClient.java
37 37
import org.gvsig.remoteclient.exceptions.WCSException;
38 38
import org.gvsig.remoteclient.exceptions.WMSException;
39 39
import org.gvsig.remoteclient.utils.BoundaryBox;
40
import org.gvsig.remoteclient.wms.WMSStatus;
40
import org.slf4j.Logger;
41
import org.slf4j.LoggerFactory;
41 42

  
42 43
/**
43 44
 * WCSClient managing the low-level comunication to the server. It is used
......
47 48
 */
48 49
public class WCSClient extends org.gvsig.remoteclient.RasterClient{
49 50

  
50
    private WCSProtocolHandler handler;
51
    private Hashtable layerPool;
51
    private WCSProtocolHandler handler   = null;
52
    private Hashtable          layerPool = null;
53
    private Logger             log       = LoggerFactory.getLogger(WCSClient.class);
52 54

  
53 55
    /**
54 56
     * Constructor.
......
59 61
    public WCSClient(String host) throws ConnectException, IOException {
60 62
        setHost(host);
61 63
        try {
62
        	handler = WCSProtocolHandlerFactory.negotiate(host);
63
        	handler.setHost(host);
64
        	handler = WCSProtocolHandlerFactory.negotiate(hostName);
65
        	handler.setHost(hostName);
64 66
        } catch(ConnectException conE) {
65 67
        	throw conE;
66 68
        } catch(IOException ioE) {
67 69
        	throw ioE;
68 70
        } catch(Exception e) {
69
        	e.printStackTrace();
71
        	log.info("Error getting handler for " + hostName, e);
70 72
        }
71 73
    }
72 74

  
......
131 133

  
132 134
        layerPool = handler.getLayers();
133 135
    }
134

  
135
    /* (non-Javadoc)
136
     * @see org.gvsig.remoteClient.RemoteClient#close()
137
     */
136
    
137
    private Hashtable getLayerPool() {
138
    	if(layerPool == null || layerPool.isEmpty()) {
139
    		layerPool = getHandLer().getLayers();
140
    		if(layerPool.isEmpty()) {
141
    			describeCoverage(null, true, null);
142
    			layerPool = getHandLer().getLayers();
143
    		}
144
    	}
145
    	return layerPool;
146
    }
147
    
148
    private WCSProtocolHandler getHandLer() {
149
    	if(handler == null) {
150
    		try {
151
            	handler = WCSProtocolHandlerFactory.negotiate(hostName);
152
            	handler.setHost(hostName);
153
            } catch(ConnectException conE) {
154
            	log.debug("Error getting handler for " + hostName, conE);
155
            } catch(IOException ioE) {
156
            	log.debug("Error getting handler for " + hostName, ioE);
157
            } catch(Exception e) {
158
            	log.debug("Error getting handler for " + hostName, e);
159
            }
160
    	}
161
    	return handler;
162
    }
163
    
138 164
    public void close() {
139 165
    }
140 166

  
......
144 170
     * @return String
145 171
     */
146 172
	public String getServiceTitle() {
147
		return handler.serviceInfo.title;
173
		return getHandLer().serviceInfo.title;
148 174
	}
149 175

  
150 176
	/**
......
152 178
	 * @return String
153 179
	 */
154 180
	public String getVersion() {
155
		return handler.getVersion();
181
		return getHandLer().getVersion();
156 182
	}
157 183

  
158 184
	/**
......
160 186
	 * @return String
161 187
	 */
162 188
	public String getDescription() {
163
		return handler.serviceInfo.abstr;
189
		return getHandLer().serviceInfo.abstr;
164 190
	}
165 191

  
166 192
	/**
......
168 194
	 * @return
169 195
	 */
170 196
	public ArrayList getFormats() {
171
		return handler.getFormats();
197
		return getHandLer().getFormats();
172 198
	}
173 199

  
174 200
	/**
......
177 203
	 * @return Hashtable.
178 204
	 */
179 205
	public Hashtable getCoverageList() {
180
		return layerPool;
206
		return getLayerPool();
181 207
	}
182 208

  
183 209
	/**
......
186 212
	 * @return String
187 213
	 */
188 214
	public String getLabel(String coverageName) {
189
		return ((WCSCoverage) layerPool.get(coverageName)).getTitle();
215
		return ((WCSCoverage) getLayerPool().get(coverageName)).getTitle();
190 216
	}
191 217

  
192 218
	/**
......
198 224
	 * @return Rectangle2D
199 225
	 */
200 226
	public Rectangle2D getExtent(String coverageName, String crs) {
201
		BoundaryBox bbox = (BoundaryBox) ((WCSCoverage) layerPool.get(coverageName)).getBbox(crs);;
227
		BoundaryBox bbox = (BoundaryBox) ((WCSCoverage) getLayerPool().get(coverageName)).getBbox(crs);
202 228
        if (bbox == null) return null;
203 229
        double xmin = bbox.getXmin();
204 230
        double xmax = bbox.getXmax();
......
216 242
	 * @throws WCSException
217 243
	 */
218 244
	public File getCoverage(WCSStatus status, ICancellable cancel) throws ServerErrorException, WCSException {
219
		return handler.getCoverage(status, cancel);
245
		return getHandLer().getCoverage(status, cancel);
220 246
	}
221 247
	
222 248
	/**
......
224 250
     * @throws ServerErrorException 
225 251
     */
226 252
    public URL getCoverageURL(WCSStatus status, ICancellable cancel) throws WMSException, ServerErrorException{   
227
       return handler.getCoverageURL(status, cancel);
253
       return getHandLer().getCoverageURL(status, cancel);
228 254
    } 
229 255
    
230 256
    /**
......
234 260
     * @throws IOException 
235 261
     */
236 262
    public String getExceptionMessage(File file) throws IOException {
237
    	return handler.getExceptionMessage(file);
263
    	return getHandLer().getExceptionMessage(file);
238 264
    }
239 265
}
240 266

  

Also available in: Unified diff