Statistics
| Revision:

root / trunk / extensions / extWFS / src / com / iver / cit / gvsig / fmap / layers / WFSAdapter.java @ 4252

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

    
43
import java.awt.geom.Rectangle2D;
44
import java.io.IOException;
45

    
46
import com.hardcode.driverManager.DriverLoadException;
47
import com.hardcode.gdbms.engine.data.DataSource;
48
import com.hardcode.gdbms.engine.data.DataSourceFactory;
49
import com.hardcode.gdbms.engine.data.NoSuchTableException;
50
import com.hardcode.gdbms.engine.data.driver.ObjectDriver;
51
import com.iver.cit.gvsig.fmap.DriverException;
52
import com.iver.cit.gvsig.fmap.core.FShape;
53
import com.iver.cit.gvsig.fmap.core.IGeometry;
54
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
55
import com.iver.cit.gvsig.fmap.drivers.IFeatureIterator;
56
import com.iver.cit.gvsig.fmap.drivers.wfs.IWFSdriver;
57

    
58

    
59
/**
60
 * Adapta un driver de WFS a la interfaz vectorial, manteniendo adem?s el
61
 * estado necesario por una capa vectorial WFS (URL del host, estado del
62
 * protocolo)
63
 */
64
public class WFSAdapter extends VectorialAdapter {
65
        //private URL host;
66
        //private VectorialAdapter tempAdapter;
67
        //private int numReg=-1;
68
        private SelectableDataSource ds = null;
69
                /**
70
                 * incrementa el contador de las veces que se ha abierto el fichero.
71
                 * Solamente cuando el contador est? a cero pide al driver que conecte con
72
                 * la base de datos
73
                 */
74
                public void start() {
75
                    try {
76
                        ((IWFSdriver)driver).open();
77
                    } catch (DriverException e) {
78
                        // TODO Auto-generated catch block
79
                        e.printStackTrace();
80
                    }
81
                
82
                }
83

    
84
                /**
85
                 * decrementa el contador de n?mero de aperturas y cuando llega a cero pide
86
                 * al driver que cierre la conexion con el servidor de base de datos
87
                 */
88
                public void stop() {
89
                    ((IWFSdriver)driver).close();
90
                }
91

    
92
                public IFeatureIterator getFeatureIterator(Rectangle2D r, String strEPSG) throws DriverException, IOException
93
                {
94
                    return ((IWFSdriver)driver).getFeatureIterator(r, strEPSG);
95
                }
96
                
97
                /*public String getFields()
98
                {
99
                    return ((IWFSDriver)driver).getFields();            
100
                }
101
                public String getWhereClause()
102
                {
103
                    return ((VectorialDatabaseDriver)driver).getWhereClause();
104
                }
105
                public String getTableName()
106
                {
107
                    return ((VectorialDatabaseDriver)driver).getTableName();
108
                }
109
                
110
                */
111
                /**
112
                 * @see com.iver.cit.gvsig.fmap.layers.ReadableVectorial#getShape(int)
113
                 */
114
                public IGeometry getShape(int index) throws DriverIOException {
115
                    IGeometry geom = null;
116
                    geom = ((IWFSdriver)driver).getShape(index);
117
                    return geom;
118
                }
119

    
120
                /**
121
                 * @throws DriverException
122
                 * @see com.iver.cit.gvsig.fmap.layers.ReadableVectorial#getShapeCount()
123
                 */
124
                public int getShapeCount() throws DriverIOException {
125
                        try {
126
                                return ((IWFSdriver)driver).getShapeCount();
127
                        } catch (IOException e) {
128
                                e.printStackTrace();
129
                        }        
130
                        return -1;
131
                }
132

    
133
                /**
134
                 * @see com.iver.cit.gvsig.fmap.layers.ReadableVectorial#getFullExtent()
135
                 */
136
                public Rectangle2D getFullExtent() {
137
                    return ((IWFSdriver)driver).getFullExtent();
138
                }
139

    
140

    
141
                /**
142
                 * @see com.iver.cit.gvsig.fmap.layers.ReadableVectorial#getShapeType()
143
                 */
144
                public int getShapeType() throws DriverIOException {
145
                        return FShape.MULTI;
146
                }
147

    
148
                /**
149
                 * @see com.iver.cit.gvsig.fmap.layers.VectorialAdapter#getRecordset()
150
                 */
151
                public SelectableDataSource getRecordset() throws DriverLoadException {
152
                    if (driver instanceof IWFSdriver)
153
                    {
154
                                String name = LayerFactory.getDataSourceFactory().addDataSource((ObjectDriver)driver);
155
                                try {
156
                        // ds = LayerFactory.getDataSourceFactory().createRandomDataSource(name, DataSourceFactory.AUTOMATIC_OPENING);
157
                        ds = new SelectableDataSource(LayerFactory.getDataSourceFactory().createRandomDataSource(name, DataSourceFactory.AUTOMATIC_OPENING));
158
                    } catch (NoSuchTableException e) {
159
                        throw new RuntimeException(e);
160
                                } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
161
                                        throw new RuntimeException(e);
162
                                }
163
                    }
164
                        return ds;
165
                }
166

    
167
                public String getClassName() {
168
                        return this.getClassName();
169
                }
170
}