Author: oheger Date: Sun Jan 22 16:19:15 2012 New Revision: 1234539 URL: http://svn.apache.org/viewvc?rev=1234539&view=rev Log: Don't use a shared JexlContext, but create a new one on each invocation.
Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/interpol/ExprLookup.java Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/interpol/ExprLookup.java URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/interpol/ExprLookup.java?rev=1234539&r1=1234538&r2=1234539&view=diff ============================================================================== --- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/interpol/ExprLookup.java (original) +++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/interpol/ExprLookup.java Sun Jan 22 16:19:15 2012 @@ -78,12 +78,12 @@ public class ExprLookup extends StrLooku /** Configuration being operated on */ private AbstractConfiguration configuration; - /** The JexlContext */ - private JexlContext context = new MapContext(); - /** The engine. */ private final JexlEngine engine = new JexlEngine(); + /** The variables maintained by this object. */ + private Variables variables; + /** The String to use to start subordinate lookup expressions */ private String prefixMatcher = DEFAULT_PREFIX; @@ -147,10 +147,7 @@ public class ExprLookup extends StrLooku */ public void setVariables(Variables list) { - for (Variable var : list) - { - context.set(var.getName(), var.getValue()); - } + variables = new Variables(list); } /** @@ -188,7 +185,7 @@ public class ExprLookup extends StrLooku try { Expression exp = engine.createExpression(result); - result = (String) exp.evaluate(context); + result = (String) exp.evaluate(createContext()); } catch (Exception e) { @@ -199,6 +196,33 @@ public class ExprLookup extends StrLooku } /** + * Creates a new {@code JexlContext} and initializes it with the variables + * managed by this Lookup object. + * + * @return the newly created context + */ + private JexlContext createContext() + { + JexlContext ctx = new MapContext(); + initializeContext(ctx); + return ctx; + } + + /** + * Initializes the specified context with the variables managed by this + * Lookup object. + * + * @param ctx the context to be initialized + */ + private void initializeContext(JexlContext ctx) + { + for (Variable var : variables) + { + ctx.set(var.getName(), var.getValue()); + } + } + + /** * List wrapper used to allow the Variables list to be created as beans in * DefaultConfigurationBuilder. */ @@ -209,11 +233,24 @@ public class ExprLookup extends StrLooku */ private static final long serialVersionUID = 20111205L; - /* - public void setVariable(Variable var) + /** + * Creates a new empty instance of {@code Variables}. + */ + public Variables() + { + super(); + } + + /** + * Creates a new instance of {@code Variables} and copies the content of + * the given object. + * + * @param vars the {@code Variables} object to be copied + */ + public Variables(Variables vars) { - add(var); - } */ + super(vars); + } public Variable getVariable() {