Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.expressionevaluator / org.gvsig.expressionevaluator.lib / org.gvsig.expressionevaluator.lib.impl / src / main / java / org / gvsig / expressionevaluator / impl / function / obj / LetFunction.java @ 43939

History | View | Annotate | Download (1.15 KB)

1
package org.gvsig.expressionevaluator.impl.function.obj;
2

    
3
import org.apache.commons.lang3.Range;
4
import org.gvsig.expressionevaluator.Function;
5
import org.gvsig.expressionevaluator.Interpreter;
6
import org.gvsig.expressionevaluator.MutableSymbolTable;
7
import org.gvsig.expressionevaluator.SymbolTable;
8
import org.gvsig.expressionevaluator.spi.AbstractFunction;
9

    
10
public class LetFunction extends AbstractFunction {
11

    
12
    public LetFunction() {
13
        super(Function.GROUP_OTHER, "let", Range.is(2));
14
    }
15

    
16
    @Override
17
    public Object call(Interpreter interpreter, Object[] args) throws Exception {
18
        String name = getStr(args,0);
19
        Object obj = getObject(args, 1);
20
        if( name == null ) {
21
            throw new NullPointerException("A string with a variable name was expected and a null was received");
22
        }
23
        SymbolTable symbolTable = interpreter.getSymbolTable();
24
        if( symbolTable instanceof MutableSymbolTable ) {
25
            ((MutableSymbolTable)symbolTable).setVar(name, obj);
26
        } else {
27
            throw new RuntimeException("A MutableSymbolTable is required for use let function.");
28
        }
29
        return obj;
30
    }
31
    
32
}