Revision 44198 trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.api/src/main/java/org/gvsig/expressionevaluator/ExpressionBuilder.java
ExpressionBuilder.java | ||
---|---|---|
1 | 1 |
package org.gvsig.expressionevaluator; |
2 | 2 |
|
3 | 3 |
import java.util.List; |
4 |
import java.util.Map; |
|
4 | 5 |
import org.cresques.cts.IProjection; |
5 | 6 |
import org.gvsig.fmap.geom.Geometry; |
6 | 7 |
import org.gvsig.fmap.geom.primitive.Envelope; |
8 |
import org.gvsig.tools.util.PropertiesSupport; |
|
9 |
import org.gvsig.tools.util.PropertiesSupportHelper; |
|
7 | 10 |
|
8 | 11 |
public interface ExpressionBuilder { |
9 | 12 |
|
13 |
public static final String OPERATOR_NOT = "NOT"; |
|
14 |
public static final String OPERATOR_IS = "IS"; |
|
15 |
public static final String OPERATOR_AND = "AND"; |
|
16 |
public static final String OPERATOR_OR = "OR"; |
|
17 |
public static final String OPERATOR_EQ = "EQ"; |
|
18 |
public static final String OPERATOR_NE = "NE"; |
|
19 |
public static final String OPERATOR_GT = "GT"; |
|
20 |
public static final String OPERATOR_GE = "GE"; |
|
21 |
public static final String OPERATOR_LT = "LT"; |
|
22 |
public static final String OPERATOR_LE = "LE"; |
|
23 |
public static final String OPERATOR_LIKE = "LIKE"; |
|
24 |
public static final String OPERATOR_ILIKE = "ILIKE"; |
|
25 |
public static final String OPERATOR_ADD = "ADD"; |
|
26 |
public static final String OPERATOR_SUBST = "SUBST"; |
|
27 |
public static final String OPERATOR_MULT = "MULT"; |
|
28 |
public static final String OPERATOR_DIV = "DIV"; |
|
29 |
public static final String OPERATOR_CONCAT = "CONCAT"; |
|
30 |
|
|
31 |
public static final String FUNCTION_ST_SRID = "ST_SRID"; |
|
32 |
public static final String FUNCTION_ST_ASTEXT = "ST_AsText"; |
|
33 |
public static final String FUNCTION_ST_ASBINARY = "ST_AsBinary"; |
|
34 |
public static final String FUNCTION_ST_ASEWKB = "ST_AsEWKB"; |
|
35 |
public static final String FUNCTION_ST_ENVELOPE = "ST_Envelope"; |
|
36 |
public static final String FUNCTION_ST_GEOMFROMTEXT = "ST_GeomFromText"; |
|
37 |
public static final String FUNCTION_ST_GEOMFROMWKB = "ST_GeomFromWKB"; |
|
38 |
public static final String FUNCTION_ST_GEOMFROMEWKB = "ST_GeomFromEWKB"; |
|
39 |
public static final String FUNCTION_ST_SIMPLIFY = "ST_Simplify"; |
|
40 |
public static final String FUNCTION_ST_EQUALS = "ST_Equals"; |
|
41 |
public static final String FUNCTION_ST_INTERSECTS = "ST_Intersects"; |
|
42 |
public static final String FUNCTION_ST_CONTAINS = "ST_Contains"; |
|
43 |
public static final String FUNCTION_ST_DISJOINT = "ST_Disjoint"; |
|
44 |
public static final String FUNCTION_ST_CROSSES = "ST_Crosses"; |
|
45 |
public static final String FUNCTION_ST_ISCLOSED = "ST_IsClosed"; |
|
46 |
public static final String FUNCTION_ST_OVERLAPS = "ST_Overlaps"; |
|
47 |
public static final String FUNCTION_ST_TOUCHES = "ST_Touches"; |
|
48 |
public static final String FUNCTION_ST_WITHIN = "ST_Within"; |
|
49 |
public static final String FUNCTION_ST_UNIONAGGREGATE = "ST_UnionAggregate"; |
|
50 |
public static final String FUNCTION_ST_EXTENTAGGREGATE = "ST_ExtentAggregate"; |
|
51 |
|
|
52 |
public static final String FUNCTION_IIF = "IIF"; |
|
53 |
public static final String FUNCTION_IFNULL = "IFNULL"; |
|
54 |
|
|
55 |
public static final String FUNCTION_LEFT = "LEFT"; |
|
56 |
public static final String FUNCTION_RIGHT = "RIGHT"; |
|
57 |
public static final String FUNCTION_LOCATE = "LOCATE"; |
|
58 |
public static final String FUNCTION_POSITION = "POSITION"; |
|
59 |
public static final String FUNCTION_LPAD = "LPAD"; |
|
60 |
public static final String FUNCTION_RPAD = "RPAD"; |
|
61 |
public static final String FUNCTION_LTRIM = "LTRIM"; |
|
62 |
public static final String FUNCTION_RTRIM = "RTRIM"; |
|
63 |
public static final String FUNCTION_TRIM = "TRIM"; |
|
64 |
public static final String FUNCTION_REPEAT = "REPEAT"; |
|
65 |
public static final String FUNCTION_REPLACE = "REPLACE"; |
|
66 |
public static final String FUNCTION_ASCII = "ASCII"; |
|
67 |
public static final String FUNCTION_LENGHT = "LENGHT"; |
|
68 |
public static final String FUNCTION_INSTR = "INSTR"; |
|
69 |
public static final String FUNCTION_LOWER = "LOWER"; |
|
70 |
public static final String FUNCTION_UPPER = "UPPER"; |
|
71 |
public static final String FUNCTION_SPACE = "SPACE"; |
|
72 |
public static final String FUNCTION_SUBSTRING = "SUBSTRING"; |
|
73 |
public static final String FUNCTION_ACOS = "ACOS"; |
|
74 |
public static final String FUNCTION_ASIN = "ASIN"; |
|
75 |
public static final String FUNCTION_ATAN = "ATAN"; |
|
76 |
public static final String FUNCTION_COS = "COS"; |
|
77 |
public static final String FUNCTION_COSH = "COSH"; |
|
78 |
public static final String FUNCTION_COT = "COT"; |
|
79 |
public static final String FUNCTION_BITAND = "BITAND"; |
|
80 |
public static final String FUNCTION_BITOR = "BITOR"; |
|
81 |
public static final String FUNCTION_BITXOR = "BITXOR"; |
|
82 |
public static final String FUNCTION_CEIL = "CEIL"; |
|
83 |
public static final String FUNCTION_DEGREES = "DEGREES"; |
|
84 |
public static final String FUNCTION_EXP = "EXP"; |
|
85 |
public static final String FUNCTION_FLOOR = "FLOOR"; |
|
86 |
public static final String FUNCTION_LOG = "LOG"; |
|
87 |
public static final String FUNCTION_LOG10 = "LOG10"; |
|
88 |
public static final String FUNCTION_PI = "PI"; |
|
89 |
public static final String FUNCTION_POWER = "POWER"; |
|
90 |
public static final String FUNCTION_RADIANS = "RADIANS"; |
|
91 |
public static final String FUNCTION_RAND = "RAND"; |
|
92 |
public static final String FUNCTION_ROUND = "ROUND"; |
|
93 |
public static final String FUNCTION_SQRT = "SQRT"; |
|
94 |
public static final String FUNCTION_SIGN = "SIGN"; |
|
95 |
public static final String FUNCTION_SIN = "SIN"; |
|
96 |
public static final String FUNCTION_SINH = "SINH"; |
|
97 |
public static final String FUNCTION_TAN = "TAN"; |
|
98 |
public static final String FUNCTION_TANH = "TANH"; |
|
99 |
public static final String FUNCTION_ZERO = "ZERO"; |
|
100 |
public static final String FUNCTION_CHR = "CHR"; |
|
101 |
public static final String FUNCTION_DATE = "DATE"; |
|
102 |
public static final String FUNCTION_NOW = "NOW"; |
|
103 |
public static final String FUNCTION_TIME = "TIME"; |
|
104 |
public static final String FUNCTION_TIMESTAMP = "TIMESTAMP"; |
|
105 |
|
|
106 |
public static final String FUNCTION_CAST = "CAST"; |
|
107 |
public static final String FUNCTION_DECODE = "DECODE"; |
|
108 |
public static final String FUNCTION_TODOUBLE = "TODOUBLE"; |
|
109 |
public static final String FUNCTION_TOFLOAT = "TOFLOAT"; |
|
110 |
public static final String FUNCTION_TOINTEGER = "TOINTEGER"; |
|
111 |
public static final String FUNCTION_TOLONG = "TOLONG"; |
|
112 |
public static final String FUNCTION_TOSTR = "TOSTR"; |
|
113 |
|
|
10 | 114 |
public enum GeometrySupportType { |
11 | 115 |
WKT, |
12 | 116 |
WKB, |
... | ... | |
19 | 123 |
Constant, |
20 | 124 |
Geometry |
21 | 125 |
} |
22 |
|
|
126 |
|
|
23 | 127 |
public interface VisitorFilter { |
24 | 128 |
boolean accept(Visitable visitable); |
25 | 129 |
} |
... | ... | |
31 | 135 |
public interface Visitable { |
32 | 136 |
public void accept(Visitor visitor, VisitorFilter filter); |
33 | 137 |
} |
34 |
|
|
35 |
public interface Config { |
|
36 |
public final static String has_spatial_functions = "has_spatial_functions"; |
|
37 |
public final static String support_schemas = "support_schemas"; |
|
38 |
public final static String quote_for_identifiers = "quote_for_identifiers"; |
|
39 |
public final static String quote_for_strings = "quote_for_strings"; |
|
40 |
public final static String geometry_type_support = "geometry_type_support"; |
|
41 |
public final static String constant_true = "constant_true"; |
|
42 |
public final static String constant_false = "constant_false"; |
|
43 |
public final static String group = "group"; |
|
44 |
public final static String attribute_crs = "crs"; |
|
45 | 138 |
|
46 |
public final static String ST_SRID = "ST_SRID"; |
|
47 |
public final static String ST_AsText = "ST_AsText"; |
|
48 |
public final static String ST_AsBinary = "ST_AsBinary"; |
|
49 |
public final static String ST_AsEWKB = "ST_AsEWKB"; |
|
50 |
public final static String ST_Contains = "ST_Contains"; |
|
51 |
public final static String ST_Crosses = "ST_Crosses"; |
|
52 |
public final static String ST_Disjoint = "ST_Disjoint"; |
|
53 |
public final static String ST_Equals = "ST_Equals"; |
|
54 |
public final static String ST_IsClosed = "ST_IsClosed"; |
|
55 |
public final static String ST_Overlaps = "ST_Overlaps"; |
|
56 |
public final static String ST_Touches = "ST_Touches"; |
|
57 |
public final static String ST_Within = "ST_Within"; |
|
58 |
public final static String ST_Intersects = "ST_Intersects"; |
|
59 |
public final static String ST_Envelope = "ST_Envelope"; |
|
60 |
public final static String ST_GeomFromText = "ST_GeomFromText"; |
|
61 |
public final static String ST_GeomFromWKB = "ST_GeomFromWKB"; |
|
62 |
public final static String ST_GeomFromEWKB = "ST_GeomFromEWKB"; |
|
63 |
public final static String ST_Simplify = "ST_Simplify"; |
|
64 |
|
|
65 |
public final static String lcase = "lcase"; |
|
66 |
public final static String ucase = "ucase"; |
|
67 |
public final static String iif = "iif"; |
|
68 |
public final static String ifnull = "ifnull"; |
|
69 |
|
|
70 |
public final static String isNull = "isNull"; |
|
71 |
public final static String notIsNull = "notIsNull"; |
|
72 |
public final static String operator_not = "operator_not"; |
|
73 |
|
|
74 |
public final static String operator_AND = "operator_AND"; |
|
75 |
public final static String operator_OR = "operator_OR"; |
|
76 |
public final static String operator_EQ = "operator_EQ"; |
|
77 |
public final static String operator_NE = "operator_NE"; |
|
78 |
public final static String operator_GT = "operator_GT"; |
|
79 |
public final static String operator_GE = "operator_GE"; |
|
80 |
public final static String operator_LT = "operator_LT"; |
|
81 |
public final static String operator_LE = "operator_LE"; |
|
82 |
public final static String operator_LIKE = "operator_LIKE"; |
|
83 |
public final static String operator_ILIKE = "operator_ILIKE"; |
|
84 |
|
|
85 |
public final static String operator_add = "operator_add"; |
|
86 |
public final static String operator_subst = "operator_subst"; |
|
87 |
public final static String operator_mult = "operator_mult"; |
|
88 |
public final static String operator_div = "operator_div"; |
|
89 |
public final static String operator_concat = "operator_concat"; |
|
90 |
|
|
91 |
|
|
92 |
public GeometrySupportType getGeometryTypeSupport(); |
|
93 |
public boolean has_spatial_functions(); |
|
94 |
public boolean has_functionality(String functionality); |
|
95 |
public void remove_functionality(String functionality); |
|
96 |
|
|
97 |
public boolean getBoolean(String name); |
|
98 |
public String getString(String name); |
|
99 |
public Object get(String name); |
|
100 |
public void set(String name, Object value); |
|
139 |
public interface Value extends Visitable, PropertiesSupport { |
|
140 |
public String toString(Formatter<Value> formatter); |
|
101 | 141 |
} |
102 |
|
|
103 |
public interface Value extends Visitable { |
|
104 | 142 |
|
105 |
} |
|
106 |
|
|
107 | 143 |
public interface Group extends Value { |
108 |
public Value getValue();
|
|
144 |
public Value value();
|
|
109 | 145 |
} |
110 | 146 |
|
111 | 147 |
public interface Constant extends Value { |
112 |
public Object getValue();
|
|
148 |
public Object value();
|
|
113 | 149 |
} |
114 | 150 |
|
115 | 151 |
public interface Custom extends Value { |
116 |
public Object getValue();
|
|
152 |
public Object value();
|
|
117 | 153 |
public Custom add(Variable variable); |
118 | 154 |
public Custom add(Parameter parameter); |
119 | 155 |
} |
120 | 156 |
|
121 |
public interface GeometryValue extends Value { |
|
122 |
public Geometry getGeometry(); |
|
123 |
public IProjection getSRS(); |
|
124 |
} |
|
125 |
|
|
126 | 157 |
public interface Variable extends Value, Comparable<Variable> { |
127 |
public String getName();
|
|
158 |
public String name();
|
|
128 | 159 |
} |
129 | 160 |
|
130 | 161 |
public interface Parameter extends Value { |
... | ... | |
133 | 164 |
public Parameter as_geometry_variable(); |
134 | 165 |
public Parameter srs(Value srs); |
135 | 166 |
public Parameter srs(IProjection srs); |
136 |
public String getName(); |
|
137 |
public Object getValue(); |
|
138 | 167 |
public Parameter value(Object value); |
139 | 168 |
public Parameter name(String value); |
140 |
public ParameterType getType(); |
|
141 |
public Value getSRS(); |
|
169 |
public String name(); |
|
170 |
public Object value(); |
|
171 |
public ParameterType type(); |
|
172 |
public Value srs(); |
|
142 | 173 |
public boolean is_constant(); |
143 | 174 |
public boolean is_variable(); |
144 | 175 |
public boolean is_geometry_variable(); |
145 | 176 |
} |
146 | 177 |
|
147 |
public interface Parameters extends List<Parameter> { |
|
148 |
public Parameter get(String name); |
|
178 |
public interface Function extends Value { |
|
179 |
public String name(); |
|
180 |
public List<Value> parameters(); |
|
181 |
public Function parameter(Value parameter); |
|
149 | 182 |
} |
150 | 183 |
|
151 |
public interface Function extends Value { |
|
152 |
public String getName(); |
|
184 |
public interface Method extends Value { |
|
185 |
public String name(); |
|
186 |
public Value instance(); |
|
153 | 187 |
public List<Value> parameters(); |
154 | 188 |
public Function parameter(Value parameter); |
155 | 189 |
} |
156 | 190 |
|
157 | 191 |
public interface BinaryOperator extends Value { |
158 |
public String getName();
|
|
159 |
public Value getLeft();
|
|
160 |
public Value getRight();
|
|
161 |
public BinaryOperator setLeft(Value operand);
|
|
162 |
public BinaryOperator setRight(Value operand);
|
|
192 |
public String name();
|
|
193 |
public Value left();
|
|
194 |
public Value right();
|
|
195 |
public BinaryOperator left(Value operand);
|
|
196 |
public BinaryOperator right(Value operand);
|
|
163 | 197 |
} |
198 |
|
|
199 |
public abstract class AbstractValue implements Value { |
|
200 |
|
|
201 |
private PropertiesSupport properties; |
|
202 |
|
|
203 |
protected AbstractValue() { |
|
204 |
this.properties = new PropertiesSupportHelper(); |
|
205 |
} |
|
206 |
|
|
207 |
@Override |
|
208 |
public void accept(Visitor visitor, VisitorFilter filter) { |
|
209 |
if (filter == null || filter.accept(this)) { |
|
210 |
visitor.visit(this); |
|
211 |
} |
|
212 |
} |
|
213 |
|
|
214 |
@Override |
|
215 |
public Map<String, Object> getProperties() { |
|
216 |
return this.properties.getProperties(); |
|
217 |
} |
|
218 |
|
|
219 |
@Override |
|
220 |
public Object getProperty(String name) { |
|
221 |
return this.properties.getProperty(name); |
|
222 |
} |
|
223 |
|
|
224 |
@Override |
|
225 |
public void setProperty(String name, Object value) { |
|
226 |
this.properties.setProperty(name, value); |
|
227 |
} |
|
228 |
|
|
229 |
} |
|
230 |
|
|
231 |
public class ClassVisitorFilter implements VisitorFilter { |
|
232 |
|
|
233 |
private final Class classFilter; |
|
234 |
|
|
235 |
public ClassVisitorFilter(Class classFilter) { |
|
236 |
this.classFilter = classFilter; |
|
237 |
} |
|
238 |
|
|
239 |
@Override |
|
240 |
public boolean accept(Visitable visitable) { |
|
241 |
return classFilter.isInstance(visitable); |
|
242 |
} |
|
243 |
|
|
244 |
} |
|
245 |
|
|
246 |
public static final Formatter<Value> EMPTY_FORMATTER = new Formatter<Value>() { |
|
247 |
@Override |
|
248 |
public boolean canApply(Value value) { |
|
249 |
return false; |
|
250 |
} |
|
251 |
|
|
252 |
@Override |
|
253 |
public String format(Value value) { |
|
254 |
return ""; |
|
255 |
} |
|
256 |
}; |
|
257 |
|
|
258 |
public String quote_for_identifiers(); |
|
164 | 259 |
|
260 |
public String quote_for_strings(); |
|
261 |
|
|
165 | 262 |
public void accept(Visitor visitor, VisitorFilter filter); |
166 | 263 |
|
167 |
public List<Variable> getVariables();
|
|
264 |
public List<Variable> variables();
|
|
168 | 265 |
|
169 |
public Parameters getParameters();
|
|
266 |
public List<String> variables_names();
|
|
170 | 267 |
|
171 |
public boolean has_spatial_functions();
|
|
268 |
public List<Parameter> parameters();
|
|
172 | 269 |
|
270 |
public List<String> parameters_names(); |
|
271 |
|
|
173 | 272 |
public GeometrySupportType geometry_support_type(); |
273 |
|
|
274 |
public ExpressionBuilder geometry_support_type(GeometrySupportType geometrySupportType); |
|
174 | 275 |
|
175 | 276 |
public String identifier(String name); |
176 | 277 |
|
177 |
public String bytearray(byte[] data); |
|
178 |
|
|
179 | 278 |
public String bytearray_hex(byte[] data); |
180 | 279 |
|
181 | 280 |
public String bytearray_0x(byte[] data); |
... | ... | |
184 | 283 |
|
185 | 284 |
public String string(String s); |
186 | 285 |
|
187 |
public Object getSRSId(IProjection projection);
|
|
286 |
public Object srs_id(IProjection projection);
|
|
188 | 287 |
|
189 |
public Config getConfig(); |
|
288 |
public Value value(); |
|
289 |
|
|
290 |
public ExpressionBuilder value(Value value); |
|
190 | 291 |
|
191 |
public Value getValue();
|
|
292 |
public Group group(Value group);
|
|
192 | 293 |
|
193 |
public ExpressionBuilder setValue(Value value);
|
|
294 |
public Constant bytearray(byte[] data);
|
|
194 | 295 |
|
195 | 296 |
public Variable variable(String name); |
196 | 297 |
|
... | ... | |
202 | 303 |
|
203 | 304 |
public Constant constant(Object value); |
204 | 305 |
|
205 |
public Group group(Value group);
|
|
306 |
public Constant geometry(Geometry geom, IProjection projection);
|
|
206 | 307 |
|
207 |
public GeometryValue geometry(Geometry geom, IProjection projection);
|
|
308 |
public Constant geometry(Geometry geom);
|
|
208 | 309 |
|
209 |
public GeometryValue geometry(Geometry geom);
|
|
310 |
public Constant envelope(Envelope envelope, IProjection projection);
|
|
210 | 311 |
|
211 |
public GeometryValue envelope(Envelope envelope, IProjection projection);
|
|
312 |
public Constant envelope(Envelope envelope);
|
|
212 | 313 |
|
213 |
public GeometryValue envelope(Envelope envelope);
|
|
314 |
public Constant srs(IProjection projection);
|
|
214 | 315 |
|
215 | 316 |
public Custom custom(Object value); |
216 | 317 |
|
217 |
public Function function(String name, Value... values);
|
|
318 |
public Function as_geometry(Value value);
|
|
218 | 319 |
|
219 |
public Constant srs(IProjection projection);
|
|
320 |
public Method method(Value instance, String name, Value... values);
|
|
220 | 321 |
|
221 |
public Function getAsGeometry(Value value); |
|
322 |
public Function function(String name, Value... values); |
|
323 |
|
|
324 |
public BinaryOperator binaryOperator(String name, Value leftOperand, Value rightOperand); |
|
222 | 325 |
|
326 |
public Value toValue(String expression); |
|
223 | 327 |
|
328 |
public String toString(Formatter<Value> formatter); |
|
329 |
|
|
224 | 330 |
public Function not(Value value); |
225 | 331 |
|
226 |
public Function notIsNull(Value value);
|
|
332 |
public Function not_is_null(Value value);
|
|
227 | 333 |
|
228 |
public Function isNull(Value value);
|
|
334 |
public Function is_null(Value value);
|
|
229 | 335 |
|
230 | 336 |
public Function ST_SRID(Value geom); |
231 | 337 |
|
... | ... | |
263 | 369 |
|
264 | 370 |
public Function ST_Within(Value geom1, Value geom2); |
265 | 371 |
|
266 |
public Function lcase(Value s);
|
|
372 |
public Function ST_UnionAggregate(Value geom);
|
|
267 | 373 |
|
268 |
public Function ucase(Value s);
|
|
269 |
|
|
374 |
public Function ST_ExtentAggregate(Value geom);
|
|
375 |
|
|
270 | 376 |
public BinaryOperator and(Value op1, Value op2); |
271 | 377 |
|
272 | 378 |
public BinaryOperator or(Value op1, Value op2); |
... | ... | |
298 | 404 |
public BinaryOperator concat(Value op1, Value op2); |
299 | 405 |
|
300 | 406 |
public ExpressionBuilder set(Value value); |
301 |
|
|
407 |
|
|
302 | 408 |
public ExpressionBuilder and(Value value); |
303 | 409 |
|
304 | 410 |
public ExpressionBuilder or(Value value); |
... | ... | |
400 | 506 |
public Function zero(); |
401 | 507 |
|
402 | 508 |
public Function chr(Value num); |
509 |
|
|
510 |
public Function decode(Value value, Value format); |
|
511 |
|
|
512 |
public Function cast(Value object, Value typeName); |
|
513 |
|
|
514 |
public Function toDouble(Value object); |
|
515 |
|
|
516 |
public Function toFloat(Value object); |
|
517 |
|
|
518 |
public Function toLong(Value object); |
|
519 |
|
|
520 |
public Function toInteger(Value object); |
|
521 |
|
|
522 |
public Function toStr(Value object); |
|
523 |
|
|
403 | 524 |
} |
Also available in: Unified diff