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 / TryFunction.java @ 44207

History | View | Annotate | Download (1.39 KB)

1 44138 jjdelcerro
package org.gvsig.expressionevaluator.impl.function.programming;
2 43512 jjdelcerro
3
import org.apache.commons.lang3.Range;
4 44138 jjdelcerro
import org.gvsig.expressionevaluator.Codes;
5 43939 jjdelcerro
import org.gvsig.expressionevaluator.Function;
6 43521 jjdelcerro
import org.gvsig.expressionevaluator.Interpreter;
7 43512 jjdelcerro
import org.gvsig.expressionevaluator.spi.AbstractFunction;
8
9 44144 jjdelcerro
public class TryFunction extends AbstractFunction {
10 43512 jjdelcerro
11 44144 jjdelcerro
    public static final String NAME = "TRY";
12 44138 jjdelcerro
13 44144 jjdelcerro
    public TryFunction() {
14 44138 jjdelcerro
        super(Function.GROUP_BOOLEAN,
15
                NAME,
16 44144 jjdelcerro
                Range.between(1,2),
17 44038 jjdelcerro
                null,
18 44144 jjdelcerro
                NAME+"( {{expression}}, onerror )",
19
                null,
20 44038 jjdelcerro
                "Object",
21
                true
22 43939 jjdelcerro
        );
23 43512 jjdelcerro
    }
24
25
    @Override
26 43939 jjdelcerro
    public boolean useArgumentsInsteadObjects() {
27
        return true;
28
    }
29
30
    @Override
31 44138 jjdelcerro
    public boolean allowConstantFolding() {
32
        return false;
33
    }
34
35
    @Override
36 43521 jjdelcerro
    public Object call(Interpreter interpreter, Object[] args) throws Exception {
37 44038 jjdelcerro
        throw new UnsupportedOperationException("Not supported yet.");
38 43939 jjdelcerro
    }
39
40
    @Override
41 44138 jjdelcerro
    public Object call(Interpreter interpreter, Codes args) throws Exception {
42 44144 jjdelcerro
        Object value = null;
43
        try {
44
            value = getObject(interpreter, args, 0);
45
        } catch(Exception ex) {
46
            if( args.size()>1 ) {
47
                value = getObject(interpreter, args, 1);
48 44138 jjdelcerro
            }
49 43512 jjdelcerro
        }
50 43939 jjdelcerro
        return value;
51 43512 jjdelcerro
    }
52
53
}