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 / DefaultSymbolTable.java @ 43987
History | View | Annotate | Download (2.74 KB)
1 |
package org.gvsig.expressionevaluator.impl; |
---|---|
2 |
|
3 |
import org.gvsig.expressionevaluator.spi.AbstractSymbolTable; |
4 |
import java.util.ArrayList; |
5 |
import java.util.Collection; |
6 |
import java.util.HashMap; |
7 |
import org.apache.commons.lang3.StringUtils; |
8 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator; |
9 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorManager; |
10 |
import org.gvsig.expressionevaluator.Function; |
11 |
import org.gvsig.expressionevaluator.MutableSymbolTable; |
12 |
import org.gvsig.tools.script.Script; |
13 |
|
14 |
/**
|
15 |
*
|
16 |
* @author jjdelcerro
|
17 |
*/
|
18 |
public class DefaultSymbolTable |
19 |
extends AbstractSymbolTable
|
20 |
implements MutableSymbolTable
|
21 |
{ |
22 |
|
23 |
|
24 |
public DefaultSymbolTable() {
|
25 |
super();
|
26 |
this.vars = new HashMap<>(); |
27 |
this.functions = new HashMap<>(); |
28 |
this.scripts = new ArrayList<>(); |
29 |
this.init();
|
30 |
} |
31 |
|
32 |
private void init() { |
33 |
DefaultExpressionEvaluatorManager manager = (DefaultExpressionEvaluatorManager) ExpressionEvaluatorLocator.getManager(); |
34 |
manager.populateSymbolTable(this);
|
35 |
} |
36 |
|
37 |
@Override
|
38 |
public void setVar(String name, Object value) { |
39 |
if( StringUtils.isEmpty(name) ) {
|
40 |
throw new IllegalArgumentException("name can't be null"); |
41 |
} |
42 |
this.vars.put(name.toUpperCase(), value);
|
43 |
} |
44 |
|
45 |
@Override
|
46 |
public void addFunction(Function function) { |
47 |
super.addFunction(function);
|
48 |
} |
49 |
|
50 |
@Override
|
51 |
public void addFunctions(Collection<Function> functions) { |
52 |
for (Function function : functions) {
|
53 |
this.addFunction(function);
|
54 |
} |
55 |
} |
56 |
|
57 |
@Override
|
58 |
public void removeVar(String name) { |
59 |
if( StringUtils.isEmpty(name) ) {
|
60 |
throw new IllegalArgumentException("name can't be null"); |
61 |
} |
62 |
this.vars.remove(name.toUpperCase());
|
63 |
} |
64 |
|
65 |
@Override
|
66 |
public void removeFunction(String name) { |
67 |
if( StringUtils.isEmpty(name) ) {
|
68 |
throw new IllegalArgumentException("name can't be null"); |
69 |
} |
70 |
this.functions.remove(name.toUpperCase());
|
71 |
} |
72 |
|
73 |
@Override
|
74 |
public void addScript(Script script) { |
75 |
if( script == null ) { |
76 |
throw new IllegalArgumentException("script can't be null"); |
77 |
} |
78 |
if (this.scripts.contains(script)) { |
79 |
return;
|
80 |
} |
81 |
this.scripts.add(script);
|
82 |
} |
83 |
|
84 |
@Override
|
85 |
public void removeScript(Script script) { |
86 |
if( script == null ) { |
87 |
throw new IllegalArgumentException("script can't be null"); |
88 |
} |
89 |
this.scripts.remove(script);
|
90 |
} |
91 |
|
92 |
@Override
|
93 |
public MutableSymbolTable clone() throws CloneNotSupportedException { |
94 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
95 |
} |
96 |
} |