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 / CodeBlockWithExceptFunction.java @ 44384
History | View | Annotate | Download (2.18 KB)
1 |
package org.gvsig.expressionevaluator.impl.function.programming; |
---|---|
2 |
|
3 |
import org.apache.commons.lang3.Range; |
4 |
import org.gvsig.expressionevaluator.Code; |
5 |
import org.gvsig.expressionevaluator.Codes; |
6 |
import org.gvsig.expressionevaluator.Function; |
7 |
import org.gvsig.expressionevaluator.Interpreter; |
8 |
import org.gvsig.expressionevaluator.impl.DefaultInterpreter; |
9 |
import org.gvsig.expressionevaluator.spi.AbstractFunction; |
10 |
|
11 |
public class CodeBlockWithExceptFunction extends AbstractFunction { |
12 |
|
13 |
public static final String NAME = "BLOCK_EXCEPT"; |
14 |
|
15 |
public CodeBlockWithExceptFunction() {
|
16 |
super(Function.GROUP_PROGRAMMING,
|
17 |
NAME, |
18 |
Range.between(1,Integer.MAX_VALUE), |
19 |
"Evaluate each of the arguments sequentially.",
|
20 |
NAME+"( {{arguments...}} )",
|
21 |
null,
|
22 |
"Object",
|
23 |
false
|
24 |
); |
25 |
} |
26 |
|
27 |
@Override
|
28 |
public boolean useArgumentsInsteadObjects() { |
29 |
return true; |
30 |
} |
31 |
|
32 |
@Override
|
33 |
public boolean allowConstantFolding() { |
34 |
return false; |
35 |
} |
36 |
|
37 |
@Override
|
38 |
public Object call(Interpreter interpreter, Object[] args) throws Exception { |
39 |
throw new UnsupportedOperationException("Not supported yet."); |
40 |
} |
41 |
|
42 |
@Override
|
43 |
public Object call(Interpreter interpreter, Codes args) throws Exception { |
44 |
Object value = null; |
45 |
Code exceptionCode = args.get(args.size()-1);
|
46 |
if( exceptionCode==null ) { |
47 |
for (int i = 0; i < args.size()-1; i++) { |
48 |
Code arg = args.get(i); |
49 |
// LLamamos a runCode para que no atrape los returns.
|
50 |
value = ((DefaultInterpreter)interpreter).runCode(arg); |
51 |
} |
52 |
} else {
|
53 |
for (int i = 0; i < args.size()-1; i++) { |
54 |
Code arg = args.get(i); |
55 |
try {
|
56 |
// LLamamos a runCode para que no atrape los returns.
|
57 |
value = ((DefaultInterpreter)interpreter).runCode(arg); |
58 |
} catch(Exception ex) { |
59 |
value = ((DefaultInterpreter)interpreter).runCode(exceptionCode); |
60 |
break;
|
61 |
} |
62 |
} |
63 |
} |
64 |
return value;
|
65 |
} |
66 |
|
67 |
} |