Revision 44644 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 | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import java.io.StringWriter; |
4 | 4 |
import java.net.URI; |
5 |
import java.util.ArrayList; |
|
5 | 6 |
import org.gvsig.expressionevaluator.Grammar; |
6 | 7 |
import org.gvsig.expressionevaluator.GrammarFactory; |
7 | 8 |
import java.util.Collection; |
8 | 9 |
import java.util.HashMap; |
10 |
import java.util.List; |
|
9 | 11 |
import java.util.Map; |
10 | 12 |
import java.util.Objects; |
11 | 13 |
import java.util.regex.Matcher; |
... | ... | |
27 | 29 |
import org.gvsig.expressionevaluator.SymbolTableFactory; |
28 | 30 |
import org.gvsig.expressionevaluator.Compiler; |
29 | 31 |
import org.gvsig.expressionevaluator.GrammarSet; |
32 |
import org.gvsig.expressionevaluator.ReprMethod; |
|
33 |
import org.gvsig.expressionevaluator.impl.repr.ReprNull; |
|
34 |
import org.gvsig.expressionevaluator.impl.repr.ReprObject; |
|
30 | 35 |
import org.gvsig.tools.bookmarksandhistory.Bookmarks; |
31 | 36 |
import org.gvsig.tools.bookmarksandhistory.History; |
32 | 37 |
import org.gvsig.tools.bookmarksandhistory.impl.BaseBookmarks; |
... | ... | |
93 | 98 |
@Override |
94 | 99 |
public Object evaluate(String source) { |
95 | 100 |
DefaultInterpreter interpreter = new DefaultInterpreter(); |
96 |
DefaultCompiler compiler = new DefaultCompiler(); |
|
101 |
DefaultCompiler compiler = new DefaultCompiler(this);
|
|
97 | 102 |
Code code = compiler.compileExpression(source); |
98 | 103 |
return interpreter.run(code); |
99 | 104 |
} |
... | ... | |
101 | 106 |
@Override |
102 | 107 |
public Object evaluate(SymbolTable symbolTable, String source) { |
103 | 108 |
DefaultInterpreter interpreter = new DefaultInterpreter(); |
104 |
DefaultCompiler compiler = new DefaultCompiler(); |
|
109 |
DefaultCompiler compiler = new DefaultCompiler(this);
|
|
105 | 110 |
Code code = compiler.compileExpression(source); |
106 | 111 |
if( symbolTable!=null ) { |
107 | 112 |
interpreter.setSymbolTable(symbolTable); |
... | ... | |
146 | 151 |
} |
147 | 152 |
StringWriter writer = new StringWriter(); |
148 | 153 |
interpreter.setWriter(writer); |
149 |
DefaultCompiler compiler = new DefaultCompiler(); |
|
154 |
DefaultCompiler compiler = new DefaultCompiler(this);
|
|
150 | 155 |
for (int i = 0; i < sources.length; i++) { |
151 | 156 |
String theSource = sources[i]; |
152 | 157 |
if( StringUtils.startsWith(theSource, "=") ) { |
... | ... | |
216 | 221 |
|
217 | 222 |
@Override |
218 | 223 |
public CodeBuilder createCodeBuilder() { |
219 |
return new DefaultCodeBuilder(); |
|
224 |
return new DefaultCodeBuilder(this);
|
|
220 | 225 |
} |
221 | 226 |
|
222 | 227 |
@Override |
223 | 228 |
public Compiler createCompiler() { |
224 |
DefaultCompiler compiler = new DefaultCompiler(); |
|
229 |
DefaultCompiler compiler = new DefaultCompiler(this);
|
|
225 | 230 |
this.populateGrammars(compiler); |
226 | 231 |
return compiler; |
227 | 232 |
} |
... | ... | |
245 | 250 |
|
246 | 251 |
@Override |
247 | 252 |
public Expression createExpression() { |
248 |
DefaultExpression e = new DefaultExpression(); |
|
253 |
DefaultExpression e = new DefaultExpression(this);
|
|
249 | 254 |
return e; |
250 | 255 |
} |
251 | 256 |
|
252 | 257 |
@Override |
253 | 258 |
public ExpressionBuilder createExpressionBuilder() { |
254 |
ExpressionBuilder x = new DefaultExpressionBuilder(); |
|
259 |
ExpressionBuilder x = new DefaultExpressionBuilder(this);
|
|
255 | 260 |
return x; |
256 | 261 |
} |
257 | 262 |
|
258 | 263 |
@Override |
259 | 264 |
public Optimizer createOptimizer() { |
260 |
Optimizer x = new DefaultOptimizer(); |
|
265 |
Optimizer x = new DefaultOptimizer(this);
|
|
261 | 266 |
return x; |
262 | 267 |
} |
263 | 268 |
|
... | ... | |
421 | 426 |
public void setScriptsResourcesStorage(ResourcesStorage scriptsResourcesStorage) { |
422 | 427 |
this.scriptsResourcesStorage = scriptsResourcesStorage; |
423 | 428 |
} |
429 |
|
|
424 | 430 |
|
431 |
private final List<ReprMethod> reprMethods = new ArrayList<>(); |
|
432 |
private final Map<Class,ReprMethod> reprMethodsCache = new HashMap<>(); |
|
433 |
private final ReprMethod reprNull = new ReprNull(); |
|
434 |
private final ReprMethod reprObject = new ReprObject(); |
|
435 |
|
|
436 |
@Override |
|
437 |
public void addReprMethod(ReprMethod method) { |
|
438 |
this.reprMethods.add(method); |
|
439 |
this.reprMethodsCache.clear(); |
|
440 |
} |
|
441 |
|
|
442 |
@Override |
|
443 |
public ReprMethod getReprMethod(Object value) { |
|
444 |
if( value == null ) { |
|
445 |
return this.reprNull; |
|
446 |
} |
|
447 |
ReprMethod method = this.reprMethodsCache.get(value.getClass()); |
|
448 |
if( method!=null ) { |
|
449 |
return method; |
|
450 |
} |
|
451 |
for (ReprMethod theMethod : reprMethods) { |
|
452 |
if( theMethod.isApplicable(value) ) { |
|
453 |
this.reprMethodsCache.put(value.getClass(), theMethod); |
|
454 |
return theMethod; |
|
455 |
} |
|
456 |
} |
|
457 |
return this.reprObject; |
|
458 |
} |
|
425 | 459 |
} |
426 | 460 |
|
Also available in: Unified diff