root / trunk / org.gvsig.postgresql / org.gvsig.postgresql.provider / src / main / java / org / gvsig / postgresql / dal / expressionbuilderformatter / ST_GeomFromWKB.java @ 527
History | View | Annotate | Download (2.49 KB)
1 |
package org.gvsig.postgresql.dal.expressionbuilderformatter; |
---|---|
2 |
|
3 |
import java.text.MessageFormat; |
4 |
import java.util.List; |
5 |
import org.apache.commons.lang3.StringUtils; |
6 |
import org.gvsig.expressionevaluator.ExpressionBuilder; |
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.feature.FeatureType; |
12 |
import static org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase.PROP_FEATURE_TYPE; |
13 |
|
14 |
/**
|
15 |
*
|
16 |
* @author jjdelcerro
|
17 |
*/
|
18 |
public class ST_GeomFromWKB implements Formatter<Value> { |
19 |
|
20 |
private final SQLBuilder sqlbuilder; |
21 |
private final Formatter<Value> formatter; |
22 |
|
23 |
public ST_GeomFromWKB(SQLBuilder sqlbuilder, Formatter<Value> formatter) { |
24 |
this.sqlbuilder = sqlbuilder;
|
25 |
this.formatter = formatter;
|
26 |
} |
27 |
@Override
|
28 |
public boolean canApply(ExpressionBuilder.Value value) { |
29 |
if (value instanceof ExpressionBuilder.Function) { |
30 |
return StringUtils.equalsIgnoreCase(ExpressionBuilder.FUNCTION_ST_GEOMFROMWKB, ((Function) value).name());
|
31 |
} |
32 |
return false; |
33 |
} |
34 |
|
35 |
@Override
|
36 |
public String format(Value function) { |
37 |
String r;
|
38 |
String wkb;
|
39 |
String srid;
|
40 |
List<Value> parameters = ((Function) function).parameters();
|
41 |
switch(parameters.size()) {
|
42 |
case 1: |
43 |
wkb = parameters.get(0).toString(formatter);
|
44 |
r = MessageFormat.format("ST_GeomFromWKB({0})", wkb); |
45 |
break;
|
46 |
case 2: |
47 |
wkb = parameters.get(0).toString(formatter);
|
48 |
srid = parameters.get(1).toString(formatter);
|
49 |
if( StringUtils.equals("0", srid) ) { |
50 |
r = MessageFormat.format("ST_GeomFromWKB({0})", wkb); |
51 |
} else {
|
52 |
FeatureType ftype = (FeatureType) function.getProperty(PROP_FEATURE_TYPE); |
53 |
if( ftype == null || ftype.getDefaultSRS()!=null ) { |
54 |
r = MessageFormat.format("ST_GeomFromWKB({0},{1})", wkb, srid); |
55 |
} else {
|
56 |
r = MessageFormat.format("ST_GeomFromWKB({0})", wkb); |
57 |
} |
58 |
} |
59 |
break;
|
60 |
default:
|
61 |
throw new IllegalArgumentException("Wrong number of arguments ("+parameters.size()+") in function ST_GeomFromWKB; requiered 1 or 2 arguments."); |
62 |
} |
63 |
return r;
|
64 |
} |
65 |
|
66 |
} |