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 / programming / CodeBlockFunction.java @ 47063
History | View | Annotate | Download (2.52 KB)
1 |
package org.gvsig.expressionevaluator.impl.function.programming; |
---|---|
2 |
|
3 |
import java.util.Objects; |
4 |
import org.apache.commons.lang3.Range; |
5 |
import org.gvsig.expressionevaluator.Code; |
6 |
import org.gvsig.expressionevaluator.Codes; |
7 |
import org.gvsig.expressionevaluator.Function; |
8 |
import org.gvsig.expressionevaluator.Interpreter; |
9 |
import org.gvsig.expressionevaluator.impl.DefaultInterpreter; |
10 |
import org.gvsig.expressionevaluator.impl.HostExpressionUtils; |
11 |
import org.gvsig.expressionevaluator.impl.function.programming.BreakFunction.BreakException; |
12 |
import org.gvsig.expressionevaluator.impl.function.programming.ReturnFunction.ReturnException; |
13 |
import org.gvsig.expressionevaluator.spi.AbstractFunction; |
14 |
|
15 |
@SuppressWarnings("UseSpecificCatch") |
16 |
public class CodeBlockFunction extends AbstractFunction { |
17 |
|
18 |
public static final String NAME = "BLOCK"; |
19 |
|
20 |
public CodeBlockFunction() {
|
21 |
super(Function.GROUP_PROGRAMMING,
|
22 |
NAME, |
23 |
Range.between(1, Integer.MAX_VALUE), |
24 |
"Evaluate each of the arguments sequentially.",
|
25 |
"BEGIN\n {{sentence}};\nEXCEPT\n PASS\nEND\n",
|
26 |
null,
|
27 |
"Object",
|
28 |
false
|
29 |
); |
30 |
} |
31 |
|
32 |
@Override
|
33 |
public boolean isHidden() { |
34 |
return true; |
35 |
} |
36 |
|
37 |
@Override
|
38 |
public boolean useArgumentsInsteadObjects() { |
39 |
return true; |
40 |
} |
41 |
|
42 |
@Override
|
43 |
public boolean allowConstantFolding() { |
44 |
return false; |
45 |
} |
46 |
|
47 |
@Override
|
48 |
public Object call(Interpreter interpreter, Object[] args) throws Exception { |
49 |
throw new UnsupportedOperationException("Not supported yet."); |
50 |
} |
51 |
|
52 |
@Override
|
53 |
public Object call(Interpreter interpreter, Codes args) throws Exception { |
54 |
Object value = null; |
55 |
int argn = 0; |
56 |
for (Code statement : args) {
|
57 |
// LLamamos a runCode para que no atrape los returns.
|
58 |
try {
|
59 |
statement = HostExpressionUtils.resolveHostExpressions(statement, interpreter); |
60 |
value = ((DefaultInterpreter) interpreter).runCode(statement); |
61 |
} catch(BreakException|ReturnException ex) {
|
62 |
throw ex;
|
63 |
} catch(Exception ex) { |
64 |
String stmt = "unknown"; |
65 |
try {
|
66 |
stmt = Objects.toString(statement); |
67 |
} catch(Exception ex2) { |
68 |
|
69 |
} |
70 |
LOGGER.warn("Error in block function calling arg "+ argn + ", "+ stmt, ex); |
71 |
throw ex;
|
72 |
} |
73 |
argn++; |
74 |
} |
75 |
return value;
|
76 |
} |
77 |
|
78 |
} |