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 @ 43983
History | View | Annotate | Download (2.93 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 | protected final void init() { |
||
33 | 43939 | jjdelcerro | ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
34 | 43983 | jjdelcerro | this.addSymbolTable(manager.getSymbolTable("SQL")); |
35 | this.addSymbolTable(manager.getSymbolTable("OGC")); |
||
36 | 43512 | jjdelcerro | } |
37 | 43939 | jjdelcerro | |
38 | 43809 | jjdelcerro | @Override
|
39 | 43983 | jjdelcerro | public void setVar(String name, Object value) { |
40 | if( StringUtils.isEmpty(name) ) {
|
||
41 | throw new IllegalArgumentException("name can't be null"); |
||
42 | } |
||
43 | this.vars.put(name.toUpperCase(), value);
|
||
44 | 43809 | jjdelcerro | } |
45 | 43939 | jjdelcerro | |
46 | @Override
|
||
47 | 43983 | jjdelcerro | public void addFunction(Function function) { |
48 | if( function==null ) { |
||
49 | throw new IllegalArgumentException("function can't be null"); |
||
50 | 43939 | jjdelcerro | } |
51 | 43983 | jjdelcerro | this.functions.put(function.name().toUpperCase(), function);
|
52 | 43939 | jjdelcerro | } |
53 | 43983 | jjdelcerro | |
54 | 43512 | jjdelcerro | @Override
|
55 | 43983 | jjdelcerro | public void addFunctions(Collection<Function> functions) { |
56 | for (Function function : functions) {
|
||
57 | this.addFunction(function);
|
||
58 | } |
||
59 | 43512 | jjdelcerro | } |
60 | |||
61 | @Override
|
||
62 | 43983 | jjdelcerro | public void removeVar(String name) { |
63 | if( StringUtils.isEmpty(name) ) {
|
||
64 | throw new IllegalArgumentException("name can't be null"); |
||
65 | 43512 | jjdelcerro | } |
66 | 43983 | jjdelcerro | this.vars.remove(name.toUpperCase());
|
67 | 43512 | jjdelcerro | } |
68 | |||
69 | @Override
|
||
70 | 43983 | jjdelcerro | public void removeFunction(String name) { |
71 | if( StringUtils.isEmpty(name) ) {
|
||
72 | throw new IllegalArgumentException("name can't be null"); |
||
73 | 43512 | jjdelcerro | } |
74 | 43983 | jjdelcerro | this.functions.remove(name.toUpperCase());
|
75 | 43512 | jjdelcerro | } |
76 | |||
77 | @Override
|
||
78 | 43983 | jjdelcerro | public void addScript(Script script) { |
79 | if( script == null ) { |
||
80 | throw new IllegalArgumentException("script can't be null"); |
||
81 | } |
||
82 | if (this.scripts.contains(script)) { |
||
83 | return;
|
||
84 | } |
||
85 | this.scripts.add(script);
|
||
86 | 43512 | jjdelcerro | } |
87 | |||
88 | @Override
|
||
89 | 43983 | jjdelcerro | public void removeScript(Script script) { |
90 | if( script == null ) { |
||
91 | throw new IllegalArgumentException("script can't be null"); |
||
92 | } |
||
93 | this.scripts.remove(script);
|
||
94 | 43512 | jjdelcerro | } |
95 | 43939 | jjdelcerro | |
96 | @Override
|
||
97 | 43983 | jjdelcerro | public MutableSymbolTable clone() throws CloneNotSupportedException { |
98 | throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
||
99 | 43939 | jjdelcerro | } |
100 | |||
101 | 43512 | jjdelcerro | } |