svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.h2spatial / org.gvsig.h2spatial.h2gis132 / org.gvsig.h2spatial.h2gis132.provider / src / main / java / org / gvsig / fmap / dal / store / h2 / expressionbuilderformatter / Decode.java @ 46092
History | View | Annotate | Download (2.76 KB)
1 |
package org.gvsig.fmap.dal.store.h2.expressionbuilderformatter; |
---|---|
2 |
|
3 |
import java.util.List; |
4 |
import org.apache.commons.lang3.StringUtils; |
5 |
import org.gvsig.expressionevaluator.ExpressionBuilder; |
6 |
import static org.gvsig.expressionevaluator.ExpressionBuilder.FUNCTION_DECODE; |
7 |
import org.gvsig.expressionevaluator.ExpressionBuilder.Function; |
8 |
import org.gvsig.expressionevaluator.ExpressionBuilder.Value; |
9 |
import org.gvsig.expressionevaluator.Formatter; |
10 |
import org.gvsig.fmap.dal.SQLBuilder; |
11 |
import org.gvsig.fmap.dal.store.jdbc2.spi.expressionbuilder.formatters.$Constant; |
12 |
|
13 |
/**
|
14 |
*
|
15 |
* @author jjdelcerro
|
16 |
*/
|
17 |
public class Decode implements Formatter<Value> { |
18 |
|
19 |
private final SQLBuilder sqlbuilder; |
20 |
private final Formatter<Value> formatter; |
21 |
|
22 |
public Decode(SQLBuilder sqlbuilder, Formatter<Value> formatter) { |
23 |
this.sqlbuilder = sqlbuilder;
|
24 |
this.formatter = formatter;
|
25 |
} |
26 |
|
27 |
@Override
|
28 |
public boolean canApply(ExpressionBuilder.Value value) { |
29 |
if (value instanceof ExpressionBuilder.Function) { |
30 |
if( StringUtils.equalsIgnoreCase(FUNCTION_DECODE, ((Function) value).name()) ) {
|
31 |
List<Value> parameters = ((Function) value).parameters();
|
32 |
if( parameters.size()==2) { |
33 |
Value p1 = parameters.get(0);
|
34 |
Value p2 = parameters.get(1);
|
35 |
// if( p1 instanceof ExpressionBuilder.Constant &&
|
36 |
// p2 instanceof ExpressionBuilder.Constant &&
|
37 |
// ((ExpressionBuilder.Constant)p1).value() instanceof String &&
|
38 |
// ((ExpressionBuilder.Constant)p2).value() instanceof String
|
39 |
// ) {
|
40 |
// String p2value = ((ExpressionBuilder.Constant)p2).value().toString();
|
41 |
// if( StringUtils.equalsIgnoreCase(p2value, "hex") ) {
|
42 |
// return true;
|
43 |
// }
|
44 |
// }
|
45 |
if( $Constant.isConstant(p1) && p2 instanceof ExpressionBuilder.Constant && |
46 |
((ExpressionBuilder.Constant)p2).value() instanceof String |
47 |
) { |
48 |
String p2value = ((ExpressionBuilder.Constant)p2).value().toString();
|
49 |
if( StringUtils.equalsIgnoreCase(p2value, "hex") ) { |
50 |
return true; |
51 |
} |
52 |
} |
53 |
|
54 |
} |
55 |
} |
56 |
} |
57 |
return false; |
58 |
} |
59 |
|
60 |
@Override
|
61 |
public String format(Value function) { |
62 |
List<Value> parameters = ((Function) function).parameters();
|
63 |
Value p1 = parameters.get(0);
|
64 |
String p1value = $Constant.resolve(this.sqlbuilder, this.formatter, p1); |
65 |
String r = "X"+p1value; |
66 |
return r;
|
67 |
} |
68 |
|
69 |
} |