Revision 1848 branches/Fmap_GisPlanet/libraries/libFMap/src/com/iver/cit/gvsig/fmap/layers/SelectableDataSource.java

View differences:

SelectableDataSource.java
40 40
 */
41 41
package com.iver.cit.gvsig.fmap.layers;
42 42

  
43
import java.io.IOException;
44

  
45
import org.apache.log4j.Logger;
46
import org.xml.sax.SAXException;
47

  
48
import com.hardcode.driverManager.DriverLoadException;
43 49
import com.hardcode.gdbms.engine.data.DataSource;
44 50
import com.hardcode.gdbms.engine.data.DataSourceFactory;
45
import com.hardcode.gdbms.engine.data.DriverException;
46 51
import com.hardcode.gdbms.engine.data.NoSuchTableException;
47
import com.hardcode.gdbms.engine.data.ReadDriver;
52
import com.hardcode.gdbms.engine.data.driver.DriverException;
53
import com.hardcode.gdbms.engine.data.driver.DriverInfo;
54
import com.hardcode.gdbms.engine.data.persistence.Handler;
55
import com.hardcode.gdbms.engine.data.persistence.Memento;
56
import com.hardcode.gdbms.engine.data.persistence.MementoContentHandler;
57
import com.hardcode.gdbms.engine.data.persistence.MementoException;
48 58
import com.hardcode.gdbms.engine.instruction.FieldNotFoundException;
59
import com.hardcode.gdbms.engine.instruction.SemanticException;
49 60
import com.hardcode.gdbms.engine.values.Value;
50

  
61
import com.hardcode.gdbms.parser.ParseException;
51 62
import com.iver.utiles.XMLEntity;
52 63

  
53
import org.apache.log4j.Logger;
54 64

  
55
import java.io.IOException;
56

  
57

  
58 65
/**
59 66
 * DataSource seleccionable.
60 67
 *
......
75 82
		dataSource = ds;
76 83
	}
77 84

  
85
	public static SelectableDataSource createSelectableDataSource(XMLEntity xml) throws NoSuchTableException, ParseException, DriverLoadException, DriverException, SemanticException, IOException, XMLException{
86
		
87
		SelectionSupport ss = new SelectionSupport();
88
		ss.setXMLEntity(xml.getChild(0));
89
		XMLEntity xmlDS = xml.getChild(1);
90
		GDBMSParser parser = new GDBMSParser(xmlDS);
91
		MementoContentHandler gdbmsHandler = new MementoContentHandler();
92
		parser.setContentHandler(gdbmsHandler);
93
		try {
94
			parser.parse();
95
		} catch (SAXException e) {
96
			throw new XMLException(e);
97
		}
98
		
99
		return new SelectableDataSource(gdbmsHandler.getDataSource(LayerFactory.getDataSourceFactory(), DataSourceFactory.AUTOMATIC_MODE));
100
	}
101

  
102
	public void setDataSourceFactory(DataSourceFactory dsf) {
103
		dataSource.setDataSourceFactory(dsf);
104
	}
105
	public void setSourceInfo(DriverInfo sourceInfo) {
106
		dataSource.setSourceInfo(sourceInfo);
107
	}
78 108
	/**
79 109
	 * A?ade el soporte para la selecci?n.
80 110
	 *
......
92 122
	public String getDBMS() {
93 123
		return dataSource.getDBMS();
94 124
	}
95

  
125
	
96 126
	/**
97
	 * Devuelve el driver de la capa.
98
	 *
99
	 * @return ReadDriver.
100
	 */
101
	public ReadDriver getDriver() {
102
		return dataSource.getDriver();
103
	}
104

  
105
	/**
106 127
	 * Devuelve el n?mero de campos.
107 128
	 *
108 129
	 * @return N?mero de campos.
......
124 145
	 * @throws FieldNotFoundException
125 146
	 */
126 147
	public int getFieldIndexByName(String arg0)
127
		throws DriverException, FieldNotFoundException {
148
		throws DriverException {
128 149
		return dataSource.getFieldIndexByName(arg0);
129 150
	}
130 151

  
......
277 298
	 */
278 299
	public void setName(String name) {
279 300
		try {
280
			DataSourceFactory.changeDataSourceName(dataSource.getName(), name);
301
			LayerFactory.getDataSourceFactory().changeDataSourceName(dataSource.getName(), name);
281 302
		} catch (NoSuchTableException e) {
282 303
			throw new RuntimeException("No se encuentra la tabla????");
283 304
		}
284 305
	}
285 306

  
307
	private void putMemento(XMLEntity xml) throws XMLException {
308
		try {
309
			GDBMSHandler handler = new GDBMSHandler();
310
			Memento m = getMemento();
311
			m.setContentHandler(handler);
312
			m.getXML();
313
			XMLEntity child = handler.getXMLEntity();
314
			
315
			xml.addChild(child);
316
		} catch (MementoException e) {
317
			throw new XMLException(e);
318
		} catch (SAXException e) {
319
			throw new XMLException(e);
320
		}
321
	}
322

  
286 323
	/**
287 324
	 * Devuelve el XMLEntity con la informaci?n necesaria para reproducir el
288 325
	 * DataSource.
289 326
	 *
290 327
	 * @return XMLEntity.
328
	 * @throws XMLException
291 329
	 */
292
	public XMLEntity getXMLEntity() {
330
	public XMLEntity getXMLEntity() throws XMLException {
293 331
		XMLEntity xml = new XMLEntity();
294 332
		xml.putProperty("className",this.getClass().getName());
295 333
		xml.addChild(selectionSupport.getXMLEntity());
334
		putMemento(xml);
296 335

  
297 336
		return xml;
298 337
	}
299 338

  
300 339
	/**
301
	 * A partir del XMLEntity se rellenan los atributos del DataSource.
302
	 *
303
	 * @param child
304
	 */
305
	public void setXMLEntity(XMLEntity child) {
306
		selectionSupport.setXMLEntity(child.getChild(0));
307
	}
308

  
309
	/**
310 340
	 * @see com.hardcode.gdbms.engine.data.DataSource#getWhereFilter()
311 341
	 */
312 342
	public long[] getWhereFilter() throws IOException {
......
316 346
	/**
317 347
	 * @see com.hardcode.gdbms.engine.data.ReadDriver#getFieldType(int)
318 348
	 */
319
	public Class getFieldType(int i) throws DriverException {
349
	public int getFieldType(int i) throws DriverException {
320 350
		return dataSource.getFieldType(i);
321 351
	}
352

  
353
	/**
354
	 * @see com.hardcode.gdbms.engine.data.DataSource#getDataSourceFactory()
355
	 */
356
	public DataSourceFactory getDataSourceFactory() {
357
		return dataSource.getDataSourceFactory();
358
	}
359

  
360
	/**
361
	 * @see com.hardcode.gdbms.engine.data.HasProperties#getProperty(java.lang.String)
362
	 */
363
	public String getProperty(String propertyName) {
364
		return dataSource.getProperty(propertyName);
365
	}
366

  
367
	/**
368
	 * @see com.hardcode.gdbms.engine.data.DataSource#getAsString()
369
	 */
370
	public String getAsString() throws DriverException {
371
		return dataSource.getAsString();
372
	}
373

  
374
	/**
375
	 * @see com.hardcode.gdbms.engine.data.DataSource#remove()
376
	 */
377
	public void remove() {
378
		dataSource.remove();
379
	}
380

  
381
	/**
382
	 * @see com.hardcode.gdbms.engine.data.DataSource#getMemento()
383
	 */
384
	public Memento getMemento() throws MementoException {
385
		return dataSource.getMemento();
386
	}
387

  
388
	/**
389
	 * @see com.hardcode.gdbms.engine.data.DataSource#getSourceInfo()
390
	 */
391
	public DriverInfo getSourceInfo() {
392
		return dataSource.getSourceInfo();
393
	}
322 394
}

Also available in: Unified diff