Statistics
| Revision:

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

History | View | Annotate | Download (16.1 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 460 fernando
package com.iver.cit.gvsig.fmap.layers;
42
43 1828 fernando
import java.io.IOException;
44
45
import org.apache.log4j.Logger;
46 1836 fernando
import org.xml.sax.SAXException;
47 1828 fernando
48 5569 jmvivo
import com.hardcode.driverManager.Driver;
49 1828 fernando
import com.hardcode.driverManager.DriverLoadException;
50 10627 caballero
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
51
import com.hardcode.gdbms.driver.exceptions.ReloadDriverException;
52
import com.hardcode.gdbms.driver.exceptions.WriteDriverException;
53 460 fernando
import com.hardcode.gdbms.engine.data.DataSource;
54 546 fernando
import com.hardcode.gdbms.engine.data.DataSourceFactory;
55 6323 fjp
import com.hardcode.gdbms.engine.data.IDataSourceListener;
56 546 fernando
import com.hardcode.gdbms.engine.data.NoSuchTableException;
57 4863 fjp
import com.hardcode.gdbms.engine.data.SourceInfo;
58 1828 fernando
import com.hardcode.gdbms.engine.data.driver.DriverException;
59 2217 fernando
import com.hardcode.gdbms.engine.data.edition.DataWare;
60 1836 fernando
import com.hardcode.gdbms.engine.data.persistence.Memento;
61
import com.hardcode.gdbms.engine.data.persistence.MementoContentHandler;
62
import com.hardcode.gdbms.engine.data.persistence.MementoException;
63 2217 fernando
import com.hardcode.gdbms.engine.instruction.EvaluationException;
64 460 fernando
import com.hardcode.gdbms.engine.instruction.FieldNotFoundException;
65 1828 fernando
import com.hardcode.gdbms.engine.instruction.SemanticException;
66 460 fernando
import com.hardcode.gdbms.engine.values.Value;
67 2183 fernando
import com.hardcode.gdbms.engine.values.ValueCollection;
68 1828 fernando
import com.hardcode.gdbms.parser.ParseException;
69 4875 fjp
import com.iver.cit.gvsig.fmap.drivers.FieldDescription;
70 3963 caballero
import com.iver.cit.gvsig.fmap.layers.layerOperations.Selectable;
71 4875 fjp
import com.iver.utiles.NumberUtilities;
72 581 vcaballero
import com.iver.utiles.XMLEntity;
73 460 fernando
74
75 527 vcaballero
/**
76 1034 vcaballero
 * DataSource seleccionable.
77 527 vcaballero
 *
78 546 fernando
 * @author Fernando Gonz?lez Cort?s
79 527 vcaballero
 */
80 3963 caballero
public class SelectableDataSource implements DataSource,Selectable {
81 527 vcaballero
        private static Logger logger = Logger.getLogger(SelectableDataSource.class.getName());
82 460 fernando
        private SelectionSupport selectionSupport = new SelectionSupport();
83
        private DataSource dataSource;
84 10627 caballero
85 4863 fjp
        private int[] mapping = null;
86 527 vcaballero
87 460 fernando
        /**
88 1034 vcaballero
         * Crea un nuevo SelectableDataSource.
89 527 vcaballero
         *
90 1034 vcaballero
         * @param name
91 460 fernando
         * @param ds
92 10627 caballero
         * @throws ReadDriverException TODO
93 460 fernando
         */
94 10627 caballero
        public SelectableDataSource(DataSource ds) throws ReadDriverException {
95 460 fernando
                dataSource = ds;
96 5663 fjp
                dataSource.start();
97 4863 fjp
                // Creamos el mapping de campos externos que no muestran el PK.
98 6259 fjp
                mapExternalFields();
99
100
101
        }
102
103
        /**
104 6335 fjp
         * Maps real fields or "external" fields. We don't want to see virtual fields.
105 10665 caballero
         * @throws ReadDriverException
106 6259 fjp
         */
107 10627 caballero
        public void mapExternalFields() throws ReadDriverException {
108 4863 fjp
                int numExternalFields = 0;
109 14588 vcaballero
                this.dataSource.start();
110 4863 fjp
                for (int i=0; i < dataSource.getFieldCount(); i++)
111
                {
112
                        if (!dataSource.isVirtualField(i))
113
                                numExternalFields++;
114 10627 caballero
115 4863 fjp
                }
116 3963 caballero
117 4863 fjp
                mapping = new int[numExternalFields];
118
                int j=0;
119
                for (int i=0; i < dataSource.getFieldCount(); i++)
120
                {
121
                        if (!dataSource.isVirtualField(i))
122
                                mapping[j++] = i;
123 10627 caballero
124 4863 fjp
                }
125 14588 vcaballero
                this.dataSource.stop();
126 460 fernando
        }
127 527 vcaballero
128 10627 caballero
        public static SelectableDataSource createSelectableDataSource(XMLEntity xml) throws DriverLoadException, XMLException{
129 3963 caballero
130 1828 fernando
                SelectionSupport ss = new SelectionSupport();
131
                ss.setXMLEntity(xml.getChild(0));
132
                XMLEntity xmlDS = xml.getChild(1);
133 1836 fernando
                GDBMSParser parser = new GDBMSParser(xmlDS);
134
                MementoContentHandler gdbmsHandler = new MementoContentHandler();
135
                parser.setContentHandler(gdbmsHandler);
136
                try {
137
                        parser.parse();
138
                } catch (SAXException e) {
139
                        throw new XMLException(e);
140 1828 fernando
                }
141 2217 fernando
                SelectableDataSource sds;
142
        try {
143 14588 vcaballero
            sds = new SelectableDataSource(gdbmsHandler.getDataSource(LayerFactory.getDataSourceFactory(), DataSourceFactory.AUTOMATIC_OPENING));
144 2217 fernando
        } catch (EvaluationException e1) {
145
            throw new XMLException(e1);
146 10627 caballero
        } catch (ReadDriverException e) {
147
                 throw new XMLException(e);
148
                } catch (DriverLoadException e) {
149
                         throw new XMLException(e);
150
                } catch (SemanticException e) {
151
                         throw new XMLException(e);
152
                } catch (ParseException e) {
153
                         throw new XMLException(e);
154
                } catch (NoSuchTableException e) {
155
                         throw new XMLException(e);
156
                }
157 2217 fernando
        sds.selectionSupport=ss;
158 2183 fernando
                return sds;
159 1828 fernando
        }
160 1836 fernando
161 1828 fernando
        public void setDataSourceFactory(DataSourceFactory dsf) {
162
                dataSource.setDataSourceFactory(dsf);
163
        }
164 2217 fernando
        public void setSourceInfo(SourceInfo sourceInfo) {
165 1828 fernando
                dataSource.setSourceInfo(sourceInfo);
166
        }
167 460 fernando
        /**
168 1034 vcaballero
         * A?ade el soporte para la selecci?n.
169 527 vcaballero
         *
170 460 fernando
         * @param selectionSupport
171
         */
172
        public void setSelectionSupport(SelectionSupport selectionSupport) {
173
                this.selectionSupport = selectionSupport;
174
        }
175
176 527 vcaballero
        /**
177 1034 vcaballero
         * Devuelve el n?mero de campos.
178 527 vcaballero
         *
179 1034 vcaballero
         * @return N?mero de campos.
180 527 vcaballero
         *
181 1034 vcaballero
         * @throws DriverException
182 527 vcaballero
         */
183 10627 caballero
        public int getFieldCount() throws ReadDriverException {
184 4863 fjp
                // return dataSource.getFieldCount()-numVirtual;
185 6478 fjp
//                if (mapping.length != dataSource.getFieldCount())
186
//                {
187
//                        mapExternalFields();
188
//                        RuntimeException e = new RuntimeException("Recalculamos los campos de recordset!!");
189
//                        e.printStackTrace();
190
//                }
191 4863 fjp
                return mapping.length;
192 460 fernando
        }
193 527 vcaballero
194
        /**
195 7631 fjp
         * Return index field searching by its name
196 527 vcaballero
         *
197 7631 fjp
         * @param arg0 field name.
198 527 vcaballero
         *
199 7631 fjp
         * @return field index. -1 if not found
200 527 vcaballero
         *
201 1034 vcaballero
         * @throws DriverException
202
         * @throws FieldNotFoundException
203 527 vcaballero
         */
204
        public int getFieldIndexByName(String arg0)
205 10627 caballero
                throws ReadDriverException {
206 4863 fjp
                int internal = dataSource.getFieldIndexByName(arg0);
207
                for (int i=0; i < mapping.length; i++)
208
                {
209
                        if (mapping[i] == internal)
210
                                return i;
211
                }
212 14577 jmvivo
                //OJO Parche para rodear poblema de gdbms + FileDriver
213
                // Cuando en le fichero existe un campo de nombre 'PK'
214
                if (arg0.equalsIgnoreCase("pk")){
215
                        for (int i=0; i < mapping.length; i++)
216
                        {
217
                                if (dataSource.getFieldName(mapping[i]).equalsIgnoreCase(arg0)){
218
                                        return i;
219
                                }
220
                        }
221
222
                }
223 4863 fjp
                return -1;
224 460 fernando
        }
225 527 vcaballero
226
        /**
227 1034 vcaballero
         * Devuelve el nombre del campo a partir del ?ndice.
228 527 vcaballero
         *
229 1034 vcaballero
         * @param arg0 ?ndice.
230 527 vcaballero
         *
231 1034 vcaballero
         * @return nombre del campo.
232 527 vcaballero
         *
233 1034 vcaballero
         * @throws DriverException
234 527 vcaballero
         */
235 10627 caballero
        public String getFieldName(int arg0) throws ReadDriverException {
236 4863 fjp
            // return dataSource.getFieldName(arg0);
237
                return dataSource.getFieldName(mapping[arg0]);
238 460 fernando
        }
239 527 vcaballero
240
        /**
241 1034 vcaballero
         * Devuelve el valor a partir del n?mro de fila y columna.
242 527 vcaballero
         *
243 1034 vcaballero
         * @param arg0 n?mero de registro.
244
         * @param arg1 n?mero de campo.
245 527 vcaballero
         *
246 1034 vcaballero
         * @return Valor.
247 527 vcaballero
         *
248 1034 vcaballero
         * @throws DriverException
249 527 vcaballero
         */
250 10627 caballero
        public Value getFieldValue(long arg0, int arg1) throws ReadDriverException {
251 4863 fjp
                return dataSource.getFieldValue(arg0, mapping[arg1]);
252
                // return dataSource.getFieldValue(arg0, arg1);
253 460 fernando
        }
254 527 vcaballero
255
        /**
256 1034 vcaballero
         * Devuelve el nombre del DataSource.
257 527 vcaballero
         *
258 1034 vcaballero
         * @return Nombre.
259 527 vcaballero
         */
260 460 fernando
        public String getName() {
261
                return dataSource.getName();
262
        }
263 527 vcaballero
264
        /**
265 2565 fernando
         * Devuelve el n?mero de filas en total.
266 527 vcaballero
         *
267 1034 vcaballero
         * @return n?mero de filas.
268 527 vcaballero
         *
269 1034 vcaballero
         * @throws DriverException
270 527 vcaballero
         */
271 10627 caballero
        public long getRowCount() throws ReadDriverException {
272 460 fernando
                return dataSource.getRowCount();
273
        }
274 527 vcaballero
275
        /**
276 1034 vcaballero
         * Inicializa el dataSource.
277 527 vcaballero
         *
278 1034 vcaballero
         * @throws DriverException
279 527 vcaballero
         */
280 10627 caballero
        public void start() throws ReadDriverException {
281 3076 fjp
                // logger.debug("dataSource.start()");
282 460 fernando
                dataSource.start();
283
        }
284 527 vcaballero
285
        /**
286 1034 vcaballero
         * Finaliza el DataSource.
287 527 vcaballero
         *
288 1034 vcaballero
         * @throws DriverException
289 527 vcaballero
         */
290 10627 caballero
        public void stop() throws ReadDriverException {
291 3076 fjp
                // logger.debug("dataSource.stop()");
292 460 fernando
                dataSource.stop();
293
        }
294
295
        /**
296 2183 fernando
         * A partir del XMLEntity se rellenan los atributos del DataSource.
297
         *
298
         * @param child
299
         */
300
        public void setXMLEntity03(XMLEntity child) {
301
                selectionSupport.setXMLEntity(child.getChild(0));
302
        }
303
304
        /**
305 527 vcaballero
         * Cuando ocurre un evento de cambio en la selecci?n, ?ste puede ser uno de
306
         * una gran cantidad de eventos. Con el fin de no propagar todos estos
307
         * eventos, se realiza la propagaci?n de manera manual al final de la
308
         * "r?faga" de eventos
309 460 fernando
         */
310
        public void fireSelectionEvents() {
311
                selectionSupport.fireSelectionEvents();
312
        }
313
314 527 vcaballero
        /**
315 1034 vcaballero
         * A?ade un nuevo Listener al SelectionSupport.
316 527 vcaballero
         *
317 1034 vcaballero
         * @param listener SelectionListener.
318 527 vcaballero
         */
319 460 fernando
        public void addSelectionListener(SelectionListener listener) {
320
                selectionSupport.addSelectionListener(listener);
321
        }
322
323 527 vcaballero
        /**
324 1034 vcaballero
         * Borra un Listener al SelectionSupport.
325 527 vcaballero
         *
326 1034 vcaballero
         * @param listener Listener a borrar.
327 527 vcaballero
         */
328 460 fernando
        public void removeSelectionListener(SelectionListener listener) {
329
                selectionSupport.removeSelectionListener(listener);
330
        }
331 527 vcaballero
332
        /**
333 1034 vcaballero
         * Borra la selecci?n.
334 527 vcaballero
         */
335 460 fernando
        public void clearSelection() {
336
                selectionSupport.clearSelection();
337
        }
338 527 vcaballero
339
        /**
340 1034 vcaballero
         * Develve un FBitSet con los ?ndices de los elementos seleccionados.
341 527 vcaballero
         *
342 1034 vcaballero
         * @return FBitset con los elementos seleccionados.
343 527 vcaballero
         */
344 884 fernando
        public FBitSet getSelection() {
345 460 fernando
                return selectionSupport.getSelection();
346
        }
347 1034 vcaballero
348
        /**
349
         * Devuelve el SelectionSupport.
350
         *
351
         * @return SelectinSuport.
352
         */
353
        public SelectionSupport getSelectionSupport() {
354 581 vcaballero
                return selectionSupport;
355
        }
356 1034 vcaballero
357 527 vcaballero
        /**
358 1034 vcaballero
         * Devuelve true si el elemento est? seleccionado.
359 527 vcaballero
         *
360 1034 vcaballero
         * @param recordIndex ?ndice del registro.
361 527 vcaballero
         *
362 1034 vcaballero
         * @return True si el registro est? seleccionado.
363 527 vcaballero
         */
364 460 fernando
        public boolean isSelected(int recordIndex) {
365
                return selectionSupport.isSelected(recordIndex);
366
        }
367 527 vcaballero
368
        /**
369 1034 vcaballero
         * Inserta una nueva selecci?n.
370 527 vcaballero
         *
371 1034 vcaballero
         * @param selection FBitSet.
372 527 vcaballero
         */
373 683 fernando
        public void setSelection(FBitSet selection) {
374 460 fernando
                selectionSupport.setSelection(selection);
375
        }
376 546 fernando
377 1828 fernando
        private void putMemento(XMLEntity xml) throws XMLException {
378
                try {
379 1836 fernando
                        GDBMSHandler handler = new GDBMSHandler();
380
                        Memento m = getMemento();
381
                        m.setContentHandler(handler);
382
                        m.getXML();
383
                        XMLEntity child = handler.getXMLEntity();
384 3963 caballero
385 1828 fernando
                        xml.addChild(child);
386
                } catch (MementoException e) {
387
                        throw new XMLException(e);
388 1836 fernando
                } catch (SAXException e) {
389
                        throw new XMLException(e);
390 1828 fernando
                }
391
        }
392
393 1034 vcaballero
        /**
394
         * Devuelve el XMLEntity con la informaci?n necesaria para reproducir el
395
         * DataSource.
396
         *
397
         * @return XMLEntity.
398 1828 fernando
         * @throws XMLException
399 1034 vcaballero
         */
400 1828 fernando
        public XMLEntity getXMLEntity() throws XMLException {
401 1034 vcaballero
                XMLEntity xml = new XMLEntity();
402 1094 vcaballero
                xml.putProperty("className",this.getClass().getName());
403 581 vcaballero
                xml.addChild(selectionSupport.getXMLEntity());
404 1828 fernando
                putMemento(xml);
405 1034 vcaballero
406 581 vcaballero
                return xml;
407
        }
408 732 fernando
409
        /**
410 884 fernando
         * @see com.hardcode.gdbms.engine.data.DataSource#getWhereFilter()
411
         */
412
        public long[] getWhereFilter() throws IOException {
413
                return dataSource.getWhereFilter();
414
        }
415 1653 fernando
416 16184 jdominguez
        /*
417 1653 fernando
         * @see com.hardcode.gdbms.engine.data.ReadDriver#getFieldType(int)
418
         */
419 10627 caballero
        public int getFieldType(int i) throws ReadDriverException {
420 4863 fjp
                // return dataSource.getFieldType(i);
421 28975 vcaballero
                if (i>mapping.length-1)
422
                        return dataSource.getFieldType(i);
423 4863 fjp
                return dataSource.getFieldType(mapping[i]);
424 1653 fernando
        }
425 1828 fernando
426 16184 jdominguez
        /*
427 1828 fernando
         * @see com.hardcode.gdbms.engine.data.DataSource#getDataSourceFactory()
428
         */
429
        public DataSourceFactory getDataSourceFactory() {
430
                return dataSource.getDataSourceFactory();
431
        }
432
433 16184 jdominguez
        /*
434 1828 fernando
         * @see com.hardcode.gdbms.engine.data.DataSource#getAsString()
435
         */
436 10627 caballero
        public String getAsString() throws ReadDriverException {
437 1828 fernando
                return dataSource.getAsString();
438
        }
439 1831 fernando
440 16184 jdominguez
        /*
441 2183 fernando
         * @throws DriverException
442 1831 fernando
         * @see com.hardcode.gdbms.engine.data.DataSource#remove()
443
         */
444 10627 caballero
        public void remove() throws WriteDriverException {
445 1831 fernando
                dataSource.remove();
446
        }
447 1836 fernando
448 16184 jdominguez
        /*
449 1836 fernando
         * @see com.hardcode.gdbms.engine.data.DataSource#getMemento()
450
         */
451
        public Memento getMemento() throws MementoException {
452
                return dataSource.getMemento();
453
        }
454
455 16184 jdominguez
        /*
456 1836 fernando
         * @see com.hardcode.gdbms.engine.data.DataSource#getSourceInfo()
457
         */
458 2217 fernando
        public SourceInfo getSourceInfo() {
459 1836 fernando
                return dataSource.getSourceInfo();
460
        }
461 2183 fernando
462 16184 jdominguez
    /*
463 2183 fernando
     * @see com.hardcode.gdbms.engine.data.DataSource#getPrimaryKeys()
464
     */
465 10627 caballero
    public int[] getPrimaryKeys() throws ReadDriverException {
466 2183 fernando
            return dataSource.getPrimaryKeys();
467
    }
468
469 16184 jdominguez
    /*
470 2183 fernando
     * @see com.hardcode.gdbms.engine.data.DataSource#getPKValue(long)
471
     */
472 10627 caballero
    public ValueCollection getPKValue(long rowIndex) throws ReadDriverException {
473 2183 fernando
        return dataSource.getPKValue(rowIndex);
474
    }
475
476 16184 jdominguez
    /*
477 2183 fernando
     * @see com.hardcode.gdbms.engine.data.DataSource#getPKName(int)
478
     */
479 10627 caballero
    public String getPKName(int fieldId) throws ReadDriverException {
480 2183 fernando
        return dataSource.getPKName(fieldId);
481
    }
482
483 16184 jdominguez
    /*
484 2183 fernando
     * @see com.hardcode.gdbms.engine.data.DataSource#getPKType(int)
485
     */
486 10627 caballero
    public int getPKType(int i) throws ReadDriverException {
487 2183 fernando
        return dataSource.getPKType(i);
488
    }
489
490 16184 jdominguez
    /*
491 2183 fernando
     * @throws DriverException
492
     * @see com.hardcode.gdbms.engine.data.DataSource#getPKCardinality()
493
     */
494 10627 caballero
    public int getPKCardinality() throws ReadDriverException {
495 2183 fernando
        return dataSource.getPKCardinality();
496
    }
497
498 16184 jdominguez
    /*
499 2183 fernando
     * @see com.hardcode.gdbms.engine.data.DataSource#getRow(long)
500
     */
501 10627 caballero
    public Value[] getRow(long rowIndex) throws ReadDriverException {
502 4863 fjp
            Value[] withoutVirtuals = new Value[mapping.length];
503
            Value[] internal = dataSource.getRow(rowIndex);
504
            for (int i=0; i < mapping.length; i++)
505
            {
506
                    withoutVirtuals[i] = internal[mapping[i]];
507 10627 caballero
508 4863 fjp
            }
509
        return withoutVirtuals;
510 2183 fernando
    }
511
512 16184 jdominguez
    /*
513 2183 fernando
     * @see com.hardcode.gdbms.engine.data.DataSource#getFieldNames()
514
     */
515 10627 caballero
    public String[] getFieldNames() throws ReadDriverException {
516 28975 vcaballero
            String[] fieldNames = new String[dataSource.getFieldCount()];
517 4863 fjp
                int j=0;
518
                for (int i=0; i < dataSource.getFieldCount(); i++)
519
                {
520
                        if (!dataSource.isVirtualField(i))
521
                                fieldNames[j++] = dataSource.getFieldName(i);
522 10627 caballero
523 4863 fjp
                }
524
        // return dataSource.getFieldNames();
525
            return fieldNames;
526 2183 fernando
    }
527
528 16184 jdominguez
    /*
529 2183 fernando
     * @see com.hardcode.gdbms.engine.data.DataSource#getPKNames()
530
     */
531 10627 caballero
    public String[] getPKNames() throws ReadDriverException {
532 2183 fernando
        return dataSource.getPKNames();
533
    }
534
535
        public void removeLinksSelectionListener() {
536
                selectionSupport.removeLinkSelectionListener();
537
        }
538 2217 fernando
539 16184 jdominguez
    /*
540 10627 caballero
     * @throws DriverException
541 2217 fernando
     * @see com.hardcode.gdbms.engine.data.DataSource#getDataWare(int)
542
     */
543 10627 caballero
    public DataWare getDataWare(int arg0) throws ReadDriverException {
544 2217 fernando
        return dataSource.getDataWare(arg0);
545
    }
546 4863 fjp
547 10627 caballero
        public int getFieldWidth(int i) throws ReadDriverException {
548 4863 fjp
                return dataSource.getFieldWidth(mapping[i]);
549
                // return dataSource.getFieldWidth(i);
550
        }
551
552 10627 caballero
        public boolean isVirtualField(int fieldId) throws ReadDriverException {
553 4863 fjp
                return dataSource.isVirtualField(fieldId);
554
        }
555 10627 caballero
556 4875 fjp
        /**
557
         * Useful to writers, to know the field definitions.
558
         * NOTE: Maximun precision: 6 decimals. (We may need to change this)
559
         * @return Description of non virtual fields
560
         * @throws DriverException
561
         */
562 10627 caballero
        public FieldDescription[] getFieldsDescription() throws ReadDriverException{
563 4875 fjp
                int numFields = getFieldCount();
564
                FieldDescription[] fieldsDescrip = new FieldDescription[numFields];
565
                for (int i = 0; i < numFields; i++) {
566
                        fieldsDescrip[i] = new FieldDescription();
567
                        int type = getFieldType(i);
568
                        fieldsDescrip[i].setFieldType(type);
569
                        fieldsDescrip[i].setFieldName(getFieldName(i));
570
                        fieldsDescrip[i].setFieldLength(getFieldWidth(i));
571 6483 fjp
                        if (NumberUtilities.isNumeric(type))
572
                        {
573
                                if (!NumberUtilities.isNumericInteger(type))
574
                                        // TODO: If there is a lost in precision, this should be changed.
575
                                        fieldsDescrip[i].setFieldDecimalCount(6);
576
                        }
577
                        else
578 4875 fjp
                                fieldsDescrip[i].setFieldDecimalCount(0);
579 6628 fjp
                        // TODO: ?DEFAULTVALUE?
580
                        // fieldsDescrip[i].setDefaultValue(get)
581 4875 fjp
                }
582
                return fieldsDescrip;
583
        }
584 5569 jmvivo
585 10627 caballero
        public Driver getDriver() {
586 5569 jmvivo
                return this.dataSource.getDriver();
587
        }
588 6323 fjp
589 10627 caballero
        public void reload() throws ReloadDriverException {
590 6323 fjp
                dataSource.reload();
591 10627 caballero
                try {
592
                        mapExternalFields();
593
                } catch (ReadDriverException e) {
594
                        throw new ReloadDriverException(getDriver().getName(),e);
595
                }
596
597 6323 fjp
        }
598
599
        public void addDataSourceListener(IDataSourceListener listener) {
600
                dataSource.addDataSourceListener(listener);
601 10627 caballero
602 6323 fjp
        }
603
604
        public void removeDataSourceListener(IDataSourceListener listener) {
605
                dataSource.removeDataSourceListener(listener);
606 10627 caballero
607 6323 fjp
        }
608 460 fernando
}