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