Statistics
| Revision:

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

History | View | Annotate | Download (7.36 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.wcs;
42

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

    
57
import com.iver.utiles.XMLEntity;
58

    
59
public class MapserverWCSLayer extends RemoteResource implements IOGCCommonMetadata{
60

    
61
        public final static String REGISTER_TAG="mapserver_wcs_layer";
62
        /*
63
         * Properties
64
         */
65
        private OGCCommonMetadata ogcMetadata = null;
66
        private MapFile.Layer config = null;
67
        /**
68
         * Constructor
69
         * 
70
         * @param service
71
         */
72
        public MapserverWCSLayer(MapserverWCS service) {
73
                super(service);
74
                ogcMetadata = new OGCCommonMetadata();
75
        }
76
        /**
77
         * Initializes the remote resource name and title with the name and title of the layer
78
         */
79
        public void setLayerInfo(ILayerInfo layerInfo) {
80
                super.setLayerInfo(layerInfo);                
81
                setName(getLayerInfo().getName());
82
                setTitle(getLayerInfo().getTitle());
83
                setAbstract("generated by gvSIG");
84
        }
85
        private Mapserver getMapServer(){
86
                //Cast to Mapserver
87
                Mapserver mapserver = (Mapserver)getService().getServer();
88
                return mapserver;
89
        }
90

    
91
        /**
92
         * Generates a new layer configuration in the mapfile when is invoked
93
         * @see org.gvsig.publish.serversmodel.RemoteResource#publish()
94
         */
95
        public void publish() throws PublishException {        
96
                config = new MapFile.Layer();
97
                getMapServer().getConfigFile().add(config);
98

    
99
                generateLayerSection();
100

    
101
                //publish all its childs                
102
                super.publish();
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.transparency = getLayerInfo().getOpacityPercent();
114
                config.dump = true;                
115

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

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

    
137

    
138
        /**
139
         * Generates the METADATA object
140
         * @param mapLayer
141
         * @throws LayerInfoNotAvailableException 
142
         */
143
        private void generateMetadata(Layer mapLayer) {
144
                //add metadata
145
                mapLayer.metadata.wcs_name = getName();
146
                mapLayer.metadata.wcs_label =getTitle();
147
                mapLayer.metadata.wcs_description = getAbstract();
148
                //Rectangle2D aux = getLayerInfo().getBBox();
149
                //String bbox = aux.getMinX() + " " + aux.getMinY() + " " + aux.getMaxX() + " " + aux.getMaxY();
150
                //mapLayer.metadata.wcs_extent = bbox;        
151
                IDataSourceInfo ds = getLayerInfo().getDataSource();
152
                mapLayer.metadata.wcs_srs= ds.getEPSG();
153
                mapLayer.metadata.wcs_formats = MapserverUtilities.getOutputformatName(ds);
154
                mapLayer.metadata.wcs_nativeformat = MapserverUtilities.getOutputformatName(ds);
155
                mapLayer.metadata.wcs_rangeset_axes = "bands";
156
        }
157

    
158
        public String getClassName() {
159
                return "MapserverWCSLayer";
160
        }
161
        public XMLEntity getXMLEntity() {
162
                XMLEntity xml=super.getXMLEntity();
163
                //put version and name
164
                xml.setName(getClassName());
165
                xml.putProperty("version", getVersion());
166
                //put associations
167
                XMLEntity child = new XMLEntity();
168
                child.setName("ogcmetadata");
169
                child.addChild(ogcMetadata.getXMLEntity());
170
                xml.addChild(child);
171
                return xml;
172
        }
173

    
174
        public void setXMLEntity(XMLEntity xml) {
175
                //check version
176
                int version = xml.getIntProperty("version");
177
                if (version != getVersion()){
178
                        PublishLogger.getLog().error("ERROR: " + getClassName() + ": the version doesn't match!");                        
179
                        return;
180
                }
181
                super.setXMLEntity(xml);                                                
182
                //set associations
183
                XMLEntity child = xml.firstChild("name","ogcmetadata");
184
                ogcMetadata.setXMLEntity(child.getChild(0));                
185
        }
186

    
187
        /*
188
         * (non-Javadoc)
189
         * @see org.gvsig.publish.serversmodel.RemoteResource#getRegisterTag()
190
         */
191
        public String getRegisterTag() {
192
                return REGISTER_TAG;
193
        }
194
        /*
195
         * (non-Javadoc)
196
         * @see org.gvsig.publish.ogcmetadata.IOGCCommonMetadata#getAbstract()
197
         */
198
        public String getAbstract() {
199

    
200
                return ogcMetadata.getAbstract();
201
        }
202
        /*
203
         * (non-Javadoc)
204
         * @see org.gvsig.publish.ogcmetadata.IOGCCommonMetadata#getName()
205
         */
206
        public String getName() {
207

    
208
                return ogcMetadata.getName();
209
        }
210
        /*
211
         * (non-Javadoc)
212
         * @see org.gvsig.publish.ogcmetadata.IOGCCommonMetadata#getTitle()
213
         */
214
        public String getTitle() {
215

    
216
                return ogcMetadata.getTitle();
217
        }
218
        /*
219
         * (non-Javadoc)
220
         * @see org.gvsig.publish.ogcmetadata.IOGCCommonMetadata#setAbstract(java.lang.String)
221
         */
222
        public void setAbstract(String description) {
223
                ogcMetadata.setAbstract(description);                
224
        }
225
        /*
226
         * (non-Javadoc)
227
         * @see org.gvsig.publish.ogcmetadata.IOGCCommonMetadata#setName(java.lang.String)
228
         */
229
        public void setName(String name) {
230
                ogcMetadata.setName(name);                
231
        }
232
        /*
233
         * (non-Javadoc)
234
         * @see org.gvsig.publish.ogcmetadata.IOGCCommonMetadata#setTitle(java.lang.String)
235
         */
236
        public void setTitle(String title) {
237
                ogcMetadata.setTitle(title);                
238
        }
239
        /*
240
         * (non-Javadoc)
241
         * @see org.gvsig.publish.IPublishPersistence#getVersion()
242
         */
243
        public int getVersion() {
244
                return 1;
245
        }
246
        /*
247
         * (non-Javadoc)
248
         * @see java.lang.Object#toString()
249
         */
250
        public String toString(){
251
                return getName();
252
        }
253

    
254
}