Revision 43983
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.csv/src/main/java/org/gvsig/fmap/dal/store/csv/CSVStoreProvider.java | ||
---|---|---|
1137 | 1137 |
} |
1138 | 1138 |
} |
1139 | 1139 |
|
1140 |
private static class PossibleDataType { |
|
1141 |
|
|
1142 |
public boolean possibleInt = true; |
|
1143 |
public boolean possibleFloat = true; |
|
1144 |
public boolean possibleDouble = true; |
|
1145 |
public boolean possibleLong = true; |
|
1146 |
public boolean possibleURL = true; |
|
1147 |
public boolean possibleDate = true; |
|
1148 |
public boolean possibleGeometry = true; |
|
1149 |
} |
|
1150 |
|
|
1151 | 1140 |
private int[] automaticDetectionOfTypes(String[] headers) throws IOException { |
1152 | 1141 |
boolean automatic_types_detection = CSVStoreParameters.getAutomaticTypesDetection(getCSVParameters()); |
1153 | 1142 |
if (!automatic_types_detection) { |
1154 | 1143 |
return null; |
1155 | 1144 |
} |
1156 |
List<PossibleDataType> possibleDataTypes; |
|
1157 |
Locale locale; |
|
1158 | 1145 |
int[] types = null; |
1159 | 1146 |
|
1160 | 1147 |
FileReader in = null; |
... | ... | |
1163 | 1150 |
try { |
1164 | 1151 |
in = new FileReader(this.getCSVParameters().getFile()); |
1165 | 1152 |
reader = getSimpleReader(in); |
1166 |
if (CSVStoreParameters.isFirstLineHeader(getCSVParameters())) { |
|
1167 |
reader.read(); |
|
1168 |
} |
|
1169 |
possibleDataTypes = new ArrayList<>(headers.length); |
|
1170 |
for (String header : headers) { |
|
1171 |
possibleDataTypes.add(new PossibleDataType()); |
|
1172 |
} |
|
1173 |
locale = CSVStoreParameters.getLocale(getCSVParameters()); |
|
1174 |
if (locale == null) { |
|
1175 |
locale = Locale.getDefault(); |
|
1176 |
} |
|
1177 |
DataTypesManager typeManager = ToolsLocator.getDataTypesManager(); |
|
1178 |
CoercionWithLocale toDouble = (CoercionWithLocale) typeManager.getCoercion(DataTypes.DOUBLE); |
|
1179 |
CoercionWithLocale toFloat = (CoercionWithLocale) typeManager.getCoercion(DataTypes.FLOAT); |
|
1180 |
CoercionWithLocale toDate = (CoercionWithLocale) typeManager.getCoercion(DataTypes.DATE); |
|
1181 |
CoercionWithLocale toInt = (CoercionWithLocale) typeManager.getCoercion(DataTypes.INT); |
|
1182 |
CoercionWithLocale toLong = (CoercionWithLocale) typeManager.getCoercion(DataTypes.LONG); |
|
1183 |
Coercion toGeom = typeManager.getCoercion(DataTypes.GEOMETRY); |
|
1184 |
|
|
1185 |
List<String> row = reader.read(); |
|
1186 |
|
|
1187 |
while (row != null) { |
|
1188 |
for (int i = 0; i < row.size(); i++) { |
|
1189 |
while( possibleDataTypes.size()<row.size() ) { |
|
1190 |
possibleDataTypes.add(new PossibleDataType()); |
|
1191 |
} |
|
1192 |
String rawvalue = row.get(i); |
|
1193 |
PossibleDataType possibleDataType = possibleDataTypes.get(i); |
|
1194 |
if (possibleDataType.possibleDouble) { |
|
1195 |
try { |
|
1196 |
toDouble.coerce(rawvalue, locale); |
|
1197 |
possibleDataType.possibleDouble = true; |
|
1198 |
} catch (Exception ex) { |
|
1199 |
possibleDataType.possibleDouble = false; |
|
1200 |
} |
|
1201 |
} |
|
1202 |
if (possibleDataType.possibleFloat) { |
|
1203 |
try { |
|
1204 |
toFloat.coerce(rawvalue, locale); |
|
1205 |
possibleDataType.possibleFloat = true; |
|
1206 |
} catch (Exception ex) { |
|
1207 |
possibleDataType.possibleFloat = false; |
|
1208 |
} |
|
1209 |
} |
|
1210 |
if (possibleDataType.possibleLong) { |
|
1211 |
possibleDataType.possibleLong = isValidLong(rawvalue); |
|
1212 |
} |
|
1213 |
if (possibleDataType.possibleInt) { |
|
1214 |
possibleDataType.possibleInt = isValidInteger(rawvalue); |
|
1215 |
} |
|
1216 |
if (possibleDataType.possibleDate) { |
|
1217 |
try { |
|
1218 |
toDate.coerce(rawvalue, locale); |
|
1219 |
possibleDataType.possibleDate = true; |
|
1220 |
} catch (Exception ex) { |
|
1221 |
possibleDataType.possibleDate = false; |
|
1222 |
} |
|
1223 |
} |
|
1224 |
if (possibleDataType.possibleURL) { |
|
1225 |
try { |
|
1226 |
new URL((String) rawvalue); |
|
1227 |
possibleDataType.possibleURL = true; |
|
1228 |
} catch (Exception ex) { |
|
1229 |
possibleDataType.possibleURL = false; |
|
1230 |
} |
|
1231 |
} |
|
1232 |
if (possibleDataType.possibleGeometry) { |
|
1233 |
try { |
|
1234 |
toGeom.coerce((String) rawvalue); |
|
1235 |
possibleDataType.possibleGeometry = true; |
|
1236 |
} catch (Exception ex) { |
|
1237 |
possibleDataType.possibleGeometry = false; |
|
1238 |
} |
|
1239 |
} |
|
1240 |
} |
|
1241 |
row = reader.read(); |
|
1242 |
} |
|
1243 |
int n = 0; |
|
1244 |
types = new int[possibleDataTypes.size()]; |
|
1245 |
for (PossibleDataType possibleDataType : possibleDataTypes) { |
|
1246 |
if (possibleDataType.possibleInt) { |
|
1247 |
types[n++] = DataTypes.INT; |
|
1248 |
continue; |
|
1249 |
} |
|
1250 |
if (possibleDataType.possibleLong) { |
|
1251 |
types[n++] = DataTypes.LONG; |
|
1252 |
continue; |
|
1253 |
} |
|
1254 |
if (possibleDataType.possibleFloat) { |
|
1255 |
// Forzamos los float a double para evitar perder precision |
|
1256 |
types[n++] = DataTypes.DOUBLE; |
|
1257 |
continue; |
|
1258 |
} |
|
1259 |
if (possibleDataType.possibleDouble) { |
|
1260 |
types[n++] = DataTypes.DOUBLE; |
|
1261 |
continue; |
|
1262 |
} |
|
1263 |
if (possibleDataType.possibleURL) { |
|
1264 |
types[n++] = DataTypes.URL; |
|
1265 |
continue; |
|
1266 |
} |
|
1267 |
if (possibleDataType.possibleDate) { |
|
1268 |
types[n++] = DataTypes.DATE; |
|
1269 |
continue; |
|
1270 |
} |
|
1271 |
if (possibleDataType.possibleGeometry) { |
|
1272 |
types[n++] = DataTypes.GEOMETRY; |
|
1273 |
continue; |
|
1274 |
} |
|
1275 |
types[n++] = DataTypes.STRING; |
|
1276 |
} |
|
1153 |
AutomaticDetectionOfTypes x = new AutomaticDetectionOfTypes( |
|
1154 |
this.getFullFileName() |
|
1155 |
); |
|
1156 |
types = x.detect( |
|
1157 |
headers.length, |
|
1158 |
reader, |
|
1159 |
CSVStoreParameters.isFirstLineHeader(getCSVParameters()), |
|
1160 |
CSVStoreParameters.getLocale(getCSVParameters()) |
|
1161 |
); |
|
1277 | 1162 |
} catch (Exception ex) { |
1278 | 1163 |
int lineno = 0; |
1279 | 1164 |
if (reader != null) { |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.csv/src/main/java/org/gvsig/fmap/dal/store/csv/AutomaticDetectionOfTypes.java | ||
---|---|---|
1 |
package org.gvsig.fmap.dal.store.csv; |
|
2 |
|
|
3 |
import java.io.IOException; |
|
4 |
import java.net.URL; |
|
5 |
import java.util.ArrayList; |
|
6 |
import java.util.List; |
|
7 |
import java.util.Locale; |
|
8 |
import org.gvsig.fmap.dal.DataTypes; |
|
9 |
import org.gvsig.tools.ToolsLocator; |
|
10 |
import org.gvsig.tools.dataTypes.DataTypesManager; |
|
11 |
|
|
12 |
/** |
|
13 |
* |
|
14 |
* @author jjdelcerro |
|
15 |
*/ |
|
16 |
public class AutomaticDetectionOfTypes { |
|
17 |
|
|
18 |
public interface Rows { |
|
19 |
public List<String> nextRowValues(); |
|
20 |
} |
|
21 |
|
|
22 |
private static class PossibleDataType { |
|
23 |
|
|
24 |
public boolean possibleInt = true; |
|
25 |
public boolean possibleFloat = true; |
|
26 |
public boolean possibleDouble = true; |
|
27 |
public boolean possibleLong = true; |
|
28 |
public boolean possibleURL = true; |
|
29 |
public boolean possibleDate = true; |
|
30 |
public boolean possibleGeometry = true; |
|
31 |
} |
|
32 |
|
|
33 |
private final String filename; |
|
34 |
|
|
35 |
public AutomaticDetectionOfTypes() { |
|
36 |
this("(unknown)"); |
|
37 |
} |
|
38 |
|
|
39 |
public AutomaticDetectionOfTypes(String filename) { |
|
40 |
this.filename = filename; |
|
41 |
} |
|
42 |
|
|
43 |
private String getFullFileName() { |
|
44 |
return this.filename; |
|
45 |
} |
|
46 |
|
|
47 |
@SuppressWarnings({"UseSpecificCatch", "ResultOfObjectAllocationIgnored"}) |
|
48 |
public int[] detect(int columns, Rows rows, boolean isFirstLineHeader, Locale locale) throws IOException { |
|
49 |
List<PossibleDataType> possibleDataTypes; |
|
50 |
int[] types = null; |
|
51 |
|
|
52 |
int lineno = 0; |
|
53 |
try { |
|
54 |
if (isFirstLineHeader) { |
|
55 |
rows.nextRowValues(); |
|
56 |
lineno++; |
|
57 |
} |
|
58 |
possibleDataTypes = new ArrayList<>(columns); |
|
59 |
for (int i = 0; i < columns; i++) { |
|
60 |
possibleDataTypes.add(new PossibleDataType()); |
|
61 |
} |
|
62 |
if (locale == null) { |
|
63 |
locale = Locale.getDefault(); |
|
64 |
} |
|
65 |
DataTypesManager typeManager = ToolsLocator.getDataTypesManager(); |
|
66 |
DataTypesManager.CoercionWithLocale toDouble = (DataTypesManager.CoercionWithLocale) typeManager.getCoercion(DataTypes.DOUBLE); |
|
67 |
DataTypesManager.CoercionWithLocale toFloat = (DataTypesManager.CoercionWithLocale) typeManager.getCoercion(DataTypes.FLOAT); |
|
68 |
DataTypesManager.CoercionWithLocale toDate = (DataTypesManager.CoercionWithLocale) typeManager.getCoercion(DataTypes.DATE); |
|
69 |
DataTypesManager.CoercionWithLocale toInt = (DataTypesManager.CoercionWithLocale) typeManager.getCoercion(DataTypes.INT); |
|
70 |
DataTypesManager.CoercionWithLocale toLong = (DataTypesManager.CoercionWithLocale) typeManager.getCoercion(DataTypes.LONG); |
|
71 |
DataTypesManager.Coercion toGeom = typeManager.getCoercion(DataTypes.GEOMETRY); |
|
72 |
|
|
73 |
List<String> row = rows.nextRowValues(); |
|
74 |
lineno++; |
|
75 |
|
|
76 |
while (row != null) { |
|
77 |
for (int i = 0; i < row.size(); i++) { |
|
78 |
while( possibleDataTypes.size()<row.size() ) { |
|
79 |
possibleDataTypes.add(new PossibleDataType()); |
|
80 |
} |
|
81 |
String rawvalue = row.get(i); |
|
82 |
PossibleDataType possibleDataType = possibleDataTypes.get(i); |
|
83 |
if (possibleDataType.possibleDouble) { |
|
84 |
try { |
|
85 |
toDouble.coerce(rawvalue, locale); |
|
86 |
possibleDataType.possibleDouble = true; |
|
87 |
} catch (Exception ex) { |
|
88 |
possibleDataType.possibleDouble = false; |
|
89 |
} |
|
90 |
} |
|
91 |
if (possibleDataType.possibleFloat) { |
|
92 |
try { |
|
93 |
toFloat.coerce(rawvalue, locale); |
|
94 |
possibleDataType.possibleFloat = true; |
|
95 |
} catch (Exception ex) { |
|
96 |
possibleDataType.possibleFloat = false; |
|
97 |
} |
|
98 |
} |
|
99 |
if (possibleDataType.possibleLong) { |
|
100 |
possibleDataType.possibleLong = isValidLong(rawvalue); |
|
101 |
} |
|
102 |
if (possibleDataType.possibleInt) { |
|
103 |
possibleDataType.possibleInt = isValidInteger(rawvalue); |
|
104 |
} |
|
105 |
if (possibleDataType.possibleDate) { |
|
106 |
try { |
|
107 |
toDate.coerce(rawvalue, locale); |
|
108 |
possibleDataType.possibleDate = true; |
|
109 |
} catch (Exception ex) { |
|
110 |
possibleDataType.possibleDate = false; |
|
111 |
} |
|
112 |
} |
|
113 |
if (possibleDataType.possibleURL) { |
|
114 |
try { |
|
115 |
new URL((String) rawvalue); |
|
116 |
possibleDataType.possibleURL = true; |
|
117 |
} catch (Exception ex) { |
|
118 |
possibleDataType.possibleURL = false; |
|
119 |
} |
|
120 |
} |
|
121 |
if (possibleDataType.possibleGeometry) { |
|
122 |
try { |
|
123 |
toGeom.coerce((String) rawvalue); |
|
124 |
possibleDataType.possibleGeometry = true; |
|
125 |
} catch (Exception ex) { |
|
126 |
possibleDataType.possibleGeometry = false; |
|
127 |
} |
|
128 |
} |
|
129 |
} |
|
130 |
row = rows.nextRowValues(); |
|
131 |
} |
|
132 |
int n = 0; |
|
133 |
types = new int[possibleDataTypes.size()]; |
|
134 |
for (PossibleDataType possibleDataType : possibleDataTypes) { |
|
135 |
if (possibleDataType.possibleInt) { |
|
136 |
types[n++] = DataTypes.INT; |
|
137 |
continue; |
|
138 |
} |
|
139 |
if (possibleDataType.possibleLong) { |
|
140 |
types[n++] = DataTypes.LONG; |
|
141 |
continue; |
|
142 |
} |
|
143 |
if (possibleDataType.possibleFloat) { |
|
144 |
// Forzamos los float a double para evitar perder precision |
|
145 |
types[n++] = DataTypes.DOUBLE; |
|
146 |
continue; |
|
147 |
} |
|
148 |
if (possibleDataType.possibleDouble) { |
|
149 |
types[n++] = DataTypes.DOUBLE; |
|
150 |
continue; |
|
151 |
} |
|
152 |
if (possibleDataType.possibleURL) { |
|
153 |
types[n++] = DataTypes.URL; |
|
154 |
continue; |
|
155 |
} |
|
156 |
if (possibleDataType.possibleDate) { |
|
157 |
types[n++] = DataTypes.DATE; |
|
158 |
continue; |
|
159 |
} |
|
160 |
if (possibleDataType.possibleGeometry) { |
|
161 |
types[n++] = DataTypes.GEOMETRY; |
|
162 |
continue; |
|
163 |
} |
|
164 |
types[n++] = DataTypes.STRING; |
|
165 |
} |
|
166 |
} catch (Exception ex) { |
|
167 |
throw new RuntimeException("Problems reading file '" + this.getFullFileName() + "' near line " + lineno + ".", ex); |
|
168 |
} |
|
169 |
return types; |
|
170 |
} |
|
171 |
|
|
172 |
@SuppressWarnings("UseSpecificCatch") |
|
173 |
private boolean isValidLong(String s) { |
|
174 |
if (s == null) { |
|
175 |
return true; |
|
176 |
} |
|
177 |
s = s.trim().toLowerCase(); |
|
178 |
if (s.isEmpty()) { |
|
179 |
return true; |
|
180 |
} |
|
181 |
try { |
|
182 |
if (s.startsWith("0x")) { |
|
183 |
Long.valueOf(s.substring(2), 16); |
|
184 |
} else { |
|
185 |
Long.valueOf(s); |
|
186 |
} |
|
187 |
return true; |
|
188 |
} catch (Exception ex) { |
|
189 |
return false; |
|
190 |
} |
|
191 |
} |
|
192 |
|
|
193 |
@SuppressWarnings("UseSpecificCatch") |
|
194 |
private boolean isValidInteger(String s) { |
|
195 |
if (s == null) { |
|
196 |
return true; |
|
197 |
} |
|
198 |
s = s.trim().toLowerCase(); |
|
199 |
if (s.isEmpty()) { |
|
200 |
return true; |
|
201 |
} |
|
202 |
try { |
|
203 |
if (s.startsWith("0x")) { |
|
204 |
Integer.valueOf(s.substring(2), 16); |
|
205 |
} else { |
|
206 |
Integer.valueOf(s); |
|
207 |
} |
|
208 |
return true; |
|
209 |
} catch (Exception ex) { |
|
210 |
return false; |
|
211 |
} |
|
212 |
} |
|
213 |
|
|
214 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.csv/src/main/java/org/gvsig/fmap/dal/store/csv/simplereaders/CSVReader.java | ||
---|---|---|
169 | 169 |
return this.reader.getLineNumber(); |
170 | 170 |
} |
171 | 171 |
|
172 |
@Override |
|
173 |
public List<String> nextRowValues() { |
|
174 |
try { |
|
175 |
return this.read(); |
|
176 |
} catch (IOException ex) { |
|
177 |
throw new RuntimeException(ex); |
|
178 |
} |
|
179 |
} |
|
180 |
|
|
172 | 181 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.csv/src/main/java/org/gvsig/fmap/dal/store/csv/simplereaders/FixedLenReader.java | ||
---|---|---|
102 | 102 |
public int getLine() { |
103 | 103 |
return this.currentLine; |
104 | 104 |
} |
105 |
|
|
106 |
@Override |
|
107 |
public List<String> nextRowValues() { |
|
108 |
try { |
|
109 |
return this.read(); |
|
110 |
} catch (IOException ex) { |
|
111 |
throw new RuntimeException(ex); |
|
112 |
} |
|
113 |
} |
|
105 | 114 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.csv/src/main/java/org/gvsig/fmap/dal/store/csv/simplereaders/SimpleReader.java | ||
---|---|---|
3 | 3 |
import java.io.IOException; |
4 | 4 |
import java.util.List; |
5 | 5 |
import java.io.Closeable; |
6 |
import org.gvsig.fmap.dal.store.csv.AutomaticDetectionOfTypes.Rows; |
|
6 | 7 |
|
7 |
public interface SimpleReader extends Closeable { |
|
8 |
public interface SimpleReader extends Closeable, Rows {
|
|
8 | 9 |
|
9 | 10 |
public String[] getHeader() throws IOException; |
10 | 11 |
|
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/feature/impl/featureset/DefaultFeatureSet.java | ||
---|---|---|
255 | 255 |
} finally { |
256 | 256 |
iter.dispose(); |
257 | 257 |
} |
258 |
} else |
|
259 |
if ((mode & EDITED) == EDITED) { |
|
260 |
long mySize = provider.getSize() |
|
261 |
+ store.getFeatureManager().getDeltaSize(); |
|
262 |
return (limit>0 && mySize>limit)? limit:mySize; |
|
263 |
} |
|
258 |
} else if ((mode & EDITED) == EDITED) { |
|
259 |
long mySize = provider.getSize() |
|
260 |
+ store.getFeatureManager().getDeltaSize(); |
|
261 |
return (limit>0 && mySize>limit)? limit:mySize; |
|
262 |
} |
|
264 | 263 |
long mySize = provider.getSize(); |
265 | 264 |
return (limit>0 && mySize>limit)? limit:mySize; |
266 | 265 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/feature/impl/DefaultFeature.java | ||
---|---|---|
746 | 746 |
this.inserted = inserted; |
747 | 747 |
} |
748 | 748 |
|
749 |
@Override |
|
749 | 750 |
public EvaluatorData getEvaluatorData() { |
750 | 751 |
return this; |
751 | 752 |
} |
753 |
|
|
754 |
public int size() { |
|
755 |
return this.data.getType().size(); |
|
756 |
} |
|
757 |
|
|
758 |
public boolean isEmpty() { |
|
759 |
return false; |
|
760 |
} |
|
761 |
|
|
762 |
public Iterator<String> iterator() { |
|
763 |
final Iterator<FeatureAttributeDescriptor> x = this.data.getType().iterator(); |
|
764 |
return new Iterator<String>() { |
|
765 |
@Override |
|
766 |
public boolean hasNext() { |
|
767 |
return x.hasNext(); |
|
768 |
} |
|
769 |
|
|
770 |
@Override |
|
771 |
public String next() { |
|
772 |
return x.next().getName(); |
|
773 |
} |
|
774 |
}; |
|
775 |
} |
|
776 |
|
|
777 |
public boolean containsKey(String key) { |
|
778 |
return this.data.getType().get(key)!=null; |
|
779 |
} |
|
752 | 780 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/impl/expressionevaluator/DefaultFeatureSymbolTable.java | ||
---|---|---|
1 |
package org.gvsig.fmap.dal.impl.expressionevaluator; |
|
2 |
|
|
3 |
import org.apache.commons.lang3.Range; |
|
4 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator; |
|
5 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorManager; |
|
6 |
import org.gvsig.expressionevaluator.Function; |
|
7 |
import org.gvsig.expressionevaluator.Interpreter; |
|
8 |
import org.gvsig.expressionevaluator.SymbolTable; |
|
9 |
import org.gvsig.expressionevaluator.spi.AbstractFunction; |
|
10 |
import org.gvsig.expressionevaluator.spi.AbstractSymbolTable; |
|
11 |
import org.gvsig.fmap.dal.expressionevaluator.FeatureSymbolTable; |
|
12 |
import org.gvsig.fmap.dal.feature.Feature; |
|
13 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
|
14 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
15 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
16 |
|
|
17 |
/** |
|
18 |
* |
|
19 |
* @author jjdelcerro |
|
20 |
*/ |
|
21 |
public class DefaultFeatureSymbolTable extends AbstractSymbolTable implements FeatureSymbolTable { |
|
22 |
|
|
23 |
private class FeatureFunction extends AbstractFunction { |
|
24 |
|
|
25 |
public FeatureFunction() { |
|
26 |
super( |
|
27 |
"Data access", |
|
28 |
"feature", |
|
29 |
Range.is(0), |
|
30 |
"Access to the current feature object when used in a filter.\n" |
|
31 |
+ "Return null if used outer a filter.", |
|
32 |
"feature()", |
|
33 |
null, |
|
34 |
"Feature" |
|
35 |
); |
|
36 |
} |
|
37 |
|
|
38 |
@Override |
|
39 |
public Object call(Interpreter interpreter, Object[] args) throws Exception { |
|
40 |
return feature; |
|
41 |
} |
|
42 |
|
|
43 |
} |
|
44 |
|
|
45 |
public class FeatureStoreFunction extends AbstractFunction { |
|
46 |
|
|
47 |
public FeatureStoreFunction() { |
|
48 |
super( |
|
49 |
"Data access", |
|
50 |
"store", |
|
51 |
Range.is(0), |
|
52 |
"Access to the current store object when used in a filter.\n" |
|
53 |
+ "Return null if used outer a filter.", |
|
54 |
"store()", |
|
55 |
null, |
|
56 |
"FeatureStore" |
|
57 |
); |
|
58 |
} |
|
59 |
|
|
60 |
@Override |
|
61 |
public Object call(Interpreter interpreter, Object[] args) throws Exception { |
|
62 |
return feature.getStore(); |
|
63 |
} |
|
64 |
|
|
65 |
} |
|
66 |
|
|
67 |
public class IsSelectedFunction extends AbstractFunction { |
|
68 |
|
|
69 |
public IsSelectedFunction() { |
|
70 |
super( |
|
71 |
"Data access", |
|
72 |
"isSelected", |
|
73 |
Range.is(0), |
|
74 |
"Return if the current feature is selected in the store when used in a filter.\n" |
|
75 |
+ "Return false if used outer a filter.", |
|
76 |
"isSelected()", |
|
77 |
null, |
|
78 |
"Boolean" |
|
79 |
); |
|
80 |
} |
|
81 |
|
|
82 |
@Override |
|
83 |
public Object call(Interpreter interpreter, Object[] args) throws Exception { |
|
84 |
FeatureStore store = feature.getStore(); |
|
85 |
FeatureSelection selection = store.getFeatureSelection(); |
|
86 |
return selection.isSelected(feature); |
|
87 |
} |
|
88 |
|
|
89 |
} |
|
90 |
|
|
91 |
private Feature feature; |
|
92 |
private FeatureType type; |
|
93 |
|
|
94 |
public DefaultFeatureSymbolTable() { |
|
95 |
super("DAL.FeatureSymbolTable"); |
|
96 |
|
|
97 |
this.addFunction(new FeatureFunction()); |
|
98 |
this.addFunction(new FeatureStoreFunction()); |
|
99 |
this.addFunction(new IsSelectedFunction()); |
|
100 |
} |
|
101 |
|
|
102 |
public final void addFunction(Function function) { |
|
103 |
if (function == null) { |
|
104 |
throw new IllegalArgumentException("function can't be null"); |
|
105 |
} |
|
106 |
this.getFunctions().put(function.name().toUpperCase(), function); |
|
107 |
} |
|
108 |
|
|
109 |
@Override |
|
110 |
public FeatureSymbolTable clone() throws CloneNotSupportedException { |
|
111 |
DefaultFeatureSymbolTable other = (DefaultFeatureSymbolTable) super.clone(); |
|
112 |
return other; |
|
113 |
} |
|
114 |
|
|
115 |
@Override |
|
116 |
public boolean exists(String name) { |
|
117 |
if (type.get(name) != null) { |
|
118 |
return true; |
|
119 |
} |
|
120 |
return false; |
|
121 |
} |
|
122 |
|
|
123 |
@Override |
|
124 |
public Object value(String name) { |
|
125 |
return this.feature.get(name); |
|
126 |
} |
|
127 |
|
|
128 |
@Override |
|
129 |
public void setFeature(Feature feature) { |
|
130 |
this.feature = feature; |
|
131 |
this.type = feature.getType(); |
|
132 |
} |
|
133 |
|
|
134 |
public static void selfRegister() { |
|
135 |
ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
|
136 |
manager.registerSymbolTable(new DefaultFeatureSymbolTable()); |
|
137 |
} |
|
138 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/impl/expressionevaluator/DefaultEvaluatorFactory.java | ||
---|---|---|
1 |
package org.gvsig.fmap.dal.impl.expressionevaluator; |
|
2 |
|
|
3 |
import org.gvsig.tools.evaluator.Evaluator; |
|
4 |
import org.gvsig.tools.evaluator.EvaluatorFactory; |
|
5 |
|
|
6 |
/** |
|
7 |
* |
|
8 |
* @author jjdelcerro |
|
9 |
*/ |
|
10 |
public class DefaultEvaluatorFactory implements EvaluatorFactory { |
|
11 |
|
|
12 |
@Override |
|
13 |
public Evaluator createEvaluator(String phrase) { |
|
14 |
Evaluator e = new DefaultExpressionEvaluator(phrase); |
|
15 |
return e; |
|
16 |
} |
|
17 |
|
|
18 |
@Override |
|
19 |
public String getName() { |
|
20 |
return "DAL expression evaluator"; |
|
21 |
} |
|
22 |
|
|
23 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/impl/expressionevaluator/DefaultExpressionEvaluator.java | ||
---|---|---|
1 |
package org.gvsig.fmap.dal.impl.expressionevaluator; |
|
2 |
|
|
3 |
import java.util.ArrayList; |
|
4 |
import java.util.HashSet; |
|
5 |
import java.util.List; |
|
6 |
import java.util.Set; |
|
7 |
import org.gvsig.expressionevaluator.Code; |
|
8 |
import org.gvsig.expressionevaluator.Interpreter; |
|
9 |
import org.gvsig.expressionevaluator.SymbolTable; |
|
10 |
import org.gvsig.expressionevaluator.Compiler; |
|
11 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator; |
|
12 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorManager; |
|
13 |
import org.gvsig.expressionevaluator.Function; |
|
14 |
import org.gvsig.fmap.dal.expressionevaluator.FeatureSymbolTable; |
|
15 |
import org.gvsig.fmap.dal.feature.Feature; |
|
16 |
import org.gvsig.tools.evaluator.AbstractEvaluator; |
|
17 |
import org.gvsig.tools.evaluator.Evaluator; |
|
18 |
import org.gvsig.tools.evaluator.EvaluatorData; |
|
19 |
import org.gvsig.tools.evaluator.EvaluatorException; |
|
20 |
import org.gvsig.tools.evaluator.EvaluatorFieldsInfo; |
|
21 |
import org.gvsig.tools.evaluator.EvaluatorWithDescriptions; |
|
22 |
import org.gvsig.tools.exception.BaseException; |
|
23 |
import org.gvsig.tools.visitor.VisitCanceledException; |
|
24 |
import org.gvsig.tools.visitor.Visitor; |
|
25 |
import org.gvsig.tools.lang.Cloneable; |
|
26 |
|
|
27 |
public class DefaultExpressionEvaluator |
|
28 |
extends AbstractEvaluator |
|
29 |
implements EvaluatorWithDescriptions, Cloneable |
|
30 |
{ |
|
31 |
|
|
32 |
private static class DescriptionAdapter implements Description { |
|
33 |
|
|
34 |
Function function; |
|
35 |
|
|
36 |
public DescriptionAdapter(Function function) { |
|
37 |
this.function = function; |
|
38 |
} |
|
39 |
|
|
40 |
@Override |
|
41 |
public String getName() { |
|
42 |
return this.function.name(); |
|
43 |
} |
|
44 |
|
|
45 |
@Override |
|
46 |
public String getDescription() { |
|
47 |
return this.function.description(); |
|
48 |
} |
|
49 |
|
|
50 |
@Override |
|
51 |
public String getTemplate() { |
|
52 |
return this.function.template(); |
|
53 |
} |
|
54 |
|
|
55 |
@Override |
|
56 |
public int getDataTypeCategories() { |
|
57 |
switch (this.function.group()) { |
|
58 |
case Function.GROUP_STRING: |
|
59 |
return Description.DATATYPE_CATEGORY_STRING; |
|
60 |
case Function.GROUP_BOOLEAN: |
|
61 |
return Description.DATATYPE_CATEGORY_BOOLEAN; |
|
62 |
case Function.GROUP_DATETIME: |
|
63 |
return Description.DATATYPE_CATEGORY_DATETIME; |
|
64 |
case Function.GROUP_NUMERIC: |
|
65 |
return Description.DATATYPE_CATEGORY_NUMBER; |
|
66 |
case Function.GROUP_OGC: |
|
67 |
return Description.DATATYPE_CATEGORY_ALL; |
|
68 |
default: |
|
69 |
return Description.DATATYPE_CATEGORY_ALL; |
|
70 |
} |
|
71 |
} |
|
72 |
|
|
73 |
} |
|
74 |
|
|
75 |
private FeatureSymbolTable featureSymbolTable; |
|
76 |
private Compiler compiler; |
|
77 |
private Interpreter interpreter; |
|
78 |
private Code code; |
|
79 |
private String source; |
|
80 |
private Description[] availableOperators; |
|
81 |
private Description[] availableFunctions; |
|
82 |
|
|
83 |
public DefaultExpressionEvaluator(String source) { |
|
84 |
this.featureSymbolTable = new DefaultFeatureSymbolTable(); |
|
85 |
this.source = source; |
|
86 |
} |
|
87 |
|
|
88 |
private void compile() { |
|
89 |
this.code = this.compiler.compileExpression(source); |
|
90 |
} |
|
91 |
|
|
92 |
@Override |
|
93 |
public Object evaluate(EvaluatorData data) throws EvaluatorException { |
|
94 |
if (this.code == null) { |
|
95 |
this.compile(); |
|
96 |
} |
|
97 |
Interpreter theInterpreter = this.getInterpreter(); |
|
98 |
theInterpreter.getSymbolTable().addSymbolTable(this.featureSymbolTable); |
|
99 |
|
|
100 |
this.featureSymbolTable.setFeature((Feature) data); |
|
101 |
Object v = this.interpreter.run(code); |
|
102 |
return v; |
|
103 |
} |
|
104 |
|
|
105 |
@Override |
|
106 |
public String getName() { |
|
107 |
return "Genereric expression"; |
|
108 |
} |
|
109 |
|
|
110 |
@Override |
|
111 |
public EvaluatorFieldsInfo getFieldsInfo() { |
|
112 |
final Set<String> names = new HashSet<>(); |
|
113 |
try { |
|
114 |
this.code.accept(new Visitor() { |
|
115 |
@Override |
|
116 |
public void visit(Object code) throws VisitCanceledException, BaseException { |
|
117 |
if (code instanceof Code.Identifier) { |
|
118 |
Code.Identifier identifier = (Code.Identifier) code; |
|
119 |
names.add(identifier.name()); |
|
120 |
} |
|
121 |
} |
|
122 |
}); |
|
123 |
EvaluatorFieldsInfo info = new EvaluatorFieldsInfo(); |
|
124 |
for (String name : names) { |
|
125 |
info.addFieldValue(name); |
|
126 |
} |
|
127 |
return info; |
|
128 |
} catch (BaseException ex) { |
|
129 |
throw new RuntimeException("Can't calculate fields information.", ex); |
|
130 |
} |
|
131 |
} |
|
132 |
|
|
133 |
@Override |
|
134 |
public Description[] getAvailableOperators() { |
|
135 |
if (availableOperators == null) { |
|
136 |
List<Description> l = new ArrayList<>(); |
|
137 |
for (Function function : getSymbolTable()) { |
|
138 |
if (function.isOperator()) { |
|
139 |
l.add(new DescriptionAdapter(function)); |
|
140 |
} |
|
141 |
} |
|
142 |
this.availableOperators = l.toArray(new Description[l.size()]); |
|
143 |
} |
|
144 |
return availableOperators; |
|
145 |
} |
|
146 |
|
|
147 |
@Override |
|
148 |
public Description[] getAvailableFunctions() { |
|
149 |
if (availableFunctions == null) { |
|
150 |
List<Description> l = new ArrayList<>(); |
|
151 |
for (Function function : getSymbolTable()) { |
|
152 |
if (!function.isOperator()) { |
|
153 |
l.add(new DescriptionAdapter(function)); |
|
154 |
} |
|
155 |
} |
|
156 |
this.availableFunctions = l.toArray(new Description[l.size()]); |
|
157 |
} |
|
158 |
return availableFunctions; |
|
159 |
} |
|
160 |
|
|
161 |
private SymbolTable getSymbolTable() { |
|
162 |
return this.getInterpreter().getSymbolTable(); |
|
163 |
} |
|
164 |
|
|
165 |
private Interpreter getInterpreter() { |
|
166 |
if (this.interpreter == null) { |
|
167 |
ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
|
168 |
this.interpreter = manager.createInterpreter(); |
|
169 |
this.interpreter.setAccuracy(ExpressionEvaluatorLocator.getManager().getAccuracy()); |
|
170 |
} |
|
171 |
return interpreter; |
|
172 |
} |
|
173 |
|
|
174 |
@Override |
|
175 |
public Evaluator clone() throws CloneNotSupportedException { |
|
176 |
DefaultExpressionEvaluator other = (DefaultExpressionEvaluator) super.clone(); |
|
177 |
other.code = this.code; |
|
178 |
other.source = this.source; |
|
179 |
other.availableFunctions = null; |
|
180 |
other.availableOperators = null; |
|
181 |
|
|
182 |
if (this.featureSymbolTable != null) { |
|
183 |
// evaluatorData don't support clone. |
|
184 |
other.featureSymbolTable = this.featureSymbolTable.clone(); |
|
185 |
} |
|
186 |
if (this.compiler != null) { |
|
187 |
other.compiler = this.compiler.clone(); |
|
188 |
} |
|
189 |
if (this.interpreter != null) { |
|
190 |
other.interpreter = this.interpreter.clone(); |
|
191 |
} |
|
192 |
return other; |
|
193 |
} |
|
194 |
|
|
195 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/impl/DefaultDataManager.java | ||
---|---|---|
21 | 21 |
import org.gvsig.fmap.dal.DataStoreParameters; |
22 | 22 |
import org.gvsig.fmap.dal.DataStoreProviderFactory; |
23 | 23 |
import org.gvsig.fmap.dal.DataTypes; |
24 |
import org.gvsig.fmap.dal.EvaluatorFactory; |
|
25 | 24 |
import org.gvsig.fmap.dal.ExpressionBuilder; |
26 | 25 |
|
27 | 26 |
import org.gvsig.fmap.dal.NewDataStoreParameters; |
... | ... | |
33 | 32 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
34 | 33 |
import org.gvsig.fmap.dal.exception.CreateFileStoreException; |
35 | 34 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
35 |
import org.gvsig.fmap.dal.expressionevaluator.FeatureSymbolTable; |
|
36 | 36 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
37 | 37 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
38 | 38 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
... | ... | |
50 | 50 |
import org.gvsig.fmap.dal.feature.spi.cache.FeatureCacheProviderFactory; |
51 | 51 |
import org.gvsig.fmap.dal.feature.spi.index.FeatureIndexProvider; |
52 | 52 |
import org.gvsig.fmap.dal.feature.spi.index.FeatureIndexProviderServices; |
53 |
import org.gvsig.fmap.dal.impl.expressionevaluator.DefaultEvaluatorFactory; |
|
54 |
import org.gvsig.fmap.dal.impl.expressionevaluator.DefaultFeatureSymbolTable; |
|
53 | 55 |
import org.gvsig.fmap.dal.raster.impl.RasterStoreFactory; |
54 | 56 |
import org.gvsig.fmap.dal.raster.impl.RasterStoreOldFactory; |
55 | 57 |
import org.gvsig.fmap.dal.raster.spi.CoverageStoreProvider; |
... | ... | |
67 | 69 |
import org.gvsig.tools.dynobject.DynStruct_v2; |
68 | 70 |
import org.gvsig.tools.dynobject.Tags; |
69 | 71 |
import org.gvsig.tools.evaluator.Evaluator; |
72 |
import org.gvsig.tools.evaluator.EvaluatorFactory; |
|
70 | 73 |
import org.gvsig.tools.exception.BaseException; |
71 | 74 |
import org.gvsig.tools.extensionpoint.ExtensionPoint; |
72 | 75 |
import org.gvsig.tools.folders.FoldersManager; |
... | ... | |
895 | 898 |
throw new CreateFileStoreException(e, providerName); |
896 | 899 |
} |
897 | 900 |
} |
901 |
|
|
902 |
@Override |
|
903 |
public FeatureSymbolTable createFeatureSymbolTable() { |
|
904 |
FeatureSymbolTable symbolTable = new DefaultFeatureSymbolTable(); |
|
905 |
return symbolTable; |
|
906 |
} |
|
907 |
|
|
908 |
@Override |
|
909 |
public EvaluatorFactory createEvaluatorFactory() { |
|
910 |
EvaluatorFactory f = new DefaultEvaluatorFactory(); |
|
911 |
return f; |
|
912 |
} |
|
913 |
|
|
898 | 914 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/impl/DALDefaultImplLibrary.java | ||
---|---|---|
50 | 50 |
import org.gvsig.fmap.dal.feature.impl.dynobjectutils.relations.DALLink_getRelatedFeatures; |
51 | 51 |
import org.gvsig.fmap.dal.feature.spi.memory.MemoryResource; |
52 | 52 |
import org.gvsig.fmap.dal.feature.spi.memory.MemoryResourceParameters; |
53 |
import org.gvsig.fmap.dal.impl.expressionevaluator.DefaultFeatureSymbolTable; |
|
53 | 54 |
import org.gvsig.fmap.dal.resource.impl.DefaultResourceManager; |
54 | 55 |
import org.gvsig.fmap.dal.resource.spi.MultiResource; |
55 | 56 |
import org.gvsig.fmap.dal.resource.spi.MultiResourceParameters; |
... | ... | |
187 | 188 |
dynObjectmanager.registerDynMethod(new DALLink_getRelatedFeature()); |
188 | 189 |
dynObjectmanager.registerDynMethod(new ComputeAvailableValuesFromTable("getAvailableValuesFromTable", "Retrieve available values from the elements of a table.")); |
189 | 190 |
|
191 |
DefaultFeatureSymbolTable.selfRegister(); |
|
192 |
|
|
190 | 193 |
if (exs.size() > 0) { |
191 | 194 |
throw new LibraryException(this.getClass(), exs); |
192 | 195 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/pom.xml | ||
---|---|---|
92 | 92 |
<artifactId>json</artifactId> |
93 | 93 |
<scope>compile</scope> |
94 | 94 |
</dependency> |
95 |
|
|
95 |
<dependency> |
|
96 |
<groupId>org.gvsig</groupId> |
|
97 |
<artifactId>org.gvsig.expressionevaluator.lib.api</artifactId> |
|
98 |
<scope>compile</scope> |
|
99 |
</dependency> |
|
96 | 100 |
</dependencies> |
97 | 101 |
|
98 | 102 |
|
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.swing/org.gvsig.fmap.dal.swing.impl/pom.xml | ||
---|---|---|
73 | 73 |
<artifactId>org.gvsig.metadata.lib.basic.api</artifactId> |
74 | 74 |
<scope>compile</scope> |
75 | 75 |
</dependency> |
76 |
<dependency> |
|
77 |
<groupId>org.gvsig</groupId> |
|
78 |
<artifactId>org.gvsig.expressionevaluator.lib.api</artifactId> |
|
79 |
<scope>compile</scope> |
|
80 |
</dependency> |
|
81 |
<dependency> |
|
82 |
<groupId>org.gvsig</groupId> |
|
83 |
<artifactId>org.gvsig.expressionevaluator.swing.api</artifactId> |
|
84 |
<scope>compile</scope> |
|
85 |
</dependency> |
|
86 |
<dependency> |
|
87 |
<groupId>commons-lang</groupId> |
|
88 |
<artifactId>commons-lang</artifactId> |
|
89 |
<scope>compile</scope> |
|
90 |
</dependency> |
|
91 |
|
|
92 |
|
|
93 |
|
|
76 | 94 |
</dependencies> |
77 | 95 |
|
78 | 96 |
</project> |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.swing/org.gvsig.fmap.dal.swing.impl/src/main/java/org/gvsig/fmap/dal/swing/impl/DefaultDALSwingLibrary.java | ||
---|---|---|
31 | 31 |
import org.gvsig.fmap.dal.swing.impl.dataStoreParameters.DataStoreDynObjectParametersPanelFactory; |
32 | 32 |
import org.gvsig.fmap.dal.swing.impl.dataStoreParameters.DefaultDataStoreParametersPanelManager; |
33 | 33 |
import org.gvsig.fmap.dal.swing.impl.dynobjectutils.CreateComboModelFromTable; |
34 |
import org.gvsig.fmap.dal.swing.impl.expressionevaluator.FeatureStoreElementFactory; |
|
34 | 35 |
import org.gvsig.tools.ToolsLocator; |
35 | 36 |
import org.gvsig.tools.dynform.spi.DynFormSPILocator; |
36 | 37 |
import org.gvsig.tools.dynform.spi.DynFormSPIManager; |
37 | 38 |
import org.gvsig.tools.dynobject.DynObjectManager; |
38 | 39 |
import org.gvsig.tools.library.AbstractLibrary; |
39 | 40 |
import org.gvsig.tools.library.LibraryException; |
41 |
import org.slf4j.Logger; |
|
42 |
import org.slf4j.LoggerFactory; |
|
40 | 43 |
|
41 | 44 |
|
42 | 45 |
/** |
... | ... | |
45 | 48 |
*/ |
46 | 49 |
public class DefaultDALSwingLibrary extends AbstractLibrary{ |
47 | 50 |
|
51 |
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultDALSwingLibrary.class); |
|
48 | 52 |
|
49 |
|
|
50 | 53 |
@Override |
51 | 54 |
public void doRegistration() { |
52 | 55 |
registerAsImplementationOf(DALSwingLibrary.class); |
... | ... | |
64 | 67 |
|
65 | 68 |
@Override |
66 | 69 |
protected void doPostInitialize() throws LibraryException { |
67 |
DynFormSPIManager manager = DynFormSPILocator.getDynFormSPIManager(); |
|
68 |
if( manager != null ) { |
|
69 |
manager.addServiceFactory(new JDynFormFieldFeatureLinkFactory()); |
|
70 |
manager.addServiceFactory(new JDynFormFieldFeaturesTableLinkFactory()); |
|
70 |
try { |
|
71 |
DynFormSPIManager manager = DynFormSPILocator.getDynFormSPIManager(); |
|
72 |
if( manager != null ) { |
|
73 |
manager.addServiceFactory(new JDynFormFieldFeatureLinkFactory()); |
|
74 |
manager.addServiceFactory(new JDynFormFieldFeaturesTableLinkFactory()); |
|
75 |
} |
|
76 |
DynObjectManager dynObjectmanager = ToolsLocator.getDynObjectManager(); |
|
77 |
dynObjectmanager.registerDynMethod(new CreateComboModelFromTable("DAL.createComboModelFromTable", "XXXXXXXXXXXXXXXXXXXX.")); |
|
78 |
|
|
79 |
DataStoreParametersPanelManager dataStoreParametersPanelManager = DALSwingLocator.getDataStoreParametersPanelManager(); |
|
80 |
dataStoreParametersPanelManager.registerFactory(new DataStoreDynObjectParametersPanelFactory()); |
|
81 |
} catch(Exception ex) { |
|
82 |
LOGGER.warn("Can't register DAL components in DynForms",ex); |
|
71 | 83 |
} |
72 |
DynObjectManager dynObjectmanager = ToolsLocator.getDynObjectManager(); |
|
73 |
dynObjectmanager.registerDynMethod(new CreateComboModelFromTable("DAL.createComboModelFromTable", "XXXXXXXXXXXXXXXXXXXX.")); |
|
74 |
|
|
75 |
DataStoreParametersPanelManager dataStoreParametersPanelManager = DALSwingLocator.getDataStoreParametersPanelManager(); |
|
76 |
dataStoreParametersPanelManager.registerFactory(new DataStoreDynObjectParametersPanelFactory()); |
|
77 |
|
|
84 |
try { |
|
85 |
FeatureStoreElementFactory.selfRegister(); |
|
86 |
} catch(Exception ex) { |
|
87 |
LOGGER.warn("Can't register DAL components in ExpressionEvaluator",ex); |
|
88 |
} |
|
78 | 89 |
} |
79 | 90 |
|
80 | 91 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.swing/org.gvsig.fmap.dal.swing.impl/src/main/java/org/gvsig/fmap/dal/swing/impl/expressionevaluator/FeatureStoreElement.java | ||
---|---|---|
1 |
package org.gvsig.fmap.dal.swing.impl.expressionevaluator; |
|
2 |
|
|
3 |
import java.util.ArrayList; |
|
4 |
import java.util.Collections; |
|
5 |
import java.util.Comparator; |
|
6 |
import java.util.Iterator; |
|
7 |
import java.util.List; |
|
8 |
import org.gvsig.expressionevaluator.Function; |
|
9 |
import org.gvsig.expressionevaluator.swing.Element; |
|
10 |
import org.gvsig.expressionevaluator.swing.Element.GroupElement; |
|
11 |
import org.gvsig.expressionevaluator.swing.ExpressionBuilderConfig; |
|
12 |
import org.gvsig.expressionevaluator.swing.spi.AbstractElement; |
|
13 |
import org.gvsig.fmap.dal.exception.DataException; |
|
14 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
|
15 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
16 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
17 |
|
|
18 |
/** |
|
19 |
* |
|
20 |
* @author jjdelcerro |
|
21 |
*/ |
|
22 |
public class FeatureStoreElement |
|
23 |
extends AbstractElement |
|
24 |
implements GroupElement |
|
25 |
{ |
|
26 |
|
|
27 |
final FeatureStore store; |
|
28 |
final FeatureType type; |
|
29 |
final List<Element> elements; |
|
30 |
final ExpressionBuilderConfig configPanel; |
|
31 |
|
|
32 |
public FeatureStoreElement(ExpressionBuilderConfig configPanel, FeatureStore store) { |
|
33 |
super(store.getName(), null, "expressionbuilder-element-table"); |
|
34 |
this.configPanel = configPanel; |
|
35 |
try { |
|
36 |
this.store = store; |
|
37 |
this.type = this.store.getDefaultFeatureType(); |
|
38 |
this.elements = new ArrayList<>(); |
|
39 |
for (FeatureAttributeDescriptor attrdesc : type) { |
|
40 |
this.elements.add(new FeatureAttributeElement( |
|
41 |
this.configPanel, |
|
42 |
this.store, |
|
43 |
attrdesc |
|
44 |
) |
|
45 |
); |
|
46 |
} |
|
47 |
Collections.sort(elements, new Comparator<Element>() { |
|
48 |
@Override |
|
49 |
public int compare(Element o1, Element o2) { |
|
50 |
return o1.getName().compareTo(o2.getName()); |
|
51 |
} |
|
52 |
}); |
|
53 |
} catch (DataException ex) { |
|
54 |
throw new RuntimeException(ex); |
|
55 |
} |
|
56 |
} |
|
57 |
|
|
58 |
@Override |
|
59 |
public Element get(int index) { |
|
60 |
return this.elements.get(index); |
|
61 |
} |
|
62 |
|
|
63 |
@Override |
|
64 |
public int size() { |
|
65 |
return this.type.size(); |
|
66 |
} |
|
67 |
|
|
68 |
@Override |
|
69 |
public Iterator<Element> iterator() { |
|
70 |
return this.elements.iterator(); |
|
71 |
} |
|
72 |
|
|
73 |
@Override |
|
74 |
public void addElement(Element element) { |
|
75 |
} |
|
76 |
|
|
77 |
@Override |
|
78 |
public void addElement(Function function) { |
|
79 |
} |
|
80 |
|
|
81 |
@Override |
|
82 |
public List<Element> getElements() { |
|
83 |
return Collections.unmodifiableList(this.elements); |
|
84 |
} |
|
85 |
|
|
86 |
@Override |
|
87 |
public boolean hasSubgroups() { |
|
88 |
return true; |
|
89 |
} |
|
90 |
|
|
91 |
@Override |
|
92 |
public boolean hasMoreElements() { |
|
93 |
return false; |
|
94 |
} |
|
95 |
|
|
96 |
|
|
97 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.swing/org.gvsig.fmap.dal.swing.impl/src/main/java/org/gvsig/fmap/dal/swing/impl/expressionevaluator/FeatureAttributeElement.java | ||
---|---|---|
1 |
package org.gvsig.fmap.dal.swing.impl.expressionevaluator; |
|
2 |
|
|
3 |
import java.util.ArrayList; |
|
4 |
import java.util.Iterator; |
|
5 |
import java.util.List; |
|
6 |
import org.apache.commons.lang.mutable.MutableInt; |
|
7 |
import org.gvsig.expressionevaluator.Function; |
|
8 |
import org.gvsig.expressionevaluator.swing.Element; |
|
9 |
import org.gvsig.expressionevaluator.swing.Element.GroupElement; |
|
10 |
import org.gvsig.expressionevaluator.swing.Element.SimpleElement; |
|
11 |
import org.gvsig.expressionevaluator.swing.Element.VariableElement; |
|
12 |
import org.gvsig.expressionevaluator.swing.ExpressionBuilderConfig; |
|
13 |
import org.gvsig.expressionevaluator.swing.spi.AbstractElement; |
|
14 |
import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingLocator; |
|
15 |
import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingManager; |
|
16 |
import org.gvsig.fmap.dal.feature.Feature; |
|
17 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
|
18 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
|
19 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
20 |
import org.gvsig.tools.exception.BaseException; |
|
21 |
import org.gvsig.tools.visitor.VisitCanceledException; |
|
22 |
import org.gvsig.tools.visitor.Visitor; |
|
23 |
|
|
24 |
/** |
|
25 |
* |
|
26 |
* @author jjdelcerro |
|
27 |
*/ |
|
28 |
public class FeatureAttributeElement |
|
29 |
extends AbstractElement |
|
30 |
implements |
|
31 |
GroupElement, |
|
32 |
SimpleElement, |
|
33 |
VariableElement |
|
34 |
{ |
|
35 |
|
|
36 |
final FeatureStore store; |
|
37 |
final FeatureAttributeDescriptor attrdesc; |
|
38 |
List<Element> elements; |
|
39 |
final ExpressionBuilderConfig configPanel; |
|
40 |
boolean hasMoreElements; |
|
41 |
|
|
42 |
FeatureAttributeElement(ExpressionBuilderConfig configPanel, FeatureStore store, FeatureAttributeDescriptor attrdesc) { |
|
43 |
super(attrdesc.getName(), attrdesc.getDescription(), "expressionbuilder-element-table-field"); |
|
44 |
this.configPanel = configPanel; |
|
45 |
this.store = store; |
|
46 |
this.attrdesc = attrdesc; |
|
47 |
this.elements = null; |
|
48 |
this.hasMoreElements = false; |
|
49 |
} |
|
50 |
|
|
51 |
@Override |
|
52 |
public String getTypeName() { |
|
53 |
return this.attrdesc.getDataTypeName(); |
|
54 |
} |
|
55 |
|
|
56 |
@Override |
|
57 |
public Element get(int index) { |
|
58 |
return this.getElements().get(index); |
|
59 |
} |
|
60 |
|
|
61 |
@Override |
|
62 |
public int size() { |
|
63 |
return this.getElements().size(); |
|
64 |
} |
|
65 |
|
|
66 |
@Override |
|
67 |
public Iterator<Element> iterator() { |
|
68 |
return this.getElements().iterator(); |
|
69 |
} |
|
70 |
|
|
71 |
@Override |
|
72 |
public void addElement(Element element) { |
|
73 |
|
|
74 |
} |
|
75 |
|
|
76 |
@Override |
|
77 |
public void addElement(Function function) { |
|
78 |
|
|
79 |
} |
|
80 |
|
|
81 |
@Override |
|
82 |
public List<Element> getElements() { |
|
83 |
if( this.elements==null ) { |
|
84 |
hasMoreElements = false; |
|
85 |
final int limit = this.configPanel==null? 1000 : this.configPanel.getSimpleElementsLimit(); |
|
86 |
ExpressionEvaluatorSwingManager manager = ExpressionEvaluatorSwingLocator.getManager(); |
|
87 |
final List<Object> values = new ArrayList<>(); |
|
88 |
try { |
|
89 |
FeatureSet set = this.store.getFeatureSet(); |
|
90 |
final MutableInt count = new MutableInt(0); |
|
91 |
set.accept(new Visitor() { |
|
92 |
@Override |
|
93 |
public void visit(Object o) throws VisitCanceledException, BaseException { |
|
94 |
Object value = ((Feature)o).get(attrdesc.getName()); |
|
95 |
if( !values.contains(value ) ) { |
|
96 |
values.add(value); |
|
97 |
} |
|
98 |
count.increment(); |
|
99 |
if( count.intValue()>= limit ) { |
|
100 |
hasMoreElements = true; |
|
101 |
throw new VisitCanceledException(); |
|
102 |
} |
|
103 |
} |
|
104 |
}); |
|
105 |
} catch(VisitCanceledException ex) { |
|
106 |
|
|
107 |
} catch (Exception ex) { |
|
108 |
// FIXME |
|
109 |
} |
|
110 |
this.elements = new ArrayList<>(); |
|
111 |
for (Object value : values) { |
|
112 |
this.elements.add(manager.createConstantElement(value)); |
|
113 |
} |
|
114 |
} |
|
115 |
return this.elements; |
|
116 |
} |
|
117 |
|
|
118 |
@Override |
|
119 |
public boolean hasSubgroups() { |
|
120 |
return false; |
|
121 |
} |
|
122 |
|
|
123 |
@Override |
|
124 |
public String getSource() { |
|
125 |
return this.store.getName(); |
|
126 |
} |
|
127 |
|
|
128 |
@Override |
|
129 |
public String getLabel() { |
|
130 |
return "Field"; |
|
131 |
} |
|
132 |
|
|
133 |
@Override |
|
134 |
public boolean hasMoreElements() { |
|
135 |
return this.hasMoreElements; |
|
136 |
} |
|
137 |
|
|
138 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.swing/org.gvsig.fmap.dal.swing.impl/src/main/java/org/gvsig/fmap/dal/swing/impl/expressionevaluator/FeatureStoreElementFactory.java | ||
---|---|---|
1 |
package org.gvsig.fmap.dal.swing.impl.expressionevaluator; |
|
2 |
|
|
3 |
import java.net.URL; |
|
4 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator; |
|
5 |
import org.gvsig.expressionevaluator.swing.Element; |
|
6 |
import org.gvsig.expressionevaluator.swing.ExpressionBuilderConfig; |
|
7 |
import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingLocator; |
|
8 |
import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingManager; |
|
9 |
import org.gvsig.expressionevaluator.swing.JExpressionBuilder; |
|
10 |
import org.gvsig.expressionevaluator.swing.spi.AbstractElementFactory; |
|
11 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
12 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
|
13 |
import org.gvsig.tools.swing.icontheme.IconTheme; |
|
14 |
|
|
15 |
/** |
|
16 |
* |
|
17 |
* @author jjdelcerro |
|
18 |
*/ |
|
19 |
public class FeatureStoreElementFactory extends AbstractElementFactory { |
|
20 |
|
|
21 |
public FeatureStoreElementFactory() { |
|
22 |
super("DAL.FeatureStoreElement", null); |
|
23 |
} |
|
24 |
|
|
25 |
@Override |
|
26 |
public Element createElement(Object... parameters) { |
|
27 |
ExpressionBuilderConfig config = (ExpressionBuilderConfig) parameters[0]; |
|
28 |
FeatureStore store = (FeatureStore) parameters[1]; |
|
29 |
Element e = new FeatureStoreElement(config, store); |
|
30 |
return e; |
|
31 |
} |
|
32 |
|
|
33 |
public static void selfRegister() { |
|
34 |
ExpressionEvaluatorSwingManager manager = ExpressionEvaluatorSwingLocator.getManager(); |
|
35 |
manager.registerElement(new FeatureStoreElementFactory()); |
|
36 |
|
|
37 |
URL url; |
|
38 |
IconTheme theme = ToolsSwingLocator.getIconThemeManager().getCurrent(); |
|
39 |
url = FeatureStoreElementFactory.class.getResource("/org/gvsig/fmap/dal/swing/impl/expressionevaluator/expressionbuilder-element-table.png"); |
|
40 |
theme.registerDefault("ExpressionBuilder", "element", "expressionbuilder-element-table", null, url); |
|
41 |
url = FeatureStoreElementFactory.class.getResource("/org/gvsig/fmap/dal/swing/impl/expressionevaluator/expressionbuilder-element-table-field.png"); |
|
42 |
theme.registerDefault("ExpressionBuilder", "element", "expressionbuilder-element-table-field", null, url); |
|
43 |
|
|
44 |
} |
|
45 |
} |
|
0 | 46 |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/main/java/org/gvsig/fmap/dal/EvaluatorFactory.java | ||
---|---|---|
1 |
|
|
2 |
package org.gvsig.fmap.dal; |
|
3 |
|
|
4 |
import org.gvsig.tools.evaluator.Evaluator; |
|
5 |
|
|
6 |
|
|
7 |
public interface EvaluatorFactory { |
|
8 |
|
|
9 |
public Evaluator createEvaluator(String expression); |
|
10 |
|
|
11 |
public String getName(); |
|
12 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/main/java/org/gvsig/fmap/dal/expressionevaluator/FeatureSymbolTable.java | ||
---|---|---|
1 |
package org.gvsig.fmap.dal.expressionevaluator; |
|
2 |
|
|
3 |
import org.gvsig.expressionevaluator.SymbolTable; |
|
4 |
import org.gvsig.fmap.dal.feature.Feature; |
|
5 |
|
|
6 |
/** |
|
7 |
* |
|
8 |
* @author jjdelcerro |
|
9 |
*/ |
|
10 |
public interface FeatureSymbolTable extends SymbolTable { |
|
11 |
|
|
12 |
public void setFeature(Feature feature); |
|
13 |
|
|
14 |
@Override |
|
15 |
public FeatureSymbolTable clone() throws CloneNotSupportedException; |
|
16 |
|
|
17 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/main/java/org/gvsig/fmap/dal/DataManager.java | ||
---|---|---|
29 | 29 |
import org.gvsig.fmap.dal.exception.InitializeException; |
30 | 30 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
31 | 31 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
32 |
import org.gvsig.fmap.dal.expressionevaluator.FeatureSymbolTable; |
|
32 | 33 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
33 | 34 |
import org.gvsig.fmap.dal.feature.Feature; |
34 | 35 |
import org.gvsig.fmap.dal.feature.FeatureIndex; |
... | ... | |
41 | 42 |
import org.gvsig.tools.dynobject.DynStruct; |
42 | 43 |
import org.gvsig.tools.dynobject.Tags; |
43 | 44 |
import org.gvsig.tools.evaluator.Evaluator; |
45 |
import org.gvsig.tools.evaluator.EvaluatorFactory; |
|
44 | 46 |
import org.gvsig.tools.exception.BaseException; |
45 | 47 |
import org.gvsig.tools.service.spi.Services; |
46 | 48 |
|
... | ... | |
298 | 300 |
public Evaluator createExpresion(String expression) |
299 | 301 |
throws InitializeException; |
300 | 302 |
|
303 |
public EvaluatorFactory createEvaluatorFactory(); |
|
304 |
|
|
301 | 305 |
/* |
302 | 306 |
* ==================================================================== |
303 | 307 |
* |
... | ... | |
461 | 465 |
*/ |
462 | 466 |
public void createFileStore(String providerName, NewDataStoreParameters params, boolean overwrite) throws DataException; |
463 | 467 |
|
468 |
public FeatureSymbolTable createFeatureSymbolTable(); |
|
464 | 469 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/pom.xml | ||
---|---|---|
72 | 72 |
<artifactId>easymockclassextension</artifactId> |
73 | 73 |
<scope>test</scope> |
74 | 74 |
</dependency> |
75 |
<dependency> |
|
76 |
<groupId>org.gvsig</groupId> |
|
77 |
<artifactId>org.gvsig.expressionevaluator.lib.api</artifactId> |
|
78 |
<scope>compile</scope> |
|
79 |
</dependency> |
|
75 | 80 |
</dependencies> |
76 | 81 |
|
77 | 82 |
<build> |
trunk/org.gvsig.desktop/org.gvsig.desktop.framework/org.gvsig.andami/pom.xml | ||
---|---|---|
230 | 230 |
<scope>compile</scope> |
231 | 231 |
</dependency> |
232 | 232 |
<dependency> |
233 |
<groupId>commons-lang</groupId> |
|
234 |
<artifactId>commons-lang</artifactId> |
|
235 |
<version>2.6</version> |
|
236 |
<scope>compile</scope> |
|
237 |
</dependency> |
|
238 |
|
|
239 |
<dependency> |
|
233 | 240 |
<groupId>org.swinglabs</groupId> |
234 | 241 |
<artifactId>swing-layout</artifactId> |
235 | 242 |
<scope>compile</scope> |
... | ... | |
371 | 378 |
<scope>runtime</scope> |
372 | 379 |
<version>1.2.8</version> |
373 | 380 |
</dependency> |
381 |
<dependency> |
|
382 |
<groupId>org.gvsig</groupId> |
|
383 |
<artifactId>org.gvsig.temporarystorage.lib.api</artifactId> |
|
384 |
<scope>runtime</scope> |
|
385 |
</dependency> |
|
386 |
<dependency> |
|
387 |
<groupId>org.gvsig</groupId> |
|
388 |
<artifactId>org.gvsig.temporarystorage.lib.impl</artifactId> |
|
389 |
<scope>runtime</scope> |
|
390 |
</dependency> |
|
374 | 391 |
|
375 | 392 |
</dependencies> |
376 | 393 |
|
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.h2spatial.app/org.gvsig.h2spatial.app.mainplugin/src/main/java/org/gvsig/h2spatial/SQLWorkbenchj.java | ||
---|---|---|
1 |
package org.gvsig.h2spatial; |
|
2 |
|
Also available in: Unified diff