Revision 44389 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/SimpleScript.java
SimpleScript.java | ||
---|---|---|
9 | 9 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorManager; |
10 | 10 |
import org.gvsig.expressionevaluator.ExpressionRuntimeException; |
11 | 11 |
import org.gvsig.expressionevaluator.Function; |
12 |
import org.gvsig.expressionevaluator.Interpreter; |
|
13 |
import org.gvsig.expressionevaluator.MutableSymbolTable; |
|
12 | 14 |
import org.gvsig.expressionevaluator.SymbolTable; |
13 | 15 |
import org.gvsig.tools.script.Script; |
14 | 16 |
|
... | ... | |
20 | 22 |
|
21 | 23 |
private final String name; |
22 | 24 |
private String source; |
23 |
private DefaultInterpreter interpreter;
|
|
25 |
private Interpreter interpreter; |
|
24 | 26 |
private List<String> names; |
27 |
private final MutableSymbolTable symbolTable; |
|
25 | 28 |
|
26 |
public SimpleScript(String name, String source) { |
|
29 |
public SimpleScript(Interpreter interpreter, String name, String source) { |
|
30 |
this.interpreter = interpreter; |
|
27 | 31 |
this.name = name; |
28 |
this.setCode(source); |
|
32 |
this.symbolTable = ExpressionEvaluatorLocator.getManager().createSymbolTable(); |
|
33 |
this.setCode(source); |
|
29 | 34 |
} |
30 | 35 |
|
36 |
public MutableSymbolTable getSymbolTable() { |
|
37 |
return this.symbolTable; |
|
38 |
} |
|
39 |
|
|
31 | 40 |
@Override |
32 | 41 |
public String getName() { |
33 | 42 |
return this.name; |
... | ... | |
50 | 59 |
|
51 | 60 |
@Override |
52 | 61 |
public void put(String name, Object value) { |
53 |
DefaultSymbolTable symbolTable = (DefaultSymbolTable) this.interpreter.getSymbolTable(); |
|
54 |
symbolTable.setVar(name, value); |
|
62 |
this.symbolTable.setVar(name, value); |
|
55 | 63 |
} |
56 | 64 |
|
57 | 65 |
@Override |
58 | 66 |
public Object invokeFunction(String funcname, Object[] args) throws NoSuchMethodException { |
59 |
if( !this.interpreter.hasFunction(funcname) ) { |
|
60 |
throw new NoSuchMethodException(funcname); |
|
67 |
if( this.symbolTable.function(funcname)==null ) { |
|
68 |
if( !this.interpreter.hasFunction(funcname) ) { |
|
69 |
throw new NoSuchMethodException(funcname); |
|
70 |
} |
|
61 | 71 |
} |
62 | 72 |
try { |
63 |
return this.interpreter.call(funcname, args); |
|
73 |
return this.interpreter.call(this.symbolTable, funcname, args);
|
|
64 | 74 |
} catch (Exception ex) { |
65 | 75 |
throw new ExpressionRuntimeException(this.interpreter.getCurrentCode(),"Error calling funcion '"+funcname+"'.", ex); |
66 | 76 |
} |
... | ... | |
71 | 81 |
this.source = source; |
72 | 82 |
this.names = null; |
73 | 83 |
ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
74 |
this.interpreter = new DefaultInterpreter(); |
|
75 | 84 |
Code code = manager.compile(source); |
76 |
this.interpreter.run(code); |
|
85 |
this.interpreter.run(this.symbolTable, code);
|
|
77 | 86 |
} |
78 | 87 |
|
79 | 88 |
@Override |
80 | 89 |
public List<String> getNames() { |
81 | 90 |
if( this.names == null ) { |
82 | 91 |
List<String> theNames = new ArrayList<>(); |
83 |
SymbolTable symbolTable = this.interpreter.getSymbolTable(); |
|
84 |
Collection<Function> funcs = symbolTable.localfunctions(); |
|
92 |
Collection<Function> funcs = this.symbolTable.localfunctions(); |
|
85 | 93 |
if( funcs!=null ) { |
86 | 94 |
for (Function function : funcs) { |
87 | 95 |
theNames.add(function.name()); |
Also available in: Unified diff