Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/MapLiteralTest.java URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/MapLiteralTest.java?rev=884650&r1=884649&r2=884650&view=diff ============================================================================== --- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/MapLiteralTest.java (original) +++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/MapLiteralTest.java Thu Nov 26 17:17:42 2009 @@ -30,7 +30,7 @@ public void testLiteralWithStrings() throws Exception { Expression e = JEXL.createExpression( "{ 'foo' : 'bar' }" ); - JexlContext jc = JexlHelper.createContext(); + JexlContext jc = new JexlContext.Mapped(); Object o = e.evaluate( jc ); assertEquals( Collections.singletonMap( "foo", "bar" ), o ); @@ -38,7 +38,7 @@ public void testLiteralWithMultipleEntries() throws Exception { Expression e = JEXL.createExpression( "{ 'foo' : 'bar', 'eat' : 'food' }" ); - JexlContext jc = JexlHelper.createContext(); + JexlContext jc = new JexlContext.Mapped(); Map<String, String> expected = new HashMap<String, String>(); expected.put( "foo", "bar" ); @@ -50,7 +50,7 @@ public void testLiteralWithNumbers() throws Exception { Expression e = JEXL.createExpression( "{ 5 : 10 }" ); - JexlContext jc = JexlHelper.createContext(); + JexlContext jc = new JexlContext.Mapped(); Object o = e.evaluate( jc ); assertEquals( Collections.singletonMap( new Integer( 5 ), new Integer( 10 ) ), o ); @@ -66,7 +66,7 @@ o = e.evaluate(jc); assertEquals(new Integer(40), o); - jc.getVars().put("i", Integer.valueOf(5)); + jc.setJexlVariable("i", Integer.valueOf(5)); e = JEXL.createExpression("m[i]"); o = e.evaluate(jc); assertEquals("fifty", o); @@ -85,12 +85,12 @@ o = e.evaluate(jc); assertEquals("SEVEN", o); - jc.getVars().put("k", Integer.valueOf(7)); + jc.setJexlVariable("k", Integer.valueOf(7)); e = JEXL.createExpression("m[k]"); o = e.evaluate(jc); assertEquals("SEVEN", o); - jc.getVars().put("k", "7"); + jc.setJexlVariable("k", "7"); e = JEXL.createExpression("m[k]"); o = e.evaluate(jc); assertEquals("seven", o); @@ -98,7 +98,7 @@ public void testSizeOfSimpleMapLiteral() throws Exception { Expression e = JEXL.createExpression( "size({ 'foo' : 'bar' })" ); - JexlContext jc = JexlHelper.createContext(); + JexlContext jc = new JexlContext.Mapped(); Object o = e.evaluate( jc ); assertEquals( new Integer( 1 ), o ); @@ -106,7 +106,7 @@ public void testCallingMethodsOnNewMapLiteral() throws Exception { Expression e = JEXL.createExpression( "size({ 'foo' : 'bar' }.values())" ); - JexlContext jc = JexlHelper.createContext(); + JexlContext jc = new JexlContext.Mapped(); Object o = e.evaluate( jc ); assertEquals( new Integer( 1 ), o ); @@ -114,7 +114,7 @@ public void testNotEmptySimpleMapLiteral() throws Exception { Expression e = JEXL.createExpression( "empty({ 'foo' : 'bar' })" ); - JexlContext jc = JexlHelper.createContext(); + JexlContext jc = new JexlContext.Mapped(); Object o = e.evaluate( jc ); assertFalse( ( (Boolean) o ).booleanValue() ); @@ -122,11 +122,11 @@ public void testMapMapLiteral() throws Exception { Expression e = JEXL.createExpression( "{'foo' : { 'inner' : 'bar' }}" ); - JexlContext jc = JexlHelper.createContext(); + JexlContext jc = new JexlContext.Mapped(); Object o = e.evaluate( jc ); assertNotNull(o); - jc.getVars().put("outer", o); + jc.setJexlVariable("outer", o); e = JEXL.createExpression("outer.foo.inner"); o = e.evaluate( jc ); assertEquals( "bar", o ); @@ -134,11 +134,11 @@ public void testMapArrayLiteral() throws Exception { Expression e = JEXL.createExpression( "{'foo' : [ 'inner' , 'bar' ]}" ); - JexlContext jc = JexlHelper.createContext(); + JexlContext jc = new JexlContext.Mapped(); Object o = e.evaluate( jc ); assertNotNull(o); - jc.getVars().put("outer", o); + jc.setJexlVariable("outer", o); e = JEXL.createExpression("outer.foo.1"); o = e.evaluate( jc ); assertEquals( "bar", o );
Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/MethodTest.java URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/MethodTest.java?rev=884650&r1=884649&r2=884650&view=diff ============================================================================== --- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/MethodTest.java (original) +++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/MethodTest.java Thu Nov 26 17:17:42 2009 @@ -132,7 +132,7 @@ funcs.put("math", new MyMath()); JEXL.setFunctions(funcs); - JexlContext jc = JexlHelper.createContext(); + JexlContext jc = new JexlContext.Mapped(); Expression e = JEXL.createExpression("ten()"); Object o = e.evaluate(jc); @@ -146,7 +146,7 @@ o = e.evaluate(jc); assertEquals("Result is not 20", new Integer(20), o); - jc.getVars().put("pi", Math.PI); + jc.setJexlVariable("pi", Math.PI); e = JEXL.createExpression("math:cos(pi)"); o = e.evaluate(jc); assertEquals(Double.valueOf(-1),o); @@ -159,27 +159,27 @@ JEXL.setFunctions(funcs); Expression e = JEXL.createExpression("func:ten()"); - JexlContext jc = JexlHelper.createContext(); + JexlContext jc = new JexlContext.Mapped(); Object o = e.evaluate(jc); assertEquals("Result is not 10", new Integer(10), o); e = JEXL.createExpression("func:plus10(10)"); - jc = JexlHelper.createContext(); + jc = new JexlContext.Mapped(); o = e.evaluate(jc); assertEquals("Result is not 20", new Integer(20), o); e = JEXL.createExpression("func:plus10(func:ten())"); - jc = JexlHelper.createContext(); + jc = new JexlContext.Mapped(); o = e.evaluate(jc); assertEquals("Result is not 20", new Integer(20), o); e = JEXL.createExpression("FUNC:PLUS20(10)"); - jc = JexlHelper.createContext(); + jc = new JexlContext.Mapped(); o = e.evaluate(jc); assertEquals("Result is not 30", new Integer(30), o); e = JEXL.createExpression("FUNC:PLUS20(FUNC:TWENTY())"); - jc = JexlHelper.createContext(); + jc = new JexlContext.Mapped(); o = e.evaluate(jc); assertEquals("Result is not 40", new Integer(40), o); } Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/ScriptTest.java URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/ScriptTest.java?rev=884650&r1=884649&r2=884650&view=diff ============================================================================== --- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/ScriptTest.java (original) +++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/ScriptTest.java Thu Nov 26 17:17:42 2009 @@ -60,8 +60,8 @@ private void simpleScript(boolean jexl) throws Exception { String code = "while (x < 10) x = x + 1;"; Script s = jexl? JEXL.createScript(code) : ScriptFactory.createScript(code); - JexlContext jc = JexlHelper.createContext(); - jc.getVars().put("x", new Integer(1)); + JexlContext jc = new JexlContext.Mapped(); + jc.setJexlVariable("x", new Integer(1)); Object o = s.execute(jc); assertEquals("Result is wrong", new Integer(10), o); @@ -77,8 +77,8 @@ private void scriptFromFile(boolean jexl) throws Exception { File testScript = new File(TEST1); Script s = jexl? JEXL.createScript(testScript) : ScriptFactory.createScript(testScript); - JexlContext jc = JexlHelper.createContext(); - jc.getVars().put("out", System.out); + JexlContext jc = new JexlContext.Mapped(); + jc.setJexlVariable("out", System.out); Object result = s.execute(jc); assertNotNull("No result", result); assertEquals("Wrong result", new Integer(7), result); @@ -93,8 +93,8 @@ private void scriptFromURL(boolean jexl) throws Exception { URL testUrl = new File("src/test/scripts/test1.jexl").toURI().toURL(); Script s = jexl? JEXL.createScript(testUrl) : ScriptFactory.createScript(testUrl); - JexlContext jc = JexlHelper.createContext(); - jc.getVars().put("out", System.out); + JexlContext jc = new JexlContext.Mapped(); + jc.setJexlVariable("out", System.out); Object result = s.execute(jc); assertNotNull("No result", result); assertEquals("Wrong result", new Integer(7), result); @@ -112,8 +112,8 @@ Script s = jexl? JEXL.createScript(jexlCode) : ScriptFactory.createScript(jexlCode); Tester resultatJexl = new Tester(); - JexlContext jc = JexlHelper.createContext(); - jc.getVars().put("resultat", resultatJexl); + JexlContext jc = new JexlContext.Mapped(); + jc.setJexlVariable("resultat", resultatJexl); resultatJexl.setCode(""); e.evaluate(jc); Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/UnifiedJEXLTest.java URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/UnifiedJEXLTest.java?rev=884650&r1=884649&r2=884650&view=diff ============================================================================== --- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/UnifiedJEXLTest.java (original) +++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/UnifiedJEXLTest.java Thu Nov 26 17:17:42 2009 @@ -15,6 +15,7 @@ * limitations under the License. */ package org.apache.commons.jexl2; +import java.util.HashMap; import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -37,8 +38,8 @@ public void setUp() throws Exception { // ensure jul logging is only error java.util.logging.Logger.getLogger(JexlEngine.class.getName()).setLevel(java.util.logging.Level.SEVERE); - context = JexlHelper.createContext(); - vars = context.getVars(); + vars = new HashMap<String,Object>(); + context = new JexlContext.Mapped(vars); } @Override Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/WhileTest.java URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/WhileTest.java?rev=884650&r1=884649&r2=884650&view=diff ============================================================================== --- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/WhileTest.java (original) +++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/WhileTest.java Thu Nov 26 17:17:42 2009 @@ -30,7 +30,7 @@ public void testSimpleWhileFalse() throws Exception { Expression e = JEXL.createExpression("while (false) ;"); - JexlContext jc = JexlHelper.createContext(); + JexlContext jc = new JexlContext.Mapped(); Object o = e.evaluate(jc); assertNull("Result is not null", o); @@ -38,8 +38,8 @@ public void testWhileExecutesExpressionWhenLooping() throws Exception { Expression e = JEXL.createExpression("while (x < 10) x = x + 1;"); - JexlContext jc = JexlHelper.createContext(); - jc.getVars().put("x", new Integer(1)); + JexlContext jc = new JexlContext.Mapped(); + jc.setJexlVariable("x", new Integer(1)); Object o = e.evaluate(jc); assertEquals("Result is wrong", new Integer(10), o); @@ -47,13 +47,13 @@ public void testWhileWithBlock() throws Exception { Expression e = JEXL.createExpression("while (x < 10) { x = x + 1; y = y * 2; }"); - JexlContext jc = JexlHelper.createContext(); - jc.getVars().put("x", new Integer(1)); - jc.getVars().put("y", new Integer(1)); + JexlContext jc = new JexlContext.Mapped(); + jc.setJexlVariable("x", new Integer(1)); + jc.setJexlVariable("y", new Integer(1)); Object o = e.evaluate(jc); assertEquals("Result is wrong", new Integer(512), o); - assertEquals("x is wrong", new Integer(10), jc.getVars().get("x")); - assertEquals("y is wrong", new Integer(512), jc.getVars().get("y")); + assertEquals("x is wrong", new Integer(10), jc.getJexlVariable("x")); + assertEquals("y is wrong", new Integer(512), jc.getJexlVariable("y")); } } Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/examples/ArrayTest.java URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/examples/ArrayTest.java?rev=884650&r1=884649&r2=884650&view=diff ============================================================================== --- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/examples/ArrayTest.java (original) +++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/examples/ArrayTest.java Thu Nov 26 17:17:42 2009 @@ -42,13 +42,13 @@ /* * Second make a jexlContext and put stuff in it */ - JexlContext jc = JexlHelper.createContext(); + JexlContext jc = new JexlContext.Mapped(); List<Object> l = new ArrayList<Object>(); l.add("Hello from location 0"); Integer two = new Integer(2); l.add(two); - jc.getVars().put("array", l); + jc.setJexlVariable("array", l); Expression e = jexl.createExpression("array[1]"); Object o = e.evaluate(jc); Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/examples/MethodPropertyTest.java URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/examples/MethodPropertyTest.java?rev=884650&r1=884649&r2=884650&view=diff ============================================================================== --- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/examples/MethodPropertyTest.java (original) +++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/examples/MethodPropertyTest.java Thu Nov 26 17:17:42 2009 @@ -40,7 +40,7 @@ /* * Second make a jexlContext and put stuff in it */ - JexlContext jc = JexlHelper.createContext(); + JexlContext jc = new JexlContext.Mapped(); /** * The Java equivalents of foo and number for comparison and checking @@ -48,8 +48,8 @@ Foo foo = new Foo(); Integer number = new Integer(10); - jc.getVars().put("foo", foo); - jc.getVars().put("number", number); + jc.setJexlVariable("foo", foo); + jc.setJexlVariable("number", number); /* * access a method w/o args Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/junit/Asserter.java URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/junit/Asserter.java?rev=884650&r1=884649&r2=884650&view=diff ============================================================================== --- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/junit/Asserter.java (original) +++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/junit/Asserter.java Thu Nov 26 17:17:42 2009 @@ -25,7 +25,6 @@ import org.apache.commons.jexl2.Expression; import org.apache.commons.jexl2.JexlContext; import org.apache.commons.jexl2.JexlEngine; -import org.apache.commons.jexl2.JexlHelper; /** * A utility class for performing JUnit based assertions using Jexl @@ -40,7 +39,7 @@ /** variables used during asserts. */ private final Map<String, Object> variables = new HashMap<String, Object>(); /** context to use during asserts. */ - private final JexlContext context = JexlHelper.createContext(); + private final JexlContext context = new JexlContext.Mapped(variables); /** Jexl engine to use during Asserts. */ private final JexlEngine engine; @@ -65,7 +64,6 @@ */ public void assertExpression(String expression, Object expected) throws Exception { Expression exp = engine.createExpression(expression); - context.setVars(variables); Object value = exp.evaluate(context); assertEquals("expression: " + expression, expected, value); Modified: commons/proper/jexl/trunk/xdocs/index.xml URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/xdocs/index.xml?rev=884650&r1=884649&r2=884650&view=diff ============================================================================== --- commons/proper/jexl/trunk/xdocs/index.xml (original) +++ commons/proper/jexl/trunk/xdocs/index.xml Thu Nov 26 17:17:42 2009 @@ -91,7 +91,7 @@ An Expression is created using <a href="http://commons.apache.org/jexl/apidocs/org/apache/commons/jexl/JexlEngine.html#createExpression(java.lang.String)">ExpressionFactory.createExpression()</a>, passing a String containing valid JEXL syntax. A JexlContext is created using - <a href="http://commons.apache.org/jexl/apidocs/org/apache/commons/jexl/JexlHelper.html#createContext()">JexlHelper.createContext()</a>, + <a href="http://commons.apache.org/jexl/apidocs/org/apache/commons/jexl/JexlHelper.html#createContext()">new JexlContext.Mapped()</a>, and variables are put into a map exposed through the <a href="http://commons.apache.org/jexl/apidocs/org/apache/commons/jexl/JexlContext.html#getVars()">getVars()</a> method on JexlContext. The following example, takes a variable named foo, and @@ -106,8 +106,8 @@ Expression e = jexl.createExpression( jexlExp ); // Create a context and add data - JexlContext jc = JexlHelper.createContext(); - jc.getVars().put("foo", new Foo() ); + JexlContext jc = new JexlContext.Mapped(); + jc.setJexlVariable("foo", new Foo() ); // Now evaluate the expression, getting the result Object o = e.evaluate(jc); Modified: commons/proper/jexl/trunk/xdocs/reference/examples.xml URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/xdocs/reference/examples.xml?rev=884650&r1=884649&r2=884650&view=diff ============================================================================== --- commons/proper/jexl/trunk/xdocs/reference/examples.xml (original) +++ commons/proper/jexl/trunk/xdocs/reference/examples.xml Thu Nov 26 17:17:42 2009 @@ -55,7 +55,7 @@ </p> <p> The easiest way of obtaining a a context is to use the - <a href="http://commons.apache.org/jexl/apidocs/org/apache/commons/jexl/JexlHelper.html#createContext()">JexlHelper.createContext()</a> + <a href="http://commons.apache.org/jexl/apidocs/org/apache/commons/jexl/JexlHelper.html#createContext()">new JexlContext.Mapped()</a> method. This creates a context which is simply an extension of a <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/util/HashMap.html">HashMap</a> </p> @@ -78,11 +78,11 @@ Expression e = ExpressionFactory.createExpression( calculateTax ); // populate the context - JexlContext context = JexlHelper.createContext(); - context.getVars().put("G1", businessObject.getTotalSales()); - context.getVars().put("G2", taxManager.getTaxCredit(businessObject.getYear())); - context.getVars().put("G3", businessObject.getIntercompanyPayments()); - context.getVars().put("G4", -taxManager.getAllowances()); + JexlContext context = new JexlContext.Mapped(); + context.setJexlVariable("G1", businessObject.getTotalSales()); + context.setJexlVariable("G2", taxManager.getTaxCredit(businessObject.getYear())); + context.setJexlVariable("G3", businessObject.getIntercompanyPayments()); + context.setJexlVariable("G4", -taxManager.getAllowances()); // ... // work it out