Statistics
| Revision:

svn-gvsig-desktop / branches / piloto3d / extensions / extCatalogYNomenclator / src / es / gva / cit / gvsig / catalogClient / loaders / WMSLayerLoader.java @ 9538

History | View | Annotate | Download (4.94 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 es.gva.cit.gvsig.catalogClient.loaders;
42

    
43
import java.io.IOException;
44
import java.lang.reflect.InvocationTargetException;
45
import java.net.MalformedURLException;
46
import java.net.ProtocolException;
47
import java.util.HashMap;
48
import java.util.Map;
49

    
50
import org.exolab.castor.xml.ValidationException;
51
import org.gvsig.i18n.Messages;
52

    
53
import com.iver.andami.PluginServices;
54
import com.iver.andami.ui.mdiManager.IWindow;
55
import com.iver.cit.gvsig.fmap.drivers.UnsupportedVersionException;
56
import com.iver.cit.gvsig.fmap.layers.FLayer;
57
import com.iver.utiles.extensionPoints.ExtensionPoint;
58
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton;
59

    
60
import es.gva.cit.catalogClient.schemas.discoverer.Resource;
61

    
62
/**
63
 * This class is used to load a WMS layer in gvSIG
64
 * 
65
 * @author Jorge Piera Llodra (piera_jor@gva.es)
66
 */
67
public class WMSLayerLoader extends LayerLoader{
68
        
69
        
70
        public WMSLayerLoader(Resource resource) {
71
                super(resource);
72
                //load(getResource().getLinkage(),getResource().getName());
73
        }
74
        
75
        /**
76
         * This function loads a WMS resource 
77
         * @param host
78
         * URL where the server is located
79
         * @param sLayer
80
         * Layer name
81
         * @param crs
82
         * Coordenates System
83
         * @throws LayerLoaderException 
84
         */
85
        
86
        public void loadLayer() throws LayerLoaderException {
87
                String host = getResource().getLinkage();
88
                String sLayer = getResource().getName();
89
                
90
                FLayer flayer;
91
                flayer = createWMSLayer(host, sLayer);
92
                ExtensionPoint extensionPoint = (ExtensionPoint)ExtensionPointsSingleton.getInstance().get("CatalogLayersTOC");
93
                Object[] args = new Object[1];
94
                args[0] = flayer;
95
        
96
                Object wmsPropsPanel;
97
                try {
98
                        wmsPropsPanel = extensionPoint.create("OGC:WMS",args);
99
                        PluginServices.getMDIManager().addWindow((IWindow)wmsPropsPanel);
100
                        addLayerToView(flayer);
101
                } catch (SecurityException e) {
102
                        // TODO Auto-generated catch block
103
                        e.printStackTrace();
104
                } catch (IllegalArgumentException e) {
105
                        // TODO Auto-generated catch block
106
                        e.printStackTrace();
107
                } catch (NoSuchMethodException e) {
108
                        // TODO Auto-generated catch block
109
                        e.printStackTrace();
110
                } catch (InstantiationException e) {
111
                        // TODO Auto-generated catch block
112
                        e.printStackTrace();
113
                } catch (IllegalAccessException e) {
114
                        // TODO Auto-generated catch block
115
                        e.printStackTrace();
116
                } catch (InvocationTargetException e) {
117
                        // TODO Auto-generated catch block
118
                        e.printStackTrace();
119
                }        
120
        }
121
        
122
        /**
123
         * It retrieves a getCapabilities file and loads the layer in gvSIG
124
         * @param host
125
         * WMS URL
126
         * @param sLayer
127
         * Layer Name
128
         * @return
129
         * FLayer
130
         * @throws ServerOutOfOrderException
131
         * @throws ProtocolException
132
         * @throws MalformedURLException
133
         * @throws WMSException
134
         * @throws IOException
135
         * @throws UnsupportedVersionException 
136
         * @throws ValidationException 
137
         * @throws IllegalStateException 
138
         * @throws LayerLoaderException 
139
         */
140
        private FLayer createWMSLayer(String host, String sLayer) throws  LayerLoaderException{
141
                ExtensionPoint extensionPoint = (ExtensionPoint)ExtensionPointsSingleton.getInstance().get("CatalogLayers");
142
                Map args = new HashMap();
143
                args.put("host",host);
144
                args.put("layer",sLayer);
145
                try {
146
                        return (FLayer)extensionPoint.create("OGC:WMS", args  );
147
                } catch(Exception e) {
148
                        throw new LayerLoaderException(getErrorMessage(),getWindowMessage());
149
                }
150
        }
151
        
152
        /*
153
         *  (non-Javadoc)
154
         * @see es.gva.cit.gvsig.catalogClient.loaders.LayerLoader#getErrorMessage()
155
         */
156
        protected String getErrorMessage() {
157
                return Messages.getText("wmsError") + ".\n" +
158
                Messages.getText("server") + ": " + 
159
                getResource().getLinkage() + "\n" +
160
                Messages.getText("layer") + ": " +
161
                getResource().getName();                
162
        }
163
        
164
        /*
165
         *  (non-Javadoc)
166
         * @see es.gva.cit.gvsig.catalogClient.loaders.LayerLoader#getWindowMessage()
167
         */
168
        protected String getWindowMessage() {
169
                return Messages.getText("loadWMS");
170
        }        
171
}