You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by at...@apache.org on 2014/01/22 15:48:29 UTC
svn commit: r1560366 -
/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/env/groovy/GroovyEvaluator.java
Author: ate
Date: Wed Jan 22 14:48:29 2014
New Revision: 1560366
URL: http://svn.apache.org/r1560366
Log:
SCXML-186: Groovy Expression evaluator support
- allow subclasses to override/customize the creation of the GroovyExtendableScriptCache for a GroovyEvaluator
Modified:
commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/env/groovy/GroovyEvaluator.java
Modified: commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/env/groovy/GroovyEvaluator.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/env/groovy/GroovyEvaluator.java?rev=1560366&r1=1560365&r2=1560366&view=diff
==============================================================================
--- commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/env/groovy/GroovyEvaluator.java (original)
+++ commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml2/env/groovy/GroovyEvaluator.java Wed Jan 22 14:48:29 2014
@@ -46,17 +46,17 @@ public class GroovyEvaluator implements
private static final String ERR_CTX_TYPE = "Error evaluating Groovy "
+ "expression, Context must be a org.apache.commons.scxml2.env.groovy.GroovyContext";
- private static final GroovyExtendableScriptCache.ScriptPreProcessor scriptPreProcessor = new GroovyExtendableScriptCache.ScriptPreProcessor () {
+ protected static final GroovyExtendableScriptCache.ScriptPreProcessor scriptPreProcessor = new GroovyExtendableScriptCache.ScriptPreProcessor () {
/**
* Pattern for case-sensitive matching of the Groovy operator aliases, delimited by whitespace
*/
- private final Pattern GROOVY_OPERATOR_ALIASES_PATTERN = Pattern.compile("(?<=\\s)(and|or|not|eq|lt|le|ne|gt|ge)(?=\\s)");
+ public final Pattern GROOVY_OPERATOR_ALIASES_PATTERN = Pattern.compile("(?<=\\s)(and|or|not|eq|lt|le|ne|gt|ge)(?=\\s)");
/**
* Groovy operator aliases mapped to their underlying Groovy operator
*/
- private final Map<String, String> GROOVY_OPERATOR_ALIASES = Collections.unmodifiableMap(new HashMap<String, String>() {{
+ public final Map<String, String> GROOVY_OPERATOR_ALIASES = Collections.unmodifiableMap(new HashMap<String, String>() {{
put("and", "&& "); put("or", "||"); put("not", " ! ");
put("eq", "=="); put("lt", "< "); put("le", "<=");
put("ne", "!="); put("gt", "> "); put("ge", ">=");
@@ -92,9 +92,21 @@ public class GroovyEvaluator implements
public GroovyEvaluator(boolean useInitialScriptAsBaseScript) {
this.useInitialScriptAsBaseScript = useInitialScriptAsBaseScript;
- this.scriptCache = new GroovyExtendableScriptCache();
+ this.scriptCache = newScriptCache();
+ }
+
+ /**
+ * Overridable factory method to create the GroovyExtendableScriptCache for this GroovyEvaluator.
+ * <p>
+ * The default implementation configures the scriptCache to use the {@link #scriptPreProcessor GroovyEvaluator scriptPreProcessor}
+ * and the {@link GroovySCXMLScript} as script base class.
+ * </p>
+ */
+ protected GroovyExtendableScriptCache newScriptCache() {
+ GroovyExtendableScriptCache scriptCache = new GroovyExtendableScriptCache();
scriptCache.setScriptPreProcessor(scriptPreProcessor);
scriptCache.setScriptBaseClass(GroovySCXMLScript.class.getName());
+ return scriptCache;
}
@SuppressWarnings("unchecked")