dizpers

Extended JexlEngine class

Nov 30th, 2011
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. package ru.dizpers.core;
  2.  
  3. import java.util.Map;
  4.  
  5. import org.apache.commons.jexl2.JexlArithmetic;
  6. import org.apache.commons.jexl2.JexlContext;
  7. import org.apache.commons.jexl2.JexlException;
  8. import org.apache.commons.jexl2.introspection.Uberspect;
  9. import org.apache.commons.jexl2.parser.JexlNode;
  10. import org.apache.commons.logging.Log;
  11.  
  12. import ru.dizpers.core.Interpreter;
  13.  
  14. public class JexlEngine extends org.apache.commons.jexl2.JexlEngine{
  15. public JexlEngine(){
  16. super();
  17. }
  18.  
  19. public JexlEngine(Uberspect anUberspect, JexlArithmetic anArithmetic, Map<String, Object> theFunctions, Log log) {
  20. super(anUberspect, anArithmetic, theFunctions, log);
  21. }
  22.  
  23. @Override
  24. public Object getProperty(JexlContext context, Object bean, String expr) {
  25. if (context == null) {
  26. context = EMPTY_CONTEXT;
  27. }
  28. // synthetize expr using register
  29. expr = "#0" + (expr.charAt(0) == '[' ? "" : ".") + expr + ";";
  30. try {
  31. parser.ALLOW_REGISTERS = true;
  32. JexlNode tree = parse(expr, null);
  33. JexlNode node = tree.jjtGetChild(0);
  34. Interpreter interpreter = createInterpreter(context);
  35. // set register
  36. interpreter.setRegisters(bean);
  37. return node.jjtAccept(interpreter, null);
  38. } catch (JexlException xjexl) {
  39. if (silent) {
  40. logger.warn(xjexl.getMessage(), xjexl.getCause());
  41. return null;
  42. }
  43. throw xjexl;
  44. } finally {
  45. parser.ALLOW_REGISTERS = false;
  46. }
  47. }
  48.  
  49. @Override
  50. protected Interpreter createInterpreter(JexlContext context) {
  51. if (context == null) {
  52. context = EMPTY_CONTEXT;
  53. }
  54. return new Interpreter(this, context);
  55. }
  56. }
  57.  
Advertisement
Add Comment
Please, Sign In to add comment