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