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