Revision 45739 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 | ||
---|---|---|
12 | 12 |
import org.apache.commons.lang3.StringUtils; |
13 | 13 |
import org.gvsig.expressionevaluator.Function; |
14 | 14 |
import org.gvsig.expressionevaluator.SymbolTable; |
15 |
import org.gvsig.tools.util.GetItemByKey; |
|
15 | 16 |
|
16 | 17 |
/** |
17 | 18 |
* |
18 | 19 |
* @author jjdelcerro |
19 | 20 |
*/ |
20 |
public abstract class AbstractSymbolTable implements SymbolTable { |
|
21 |
public abstract class AbstractSymbolTable implements SymbolTable, GetItemByKey<String, Object> {
|
|
21 | 22 |
|
22 | 23 |
private final String name; |
23 | 24 |
|
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 |
// } |
|
44 | 25 |
|
45 | 26 |
private Map<String, Object> vars; |
46 | 27 |
|
47 | 28 |
protected final List<SymbolTable> symbolTables; |
48 | 29 |
protected Map<String, Function> functions; |
49 | 30 |
protected Map<String, Function> functionAlias; |
50 |
// protected List<Script> scripts; |
|
51 | 31 |
|
52 | 32 |
public AbstractSymbolTable() { |
53 | 33 |
this(null); |
54 | 34 |
} |
55 | 35 |
|
56 | 36 |
public AbstractSymbolTable(String name) { |
57 |
this.name = name; |
|
37 |
if( name == null ) { |
|
38 |
this.name = "Anonymous"; |
|
39 |
} else { |
|
40 |
this.name = name; |
|
41 |
} |
|
58 | 42 |
this.symbolTables = new ArrayList<>(); |
59 | 43 |
this.vars = null; |
60 | 44 |
this.functions = null; |
... | ... | |
162 | 146 |
if (this.getVars().containsKey(name.toUpperCase())) { |
163 | 147 |
return true; |
164 | 148 |
} |
149 |
if( StringUtils.equalsIgnoreCase(name, "$symboltable") ) { |
|
150 |
return true; |
|
151 |
} |
|
165 | 152 |
for (SymbolTable other : this.symbolTables) { |
166 | 153 |
if (other.exists(name)) { |
167 | 154 |
return true; |
... | ... | |
179 | 166 |
if (this.getVars().containsKey(name)) { |
180 | 167 |
return this.getVars().get(name); |
181 | 168 |
} |
169 |
if( name.equals("$SYMBOLTABLE") ) { |
|
170 |
return this; |
|
171 |
} |
|
182 | 172 |
for (SymbolTable other : this.symbolTables) { |
183 | 173 |
if (other.exists(name)) { |
184 | 174 |
return other.value(name); |
185 | 175 |
} |
176 |
if( StringUtils.equalsIgnoreCase(name, other.getName())) { |
|
177 |
return other; |
|
178 |
} |
|
186 | 179 |
} |
187 | 180 |
return null; |
188 | 181 |
} |
189 | 182 |
|
190 | 183 |
@Override |
184 |
public Object get(String name) { |
|
185 |
return this.value(name); |
|
186 |
} |
|
187 |
|
|
188 |
@Override |
|
191 | 189 |
public Function function(String name) { |
192 | 190 |
if (StringUtils.isEmpty(name)) { |
193 | 191 |
return null; |
... | ... | |
271 | 269 |
return true; |
272 | 270 |
} |
273 | 271 |
|
272 |
public List<SymbolTable> getSymbolTables() { |
|
273 |
return Collections.unmodifiableList(symbolTables); |
|
274 |
} |
|
275 |
|
|
276 |
@Override |
|
277 |
public String toString() { |
|
278 |
return this.name; |
|
279 |
} |
|
280 |
|
|
274 | 281 |
} |
Also available in: Unified diff