Statistics
| Revision:

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 @ 44858

History | View | Annotate | Download (3.35 KB)

1
/**
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
import java.util.Map;
27
import java.util.Objects;
28
import org.apache.commons.lang3.Range;
29
import org.gvsig.expressionevaluator.Code;
30
import org.gvsig.expressionevaluator.Codes;
31
import org.gvsig.expressionevaluator.ExpressionRuntimeException;
32
import org.gvsig.expressionevaluator.Interpreter;
33
import org.gvsig.expressionevaluator.impl.DALFunctions;
34
import org.gvsig.fmap.dal.DataManager;
35
import org.gvsig.fmap.dal.feature.Feature;
36
import org.gvsig.tools.util.GetItemByKey;
37

    
38
/**
39
 *
40
 * @author jjdelcerro
41
 */
42
public class RowTagFunction extends AbstractFeatureFunction {
43

    
44
  public RowTagFunction() {
45
    super(DALFunctions.SYMBOLTABLE_NAME,
46
            DataManager.FUNCTION_ROW_TAG,
47
            Range.between(1,2),
48
            "Retrieves a value associated with a tag from the current line.",
49
            DataManager.FUNCTION_ROW_TAG+"({{name}})",
50
            null,
51
            "Object",
52
            false
53
    );
54
  }
55

    
56
  @Override
57
  public boolean allowConstantFolding() {
58
    return false;
59
  }
60

    
61
  @Override
62
  public boolean useArgumentsInsteadObjects() {
63
    return true;
64
  }
65

    
66
  @Override
67
  public Object call(Interpreter interpreter, Object[] args) throws Exception {
68
    return null;
69
  }
70

    
71
  @Override
72
  public Object call(Interpreter interpreter, Codes args) throws Exception {
73
    Feature f = this.current_row(interpreter);
74
    if( f==null ) {
75
      return null;
76
    }
77
    String name = Objects.toString(getObject(interpreter, args, 0),null);
78
    if( name == null ) {
79
      throw new ExpressionRuntimeException("The first argument of '"+DataManager.FUNCTION_SET_ROW_TAG+"' can't be null.");    
80
    }
81
    if( args.size()==2 ) {
82
      if( !f.hasExtraValue(name) ) {
83
        Object map = Objects.toString(getObject(interpreter, args, 1),null);
84
        if( map instanceof Map) {
85
          for (Map.Entry<Object, Object> entry : ((Map<Object,Object>)map).entrySet()) {
86
            String key = Objects.toString(entry.getKey(),null);
87
            Object val = entry.getValue();
88
            if( key!=null ) {
89
              f.setExtraValue(key, val);
90
            }
91
          }
92
  //      } else if( map instanceof GetItemByKey && map instanceof GetKeys ) {
93
  //        for (String key : ((GetKeys<String>)map).getKeys() ) {
94
  //          Object val = ((GetItemByKey<String,Object>)map).get(key);
95
  //          f.setExtraValue(key, val);
96
  //        }
97
        }
98
      }
99
    }
100
   return f.getExtraValue(name);
101
  }
102
}