gvsig-geoprocess / org.gvsig.sextante / trunk / org.gvsig.sextante.app / org.gvsig.sextante.app.extension / src / main / java / org / gvsig / sextante / app / extension / core / gvTable.java @ 31
History | View | Annotate | Download (3.44 KB)
1 |
package org.gvsig.sextante.app.extension.core; |
---|---|
2 |
|
3 |
import org.gvsig.app.project.ProjectManager; |
4 |
import org.gvsig.app.project.documents.table.TableDocument; |
5 |
import org.gvsig.app.project.documents.table.TableManager; |
6 |
import org.gvsig.fmap.dal.exception.DataException; |
7 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
8 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
9 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
10 |
import org.gvsig.fmap.dal.feature.FeatureType; |
11 |
import org.gvsig.tools.dispose.DisposeUtils; |
12 |
|
13 |
import es.unex.sextante.dataObjects.AbstractTable; |
14 |
import es.unex.sextante.dataObjects.IRecordsetIterator; |
15 |
|
16 |
public class gvTable extends AbstractTable { |
17 |
|
18 |
private Object m_BaseDataObject; |
19 |
private String m_sName; |
20 |
private String m_sFilename; |
21 |
private FeatureSet featureSet;
|
22 |
private FeatureType featureType;
|
23 |
private FeatureStore featureStore;
|
24 |
|
25 |
public String getName() { |
26 |
|
27 |
if (m_BaseDataObject instanceof TableDocument){ |
28 |
TableDocument table = (TableDocument) m_BaseDataObject; |
29 |
return table.getName();
|
30 |
} |
31 |
else{
|
32 |
return m_sName;
|
33 |
} |
34 |
|
35 |
} |
36 |
|
37 |
public void create(Object obj) { |
38 |
|
39 |
if (obj instanceof TableDocument){ |
40 |
try {
|
41 |
featureStore =((TableDocument)obj).getStore(); |
42 |
featureSet = featureStore.getFeatureSet(((TableDocument)obj).getQuery()); |
43 |
featureType = featureStore.getDefaultFeatureType(); |
44 |
|
45 |
} catch (DataException e) {
|
46 |
e.printStackTrace(); |
47 |
} |
48 |
} |
49 |
|
50 |
} |
51 |
|
52 |
public void create(String sName, String sFilename, Class[] types, String[] sFields) { |
53 |
|
54 |
// m_sFilename = sFilename;
|
55 |
// TableMemoryDriver table = new TableMemoryDriver(sFields, DataTools.getgvSIGTypes(types));
|
56 |
// m_sName = sName;
|
57 |
// m_BaseDataObject = table;
|
58 |
|
59 |
} |
60 |
|
61 |
public void create(String sName, Object inputParams, Class[] types, String[] sFields) { |
62 |
|
63 |
} |
64 |
|
65 |
public void addRecord(Object[] record) { |
66 |
|
67 |
// if (m_BaseDataObject instanceof TableMemoryDriver) {
|
68 |
// TableMemoryDriver table = (TableMemoryDriver) m_BaseDataObject;
|
69 |
// table.addRow(DataTools.getGVSIGValues(record));
|
70 |
// }
|
71 |
|
72 |
} |
73 |
|
74 |
public IRecordsetIterator iterator() {
|
75 |
try {
|
76 |
return new gvRecordsetIterator(featureSet); |
77 |
} catch (DataException e) {
|
78 |
throw new RuntimeException(e); |
79 |
} |
80 |
} |
81 |
|
82 |
public String getFieldName(int i) { |
83 |
return ((FeatureAttributeDescriptor)featureType.get(i)).getName();
|
84 |
} |
85 |
|
86 |
public Class getFieldType(int i) { |
87 |
return DataTools.getTypeClass(((FeatureAttributeDescriptor)featureType.get(i)).getDataType());
|
88 |
} |
89 |
|
90 |
public int getFieldCount() { |
91 |
return featureType.size();
|
92 |
} |
93 |
|
94 |
public long getRecordCount() { |
95 |
try {
|
96 |
return featureSet.getSize();
|
97 |
} catch (DataException e) {
|
98 |
e.printStackTrace(); |
99 |
} |
100 |
return 0; |
101 |
} |
102 |
|
103 |
public void postProcess() { |
104 |
try {
|
105 |
TableDocument table = (TableDocument) ProjectManager.getInstance().createDocument( |
106 |
TableManager.TYPENAME, |
107 |
m_sName |
108 |
); |
109 |
table.setStore( featureStore); |
110 |
} catch (Exception e) { |
111 |
return;
|
112 |
} |
113 |
|
114 |
TableDocument table = FileTools.openTable(m_sFilename, m_sName); |
115 |
create(table); |
116 |
} |
117 |
|
118 |
public void open() { |
119 |
|
120 |
} |
121 |
|
122 |
public void close() { |
123 |
DisposeUtils.dispose(featureSet); |
124 |
} |
125 |
|
126 |
public String getFilename() { |
127 |
return m_sFilename;
|
128 |
} |
129 |
|
130 |
public void setName(String name) { |
131 |
if (m_BaseDataObject instanceof TableDocument){ |
132 |
TableDocument table = (TableDocument) m_BaseDataObject; |
133 |
table.setName(name); |
134 |
} |
135 |
else{
|
136 |
m_sName = name; |
137 |
} |
138 |
} |
139 |
|
140 |
public Object getBaseDataObject() { |
141 |
return m_BaseDataObject;
|
142 |
} |
143 |
|
144 |
} |