Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extWMS / src / com / iver / cit / gvsig / fmap / drivers / wms / FMapWMSDriver.java @ 3333

History | View | Annotate | Download (3.73 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. 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
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package com.iver.cit.gvsig.fmap.drivers.wms;
42

    
43
import com.iver.cit.gvsig.fmap.drivers.WMSDriver;
44
import com.iver.cit.gvsig.fmap.drivers.WMSException;
45

    
46
import com.iver.wmsclient.Capabilities;
47
import com.iver.wmsclient.FeatureInfoQuery;
48
import com.iver.wmsclient.MapQuery;
49
import com.iver.wmsclient.UnsupportedVersionException;
50
import com.iver.wmsclient.WMSClient;
51
import com.iver.wmsclient.WMSClientFactory;
52

    
53
import org.exolab.castor.xml.ValidationException;
54

    
55
import java.awt.Image;
56
import java.awt.image.BufferedImage;
57

    
58
import java.io.ByteArrayInputStream;
59
import java.io.IOException;
60

    
61
import java.net.ProtocolException;
62
import java.net.URL;
63

    
64
import javax.imageio.ImageIO;
65

    
66

    
67
/**
68
 * Driver WMS.
69
 *
70
 * @author Vicente Caballero Navarro
71
 */
72
public class FMapWMSDriver implements WMSDriver {
73
        private MapQuery lastMapQuery;
74
        private WMSClient client;
75

    
76
        /**
77
         * @see com.iver.cit.gvsig.fmap.drivers.WMSDriver#getCapabilities(java.net.URL)
78
         */
79
        public void getCapabilities(URL servidor)
80
                throws WMSException, IOException, ProtocolException {
81
                try {
82
                        Capabilities c = getClient(servidor).getCapabilities(servidor);
83
                } catch (UnsupportedVersionException e) {
84
                        throw new WMSException(e);
85
                }
86
        }
87

    
88
        /**
89
         * @see com.iver.cit.gvsig.fmap.drivers.WMSDriver#getMap(com.iver.cit.gvsig.fmap.drivers.wms.MapQuery)
90
         */
91
        public Image getMap(MapQuery mapQuery)
92
                throws WMSException, IOException, ProtocolException {
93
                BufferedImage image = new BufferedImage(mapQuery.getWidth(),
94
                                mapQuery.getHeight(), BufferedImage.TYPE_INT_ARGB);
95

    
96
                try {
97
                        byte[] res = client.doMapQuery(mapQuery);
98
                        ByteArrayInputStream inbytes = new ByteArrayInputStream(res);
99
                        image = ImageIO.read(inbytes);
100

    
101
                        return image;
102
                } catch (ValidationException e) {
103
                        throw new ProtocolException();
104
                } catch (com.iver.wmsclient.WMSException e) {
105
                        throw new WMSException(e);
106
                } catch (NoSuchFieldException e) {
107
                        throw new RuntimeException(
108
                                "No se incluyeron todos los campos necesarios de la petici?n");
109
                }
110
        }
111

    
112
        /**
113
         * @see com.iver.cit.gvsig.fmap.drivers.WMSDriver#getFeatureInfo(com.iver.cit.gvsig.fmap.drivers.wms.InfoQuery)
114
         */
115
        public String getFeatureInfo(FeatureInfoQuery infoQuery)
116
                throws WMSException, IOException, ProtocolException {
117
                return null;
118
        }
119

    
120
        /**
121
         * Devuelve WMSClient a partir de su URL.
122
         *
123
         * @param url URL.
124
         *
125
         * @return WMSClient.
126
         *
127
         * @throws UnsupportedVersionException
128
         * @throws IOException
129
         */
130
        private WMSClient getClient(URL url)
131
                throws UnsupportedVersionException, IOException {
132
                if (client == null) {
133
                        client = WMSClientFactory.getClient(url);
134
                }
135

    
136
                return client;
137
        }
138
}