Revision 43939 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/AbstractSymbolTable.java
AbstractSymbolTable.java | ||
---|---|---|
1 | 1 |
|
2 | 2 |
package org.gvsig.expressionevaluator.impl; |
3 | 3 |
|
4 |
import java.util.ArrayList; |
|
5 |
import java.util.Collection; |
|
4 | 6 |
import java.util.HashMap; |
5 | 7 |
import java.util.Iterator; |
8 |
import java.util.List; |
|
6 | 9 |
import java.util.Map; |
10 |
import org.apache.commons.lang3.StringUtils; |
|
11 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator; |
|
12 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorManager; |
|
7 | 13 |
import org.gvsig.expressionevaluator.Function; |
8 | 14 |
import org.gvsig.expressionevaluator.SymbolTable; |
9 | 15 |
import org.gvsig.expressionevaluator.impl.function.ScriptFunction; |
... | ... | |
19 | 25 |
|
20 | 26 |
protected Map<String, Function> functions; |
21 | 27 |
protected SymbolTable delegatedSymbolTable; |
22 |
protected Script script = null; |
|
23 | 28 |
|
24 |
|
|
25 | 29 |
public AbstractSymbolTable() { |
26 | 30 |
this.functions = new HashMap<>(); |
27 | 31 |
} |
28 | 32 |
|
33 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
|
29 | 34 |
public AbstractSymbolTable(SymbolTable delegatedSymbolTable) { |
30 | 35 |
this(); |
31 | 36 |
this.delegatedSymbolTable = delegatedSymbolTable; |
37 |
ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
|
38 |
this.addFunctions(manager.getAllOperators().values()); |
|
32 | 39 |
} |
33 | 40 |
|
34 | 41 |
@Override |
... | ... | |
40 | 47 |
other.functions = new HashMap<>(functions); |
41 | 48 |
return other; |
42 | 49 |
} |
43 |
|
|
44 |
@Override |
|
45 |
public Script getScript() { |
|
46 |
return this.script; |
|
47 |
} |
|
48 |
|
|
49 |
@Override |
|
50 |
public void setScript(String name) { |
|
51 |
ScriptManager scriptManager = ToolsLocator.getScriptManager(); |
|
52 |
this.script = scriptManager.locateScript(name); |
|
53 |
} |
|
54 |
|
|
55 |
@Override |
|
56 |
public void setScript(Script script) { |
|
57 |
this.script = script; |
|
58 |
} |
|
59 |
|
|
50 |
|
|
60 | 51 |
public void addFunction(Function function) { |
61 | 52 |
this.functions.put(function.name(), function); |
62 | 53 |
} |
63 | 54 |
|
64 | 55 |
@Override |
65 | 56 |
public Function function(String name) { |
66 |
Function fn = this.functions.get(name); |
|
57 |
if( StringUtils.isEmpty(name) ) { |
|
58 |
return null; |
|
59 |
} |
|
60 |
Function fn = this.functions.get(name.toUpperCase()); |
|
67 | 61 |
if( fn == null ) { |
68 | 62 |
if( this.delegatedSymbolTable != null ) { |
69 |
fn = this.delegatedSymbolTable.function(name); |
|
63 |
fn = this.delegatedSymbolTable.function(name.toUpperCase());
|
|
70 | 64 |
} |
71 |
if( fn == null && this.script != null ) { |
|
72 |
fn = new ScriptFunction(this.script, name); |
|
73 |
} |
|
74 | 65 |
} |
75 | 66 |
return fn; |
76 | 67 |
} |
... | ... | |
96 | 87 |
public void removeFunction(String name) { |
97 | 88 |
this.functions.remove(name); |
98 | 89 |
} |
90 |
|
|
91 |
public void addFunctions(Collection<Function> functions) { |
|
92 |
for (Function function : functions) { |
|
93 |
this.addFunction(function); |
|
94 |
} |
|
95 |
} |
|
99 | 96 |
} |
Also available in: Unified diff