Statistics
| Revision:

svn-gvsig-desktop / branches / v10 / libraries / libArcIMS_old / src / org / gvsig / remoteClient / arcims / ArcImsClientP.java @ 12255

History | View | Annotate | Download (6.92 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2006 Prodevelop and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *   +34 963862235
28
 *   gvsig@gva.es
29
 *   www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   Prodevelop Integraci?n de Tecnolog?as SL
34
 *   Conde Salvatierra de ?lava , 34-10
35
 *   46004 Valencia
36
 *   Spain
37
 *
38
 *   +34 963 510 612
39
 *   +34 963 510 968
40
 *   gis@prodevelop.es
41
 *   http://www.prodevelop.es
42
 */
43

    
44
package org.gvsig.remoteClient.arcims;
45

    
46
import com.iver.cit.gvsig.fmap.rendering.Legend;
47

    
48
import org.apache.log4j.Logger;
49

    
50
import org.gvsig.remoteClient.RasterClient;
51
import org.gvsig.remoteClient.arcims.exceptions.ArcImsException;
52
import org.gvsig.remoteClient.arcims.utils.ServiceInformation;
53
import org.gvsig.remoteClient.wms.ICancellable;
54

    
55
import java.net.URL;
56

    
57
import java.util.TreeMap;
58

    
59

    
60
/**
61
 * Abstract class the with the necessary logic
62
 * to connect to a ArcIms and interpretate the data.
63
 *
64
 * The P at the end of the name is to avoid conflict with existing empty
65
 * class at libRemoteServices package @seeorg.gvsig.remoteClient.arcims.ArcImsClient
66
 *
67
 */
68
public abstract class ArcImsClientP extends RasterClient {
69
    private static Logger logger = Logger.getLogger(ArcImsProtocolHandler.class.getName());
70

    
71
    /**
72
     * Handler of the service used by the client to contact with ArcIMS
73
     * @see ArcImsProtocolHandler#ArcImsProtocolHandler()
74
     */
75
    protected ArcImsProtocolHandler handler;
76

    
77
    /**
78
     * Layers of the service
79
     */
80
    private TreeMap layers = new TreeMap();
81

    
82
    //    /**
83
    //     * Version and build number of the ArcIMS Server. This data is only 
84
    //     * for information purposes as the ArcXML is (at this time) fully compatible with 
85
    //     * 4 and 9 versions of ArcIMS.
86
    //     */
87
    //    private String[] version = new String[2]; 
88

    
89
    /**
90
    * Constructor.
91
    * the parameter host, indicates the ArcIms host to connect.
92
    * */
93
    public ArcImsClientP(String host, String service, String serviceType) {
94
        //m_log = LogManager.getLogManager().getLogger(getClass().getName());
95
        setHost(host);
96
        setServiceName(service);
97

    
98
        try {
99
            handler = ArcImsProtocolHandlerFactory.negotiate(serviceType);
100

    
101
            //handler = new org.gvsig.remoteClient.arcims.
102
            handler.setHost(host);
103
            handler.setService(service);
104
            handler.serviceInfo.setType(serviceType);
105
        } catch (Exception e) {
106
            e.printStackTrace();
107
            logger.error(e.getMessage(), e);
108
        }
109
    }
110

    
111
    /**
112
     * <p>One of the three interfaces that  ArcIms defines. Request a map.</p>
113
     * @throws ServerErrorException
114
     * @throws ArcImsException
115
     * @throws ServerErrorException
116
     */
117

    
118
    //public abstract File getMap(ArcImsStatus status) throws ArcImsException, ServerErrorException;
119

    
120
    /**
121
     * <p>One of the three interfaces defined by  ArcIms, it gets the service capabilities</p>
122
     *
123
     */
124
    public void getCapabilities(ArcImsStatus status) throws ArcImsException {
125
        handler.getCapabilities(status);
126

    
127
        layers = handler.layers;
128

    
129
        // rootLayer = handler.rootLayer;
130
    }
131

    
132
    /**
133
     * <p>One of the three interfaces defined by  ArcIms, it gets the service capabilities</p>
134
     *
135
     */
136

    
137
    /*
138
    public void getCapabilities(URL url) {
139
        handler.getCapabilities(url);
140
        layers = handler.layers;
141
        rootLayer = handler.rootLayer;
142
    }
143
    */
144

    
145
    /**
146
     * <p>One of the three interfaces defined by the  ArcIms,
147
     * it gets the information about a feature requested</p>
148
     * @return  Proper XML to build the Element Info GUI
149
     */
150
    public String getFeatureInfo(ArcImsStatus status, int x, int y,
151
        int featureCount) throws ArcImsException {
152
        return handler.getElementInfo(status, x, y, featureCount);
153
    }
154

    
155
    /**
156
     * <p> Reads from the ArcIms Capabilities, the layers available in the service</p>
157
     * @return a TreeMap with the available layers in the ArcIms
158
     */
159
    public TreeMap getLayers() {
160
        return layers;
161
    }
162

    
163
    /**
164
     * <p>Reads from the ArcIms Capabilities the number if layers available in the service</p>
165
     * @return number of layers available
166
     */
167
    public int getNumberOfLayers() {
168
        if (layers != null) {
169
            return layers.size();
170
        }
171

    
172
        return 0;
173
    }
174

    
175
    /**
176
     * <p>Gets the image formats available in the Service to retrieve the maps</p>
177
     * @return a vector with all the available formats
178
     */
179
    public boolean isQueryable() {
180
        return handler.getServiceInformation().isQueryable();
181
    }
182

    
183
    public void close() {
184
        // your code here
185
    }
186

    
187
    /**
188
     * Gets the Service information included in the Capabilities
189
     * */
190
    public ServiceInformation getServiceInformation() {
191
        return handler.getServiceInformation();
192
    }
193

    
194
    /**
195
     * <p>Checks the connection to de remote ArcIms and requests its capabilities.</p>
196
     *
197
     */
198
    public boolean connect(boolean override, ICancellable cancel) {
199
        try {
200
            if (handler == null) {
201
                if (getHost().trim().length() > 0) {
202
                    handler.setHost(getHost());
203
                } else {
204
                    //must to specify host first!!!!
205
                    return false;
206
                }
207
            }
208

    
209
            getCapabilities(null);
210

    
211
            return true;
212
        } catch (Exception e) {
213
            logger.error("While connecting", e);
214

    
215
            return false;
216
        }
217
    }
218

    
219
    public boolean connect(URL server, ICancellable cancel) {
220
        setHost(server.toString());
221

    
222
        return connect(false, cancel);
223
    }
224

    
225
    /**
226
     * Returns the handler.
227
     * @return The handler
228
     */
229
    public ArcImsProtocolHandler getHandler() {
230
        return handler;
231
    }
232

    
233
    /**
234
     * Method called to obtain the Legend for an ArcIMS layer ID
235
     * @see es.prodevelop.cit.gvsig.arcims.fmap.layers.FFeatureLyrArcIMS#setInitialLegend()
236
     * @param layerId
237
     * @return
238
     * @throws ArcImsException
239
     */
240
    public Legend getLegend(String layerId) throws ArcImsException {
241
        return handler.getLegend(layerId);
242
    }
243
}