Revision 591 trunk/applications/appgvSIG/src/com/iver/cit/gvsig/project/castor/ProjectTable.java
ProjectTable.java | ||
---|---|---|
1 | 1 |
package com.iver.cit.gvsig.project.castor; |
2 | 2 |
|
3 |
import com.hardcode.driverManager.DriverLoadException; |
|
4 |
import com.hardcode.gdbms.engine.data.DBDriver; |
|
5 |
import com.hardcode.gdbms.engine.data.DataSource; |
|
6 |
import com.hardcode.gdbms.engine.data.DataSourceFactory; |
|
7 |
import com.hardcode.gdbms.engine.data.DriverException; |
|
8 |
import com.hardcode.gdbms.engine.data.NoSuchTableException; |
|
9 |
import com.iver.cit.gvsig.fmap.drivers.VectorialDriver; |
|
10 |
import com.iver.cit.gvsig.fmap.layers.CommonOperations; |
|
3 | 11 |
import java.text.DateFormat; |
4 | 12 |
import java.util.Date; |
5 | 13 |
|
6 | 14 |
import com.hardcode.gdbms.engine.data.DriverException; |
7 | 15 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
16 |
import com.iver.cit.gvsig.fmap.layers.SelectionSupport; |
|
17 |
import com.iver.cit.gvsig.fmap.layers.XMLException; |
|
18 |
import com.iver.cit.gvsig.project.ProjectFactory; |
|
19 |
|
|
8 | 20 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
9 | 21 |
import com.iver.utiles.XMLEntity; |
10 | 22 |
|
23 |
import com.hardcode.gdbms.engine.data.DataSourceFactory.DriverInfo; |
|
24 |
import com.hardcode.gdbms.engine.data.DataSourceFactory.FileDriverInfo; |
|
25 |
import com.hardcode.gdbms.engine.data.DataSourceFactory.DBDriverInfo; |
|
11 | 26 |
|
27 |
import java.text.DateFormat; |
|
28 |
|
|
29 |
import java.util.Date; |
|
30 |
|
|
31 |
|
|
12 | 32 |
/** |
13 | 33 |
* Tabla del proyecto |
14 | 34 |
* |
... | ... | |
17 | 37 |
public class ProjectTable extends ProjectElement { |
18 | 38 |
private static int numTables = 0; |
19 | 39 |
private SelectableDataSource modelo; |
20 |
|
|
40 |
private String nameLayer; |
|
21 | 41 |
/* No es necesaria para operar, s?lo para guardar el proyecto */ |
22 | 42 |
private AlphanumericData associatedTable; |
23 | 43 |
|
... | ... | |
64 | 84 |
*/ |
65 | 85 |
public void setName(String string) { |
66 | 86 |
super.setName(string); |
67 |
modelo.setName(string); |
|
87 |
if (modelo !=null){ |
|
88 |
modelo.setName(string); |
|
89 |
} |
|
68 | 90 |
} |
69 | 91 |
|
70 | 92 |
/** |
... | ... | |
124 | 146 |
XMLEntity xml = super.getXMLEntity(); |
125 | 147 |
xml.putProperty("nameClass", this.getClass().getName()); |
126 | 148 |
xml.putProperty("numTables", numTables); |
127 |
|
|
128 |
//TODO xml.addChild(DataSource); |
|
149 |
xml.addChild(modelo.getXMLEntity()); |
|
150 |
DriverInfo di=DataSourceFactory.getDriverInfo(modelo.getName()); |
|
151 |
xml.putProperty("driverName",di.driverName); |
|
152 |
xml.putProperty("name",di.name); |
|
153 |
xml.putProperty("dbms",di.dbms); |
|
154 |
if (associatedTable!=null){ |
|
155 |
xml.putProperty("nameLayer",associatedTable.getName()); |
|
156 |
} |
|
157 |
if (di instanceof FileDriverInfo){ |
|
158 |
xml.putProperty("type","file"); |
|
159 |
xml.putProperty("file",((FileDriverInfo)di).file); |
|
160 |
}else if (di instanceof DBDriverInfo){ |
|
161 |
xml.putProperty("type","db"); |
|
162 |
DBDriverInfo dbdi=(DBDriverInfo)di; |
|
163 |
|
|
164 |
xml.putProperty("host",dbdi.host); |
|
165 |
xml.putProperty("port",dbdi.port); |
|
166 |
xml.putProperty("user",dbdi.user); |
|
167 |
xml.putProperty("password",dbdi.password); |
|
168 |
xml.putProperty("dbName",dbdi.dbName); |
|
169 |
xml.putProperty("tableName",dbdi.sqlQuery); |
|
170 |
xml.putProperty("driverInfo",dbdi.driverInfo); |
|
171 |
|
|
172 |
} |
|
129 | 173 |
return xml; |
130 | 174 |
} |
131 |
|
|
175 |
private void setProjectTable(ProjectTable pt){ |
|
176 |
numTables=ProjectTable.numTables; |
|
177 |
associatedTable=pt.associatedTable; |
|
178 |
modelo=pt.modelo; |
|
179 |
} |
|
180 |
public void setSelectionSupport(SelectionSupport ss){ |
|
181 |
modelo.setSelectionSupport(ss); |
|
182 |
} |
|
132 | 183 |
/** |
184 |
* @throws XMLException |
|
133 | 185 |
* @see com.iver.cit.gvsig.project.castor.ProjectElement#setXMLEntity(com.iver.utiles.XMLEntity) |
134 | 186 |
*/ |
135 |
public void setXMLEntity(XMLEntity xml, Project p) { |
|
187 |
public void setXMLEntity(XMLEntity xml, Project p) throws XMLException {
|
|
136 | 188 |
numTables = xml.getIntProperty("numViews"); |
137 |
|
|
189 |
if (xml.getStringProperty("nameLayer")!=null){ |
|
190 |
nameLayer=xml.getStringProperty("nameLayer"); |
|
191 |
} |
|
192 |
if (xml.getStringProperty("type").equals("file")){ |
|
193 |
DataSourceFactory.addFileDataSource(xml.getStringProperty("driverName"),xml.getStringProperty("name"),xml.getStringProperty("file"),xml.getStringProperty("dbms")); |
|
194 |
DataSource dataSource; |
|
195 |
try { |
|
196 |
dataSource = DataSourceFactory.createRandomDataSource(xml.getStringProperty("name")); |
|
197 |
} catch (NoSuchTableException e) { |
|
198 |
throw new XMLException(e); |
|
199 |
} catch (DriverLoadException e) { |
|
200 |
throw new XMLException(e); |
|
201 |
} |
|
202 |
|
|
203 |
///modelo = new SelectableDataSource(xml.getStringProperty("name"), dataSource); |
|
204 |
ProjectTable pt=ProjectFactory.createTable(xml.getStringProperty("nameLayer"), new SelectableDataSource(xml.getStringProperty("name"), dataSource)); |
|
205 |
setProjectTable(pt); |
|
206 |
/*for (int i=0;i<p.getViews().size();i++){ |
|
207 |
//if (p.getViews().get(i) instanceof CommonOperations){ |
|
208 |
CommonOperations co=(CommonOperations)((ProjectView)p.getViews().get(i)); |
|
209 |
|
|
210 |
if (co.getName().equals(getNameLayer())){ |
|
211 |
try { |
|
212 |
setSelectionSupport(co.getRecordset().getSelectionSupport()); |
|
213 |
} catch (DriverLoadException e1) { |
|
214 |
throw new XMLException(e1); |
|
215 |
} |
|
216 |
} |
|
217 |
|
|
218 |
//} |
|
219 |
} |
|
220 |
*/ |
|
221 |
for (int i=0;i<p.getViews().size();i++){ |
|
222 |
((ProjectView)p.getViews().get(i)).getMapContext().getLayers().getLayerByName(getNameLayer()); |
|
223 |
} |
|
224 |
}else if (xml.getStringProperty("type").equals("db")){ |
|
225 |
DataSourceFactory.addDBDataSource(xml.getStringProperty("name"),xml.getStringProperty("host"),xml.getIntProperty("port"),xml.getStringProperty("user"),xml.getStringProperty("password"),xml.getStringProperty("dbName"),xml.getStringProperty("tableName"),xml.getStringProperty("driverName")); |
|
226 |
} |
|
227 |
setName(xml.getStringProperty("name")); |
|
228 |
//}else{ |
|
229 |
|
|
230 |
|
|
231 |
//} |
|
138 | 232 |
///setModelo(dataSource); |
139 | 233 |
} |
140 | 234 |
|
... | ... | |
143 | 237 |
* |
144 | 238 |
* @return DOCUMENT ME! |
145 | 239 |
*/ |
146 |
public AlphanumericData getAssociatedTable() {
|
|
240 |
/*private CommonOperations getAssociatedTable() {
|
|
147 | 241 |
return associatedTable; |
148 | 242 |
} |
149 |
|
|
243 |
*/ |
|
150 | 244 |
/** |
151 | 245 |
* DOCUMENT ME! |
152 | 246 |
* |
153 | 247 |
* @param associatedTable DOCUMENT ME! |
248 |
* @throws DriverLoadException |
|
154 | 249 |
*/ |
155 | 250 |
public void setAssociatedTable(AlphanumericData associatedTable) { |
156 | 251 |
this.associatedTable = associatedTable; |
252 |
setSelectionSupport(associatedTable.getRecordset().getSelectionSupport()); |
|
157 | 253 |
} |
254 |
public String getNameLayer(){ |
|
255 |
return nameLayer; |
|
256 |
} |
|
158 | 257 |
} |
Also available in: Unified diff