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 / programming / CodeBlockWithExceptFunction.java @ 44738

History | View | Annotate | Download (2.25 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 isHidden() {
29
      return true;
30
    }
31
    
32
    @Override
33
    public boolean useArgumentsInsteadObjects() {
34
        return true;
35
    }
36

    
37
    @Override
38
    public boolean allowConstantFolding() {
39
        return false;
40
    }
41
    
42
    @Override
43
    public Object call(Interpreter interpreter, Object[] args) throws Exception {
44
        throw new UnsupportedOperationException("Not supported yet.");
45
    }
46
    
47
    @Override
48
    public Object call(Interpreter interpreter, Codes args) throws Exception {
49
        Object value = null;
50
        Code exceptionCode = args.get(args.size()-1);
51
        if( exceptionCode==null ) {
52
            for (int i = 0; i < args.size()-1; i++) {
53
                Code arg = args.get(i);
54
                // LLamamos a runCode para que no atrape los returns.
55
                value = ((DefaultInterpreter)interpreter).runCode(arg);
56
            }
57
        } else {
58
            for (int i = 0; i < args.size()-1; i++) {
59
                Code arg = args.get(i);
60
                try {
61
                    // LLamamos a runCode para que no atrape los returns.
62
                    value = ((DefaultInterpreter)interpreter).runCode(arg);
63
                } catch(Exception ex) {
64
                    value = ((DefaultInterpreter)interpreter).runCode(exceptionCode);
65
                    break;
66
                }
67
            }
68
        }
69
        return value;
70
    }
71
    
72
}