Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / VectorialAdapter.java @ 3601

History | View | Annotate | Download (4.12 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.Image;
44

    
45
import com.hardcode.driverManager.DriverLoadException;
46
import com.hardcode.gdbms.engine.data.DataSource;
47
import com.hardcode.gdbms.engine.values.Value;
48
import com.iver.cit.gvsig.fmap.DriverException;
49
import com.iver.cit.gvsig.fmap.core.DefaultFeature;
50
import com.iver.cit.gvsig.fmap.core.IFeature;
51
import com.iver.cit.gvsig.fmap.core.IGeometry;
52
import com.iver.cit.gvsig.fmap.drivers.DriverAttributes;
53
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
54
import com.iver.cit.gvsig.fmap.drivers.VectorialDriver;
55

    
56

    
57
/**
58
 * Clase padre de los adaptadores de los drivers. De momento mantiene solo el
59
 * ?ndice creado sobre la capa
60
 */
61
public abstract class VectorialAdapter implements ReadableVectorial {
62
        protected VectorialDriver driver;
63

    
64
        /**
65
         * Establece el driver sobre el que act?a el adaptador
66
         *
67
         * @param driver
68
         */
69
        public void setDriver(VectorialDriver driver) {
70
                this.driver = driver;
71
        }
72

    
73
        /**
74
         * Obtiene una referencia al objeto que implementa la interfaz vectorial
75
         * con el fin de que las Strategy puedan optimizar en funci?n del driver.
76
         *
77
         * @return VectorialDriver
78
         */
79
        public VectorialDriver getDriver() {
80
                return driver;
81
        }
82

    
83

    
84
        /**
85
         * Devuelve el DataSource a pasrtir del nombre.
86
         *
87
         * @return DataSource.
88
         *
89
         * @throws DriverLoadException
90
         */
91
        public abstract DataSource getRecordset()
92
                throws DriverLoadException;
93

    
94
    
95
            
96
        /**
97
         * Por defecto devuelve null, y se le pone el icono por defecto.
98
         * Si el driver reescribe este m?todo, se usar? este icono en el TOC.
99
         * 
100
         * @return
101
         */
102
        public Image getImageIcon()
103
        {
104
            return null; 
105
        }
106
        
107
        public DriverAttributes getDriverAttributes()
108
        {
109
            if (driver != null)
110
                return driver.getDriverAttributes();
111
            return null;
112
        }
113
    
114
    /**
115
     * En la implementaci?n por defecto podemos hacer que cada
116
     * feature tenga ID = numero de registro.
117
     * En el DBAdapter podr?amos "overrride" este m?todo y poner
118
     * como ID de la Feature el campo ?nico escogido en
119
     * la base de datos.
120
     * @param numReg
121
     * @return
122
     * @throws DriverException
123
     */
124
    public IFeature getFeature(int numReg) throws DriverException
125
    {
126
        IGeometry geom;
127
        IFeature feat = null;
128
        try {
129
            geom = getShape(numReg);
130
            DataSource rs = getRecordset();
131
            Value[] regAtt = new Value[rs.getFieldCount()];
132
            for (int fieldId=0; fieldId < rs.getFieldCount(); fieldId++ )
133
            {       
134
                regAtt[fieldId] =  rs.getFieldValue(numReg, fieldId);
135
            }
136
            
137
            feat = new DefaultFeature(geom, regAtt, numReg + "");
138
        } catch (DriverIOException e) {
139
            throw new DriverException(e);
140
        } catch (DriverLoadException e) {
141
            throw new DriverException(e);
142
        } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
143
            throw new DriverException(e);
144
        }
145
        return feat;
146
    }
147

    
148
}