1 16 package scriptella.expression; 17 18 import scriptella.core.SystemException; 19 import scriptella.spi.ParametersCallback; 20 21 import java.util.Map ; 22 import java.util.WeakHashMap ; 23 24 25 31 public abstract class Expression { 32 private static final Map <String , Expression> EXPRESSIONS_CACHE = new WeakHashMap <String , Expression>(); 33 private String expression; 34 35 protected Expression(String expression) { 36 this.expression = expression; 37 } 38 39 public abstract Object evaluate(final ParametersCallback callback) 40 throws EvaluationException; 41 42 public String getExpression() { 43 return expression; 44 } 45 46 public static Expression compile(final String expression) 47 throws ParseException { 48 Expression ex = EXPRESSIONS_CACHE.get(expression); 49 50 if (ex != null) { 51 return ex; 52 } 53 54 ex = new JexlExpression(expression); 55 EXPRESSIONS_CACHE.put(expression, ex); 56 57 return ex; 58 } 59 60 public static class ParseException extends SystemException { 61 public ParseException() { 62 } 63 64 public ParseException(String message) { 65 super(message); 66 } 67 68 public ParseException(String message, Throwable cause) { 69 super(message, cause); 70 } 71 72 public ParseException(Throwable cause) { 73 super(cause); 74 } 75 } 76 77 public static class EvaluationException extends SystemException { 78 public EvaluationException() { 79 } 80 81 public EvaluationException(String message) { 82 super(message); 83 } 84 85 public EvaluationException(String message, Throwable cause) { 86 super(message, cause); 87 } 88 89 public EvaluationException(Throwable cause) { 90 super(cause); 91 } 92 } 93 } 94 | Popular Tags |