root / trunk / libraries / libDataSource / src / org / gvsig / data / datastores / vectorial / driver / MemoryDriver.java @ 19399
History | View | Annotate | Download (8.56 KB)
1 |
/*
|
---|---|
2 |
* Created on 27-dic-2004
|
3 |
*
|
4 |
* TODO To change the template for this generated file go to
|
5 |
* Window - Preferences - Java - Code Generation - Code and Comments
|
6 |
*/
|
7 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
8 |
*
|
9 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
10 |
*
|
11 |
* This program is free software; you can redistribute it and/or
|
12 |
* modify it under the terms of the GNU General Public License
|
13 |
* as published by the Free Software Foundation; either version 2
|
14 |
* of the License, or (at your option) any later version.
|
15 |
*
|
16 |
* This program is distributed in the hope that it will be useful,
|
17 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
19 |
* GNU General Public License for more details.
|
20 |
*
|
21 |
* You should have received a copy of the GNU General Public License
|
22 |
* along with this program; if not, write to the Free Software
|
23 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
24 |
*
|
25 |
* For more information, contact:
|
26 |
*
|
27 |
* Generalitat Valenciana
|
28 |
* Conselleria d'Infraestructures i Transport
|
29 |
* Av. Blasco Ib??ez, 50
|
30 |
* 46010 VALENCIA
|
31 |
* SPAIN
|
32 |
*
|
33 |
* +34 963862235
|
34 |
* gvsig@gva.es
|
35 |
* www.gvsig.gva.es
|
36 |
*
|
37 |
* or
|
38 |
*
|
39 |
* IVER T.I. S.A
|
40 |
* Salamanca 50
|
41 |
* 46005 Valencia
|
42 |
* Spain
|
43 |
*
|
44 |
* +34 963163400
|
45 |
* dac@iver.es
|
46 |
*/
|
47 |
package org.gvsig.data.datastores.vectorial.driver; |
48 |
|
49 |
import java.awt.geom.Rectangle2D; |
50 |
import java.sql.Types; |
51 |
import java.util.ArrayList; |
52 |
import java.util.Date; |
53 |
|
54 |
import javax.swing.table.DefaultTableModel; |
55 |
|
56 |
import org.gvsig.data.vectorial.IFeature; |
57 |
|
58 |
|
59 |
public abstract class MemoryDriver implements IDriver{ |
60 |
private ArrayList arrayFeatures = new ArrayList(); |
61 |
private Rectangle2D fullExtent; |
62 |
private int m_Position; |
63 |
private DefaultTableModel m_TableModel = new DefaultTableModel(); |
64 |
private int[] fieldWidth=null; |
65 |
|
66 |
public void addFeature(IFeature feature){ |
67 |
arrayFeatures.add(feature); |
68 |
// Rectangle2D boundsShp=((IGeometry)feature.getDefaultGeometry()).getRectangle2D();
|
69 |
// if (fullExtent == null) {
|
70 |
// fullExtent = boundsShp;
|
71 |
// } else {
|
72 |
// fullExtent.add(boundsShp);
|
73 |
// }
|
74 |
} |
75 |
// /**
|
76 |
// * A?ade un shape.
|
77 |
// *
|
78 |
// * @param geom shape.
|
79 |
// * @param row fila.
|
80 |
// */
|
81 |
// public void addGeometry(IGeometry geom, Object[] row) {
|
82 |
// if (geom == null) {
|
83 |
// return; // No a?adimos nada
|
84 |
// }
|
85 |
//
|
86 |
// Rectangle2D boundsShp = geom.getBounds();
|
87 |
// memShapeInfo.addShapeInfo(boundsShp, geom.getGeometryType());
|
88 |
// arrayGeometries.add(geom);
|
89 |
// if (fieldWidth==null) {
|
90 |
// initializeFieldWidth(row);
|
91 |
// }
|
92 |
// actualizeFieldWidth(row);
|
93 |
// m_TableModel.addRow(row);
|
94 |
//
|
95 |
// try {
|
96 |
// fullExtent = getFullExtent();
|
97 |
// } catch (ReadDriverException e) {
|
98 |
// e.printStackTrace();
|
99 |
// }
|
100 |
//
|
101 |
// if (fullExtent == null) {
|
102 |
// fullExtent = boundsShp;
|
103 |
// } else {
|
104 |
// fullExtent.add(boundsShp);
|
105 |
// }
|
106 |
//
|
107 |
// m_Position++;
|
108 |
// }
|
109 |
|
110 |
|
111 |
// /**
|
112 |
// * M?todo de conveniencia, para poder a?adir directamente un shape
|
113 |
// * o una IGeometry. (Arriba est? el de a?adir una IGeometry.
|
114 |
// * @param shp
|
115 |
// * @param row
|
116 |
// */
|
117 |
// public void addShape(FShape shp, Object[] row) {
|
118 |
// if (shp == null) {
|
119 |
// return; // No a?adimos nada
|
120 |
// }
|
121 |
// IGeometry geom = ShapeFactory.createGeometry(shp);
|
122 |
//
|
123 |
// addGeometry(geom, row);
|
124 |
// }
|
125 |
|
126 |
// /**
|
127 |
// * Devuelve el extent a partir de un ?ndice.
|
128 |
// *
|
129 |
// * @param index ?ndice.
|
130 |
// *
|
131 |
// * @return Extent.
|
132 |
// */
|
133 |
// public Rectangle2D getShapeBounds(int index) throws ReadDriverException {
|
134 |
// return memShapeInfo.getBoundingBox(index);
|
135 |
// }
|
136 |
|
137 |
// /**
|
138 |
// * Devuelve el tipo del shape.
|
139 |
// *
|
140 |
// * @param index ?ndice.
|
141 |
// *
|
142 |
// * @return tipo del shape.
|
143 |
// */
|
144 |
// public int getShapeType(int index) {
|
145 |
// return memShapeInfo.getType(index);
|
146 |
// }
|
147 |
|
148 |
|
149 |
public IFeature getFeature(int index) { |
150 |
IFeature feature = (IFeature) arrayFeatures.get(index); |
151 |
|
152 |
return feature;
|
153 |
} |
154 |
|
155 |
public long getFeatureCount() { |
156 |
return arrayFeatures.size();
|
157 |
} |
158 |
|
159 |
/* (non-Javadoc)
|
160 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#getFullExtent()
|
161 |
*/
|
162 |
public Rectangle2D getFullExtent() { |
163 |
return fullExtent;
|
164 |
} |
165 |
|
166 |
|
167 |
/* (non-Javadoc)
|
168 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#getShapeType()
|
169 |
*/
|
170 |
public abstract int getShapeType(); |
171 |
|
172 |
/* (non-Javadoc)
|
173 |
* @see com.hardcode.driverManager.Driver#getName()
|
174 |
*/
|
175 |
public abstract String getName(); |
176 |
|
177 |
/**
|
178 |
* @see com.hardcode.gdbms.engine.data.ReadDriver#getFieldType(int)
|
179 |
*/
|
180 |
|
181 |
/*
|
182 |
* azabala, bug 666
|
183 |
* Habra que estudiar como hacer, porque si una fila tiene el primer valor
|
184 |
* (o todos) a NullValue, devolvera como tipo de dato Types.NULL.
|
185 |
* Quizas, habra que hacer que los MemoryDriver tb tengan un ITableDefinition.
|
186 |
*
|
187 |
* DxfMemoryDriver no obstante si que tiene informacion sobre el esquema, asi
|
188 |
* que debera sobreescribir este metodo para salvar el bug
|
189 |
* (metodo getTableDefinition)
|
190 |
*
|
191 |
*
|
192 |
*
|
193 |
*
|
194 |
*/
|
195 |
// public int getFieldType(int i) throws ReadDriverException {
|
196 |
// // TODO: Revisar esto. Por ejemplo, el long
|
197 |
// if (getRowCount() > 1)
|
198 |
// {
|
199 |
// Value val = getFieldValue(0,i);
|
200 |
// if (val.getSQLType() == Types.INTEGER)
|
201 |
// // Sabemos que es num?rico, pero no sabemos
|
202 |
// // si luego habr? otra cosa.
|
203 |
// return Types.FLOAT;
|
204 |
// else
|
205 |
// return val.getSQLType();
|
206 |
// }
|
207 |
// else
|
208 |
// {
|
209 |
// // TODO: ESTO CREO QUE NO TIENE SENTIDO. SIEMPRE DEVUELVE Object.class, lo dice en
|
210 |
// // la documentaci?n. Creo que habr?a que quitarlo.
|
211 |
// if (m_TableModel.getColumnClass(i) == String.class)
|
212 |
// return Types.VARCHAR;
|
213 |
// if (m_TableModel.getColumnClass(i) == Float.class)
|
214 |
// return Types.FLOAT;
|
215 |
// if (m_TableModel.getColumnClass(i) == Double.class)
|
216 |
// return Types.DOUBLE;
|
217 |
// if (m_TableModel.getColumnClass(i) == Double.class)
|
218 |
// return Types.INTEGER;
|
219 |
// if (m_TableModel.getColumnClass(i) == Float.class)
|
220 |
// return Types.INTEGER;
|
221 |
// if (m_TableModel.getColumnClass(i) == Boolean.class)
|
222 |
// return Types.BIT;
|
223 |
// if (m_TableModel.getColumnClass(i) == Date.class)
|
224 |
// return Types.DATE;
|
225 |
// }
|
226 |
// return Types.VARCHAR;
|
227 |
// // return m_TableModel.getColumnClass(i);
|
228 |
//// throw new DriverException("Tipo no soportado: " + m_TableModel.getColumnClass(i).getName());
|
229 |
// }
|
230 |
// /* (non-Javadoc)
|
231 |
// * @see com.hardcode.gdbms.engine.data.ReadDriver#getFieldValue(long, int)
|
232 |
// */
|
233 |
// public Value getFieldValue(long rowIndex, int fieldId)
|
234 |
// throws ReadDriverException {
|
235 |
// return (Value) m_TableModel.getValueAt((int) rowIndex, fieldId);
|
236 |
// }
|
237 |
|
238 |
// /* (non-Javadoc)
|
239 |
// * @see com.hardcode.gdbms.engine.data.ReadDriver#getFieldCount()
|
240 |
// */
|
241 |
// public int getFieldCount() throws ReadDriverException {
|
242 |
// return m_TableModel.getColumnCount();
|
243 |
// }
|
244 |
|
245 |
// /* (non-Javadoc)
|
246 |
// * @see com.hardcode.gdbms.engine.data.ReadDriver#getFieldName(int)
|
247 |
// */
|
248 |
// public String getFieldName(int fieldId) throws ReadDriverException {
|
249 |
// return m_TableModel.getColumnName(fieldId);
|
250 |
// }
|
251 |
//
|
252 |
// /* (non-Javadoc)
|
253 |
// * @see com.hardcode.gdbms.engine.data.ReadDriver#getRowCount()
|
254 |
// */
|
255 |
// public long getRowCount() throws ReadDriverException {
|
256 |
// return arrayGeometries.size();
|
257 |
// }
|
258 |
|
259 |
// /* (non-Javadoc)
|
260 |
// * @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#reLoad()
|
261 |
// */
|
262 |
// public void reload() throws ReloadDriverException{
|
263 |
// memShapeInfo = new MemoryShapeInfo();
|
264 |
// arrayGeometries.clear();
|
265 |
// m_TableModel= new DefaultTableModel();
|
266 |
// fullExtent = null;
|
267 |
// m_Position = 0;
|
268 |
//
|
269 |
// }
|
270 |
// private void initializeFieldWidth(Object[] row) {
|
271 |
// fieldWidth=new int[row.length];
|
272 |
// for (int i=0;i<row.length;i++) {
|
273 |
// if (row[i] instanceof StringValue && row[i]==null)
|
274 |
// fieldWidth[i]=0;
|
275 |
// else
|
276 |
// fieldWidth[i]=((Value)row[i]).getWidth();
|
277 |
// }
|
278 |
// }
|
279 |
// /**
|
280 |
// * Actualize the width fields with StringValue.
|
281 |
// * @param row
|
282 |
// */
|
283 |
// private void actualizeFieldWidth(Object[] row) {
|
284 |
// for (int i=0;i<row.length;i++) {
|
285 |
// if (row[i] instanceof StringValue) {
|
286 |
// if (row[i]!=null) {
|
287 |
// int width=((StringValue)row[i]).getWidth();
|
288 |
// if (fieldWidth[i]<width) {
|
289 |
// fieldWidth[i]=width;
|
290 |
// }
|
291 |
// }
|
292 |
// }
|
293 |
// }
|
294 |
// }
|
295 |
public int getFieldWidth(int fieldId){ |
296 |
if (fieldWidth==null) |
297 |
return 1; |
298 |
return fieldWidth[fieldId];
|
299 |
} |
300 |
|
301 |
|
302 |
} |