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