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 / ScriptFunction.java @ 44198

History | View | Annotate | Download (1.13 KB)

1 43913 jjdelcerro
package org.gvsig.expressionevaluator.impl.function;
2
3 43939 jjdelcerro
import java.util.List;
4 43913 jjdelcerro
import org.apache.commons.lang3.Range;
5
import org.gvsig.expressionevaluator.Interpreter;
6
import org.gvsig.expressionevaluator.spi.AbstractFunction;
7
import org.gvsig.tools.script.Script;
8
9
/**
10
 *
11
 * @author jjdelcerro
12
 */
13
public class ScriptFunction extends AbstractFunction {
14
15 43939 jjdelcerro
    private final List<Script> scripts;
16 43913 jjdelcerro
17
    /**
18
     *
19 43939 jjdelcerro
     * @param scripts
20 43913 jjdelcerro
     * @param funcName
21
     */
22 43939 jjdelcerro
    public ScriptFunction(List<Script> scripts, String funcName) {
23 43913 jjdelcerro
        super("Script", funcName,  Range.between(1,Integer.MAX_VALUE));
24 43939 jjdelcerro
        this.scripts = scripts;
25 43913 jjdelcerro
26
    }
27
28
    @Override
29
    public Object call(Interpreter interpreter, Object[] args) throws Exception {
30 43939 jjdelcerro
        for (Script script : this.scripts) {
31
            try {
32
                return script.invokeFunction(this.name(), args);
33
            } catch(NoSuchMethodException ex) {
34
                // Si la funcion no existe en el script pasamos al siguiente
35
                // script.
36
            }
37
        }
38
        throw new NoSuchMethodException("Can't locate funcion '"+this.name()+"'.");
39 43913 jjdelcerro
    }
40
41
}