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 @ 44098
History | View | Annotate | Download (1.55 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(
|
14 |
Function.GROUP_OTHER, |
15 |
"LET",
|
16 |
Range.is(2),
|
17 |
"Assigns the value indicated in the second argument to the variable indicated in the first argument.",
|
18 |
"LET({{identifier_name}},value)",
|
19 |
new String[]{ |
20 |
"identifier_name - Name of the variable",
|
21 |
"value - Value to assign to the variable"
|
22 |
}, |
23 |
"Object",
|
24 |
false
|
25 |
); |
26 |
} |
27 |
|
28 |
@Override
|
29 |
public Object call(Interpreter interpreter, Object[] args) throws Exception { |
30 |
String name = getStr(args,0); |
31 |
Object obj = getObject(args, 1); |
32 |
if( name == null ) { |
33 |
throw new NullPointerException("A string with a variable name was expected and a null was received"); |
34 |
} |
35 |
SymbolTable symbolTable = interpreter.getSymbolTable(); |
36 |
if( symbolTable instanceof MutableSymbolTable ) { |
37 |
((MutableSymbolTable)symbolTable).setVar(name, obj); |
38 |
} else {
|
39 |
throw new RuntimeException("A MutableSymbolTable is required for use let function."); |
40 |
} |
41 |
return obj;
|
42 |
} |
43 |
|
44 |
} |