Statistics
| Revision:

svn-gvsig-desktop / branches / gvSIG_WMSv2 / extensions / extWMS / src / com / iver / cit / gvsig / fmap / drivers / wms / FMapWMSDriver.java @ 3377

History | View | Annotate | Download (4 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 java.awt.Image;
44
import java.awt.image.BufferedImage;
45
import java.io.ByteArrayInputStream;
46
import java.io.IOException;
47
import java.net.ProtocolException;
48
import java.net.URL;
49

    
50
import javax.imageio.ImageIO;
51

    
52
import org.gvsig.remoteClient.wms.WMSClient;
53
import org.gvsig.remoteClient.wms.WMSStatus;
54

    
55
import com.iver.cit.gvsig.fmap.drivers.WMSDriver;
56
import com.iver.cit.gvsig.fmap.drivers.WMSException;
57
//import com.iver.wmsclient.Capabilities;
58
//import com.iver.wmsclient.FeatureInfoQuery;
59
//import com.iver.wmsclient.MapQuery;
60
//import com.iver.wmsclient.UnsupportedVersionException;
61
//import com.iver.wmsclient.WMSClient;
62
//import com.iver.wmsclient.WMSClientFactory;
63

    
64

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

    
74
        private WMSStatus wmsStatus;
75
        private WMSClient client;
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
                        getClient(servidor).connect();
84
                //} catch (UnsupportedVersionException e) {
85
                } catch (Exception e) {                        
86
                        throw new WMSException(e);
87
                }
88
        }
89

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

    
98
                try {
99
                        byte[] res = client.getMap(wmsstatus);                        
100
                        ByteArrayInputStream inbytes = new ByteArrayInputStream(res);
101
                        image = ImageIO.read(inbytes);
102

    
103
                        return image;
104
//                } catch (ValidationException e) {
105
//                        throw new ProtocolException();
106
                } catch (org.gvsig.remoteClient.exceptions.WMSException e) {
107
                        throw new WMSException(e);
108
//                } catch (NoSuchFieldException e) {
109
//                        throw new RuntimeException(
110
//                                "No se incluyeron todos los campos necesarios de la petici?n");
111
                }
112
        }
113

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

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

    
140
                return client;
141
        }
142
}