Revision 44533 trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.api/src/main/java/org/gvsig/expressionevaluator/spi/AbstractSymbolTable.java
AbstractSymbolTable.java | ||
---|---|---|
9 | 9 |
import java.util.List; |
10 | 10 |
import java.util.Map; |
11 | 11 |
import java.util.Set; |
12 |
import org.apache.commons.lang3.Range; |
|
13 | 12 |
import org.apache.commons.lang3.StringUtils; |
14 | 13 |
import org.gvsig.expressionevaluator.Function; |
15 |
import org.gvsig.expressionevaluator.Interpreter; |
|
16 | 14 |
import org.gvsig.expressionevaluator.SymbolTable; |
17 |
import org.gvsig.tools.script.Script; |
|
18 | 15 |
|
19 | 16 |
/** |
20 | 17 |
* |
... | ... | |
24 | 21 |
|
25 | 22 |
private final String name; |
26 | 23 |
|
27 |
public class ScriptFunction extends AbstractFunction { |
|
24 |
// public class ScriptFunction extends AbstractFunction { |
|
25 |
// |
|
26 |
// public ScriptFunction(String funcName) { |
|
27 |
// super("Script", funcName, Range.between(1, Integer.MAX_VALUE)); |
|
28 |
// } |
|
29 |
// |
|
30 |
// @Override |
|
31 |
// public Object call(Interpreter interpreter, Object[] args) throws Exception { |
|
32 |
// for (Script script : scripts()) { |
|
33 |
// try { |
|
34 |
// return script.invokeFunction(this.name(), args); |
|
35 |
// } catch (NoSuchMethodException ex) { |
|
36 |
// // Si la funcion no existe en el script pasamos al siguiente |
|
37 |
// // script. |
|
38 |
// } |
|
39 |
// } |
|
40 |
// throw new NoSuchMethodException("Can't locate funcion '" + this.name() + "'."); |
|
41 |
// } |
|
42 |
// |
|
43 |
// } |
|
28 | 44 |
|
29 |
public ScriptFunction(String funcName) { |
|
30 |
super("Script", funcName, Range.between(1, Integer.MAX_VALUE)); |
|
31 |
} |
|
32 |
|
|
33 |
@Override |
|
34 |
public Object call(Interpreter interpreter, Object[] args) throws Exception { |
|
35 |
for (Script script : scripts()) { |
|
36 |
try { |
|
37 |
return script.invokeFunction(this.name(), args); |
|
38 |
} catch (NoSuchMethodException ex) { |
|
39 |
// Si la funcion no existe en el script pasamos al siguiente |
|
40 |
// script. |
|
41 |
} |
|
42 |
} |
|
43 |
throw new NoSuchMethodException("Can't locate funcion '" + this.name() + "'."); |
|
44 |
} |
|
45 |
|
|
46 |
} |
|
47 |
|
|
48 | 45 |
protected final List<SymbolTable> symbolTables; |
49 | 46 |
protected Map<String, Object> vars; |
50 | 47 |
protected Map<String, Function> functions; |
51 | 48 |
protected Map<String, Function> functionAlias; |
52 |
protected List<Script> scripts; |
|
49 |
// protected List<Script> scripts;
|
|
53 | 50 |
|
54 | 51 |
public AbstractSymbolTable() { |
55 | 52 |
this(null); |
... | ... | |
61 | 58 |
this.vars = null; |
62 | 59 |
this.functions = null; |
63 | 60 |
this.functionAlias = null; |
64 |
this.scripts = null; |
|
61 |
// this.scripts = null;
|
|
65 | 62 |
} |
66 | 63 |
|
67 | 64 |
@Override |
... | ... | |
127 | 124 |
return this.functionAlias; |
128 | 125 |
} |
129 | 126 |
|
130 |
protected List<Script> getScripts() { |
|
131 |
if (this.scripts == null) { |
|
132 |
this.scripts = new ArrayList<>(); |
|
133 |
} |
|
134 |
return this.scripts; |
|
135 |
} |
|
136 |
|
|
127 |
// protected List<Script> getScripts() {
|
|
128 |
// if (this.scripts == null) {
|
|
129 |
// this.scripts = new ArrayList<>();
|
|
130 |
// }
|
|
131 |
// return this.scripts;
|
|
132 |
// }
|
|
133 |
// |
|
137 | 134 |
@Override |
138 | 135 |
public boolean exists(String name) { |
139 | 136 |
if (StringUtils.isEmpty(name)) { |
... | ... | |
191 | 188 |
for (SymbolTable other : this.symbolTables) { |
192 | 189 |
Function fn = other.function(name); |
193 | 190 |
if (fn != null) { |
194 |
if (fn instanceof ScriptFunction) { |
|
195 |
continue; |
|
196 |
} |
|
191 |
// if (fn instanceof ScriptFunction) {
|
|
192 |
// continue;
|
|
193 |
// }
|
|
197 | 194 |
return fn; |
198 | 195 |
} |
199 | 196 |
} |
200 |
if (this.scripts == null || this.scripts.isEmpty()) {
|
|
201 |
return null;
|
|
202 |
} |
|
203 |
return new ScriptFunction(name);
|
|
197 |
// if (this.scripts != null && ! this.scripts.isEmpty()) {
|
|
198 |
// return new ScriptFunction(name);
|
|
199 |
// }
|
|
200 |
return null;
|
|
204 | 201 |
} |
205 | 202 |
|
206 | 203 |
@Override |
... | ... | |
241 | 238 |
return Collections.unmodifiableCollection(this.vars.keySet()); |
242 | 239 |
} |
243 | 240 |
|
241 |
// @Override |
|
242 |
// public Collection<Script> scripts() { |
|
243 |
// Set<Script> theScripts = new HashSet<>(); |
|
244 |
// for (SymbolTable symbolTable : this.symbolTables) { |
|
245 |
// theScripts.addAll(symbolTable.scripts()); |
|
246 |
// } |
|
247 |
// if (this.scripts != null) { |
|
248 |
// theScripts.addAll(this.scripts); |
|
249 |
// } |
|
250 |
// return Collections.unmodifiableCollection(theScripts); |
|
251 |
// } |
|
252 |
// |
|
244 | 253 |
@Override |
245 |
public Collection<Script> scripts() { |
|
246 |
Set<Script> theScripts = new HashSet<>(); |
|
247 |
for (SymbolTable symbolTable : this.symbolTables) { |
|
248 |
theScripts.addAll(symbolTable.scripts()); |
|
249 |
} |
|
250 |
if (this.scripts != null) { |
|
251 |
theScripts.addAll(this.scripts); |
|
252 |
} |
|
253 |
return Collections.unmodifiableCollection(theScripts); |
|
254 |
} |
|
255 |
|
|
256 |
@Override |
|
257 | 254 |
public Iterator<Function> iterator() { |
258 | 255 |
return this.functions().iterator(); |
259 | 256 |
} |
Also available in: Unified diff