Statistics
| Revision:

svn-gvsig-desktop / tags / v1_1_Build_1001 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / VectorialAdapter.java @ 11984

History | View | Annotate | Download (5.82 KB)

1 1100 fjp
/* 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 214 fernando
package com.iver.cit.gvsig.fmap.layers;
42
43 3601 fjp
import java.awt.Image;
44 3936 fjp
import java.awt.geom.Rectangle2D;
45
import java.io.IOException;
46 214 fernando
47 3601 fjp
import com.hardcode.driverManager.DriverLoadException;
48 408 fernando
import com.hardcode.gdbms.engine.data.DataSource;
49 3612 fjp
import com.hardcode.gdbms.engine.data.DataSourceFactory;
50
import com.hardcode.gdbms.engine.data.driver.ObjectDriver;
51
import com.hardcode.gdbms.engine.data.edition.DataWare;
52 3207 fjp
import com.hardcode.gdbms.engine.values.Value;
53 651 fernando
import com.iver.cit.gvsig.fmap.DriverException;
54 3207 fjp
import com.iver.cit.gvsig.fmap.core.DefaultFeature;
55
import com.iver.cit.gvsig.fmap.core.IFeature;
56
import com.iver.cit.gvsig.fmap.core.IGeometry;
57 1233 fjp
import com.iver.cit.gvsig.fmap.drivers.DriverAttributes;
58 214 fernando
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
59 4085 fjp
import com.iver.cit.gvsig.fmap.drivers.IFeatureIterator;
60
import com.iver.cit.gvsig.fmap.drivers.RandomAccessFeatureIterator;
61 11928 caballero
import com.iver.cit.gvsig.fmap.drivers.IVectorialDatabaseDriver;
62 214 fernando
import com.iver.cit.gvsig.fmap.drivers.VectorialDriver;
63 1034 vcaballero
64 214 fernando
/**
65 1034 vcaballero
 * Clase padre de los adaptadores de los drivers. De momento mantiene solo el
66
 * ?ndice creado sobre la capa
67 214 fernando
 */
68 1691 fjp
public abstract class VectorialAdapter implements ReadableVectorial {
69
        protected VectorialDriver driver;
70 4085 fjp
71 214 fernando
        /**
72 1034 vcaballero
         * Establece el driver sobre el que act?a el adaptador
73 4085 fjp
         *
74 1034 vcaballero
         * @param driver
75
         */
76
        public void setDriver(VectorialDriver driver) {
77
                this.driver = driver;
78
        }
79 214 fernando
80 1034 vcaballero
        /**
81 4085 fjp
         * Obtiene una referencia al objeto que implementa la interfaz vectorial con
82
         * el fin de que las Strategy puedan optimizar en funci?n del driver.
83
         *
84 1034 vcaballero
         * @return VectorialDriver
85
         */
86
        public VectorialDriver getDriver() {
87
                return driver;
88
        }
89 214 fernando
90 1034 vcaballero
        /**
91
         * Devuelve el DataSource a pasrtir del nombre.
92 4085 fjp
         *
93 1034 vcaballero
         * @return DataSource.
94 4085 fjp
         *
95 408 fernando
         * @throws DriverLoadException
96 217 fernando
         */
97 3959 caballero
        public abstract SelectableDataSource getRecordset()
98 4085 fjp
                        throws DriverLoadException;
99 1034 vcaballero
100 309 fernando
        /**
101 4085 fjp
         * Por defecto devuelve null, y se le pone el icono por defecto. Si el
102
         * driver reescribe este m?todo, se usar? este icono en el TOC.
103
         *
104 1233 fjp
         * @return
105
         */
106 4085 fjp
        public Image getImageIcon() {
107
                return null;
108 1233 fjp
        }
109 3959 caballero
110 4085 fjp
        public DriverAttributes getDriverAttributes() {
111
                if (driver != null)
112
                        return driver.getDriverAttributes();
113
                return null;
114 1233 fjp
        }
115 3959 caballero
116 3943 fjp
        /**
117
         * @see com.iver.cit.gvsig.fmap.layers.ReadableVectorial#getShapeCount()
118
         */
119
        public int getShapeCount() throws DriverIOException {
120 3959 caballero
                try {
121 3943 fjp
                        return getDriver().getShapeCount();
122
                } catch (IOException e) {
123
                        throw new DriverIOException(e);
124
                }
125
        }
126
127
        /**
128
         * @see com.iver.cit.gvsig.fmap.layers.ReadableVectorial#getFullExtent()
129
         */
130
        public Rectangle2D getFullExtent() throws DriverIOException {
131
                try {
132 5400 fjp
                        Rectangle2D aux = getDriver().getFullExtent();
133
                        // Para evitar que una nueva capa a?adida a una vista vac?a no
134
                        // tenga un lienzo para pintar.
135
                        if (aux == null)
136
                                aux = new Rectangle2D.Double(1,1,10,10);
137
                        return aux;
138 3943 fjp
                } catch (IOException e) {
139
                        throw new DriverIOException(e);
140
                }
141
        }
142 3959 caballero
143 4085 fjp
        /**
144
         * En la implementaci?n por defecto podemos hacer que cada feature tenga ID =
145
         * numero de registro. En el DBAdapter podr?amos "overrride" este m?todo y
146
         * poner como ID de la Feature el campo ?nico escogido en la base de datos.
147
         *
148
         * @param numReg
149
         * @return
150
         * @throws DriverException
151
         */
152
        public IFeature getFeature(int numReg) throws DriverException {
153
                IGeometry geom;
154
                IFeature feat = null;
155
                try {
156
                        geom = getShape(numReg);
157
                        DataSource rs = getRecordset();
158
                        Value[] regAtt = new Value[rs.getFieldCount()];
159
                        for (int fieldId = 0; fieldId < rs.getFieldCount(); fieldId++) {
160
                                regAtt[fieldId] = rs.getFieldValue(numReg, fieldId);
161
                        }
162 3959 caballero
163 4085 fjp
                        feat = new DefaultFeature(geom, regAtt, numReg + "");
164
                } catch (DriverIOException e) {
165
                        throw new DriverException(e);
166
                } catch (DriverLoadException e) {
167
                        throw new DriverException(e);
168
                } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
169
                        throw new DriverException(e);
170
                }
171
                return feat;
172
        }
173 3248 fjp
174 4085 fjp
        /*
175
         * (non-Javadoc)
176
         *
177
         * @see com.iver.cit.gvsig.fmap.layers.ReadableVectorial#getFeatureIterator(java.awt.geom.Rectangle2D,
178
         *      java.lang.String) Lo sobreescribir?n los adapters para base de datos
179
         *      espacial. Por defecto, suponemos un buen acceso aleatorio y usamos
180
         *      getFeature(i)
181
         */
182 4115 fjp
        /* public IFeatureIterator getFeatureIterator(Rectangle2D r, String strEPSG)
183 4085 fjp
                        throws DriverException {
184
                try {
185
                        return new RandomAccessFeatureIterator(driver, getRecordset(), r,
186
                                        strEPSG);
187
                } catch (DriverLoadException e) {
188
                        throw new DriverException(e);
189
                }
190
        }
191 3959 caballero

192 4085 fjp
        public IFeatureIterator getFeatureIterator(String strEPSG)
193
                        throws DriverException {
194
                try {
195
                        return new RandomAccessFeatureIterator(driver, getRecordset(), strEPSG);
196
                } catch (DriverLoadException e) {
197
                        throw new DriverException(e);
198
                }
199 4115 fjp
        } */
200 3959 caballero
201 214 fernando
}