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