svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.db / org.gvsig.fmap.dal.db.jdbc / src / main / java / org / gvsig / fmap / dal / store / jdbc2 / spi / expressionbuilder / formatters / $Identifier.java @ 46050
History | View | Annotate | Download (2.61 KB)
1 | 46010 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | *
|
||
4 | * Copyright (C) 2007-2020 gvSIG Association.
|
||
5 | *
|
||
6 | * This program is free software; you can redistribute it and/or
|
||
7 | * modify it under the terms of the GNU General Public License
|
||
8 | * as published by the Free Software Foundation; either version 3
|
||
9 | * of the License, or (at your option) any later version.
|
||
10 | *
|
||
11 | * This program is distributed in the hope that it will be useful,
|
||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
14 | * GNU General Public License for more details.
|
||
15 | *
|
||
16 | * You should have received a copy of the GNU General Public License
|
||
17 | * along with this program; if not, write to the Free Software
|
||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||
19 | * MA 02110-1301, USA.
|
||
20 | *
|
||
21 | * For any additional information, do not hesitate to contact us
|
||
22 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
23 | */
|
||
24 | package org.gvsig.fmap.dal.store.jdbc2.spi.expressionbuilder.formatters; |
||
25 | |||
26 | import java.util.Objects; |
||
27 | import org.apache.commons.lang3.StringUtils; |
||
28 | import org.gvsig.expressionevaluator.ExpressionBuilder; |
||
29 | import org.gvsig.expressionevaluator.ExpressionBuilder.Function; |
||
30 | import org.gvsig.expressionevaluator.ExpressionBuilder.Value; |
||
31 | import org.gvsig.expressionevaluator.ExpressionUtils; |
||
32 | import org.gvsig.expressionevaluator.Formatter; |
||
33 | import org.gvsig.expressionevaluator.SymbolTable; |
||
34 | import org.gvsig.fmap.dal.SQLBuilder; |
||
35 | import static org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase.PROP_SYMBOLTABLE; |
||
36 | 46050 | omartinez | import static org.gvsig.expressionevaluator.ExpressionBuilder.FUNCTION_$IDENTIFIER; |
37 | 46010 | jjdelcerro | |
38 | /**
|
||
39 | *
|
||
40 | * @author jjdelcerro
|
||
41 | */
|
||
42 | 46050 | omartinez | public class $Identifier implements Formatter<Value> { |
43 | 46010 | jjdelcerro | |
44 | private final SQLBuilder sqlbuilder; |
||
45 | private final Formatter<Value> formatter; |
||
46 | |||
47 | 46050 | omartinez | public $Identifier(SQLBuilder sqlbuilder, Formatter<Value> formatter) { |
48 | 46010 | jjdelcerro | this.sqlbuilder = sqlbuilder;
|
49 | this.formatter = formatter;
|
||
50 | } |
||
51 | |||
52 | @Override
|
||
53 | public boolean canApply(ExpressionBuilder.Value value) { |
||
54 | if (value instanceof ExpressionBuilder.Function) { |
||
55 | 46050 | omartinez | return StringUtils.equalsIgnoreCase(FUNCTION_$IDENTIFIER, ((Function) value).name()); |
56 | 46010 | jjdelcerro | } |
57 | return false; |
||
58 | } |
||
59 | |||
60 | @Override
|
||
61 | public String format(Value value) { |
||
62 | SymbolTable symbolTable = (SymbolTable) value.getProperty(PROP_SYMBOLTABLE); |
||
63 | Value p1 = ((ExpressionBuilder.Function)value).parameters().get(0);
|
||
64 | Object x = ExpressionUtils.evaluate(symbolTable, p1.toString());
|
||
65 | return this.sqlbuilder.expression().variable(Objects.toString(x, "")).toString(this.formatter); |
||
66 | } |
||
67 | |||
68 | } |