svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.impl / src / main / java / org / gvsig / expressionevaluator / impl / function / dataaccess / RowTagFunction.java @ 44925
History | View | Annotate | Download (3.47 KB)
1 | 44738 | 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.expressionevaluator.impl.function.dataaccess; |
||
25 | |||
26 | 44858 | jjdelcerro | import java.util.Map; |
27 | import java.util.Objects; |
||
28 | 44738 | jjdelcerro | import org.apache.commons.lang3.Range; |
29 | import org.gvsig.expressionevaluator.Codes; |
||
30 | import org.gvsig.expressionevaluator.ExpressionRuntimeException; |
||
31 | import org.gvsig.expressionevaluator.Interpreter; |
||
32 | import org.gvsig.expressionevaluator.impl.DALFunctions; |
||
33 | 44858 | jjdelcerro | import org.gvsig.fmap.dal.DataManager; |
34 | import org.gvsig.fmap.dal.feature.Feature; |
||
35 | import org.gvsig.tools.util.GetItemByKey; |
||
36 | 44925 | jjdelcerro | import org.gvsig.tools.util.GetKeys; |
37 | 44738 | jjdelcerro | |
38 | /**
|
||
39 | *
|
||
40 | * @author jjdelcerro
|
||
41 | */
|
||
42 | 44858 | jjdelcerro | public class RowTagFunction extends AbstractFeatureFunction { |
43 | 44738 | jjdelcerro | |
44 | 44858 | jjdelcerro | public RowTagFunction() {
|
45 | 44896 | jjdelcerro | super( DALFunctions.GROUP_DATA_ACCESS,
|
46 | 44858 | jjdelcerro | DataManager.FUNCTION_ROW_TAG, |
47 | Range.between(1,2), |
||
48 | 44925 | jjdelcerro | "Retrieves a value associated with a tag from the current line.\n" +
|
49 | "Return null if used outer a table filter or if the row don't " +
|
||
50 | "have a tag with the value indicated.",
|
||
51 | 44858 | jjdelcerro | DataManager.FUNCTION_ROW_TAG+"({{name}})",
|
52 | null,
|
||
53 | "Object",
|
||
54 | false
|
||
55 | 44738 | jjdelcerro | ); |
56 | } |
||
57 | |||
58 | @Override
|
||
59 | public boolean allowConstantFolding() { |
||
60 | return false; |
||
61 | } |
||
62 | |||
63 | @Override
|
||
64 | public boolean useArgumentsInsteadObjects() { |
||
65 | return true; |
||
66 | } |
||
67 | |||
68 | @Override
|
||
69 | public Object call(Interpreter interpreter, Object[] args) throws Exception { |
||
70 | 44858 | jjdelcerro | return null; |
71 | 44738 | jjdelcerro | } |
72 | |||
73 | @Override
|
||
74 | public Object call(Interpreter interpreter, Codes args) throws Exception { |
||
75 | 44858 | jjdelcerro | Feature f = this.current_row(interpreter);
|
76 | if( f==null ) { |
||
77 | return null; |
||
78 | } |
||
79 | String name = Objects.toString(getObject(interpreter, args, 0),null); |
||
80 | if( name == null ) { |
||
81 | throw new ExpressionRuntimeException("The first argument of '"+DataManager.FUNCTION_SET_ROW_TAG+"' can't be null."); |
||
82 | } |
||
83 | if( args.size()==2 ) { |
||
84 | if( !f.hasExtraValue(name) ) {
|
||
85 | Object map = Objects.toString(getObject(interpreter, args, 1),null); |
||
86 | if( map instanceof Map) { |
||
87 | for (Map.Entry<Object, Object> entry : ((Map<Object,Object>)map).entrySet()) { |
||
88 | String key = Objects.toString(entry.getKey(),null); |
||
89 | Object val = entry.getValue();
|
||
90 | if( key!=null ) { |
||
91 | f.setExtraValue(key, val); |
||
92 | } |
||
93 | 44738 | jjdelcerro | } |
94 | 44925 | jjdelcerro | } else if( map instanceof GetItemByKey && map instanceof GetKeys ) { |
95 | for (String key : ((GetKeys<String>)map).getKeys() ) { |
||
96 | Object val = ((GetItemByKey<String,Object>)map).get(key); |
||
97 | f.setExtraValue(key, val); |
||
98 | } |
||
99 | 44738 | jjdelcerro | } |
100 | } |
||
101 | } |
||
102 | 44858 | jjdelcerro | return f.getExtraValue(name);
|
103 | 44738 | jjdelcerro | } |
104 | } |