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 @ 94
History | View | Annotate | Download (3.45 KB)
1 | 20 | nbrodin | 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 | 31 | nbrodin | |
61 | public void create(String sName, Object inputParams, Class[] types, String[] sFields) { |
||
62 | 20 | nbrodin | |
63 | 31 | nbrodin | } |
64 | |||
65 | 20 | nbrodin | 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 | 94 | cordinyana | return DataTools.getTypeClass(((FeatureAttributeDescriptor) featureType
|
88 | .get(i)).getDataType().getType()); |
||
89 | 20 | nbrodin | } |
90 | |||
91 | public int getFieldCount() { |
||
92 | return featureType.size();
|
||
93 | } |
||
94 | |||
95 | public long getRecordCount() { |
||
96 | try {
|
||
97 | return featureSet.getSize();
|
||
98 | } catch (DataException e) {
|
||
99 | e.printStackTrace(); |
||
100 | } |
||
101 | return 0; |
||
102 | } |
||
103 | |||
104 | public void postProcess() { |
||
105 | try {
|
||
106 | TableDocument table = (TableDocument) ProjectManager.getInstance().createDocument( |
||
107 | TableManager.TYPENAME, |
||
108 | m_sName |
||
109 | ); |
||
110 | table.setStore( featureStore); |
||
111 | } catch (Exception e) { |
||
112 | return;
|
||
113 | } |
||
114 | |||
115 | TableDocument table = FileTools.openTable(m_sFilename, m_sName); |
||
116 | create(table); |
||
117 | } |
||
118 | |||
119 | public void open() { |
||
120 | |||
121 | } |
||
122 | |||
123 | public void close() { |
||
124 | DisposeUtils.dispose(featureSet); |
||
125 | } |
||
126 | |||
127 | public String getFilename() { |
||
128 | return m_sFilename;
|
||
129 | } |
||
130 | |||
131 | public void setName(String name) { |
||
132 | if (m_BaseDataObject instanceof TableDocument){ |
||
133 | TableDocument table = (TableDocument) m_BaseDataObject; |
||
134 | table.setName(name); |
||
135 | } |
||
136 | else{
|
||
137 | m_sName = name; |
||
138 | } |
||
139 | } |
||
140 | |||
141 | public Object getBaseDataObject() { |
||
142 | return m_BaseDataObject;
|
||
143 | } |
||
144 | |||
145 | } |