Revision 44139 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/DefaultExpressionEvaluatorManager.java
DefaultExpressionEvaluatorManager.java | ||
---|---|---|
1 | 1 |
package org.gvsig.expressionevaluator.impl; |
2 | 2 |
|
3 |
import org.gvsig.expressionevaluator.Grammar; |
|
4 |
import org.gvsig.expressionevaluator.GrammarFactory; |
|
3 | 5 |
import java.util.Collection; |
4 | 6 |
import java.util.HashMap; |
5 | 7 |
import java.util.Map; |
6 | 8 |
import org.gvsig.expressionevaluator.Code; |
7 | 9 |
import org.gvsig.expressionevaluator.CodeBuilder; |
8 |
import org.gvsig.expressionevaluator.Compiler; |
|
9 | 10 |
import org.gvsig.expressionevaluator.Expression; |
10 | 11 |
import org.gvsig.expressionevaluator.ExpressionBuilder; |
11 | 12 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorManager; |
... | ... | |
15 | 16 |
import org.gvsig.expressionevaluator.Optimizer; |
16 | 17 |
import org.gvsig.expressionevaluator.SymbolTable; |
17 | 18 |
import org.gvsig.expressionevaluator.SymbolTableFactory; |
18 |
import org.gvsig.expressionevaluator.impl.symboltable.BasicImageSymbolTableFactory; |
|
19 |
import org.gvsig.expressionevaluator.impl.symboltable.OGCSymbolTableFactory; |
|
20 |
import org.gvsig.expressionevaluator.impl.symboltable.SQLSymbolTableFactory; |
|
21 |
import org.gvsig.expressionevaluator.impl.symboltable.UtilsSymbolTableFactory; |
|
19 |
import org.gvsig.expressionevaluator.Compiler; |
|
20 |
import org.gvsig.expressionevaluator.GrammarSet; |
|
22 | 21 |
import org.slf4j.Logger; |
23 | 22 |
import org.slf4j.LoggerFactory; |
24 | 23 |
|
... | ... | |
29 | 28 |
|
30 | 29 |
private Double accuracy; |
31 | 30 |
private final Map<String,SymbolTableFactory>symbolTableFactories; |
31 |
private final Map<String,GrammarFactory> grammarFactories; |
|
32 | 32 |
|
33 | 33 |
public DefaultExpressionEvaluatorManager() { |
34 | 34 |
this.symbolTableFactories = new HashMap<>(); |
35 |
this.registerSymbolTable(new SQLSymbolTableFactory()); |
|
36 |
this.registerSymbolTable(new OGCSymbolTableFactory()); |
|
37 |
this.registerSymbolTable(new UtilsSymbolTableFactory()); |
|
38 |
this.registerSymbolTable(new BasicImageSymbolTableFactory()); |
|
35 |
this.grammarFactories = new HashMap<>(); |
|
39 | 36 |
} |
40 | 37 |
|
41 | 38 |
@Override |
... | ... | |
89 | 86 |
|
90 | 87 |
@Override |
91 | 88 |
public Code compile(String source) { |
92 |
DefaultCompiler compiler = new DefaultCompiler();
|
|
89 |
Compiler compiler = this.createCompiler();
|
|
93 | 90 |
return compiler.compileExpression(source); |
94 | 91 |
} |
95 | 92 |
|
96 | 93 |
@Override |
97 | 94 |
public Code compile(LexicalAnalyzer lex, String source) { |
98 |
DefaultCompiler compiler = new DefaultCompiler();
|
|
95 |
Compiler compiler = this.createCompiler();
|
|
99 | 96 |
compiler.setLexicalAnalyzer(lex); |
100 | 97 |
return compiler.compileExpression(source); |
101 | 98 |
} |
... | ... | |
133 | 130 |
|
134 | 131 |
@Override |
135 | 132 |
public Compiler createCompiler() { |
136 |
return new DefaultCompiler(); |
|
133 |
DefaultCompiler compiler = new DefaultCompiler(); |
|
134 |
this.populateGrammars(compiler); |
|
135 |
return compiler; |
|
137 | 136 |
} |
138 | 137 |
|
139 | 138 |
@Override |
... | ... | |
168 | 167 |
Optimizer x = new DefaultOptimizer(); |
169 | 168 |
return x; |
170 | 169 |
} |
170 |
|
|
171 |
@Override |
|
172 |
public void registerGrammar(GrammarFactory factory) { |
|
173 |
if( factory==null ) { |
|
174 |
throw new IllegalArgumentException("factory can't be null"); |
|
175 |
} |
|
176 |
this.grammarFactories.put(factory.getName(), factory); |
|
177 |
} |
|
178 |
|
|
179 |
@Override |
|
180 |
public Collection<GrammarFactory> getGrammarFactories() { |
|
181 |
return this.grammarFactories.values(); |
|
182 |
} |
|
183 |
|
|
184 |
public void populateGrammars(Compiler compiler) { |
|
185 |
GrammarSet grammarSet = compiler.getGrammars(); |
|
186 |
for (GrammarFactory factory : this.getGrammarFactories() ) { |
|
187 |
if( factory.isAutoload() ) { |
|
188 |
Grammar grammar = factory.createGrammar(); |
|
189 |
grammarSet.add(grammar); |
|
190 |
} |
|
191 |
} |
|
192 |
} |
|
193 |
|
|
194 |
public Grammar createGrammar(String name) { |
|
195 |
DefaultGrammar grammar = new DefaultGrammar(name); |
|
196 |
return grammar; |
|
197 |
} |
|
171 | 198 |
} |
172 | 199 |
|
Also available in: Unified diff