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 @ 44738

History | View | Annotate | Download (1.47 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 44262 jjdelcerro
        super(Function.GROUP_PROGRAMMING,
15 44138 jjdelcerro
                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 44738 jjdelcerro
    public boolean isHidden() {
27
      return true;
28
    }
29
30
    @Override
31 43939 jjdelcerro
    public boolean useArgumentsInsteadObjects() {
32
        return true;
33
    }
34
35
    @Override
36 44138 jjdelcerro
    public boolean allowConstantFolding() {
37
        return false;
38
    }
39
40
    @Override
41 43521 jjdelcerro
    public Object call(Interpreter interpreter, Object[] args) throws Exception {
42 44038 jjdelcerro
        throw new UnsupportedOperationException("Not supported yet.");
43 43939 jjdelcerro
    }
44
45
    @Override
46 44138 jjdelcerro
    public Object call(Interpreter interpreter, Codes args) throws Exception {
47 44144 jjdelcerro
        Object value = null;
48
        try {
49
            value = getObject(interpreter, args, 0);
50
        } catch(Exception ex) {
51
            if( args.size()>1 ) {
52
                value = getObject(interpreter, args, 1);
53 44138 jjdelcerro
            }
54 43512 jjdelcerro
        }
55 43939 jjdelcerro
        return value;
56 43512 jjdelcerro
    }
57
58
}