Revision 7618
branches/v10/extensions/extAddEventTheme/src/com/iver/gvsig/addeventtheme/AddEventThemeDriver.java | ||
---|---|---|
51 | 51 |
import com.hardcode.gdbms.engine.data.DataSourceFactory; |
52 | 52 |
import com.hardcode.gdbms.engine.data.IDataSourceListener; |
53 | 53 |
import com.hardcode.gdbms.engine.data.NoSuchTableException; |
54 |
import com.hardcode.gdbms.engine.data.SourceInfo; |
|
54 | 55 |
import com.hardcode.gdbms.engine.data.driver.DriverException; |
55 | 56 |
import com.hardcode.gdbms.engine.data.driver.ObjectDriver; |
56 | 57 |
import com.hardcode.gdbms.engine.data.edition.DataWare; |
57 |
import com.hardcode.gdbms.engine.values.StringValue; |
|
58 | 58 |
import com.hardcode.gdbms.engine.values.Value; |
59 |
import com.iver.andami.PluginServices; |
|
60 |
import com.iver.cit.gvsig.ProjectExtension; |
|
59 | 61 |
import com.iver.cit.gvsig.fmap.core.FGeometry; |
60 | 62 |
import com.iver.cit.gvsig.fmap.core.FPoint2D; |
61 | 63 |
import com.iver.cit.gvsig.fmap.core.FShape; |
... | ... | |
77 | 79 |
*/ |
78 | 80 |
public class AddEventThemeDriver implements VectorialDriver, ObjectDriver, BoundedShapes, IPersistance, IDataSourceListener { |
79 | 81 |
private Rectangle2D fullExtent = null; |
80 |
private DataSource ds; |
|
82 |
private SelectableDataSource ds;
|
|
81 | 83 |
private int xFieldIndex; |
82 | 84 |
private int yFieldIndex; |
83 | 85 |
|
... | ... | |
217 | 219 |
public String getClassName() { |
218 | 220 |
return this.getClass().getName(); |
219 | 221 |
} |
222 |
|
|
220 | 223 |
|
221 | 224 |
// Para guardar en el xml file |
222 | 225 |
public XMLEntity getXMLEntity() { |
... | ... | |
225 | 228 |
xml.putProperty("xFieldIndex", xFieldIndex); |
226 | 229 |
xml.putProperty("yFieldIndex", yFieldIndex); |
227 | 230 |
xml.putProperty("tableName", ds.getName()); |
228 |
return xml; |
|
231 |
XMLEntity dsXML = null; |
|
232 |
|
|
233 |
dsXML = this.getDataSourceXML(); |
|
234 |
if (dsXML != null) { |
|
235 |
xml.putProperty("hasDSInfo", true); |
|
236 |
xml.addChild(dsXML); |
|
237 |
} else { |
|
238 |
xml.putProperty("hasDSInfo", false); |
|
239 |
} |
|
240 |
return xml; |
|
229 | 241 |
} |
230 | 242 |
|
231 | 243 |
// Para recuperar del xml file |
... | ... | |
233 | 245 |
int xFieldIndex = xml.getIntProperty("xFieldIndex"); |
234 | 246 |
int yFieldIndex = xml.getIntProperty("yFieldIndex"); |
235 | 247 |
String tableName = xml.getStringProperty("tableName"); |
248 |
DataSource ds; |
|
236 | 249 |
try { |
237 |
DataSource ds = LayerFactory.getDataSourceFactory().createRandomDataSource(tableName, DataSourceFactory.AUTOMATIC_OPENING); |
|
238 |
setData(ds, xFieldIndex, yFieldIndex); |
|
250 |
ds = LayerFactory.getDataSourceFactory().createRandomDataSource(tableName, DataSourceFactory.AUTOMATIC_OPENING); |
|
239 | 251 |
} catch (NoSuchTableException e) { |
240 |
throw new RuntimeException(e); |
|
252 |
if (!xml.contains("hasDSInfo") || !xml.getBooleanProperty("hasDSInfo")) { |
|
253 |
// No esta registrado el DS y no tenemos su informacion en el |
|
254 |
// xml (proyecto viejo)... no podemos arreglarlo |
|
255 |
throw new RuntimeException(e); |
|
256 |
} |
|
257 |
//Intentar reconstruir el DS!!!!!!!!!! |
|
258 |
try { |
|
259 |
ds = this.getDataSourceFromXML(xml.getChild(0)); |
|
260 |
} catch (Exception e1) { |
|
261 |
throw new RuntimeException(e1); |
|
262 |
} |
|
241 | 263 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) { |
242 | 264 |
throw new RuntimeException(e); |
243 | 265 |
} catch (DriverLoadException e) { |
244 | 266 |
// TODO Auto-generated catch block |
245 |
e.printStackTrace();
|
|
267 |
throw new RuntimeException(e);
|
|
246 | 268 |
} |
269 |
try { |
|
270 |
setData(ds, xFieldIndex, yFieldIndex); |
|
271 |
} catch (DriverException e) { |
|
272 |
// TODO Auto-generated catch block |
|
273 |
throw new RuntimeException(e); |
|
274 |
} |
|
247 | 275 |
} |
276 |
|
|
248 | 277 |
|
249 | 278 |
public int getFieldWidth(int i) throws DriverException { |
250 | 279 |
return ds.getFieldWidth(i); |
... | ... | |
270 | 299 |
this.ds.reload(); |
271 | 300 |
|
272 | 301 |
} |
302 |
|
|
303 |
private XMLEntity getDataSourceXML() { |
|
304 |
SourceInfo di = this.ds.getSourceInfo(); |
|
305 |
ProjectExtension ext = (ProjectExtension) PluginServices.getExtension(ProjectExtension.class); |
|
306 |
|
|
307 |
return ext.getProject().getSourceInfoXMLEntity(di); |
|
308 |
} |
|
309 |
|
|
310 |
private DataSource getDataSourceFromXML(XMLEntity xml) throws Exception{ |
|
311 |
if (xml.getStringProperty("type").equals("otherDriverFile")) { |
|
312 |
LayerFactory.getDataSourceFactory().addFileDataSource(xml.getStringProperty( |
|
313 |
"driverName"), xml.getStringProperty("gdbmsname"), |
|
314 |
xml.getStringProperty("file")); |
|
315 |
} else if (xml.getStringProperty("type").equals("sameDriverFile")) { |
|
316 |
} else if (xml.getStringProperty("type").equals("db")) { |
|
317 |
LayerFactory.getDataSourceFactory().addDBDataSourceByTable(xml.getStringProperty( |
|
318 |
"gdbmsname"), xml.getStringProperty("host"), |
|
319 |
xml.getIntProperty("port"), |
|
320 |
xml.getStringProperty("user"), |
|
321 |
xml.getStringProperty("password"), |
|
322 |
xml.getStringProperty("dbName"), |
|
323 |
xml.getStringProperty("tableName"), |
|
324 |
xml.getStringProperty("driverInfo")); |
|
325 |
} |
|
326 |
|
|
327 |
|
|
328 |
DataSource ds = LayerFactory.getDataSourceFactory().createRandomDataSource(xml.getStringProperty( |
|
329 |
"gdbmsname"), DataSourceFactory.AUTOMATIC_OPENING); |
|
330 |
|
|
331 |
return ds; |
|
332 |
|
|
333 |
} |
|
273 | 334 |
|
274 | 335 |
} |
Also available in: Unified diff