Statistics
| Revision:

svn-gvsig-desktop / branches / v10 / extensions / extPublishMapserver / src / org / gvsig / publish / mapserver / model / wfs / MapserverWFSLayer.java @ 22616

History | View | Annotate | Download (7.87 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004-2006 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 Iba?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 org.gvsig.publish.mapserver.model.wfs;
42

    
43
import java.awt.geom.Rectangle2D;
44

    
45
import org.gvsig.publish.PublishLogger;
46
import org.gvsig.publish.exceptions.PublishException;
47
import org.gvsig.publish.infoproject.IDataSourceInfo;
48
import org.gvsig.publish.infoproject.ILayerInfo;
49
import org.gvsig.publish.infoproject.datasources.IDataBaseInfo;
50
import org.gvsig.publish.mapserver.conf.MapFile;
51
import org.gvsig.publish.mapserver.conf.MapFile.CRS;
52
import org.gvsig.publish.mapserver.conf.MapFile.Layer;
53
import org.gvsig.publish.mapserver.model.Mapserver;
54
import org.gvsig.publish.mapserver.util.MapserverUtilities;
55
import org.gvsig.publish.ogcmetadata.IOGCCommonMetadata;
56
import org.gvsig.publish.ogcmetadata.OGCCommonMetadata;
57
import org.gvsig.publish.serversmodel.RemoteResource;
58

    
59
import com.iver.utiles.XMLEntity;
60

    
61
public class MapserverWFSLayer extends RemoteResource implements IOGCCommonMetadata {
62

    
63
        public final static String REGISTER_TAG="mapserver_wfs_feature";
64
        //associations
65
        private OGCCommonMetadata ogcMetadata = null;
66
        private MapFile.Layer config = null;
67
        /**
68
         * Constructor
69
         * 
70
         * @param service
71
         */
72
        public MapserverWFSLayer(MapserverWFS service) {
73
                super(service);
74
                ogcMetadata = new OGCCommonMetadata();                
75
        }
76

    
77
        /**
78
         * Initializes the remote resource name and title with the name and title of the layer
79
         *
80
         * @see org.gvsig.publish.serversmodel.RemoteResource#setLayerInfo(org.gvsig.publish.infoproject.ILayerInfo)
81
         */
82
        public void setLayerInfo(ILayerInfo layerInfo) {
83
                super.setLayerInfo(layerInfo);
84
                setName(getLayerInfo().getName());
85
                setTitle(getLayerInfo().getTitle());
86
                setAbstract("generated by gvSIG");        
87
        }
88

    
89
        /**
90
         * Generates a new layer configuration in the mapfile when is invoked 
91
         * @see org.gvsig.publish.serversmodel.RemoteResource#publish()
92
         */
93
        public void publish() throws PublishException {
94
                config = new MapFile.Layer();
95
                getMapServer().getConfigFile().add(config);
96
                generateLayerSection();
97
                //publish all its childs                
98
                super.publish();
99
        }
100
        /**
101
         * Creates the object MAP->LAYER
102
         * @throws PublishException
103
         */
104
        private void generateLayerSection() throws PublishException{
105
                //LAYER
106
                config.name = getName();
107
                config.status = "ON";
108
                config.debug = getMapServer().isDebug();
109
                config.type = MapserverUtilities.getTypeParameter(getLayerInfo().getDataSource());
110
                generateDataParameter();
111
                config.connectiontype = MapserverUtilities.getConnectionTypeParameter(getLayerInfo().getDataSource());
112
                config.connection = MapserverUtilities.getConnectionParameter(getLayerInfo().getDataSource());                
113
                config.dump = true;                
114

    
115
                //PROJECTION                 
116
                config.layercrs = new CRS(getLayerInfo().getDataSource().getEPSG(),true);                                
117
                //METADATA
118
                generateMetadata(config);
119

    
120
        }
121
        /**
122
         * Generates the LAYER->DATA parameter 
123
         *  
124
         */
125
        private void generateDataParameter(){
126
                IDataSourceInfo ds = getLayerInfo().getDataSource();
127
                if (ds.getType() == IDataSourceInfo.POSTGIS_TYPE){
128
                        IDataBaseInfo db = (IDataBaseInfo)ds;
129
                        String table = db.getTableName();
130
                        String schema = db.getSchemaName();
131
                        if (schema !=null){
132
                                table = schema+ "." + table;
133
                        }
134
                        config.data ="the_geom from "  + table + " using unique " + db.getGID() + " using srid=" + ds.getSRID(); 
135
                }else{
136
                        config.data = getService().getServer().getPublication().getServerSideFilePath(ds);
137
                }                                
138
        }
139

    
140
        private Mapserver getMapServer(){
141
                //Cast to Mapserver
142
                Mapserver mapserver = (Mapserver)getService().getServer();
143
                return mapserver;
144
        }
145
        /**
146
         * Generates the METADATA object
147
         * @param mapLayer
148
         */
149
        private void generateMetadata(Layer mapLayer){
150
                //add metadata
151
                mapLayer.metadata.wfs_name = getName();
152
                mapLayer.metadata.wfs_title = getTitle();
153
                mapLayer.metadata.wfs_abstract = getAbstract();
154
                Rectangle2D aux = getLayerInfo().getDataSource().getNativeBBox();
155
                String bbox = aux.getMinX() + " " + aux.getMinY() + " " + aux.getMaxX() + " " + aux.getMaxY();
156
                mapLayer.metadata.wfs_extent = bbox;
157
                mapLayer.metadata.gml_include_items = "all";
158

    
159
        }
160
        /*
161
         * (non-Javadoc)
162
         * @see com.iver.utiles.IPersistance#getClassName()
163
         */                
164
        public String getClassName() {
165
                return "MapserverWFSLayer";
166
        }
167
        /*
168
         * (non-Javadoc)
169
         * @see org.gvsig.publish.serversmodel.RemoteResource#getXMLEntity()
170
         */
171
        public XMLEntity getXMLEntity() {                
172
                XMLEntity xml=super.getXMLEntity();
173
                //put version and name
174
                xml.setName(getClassName());
175
                xml.putProperty("version", getVersion());
176
                //put associations
177
                XMLEntity child = new XMLEntity();
178
                child.setName("ogcmetadata");
179
                child.addChild(ogcMetadata.getXMLEntity());
180
                xml.addChild(child);
181
//                child = new XMLEntity();
182
//                child.setName("mapserverlayer");
183
//                child.addChild(layerMapserver.getXMLEntity());
184
//                xml.addChild(child);        
185
                return xml;
186
        }
187
        /*
188
         * (non-Javadoc)
189
         * @see org.gvsig.publish.serversmodel.RemoteResource#setXMLEntity(com.iver.utiles.XMLEntity)
190
         */
191
        public void setXMLEntity(XMLEntity xml) {
192
                //check version
193
                int version = xml.getIntProperty("version");
194
                if (version != getVersion()){
195
                        PublishLogger.getLog().error("ERROR: " + getClassName() + ": the version doesn't match!");                        
196
                        return;
197
                }
198
                super.setXMLEntity(xml);                                                
199
                //set associations
200
                XMLEntity child = xml.firstChild("name","ogcmetadata");
201
                ogcMetadata.setXMLEntity(child.getChild(0));                
202
//                child = xml.firstChild("name","mapserverlayer");
203
//                layerMapserver.setXMLEntity(child.getChild(0));
204

    
205
        }
206

    
207
        /*
208
         * (non-Javadoc)
209
         * @see org.gvsig.publish.serversmodel.RemoteResource#getRegisterTag()
210
         */
211
        public String getRegisterTag() {                
212
                return REGISTER_TAG;
213
        }
214
        /*
215
         * (non-Javadoc)
216
         * @see org.gvsig.publish.ogcmetadata.IOGCCommonMetadata#getTitle()
217
         */
218
        public String getTitle() {
219
                return ogcMetadata.getTitle();
220
        }
221
        /*
222
         * (non-Javadoc)
223
         * @see org.gvsig.publish.ogcmetadata.IOGCCommonMetadata#getAbstract()
224
         */
225
        public String getAbstract() {                
226
                return ogcMetadata.getAbstract();
227
        }
228
        /*
229
         * (non-Javadoc)
230
         * @see org.gvsig.publish.ogcmetadata.IOGCCommonMetadata#getName()
231
         */
232
        public String getName() {                
233
                return ogcMetadata.getName();
234
        }
235
        /*
236
         * (non-Javadoc)
237
         * @see org.gvsig.publish.ogcmetadata.IOGCCommonMetadata#setAbstract(java.lang.String)
238
         */
239
        public void setAbstract(String description) {
240
                ogcMetadata.setAbstract(description);                
241
        }
242
        /*
243
         * (non-Javadoc)
244
         * @see org.gvsig.publish.ogcmetadata.IOGCCommonMetadata#setName(java.lang.String)
245
         */
246
        public void setName(String name) {
247
                ogcMetadata.setName(name);                
248
        }
249
        /*
250
         * (non-Javadoc)
251
         * @see org.gvsig.publish.ogcmetadata.IOGCCommonMetadata#setTitle(java.lang.String)
252
         */
253
        public void setTitle(String title) {
254
                ogcMetadata.setTitle(title);                
255
        }
256
        /*
257
         * (non-Javadoc)
258
         * @see org.gvsig.publish.IPublishPersistence#getVersion()
259
         */
260
        public int getVersion() {                
261
                return 1;
262
        }
263
        /*
264
         * (non-Javadoc)
265
         * @see java.lang.Object#toString()
266
         */
267
        public String toString(){
268
                return getName();
269
        }
270
}