You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by he...@apache.org on 2009/11/30 20:28:41 UTC
svn commit: r885553 [2/2] - in /commons/proper/jexl/trunk:
src/main/java/org/apache/commons/jexl2/
src/main/java/org/apache/commons/jexl2/introspection/
src/main/java/org/apache/commons/jexl2/parser/
src/main/java/org/apache/commons/jexl2/scripting/ sr...
Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/CacheTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/CacheTest.java?rev=885553&r1=885552&r2=885553&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/CacheTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/CacheTest.java Mon Nov 30 19:28:40 2009
@@ -259,7 +259,7 @@
jexl.setCache(0);
}
Map<String, Object> vars = new HashMap<String,Object>();
- JexlContext jc = new JexlContext.Mapped(vars);
+ JexlContext jc = new MapContext(vars);
Expression cacheGetValue = jexl.createExpression("cache.value");
Expression cacheSetValue = jexl.createExpression("cache.value = value");
Object result;
@@ -318,7 +318,7 @@
jexl.setCache(0);
}
Map<String, Object> vars = new HashMap<String,Object>();
- JexlContext jc = new JexlContext.Mapped(vars);
+ JexlContext jc = new MapContext(vars);
Expression cacheGetValue = jexl.createExpression("cache.flag");
Expression cacheSetValue = jexl.createExpression("cache.flag = value");
Object result;
@@ -359,7 +359,7 @@
jexl.setCache(0);
}
Map<String, Object> vars = new HashMap<String,Object>();
- JexlContext jc = new JexlContext.Mapped(vars);
+ JexlContext jc = new MapContext(vars);
Expression cacheGetValue = jexl.createExpression("cache.0");
Expression cacheSetValue = jexl.createExpression("cache[0] = value");
Object result;
@@ -414,7 +414,7 @@
jexl.setCache(0);
}
Map<String, Object> vars = new HashMap<String,Object>();
- JexlContext jc = new JexlContext.Mapped(vars);
+ JexlContext jc = new MapContext(vars);
jexl.setDebug(true);
Expression compute2 = jexl.createExpression("cache.compute(a0, a1)");
Expression compute1 = jexl.createExpression("cache.compute(a0)");
@@ -513,7 +513,7 @@
jexl.setCache(0);
}
Map<String, Object> vars = new HashMap<String,Object>();
- JexlContext jc = new JexlContext.Mapped(vars);
+ JexlContext jc = new MapContext(vars);
java.util.Map<String, Object> funcs = new java.util.HashMap<String, Object>();
jexl.setFunctions(funcs);
Expression compute2 = jexl.createExpression("cached:COMPUTE(a0, a1)");
Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/ClassCreatorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/ClassCreatorTest.java?rev=885553&r1=885552&r2=885553&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/ClassCreatorTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/ClassCreatorTest.java Mon Nov 30 19:28:40 2009
@@ -112,7 +112,7 @@
// List<Object> mm = new ArrayList<Object>();
Expression expr = jexl.createExpression("foo.value");
Expression newx = jexl.createExpression("foo = new(clazz)");
- JexlContext context = new JexlContext.Mapped();
+ JexlContext context = new MapContext();
ClassCreator cctor = new ClassCreator(jexl, base);
for (int i = 0; i < LOOPS && gced < 0; ++i) {
@@ -132,12 +132,12 @@
// Method m = clazz.getDeclaredMethod("getValue", new Class<?>[0]);
// mm.add(m);
// we should not be able to create foox since it is unknown to the Jexl classloader
- context.setJexlVariable("clazz", cctor.getClassName());
- context.setJexlVariable("foo", null);
+ context.set("clazz", cctor.getClassName());
+ context.set("foo", null);
Object z = newx.evaluate(context);
assertNull(z);
// check with the class itself
- context.setJexlVariable("clazz", clazz);
+ context.set("clazz", clazz);
z = newx.evaluate(context);
assertNotNull(clazz + ": class " + i + " could not be instantiated on pass " + pass, z);
assertEquals(new Integer(i), expr.evaluate(context));
Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/ForEachTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/ForEachTest.java?rev=885553&r1=885552&r2=885553&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/ForEachTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/ForEachTest.java Mon Nov 30 19:28:40 2009
@@ -37,7 +37,7 @@
public void testForEachWithEmptyStatement() throws Exception {
Expression e = JEXL.createExpression("for(item : list) ;");
- JexlContext jc = new JexlContext.Mapped();
+ JexlContext jc = new MapContext();
Object o = e.evaluate(jc);
assertNull("Result is not null", o);
@@ -45,7 +45,7 @@
public void testForEachWithEmptyList() throws Exception {
Expression e = JEXL.createExpression("for(item : list) 1+1");
- JexlContext jc = new JexlContext.Mapped();
+ JexlContext jc = new MapContext();
Object o = e.evaluate(jc);
assertNull("Result is not null", o);
@@ -53,78 +53,78 @@
public void testForEachWithArray() throws Exception {
Expression e = JEXL.createExpression("for(item : list) item");
- JexlContext jc = new JexlContext.Mapped();
- jc.setJexlVariable("list", new Object[] {"Hello", "World"});
+ JexlContext jc = new MapContext();
+ jc.set("list", new Object[] {"Hello", "World"});
Object o = e.evaluate(jc);
assertEquals("Result is not last evaluated expression", "World", o);
}
public void testForEachWithCollection() throws Exception {
Expression e = JEXL.createExpression("for(item : list) item");
- JexlContext jc = new JexlContext.Mapped();
- jc.setJexlVariable("list", Arrays.asList(new Object[] {"Hello", "World"}));
+ JexlContext jc = new MapContext();
+ jc.set("list", Arrays.asList(new Object[] {"Hello", "World"}));
Object o = e.evaluate(jc);
assertEquals("Result is not last evaluated expression", "World", o);
}
public void testForEachWithEnumeration() throws Exception {
Expression e = JEXL.createExpression("for(item : list) item");
- JexlContext jc = new JexlContext.Mapped();
- jc.setJexlVariable("list", new StringTokenizer("Hello,World", ","));
+ JexlContext jc = new MapContext();
+ jc.set("list", new StringTokenizer("Hello,World", ","));
Object o = e.evaluate(jc);
assertEquals("Result is not last evaluated expression", "World", o);
}
public void testForEachWithIterator() throws Exception {
Expression e = JEXL.createExpression("for(item : list) item");
- JexlContext jc = new JexlContext.Mapped();
- jc.setJexlVariable("list", Arrays.asList(new Object[] {"Hello", "World"}).iterator());
+ JexlContext jc = new MapContext();
+ jc.set("list", Arrays.asList(new Object[] {"Hello", "World"}).iterator());
Object o = e.evaluate(jc);
assertEquals("Result is not last evaluated expression", "World", o);
}
public void testForEachWithMap() throws Exception {
Expression e = JEXL.createExpression("for(item : list) item");
- JexlContext jc = new JexlContext.Mapped();
+ JexlContext jc = new MapContext();
Map<?, ?> map = System.getProperties();
String lastProperty = (String) new ArrayList<Object>(map.values()).get(System.getProperties().size() - 1);
- jc.setJexlVariable("list", map);
+ jc.set("list", map);
Object o = e.evaluate(jc);
assertEquals("Result is not last evaluated expression", lastProperty, o);
}
public void testForEachWithBlock() throws Exception {
Expression e = JEXL.createExpression("for(item : list) { x = x + item; }");
- JexlContext jc = new JexlContext.Mapped();
- jc.setJexlVariable("list", new Object[] {"1", "1"});
- jc.setJexlVariable("x", new Integer(0));
+ JexlContext jc = new MapContext();
+ jc.set("list", new Object[] {"1", "1"});
+ jc.set("x", new Integer(0));
Object o = e.evaluate(jc);
assertEquals("Result is wrong", new Integer(2), o);
- assertEquals("x is wrong", new Integer(2), jc.getJexlVariable("x"));
+ assertEquals("x is wrong", new Integer(2), jc.get("x"));
}
public void testForEachWithListExpression() throws Exception {
Expression e = JEXL.createExpression("for(item : list.keySet()) item");
- JexlContext jc = new JexlContext.Mapped();
+ JexlContext jc = new MapContext();
Map<?, ?> map = System.getProperties();
String lastKey = (String) new ArrayList<Object>(map.keySet()).get(System.getProperties().size() - 1);
- jc.setJexlVariable("list", map);
+ jc.set("list", map);
Object o = e.evaluate(jc);
assertEquals("Result is not last evaluated expression", lastKey, o);
}
public void testForEachWithProperty() throws Exception {
Expression e = JEXL.createExpression("for(item : list.cheeseList) item");
- JexlContext jc = new JexlContext.Mapped();
- jc.setJexlVariable("list", new Foo());
+ JexlContext jc = new MapContext();
+ jc.set("list", new Foo());
Object o = e.evaluate(jc);
assertEquals("Result is not last evaluated expression", "brie", o);
}
public void testForEachWithIteratorMethod() throws Exception {
Expression e = JEXL.createExpression("for(item : list.cheezy) item");
- JexlContext jc = new JexlContext.Mapped();
- jc.setJexlVariable("list", new Foo());
+ JexlContext jc = new MapContext();
+ jc.set("list", new Foo());
Object o = e.evaluate(jc);
assertEquals("Result is not last evaluated expression", "brie", o);
}
Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/IfTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/IfTest.java?rev=885553&r1=885552&r2=885553&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/IfTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/IfTest.java Mon Nov 30 19:28:40 2009
@@ -37,7 +37,7 @@
*/
public void testSimpleIfTrue() throws Exception {
Expression e = JEXL.createExpression("if (true) 1");
- JexlContext jc = new JexlContext.Mapped();
+ JexlContext jc = new MapContext();
Object o = e.evaluate(jc);
assertEquals("Result is not 1", new Integer(1), o);
@@ -50,7 +50,7 @@
*/
public void testSimpleIfFalse() throws Exception {
Expression e = JEXL.createExpression("if (false) 1");
- JexlContext jc = new JexlContext.Mapped();
+ JexlContext jc = new MapContext();
Object o = e.evaluate(jc);
assertNull("Return value is not empty", o);
@@ -64,7 +64,7 @@
public void testSimpleElse() throws Exception {
Expression e = JEXL
.createExpression("if (false) 1 else 2;");
- JexlContext jc = new JexlContext.Mapped();
+ JexlContext jc = new MapContext();
Object o = e.evaluate(jc);
assertEquals("Result is not 2", new Integer(2), o);
@@ -78,7 +78,7 @@
public void testBlockIfTrue() throws Exception {
Expression e = JEXL
.createExpression("if (true) { 'hello'; }");
- JexlContext jc = new JexlContext.Mapped();
+ JexlContext jc = new MapContext();
Object o = e.evaluate(jc);
assertEquals("Result is wrong", "hello", o);
@@ -92,7 +92,7 @@
public void testBlockElse() throws Exception {
Expression e = JEXL
.createExpression("if (false) {1} else {2 ; 3}");
- JexlContext jc = new JexlContext.Mapped();
+ JexlContext jc = new MapContext();
Object o = e.evaluate(jc);
assertEquals("Result is wrong", new Integer(3), o);
@@ -106,8 +106,8 @@
public void testIfWithSimpleExpression() throws Exception {
Expression e = JEXL
.createExpression("if (x == 1) true;");
- JexlContext jc = new JexlContext.Mapped();
- jc.setJexlVariable("x", new Integer(1));
+ JexlContext jc = new MapContext();
+ jc.set("x", new Integer(1));
Object o = e.evaluate(jc);
assertEquals("Result is not true", Boolean.TRUE, o);
@@ -121,8 +121,8 @@
public void testIfWithArithmeticExpression() throws Exception {
Expression e = JEXL
.createExpression("if ((x * 2) + 1 == 5) true;");
- JexlContext jc = new JexlContext.Mapped();
- jc.setJexlVariable("x", new Integer(2));
+ JexlContext jc = new MapContext();
+ jc.set("x", new Integer(2));
Object o = e.evaluate(jc);
assertEquals("Result is not true", Boolean.TRUE, o);
@@ -136,8 +136,8 @@
public void testIfWithDecimalArithmeticExpression() throws Exception {
Expression e = JEXL
.createExpression("if ((x * 2) == 5) true");
- JexlContext jc = new JexlContext.Mapped();
- jc.setJexlVariable("x", new Float(2.5f));
+ JexlContext jc = new MapContext();
+ jc.set("x", new Float(2.5f));
Object o = e.evaluate(jc);
assertEquals("Result is not true", Boolean.TRUE, o);
@@ -151,11 +151,11 @@
public void testIfWithAssignment() throws Exception {
Expression e = JEXL
.createExpression("if ((x * 2) == 5) {y = 1} else {y = 2;}");
- JexlContext jc = new JexlContext.Mapped();
- jc.setJexlVariable("x", new Float(2.5f));
+ JexlContext jc = new MapContext();
+ jc.set("x", new Float(2.5f));
e.evaluate(jc);
- Object result = jc.getJexlVariable("y");
+ Object result = jc.get("y");
assertEquals("y has the wrong value", new Integer(1), result);
}
@@ -167,7 +167,7 @@
public void testTernary() throws Exception {
JexlEngine jexl = new JexlEngine();
jexl.setCache(64);
- JexlContext jc = new JexlContext.Mapped();
+ JexlContext jc = new MapContext();
Expression e = jexl.createExpression("x.y.z = foo ?'bar':'quux'");
Object o;
@@ -178,40 +178,40 @@
jexl.setSilent((l & 2) != 0);
o = e.evaluate(jc);
assertEquals("Should be quux", "quux", o);
- o = jc.getJexlVariable("x.y.z");
+ o = jc.get("x.y.z");
assertEquals("Should be quux", "quux", o);
}
- jc.setJexlVariable("foo", null);
+ jc.set("foo", null);
for(int l = 0; l < 4; ++l) {
jexl.setLenient((l & 1) != 0);
jexl.setSilent((l & 2) != 0);
o = e.evaluate(jc);
assertEquals("Should be quux", "quux", o);
- o = jc.getJexlVariable("x.y.z");
+ o = jc.get("x.y.z");
assertEquals("Should be quux", "quux", o);
}
- jc.setJexlVariable("foo",Boolean.FALSE);
+ jc.set("foo",Boolean.FALSE);
for(int l = 0; l < 4; ++l) {
jexl.setLenient((l & 1) != 0);
jexl.setSilent((l & 2) != 0);
o = e.evaluate(jc);
assertEquals("Should be quux", "quux", o);
- o = jc.getJexlVariable("x.y.z");
+ o = jc.get("x.y.z");
assertEquals("Should be quux", "quux", o);
}
- jc.setJexlVariable("foo",Boolean.TRUE);
+ jc.set("foo",Boolean.TRUE);
for(int l = 0; l < 4; ++l) {
jexl.setLenient((l & 1) != 0);
jexl.setSilent((l & 2) != 0);
o = e.evaluate(jc);
assertEquals("Should be bar", "bar", o);
- o = jc.getJexlVariable("x.y.z");
+ o = jc.get("x.y.z");
assertEquals("Should be bar", "bar", o);
}
@@ -226,7 +226,7 @@
public void testTernaryShorthand() throws Exception {
JexlEngine jexl = new JexlEngine();
jexl.setCache(64);
- JexlContext jc = new JexlContext.Mapped();
+ JexlContext jc = new MapContext();
Expression e = JEXL.createExpression("x.y.z = foo?:'quux'");
Object o;
@@ -237,40 +237,40 @@
jexl.setSilent((l & 2) != 0);
o = e.evaluate(jc);
assertEquals("Should be quux", "quux", o);
- o = jc.getJexlVariable("x.y.z");
+ o = jc.get("x.y.z");
assertEquals("Should be quux", "quux", o);
}
- jc.setJexlVariable("foo", null);
+ jc.set("foo", null);
for(int l = 0; l < 4; ++l) {
jexl.setLenient((l & 1) != 0);
jexl.setSilent((l & 2) != 0);
o = e.evaluate(jc);
assertEquals("Should be quux", "quux", o);
- o = jc.getJexlVariable("x.y.z");
+ o = jc.get("x.y.z");
assertEquals("Should be quux", "quux", o);
}
- jc.setJexlVariable("foo", Boolean.FALSE);
+ jc.set("foo", Boolean.FALSE);
for(int l = 0; l < 4; ++l) {
jexl.setLenient((l & 1) != 0);
jexl.setSilent((l & 2) != 0);
o = e.evaluate(jc);
assertEquals("Should be quux", "quux", o);
- o = jc.getJexlVariable("x.y.z");
+ o = jc.get("x.y.z");
assertEquals("Should be quux", "quux", o);
}
- jc.setJexlVariable("foo","bar");
+ jc.set("foo","bar");
for(int l = 0; l < 4; ++l) {
jexl.setLenient((l & 1) != 0);
jexl.setSilent((l & 2) != 0);
o = e.evaluate(jc);
assertEquals("Should be bar", "bar", o);
- o = jc.getJexlVariable("x.y.z");
+ o = jc.get("x.y.z");
assertEquals("Should be bar", "bar", o);
}
Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/IssuesTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/IssuesTest.java?rev=885553&r1=885552&r2=885553&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/IssuesTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/IssuesTest.java Mon Nov 30 19:28:40 2009
@@ -15,7 +15,8 @@
* limitations under the License.
*/
package org.apache.commons.jexl2;
-
+import org.apache.commons.jexl2.introspection.Uberspect;
+import org.apache.commons.jexl2.util.Introspector;
import java.util.HashMap;
import java.util.Map;
@@ -32,7 +33,7 @@
// JEXL-49: blocks not parsed (fixed)
public void test49() throws Exception {
Map<String,Object> vars = new HashMap<String,Object>();
- JexlContext ctxt = new JexlContext.Mapped(vars);
+ JexlContext ctxt = new MapContext(vars);
String stmt = "{a = 'b'; c = 'd';}";
Script expr = JEXL.createScript(stmt);
/* Object value = */ expr.execute(ctxt);
@@ -70,8 +71,8 @@
jexl.setSilent(false);
String jexlExp = "(foo.getInner().foo() eq true) and (foo.getInner().goo() = (foo.getInner().goo()+1-1))";
Expression e = jexl.createExpression(jexlExp);
- JexlContext jc = new JexlContext.Mapped();
- jc.setJexlVariable("foo", new Foo());
+ JexlContext jc = new MapContext();
+ jc.set("foo", new Foo());
try {
/* Object o = */ e.evaluate(jc);
@@ -87,7 +88,7 @@
JexlEngine jexl = new JexlEngine();
// ensure errors will throw
jexl.setSilent(false);
- JexlContext ctxt = new JexlContext.Mapped();
+ JexlContext ctxt = new MapContext();
Expression expr = jexl.createExpression("true//false\n");
Object value = expr.evaluate(ctxt);
@@ -109,8 +110,8 @@
UnifiedJEXL uel = new UnifiedJEXL(jexl);
// ensure errors will throw
//jexl.setSilent(false);
- JexlContext ctxt = new JexlContext.Mapped();
- ctxt.setJexlVariable("ax", "ok");
+ JexlContext ctxt = new MapContext();
+ ctxt.set("ax", "ok");
UnifiedJEXL.Expression expr = uel.parse("${ax+(bx)}");
Object value = expr.evaluate(ctxt);
@@ -134,8 +135,8 @@
JexlEngine jexl = new JexlEngine();
// ensure errors will throw
jexl.setSilent(false);
- JexlContext ctxt = new JexlContext.Mapped();
- ctxt.setJexlVariable("derived", new Derived());
+ JexlContext ctxt = new MapContext();
+ ctxt.set("derived", new Derived());
Expression expr = jexl.createExpression("derived.foo()");
Object value = expr.evaluate(ctxt);
@@ -145,8 +146,9 @@
// JEXL-52: can be implemented by deriving Interpreter.{g,s}etAttribute; later
public void test52base() throws Exception {
JexlEngine jexl = new JexlEngine();
+ Uberspect uber = jexl.getUberspect();
// most likely, call will be in an Interpreter, getUberspect
- String[] names = jexl.uberspect.getIntrospector().getMethodNames(Another.class);
+ String[] names = ((Introspector) uber).getMethodNames(Another.class);
assertTrue("should find methods", names.length > 0);
int found = 0;
for (String name : names) {
@@ -163,8 +165,8 @@
// ensure errors will throw
jexl.setSilent(false);
jexl.setLenient(false);
- JexlContext ctxt = new JexlContext.Mapped();
- ctxt.setJexlVariable("a", null);
+ JexlContext ctxt = new MapContext();
+ ctxt.set("a", null);
String[] exprs = {
//"10 + null",
@@ -192,11 +194,11 @@
Script jscript;
- ctxt = new JexlContext.Mapped();
+ ctxt = new MapContext();
jscript = jexl.createScript("dummy.hashCode()");
assertEquals(jscript.getText(), null, jscript.execute(ctxt)); // OK
- ctxt.setJexlVariable("dummy", "abcd");
+ ctxt.set("dummy", "abcd");
assertEquals(jscript.getText(), Integer.valueOf("abcd".hashCode()), jscript.execute(ctxt)); // OK
jscript = jexl.createScript("dummy.hashCode");
@@ -204,11 +206,11 @@
Expression jexpr;
- ctxt = new JexlContext.Mapped();
+ ctxt = new MapContext();
jexpr = jexl.createExpression("dummy.hashCode()");
assertEquals(jexpr.getExpression(), null, jexpr.evaluate(ctxt)); // OK
- ctxt.setJexlVariable("dummy", "abcd");
+ ctxt.set("dummy", "abcd");
assertEquals(jexpr.getExpression(), Integer.valueOf("abcd".hashCode()), jexpr.evaluate(ctxt)); // OK
jexpr = jexl.createExpression("dummy.hashCode");
@@ -217,7 +219,7 @@
// JEXL-73
public void test73() throws Exception {
- JexlContext ctxt = new JexlContext.Mapped();
+ JexlContext ctxt = new MapContext();
JexlEngine jexl = new JexlEngine();
jexl.setSilent(false);
jexl.setLenient(false);
@@ -230,8 +232,8 @@
assertTrue(msg.indexOf("variable c.e") > 0);
}
- ctxt.setJexlVariable("c", "{ 'a' : 3, 'b' : 5}");
- ctxt.setJexlVariable("e", Integer.valueOf(2));
+ ctxt.set("c", "{ 'a' : 3, 'b' : 5}");
+ ctxt.set("e", Integer.valueOf(2));
try {
/* Object o = */ e.evaluate(ctxt);
} catch (JexlException xjexl) {
@@ -243,27 +245,27 @@
// JEXL-87
public void test87() throws Exception {
- JexlContext ctxt = new JexlContext.Mapped();
+ JexlContext ctxt = new MapContext();
JexlEngine jexl = new JexlEngine();
jexl.setSilent(false);
jexl.setLenient(false);
Expression divide = jexl.createExpression("l / r");
Expression modulo = jexl.createExpression("l % r");
- ctxt.setJexlVariable("l", java.math.BigInteger.valueOf(7));
- ctxt.setJexlVariable("r", java.math.BigInteger.valueOf(2));
+ ctxt.set("l", java.math.BigInteger.valueOf(7));
+ ctxt.set("r", java.math.BigInteger.valueOf(2));
assertEquals("3", divide.evaluate(ctxt).toString());
assertEquals("1", modulo.evaluate(ctxt).toString());
- ctxt.setJexlVariable("l", java.math.BigDecimal.valueOf(7));
- ctxt.setJexlVariable("r", java.math.BigDecimal.valueOf(2));
+ ctxt.set("l", java.math.BigDecimal.valueOf(7));
+ ctxt.set("r", java.math.BigDecimal.valueOf(2));
assertEquals("3.5", divide.evaluate(ctxt).toString());
assertEquals("1", modulo.evaluate(ctxt).toString());
}
// JEXL-90
public void test90() throws Exception {
- JexlContext ctxt = new JexlContext.Mapped();
+ JexlContext ctxt = new MapContext();
JexlEngine jexl = new JexlEngine();
jexl.setSilent(false);
jexl.setLenient(false);
@@ -292,8 +294,8 @@
"for(z : [3, 4, 5]) { z } y ? 2 : 1",
"for(z : [3, 4, 5]) { z } if (y) 2 else 1"
};
- ctxt.setJexlVariable("x", Boolean.FALSE);
- ctxt.setJexlVariable("y", Boolean.TRUE);
+ ctxt.set("x", Boolean.FALSE);
+ ctxt.set("y", Boolean.TRUE);
for (int e = 0; e < exprs.length; ++e) {
Script s = jexl.createScript(exprs[e]);
assertEquals(Integer.valueOf(2), s.execute(ctxt));
@@ -303,7 +305,7 @@
// JEXL-44
public void test44() throws Exception {
- JexlContext ctxt = new JexlContext.Mapped();
+ JexlContext ctxt = new MapContext();
JexlEngine jexl = new JexlEngine();
jexl.setSilent(false);
jexl.setLenient(false);
Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/Jexl.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/Jexl.java?rev=885553&r1=885552&r2=885553&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/Jexl.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/Jexl.java Mon Nov 30 19:28:40 2009
@@ -28,9 +28,12 @@
public static void main(String[] args) {
final JexlEngine JEXL = new JexlEngine();
- Map m = System.getProperties();
+ Map<Object,Object> m = System.getProperties();
// dummy context to get variables
- JexlContext context = new JexlContext.Mapped(System.getProperties());
+ JexlContext context = new MapContext();
+ for(Map.Entry<Object,Object> e : m.entrySet()) {
+ context.set(e.getKey().toString(), e.getValue());
+ }
try {
for (int i = 0; i < args.length; i++) {
Expression e = JEXL.createExpression(args[i]);
Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/JexlTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/JexlTest.java?rev=885553&r1=885552&r2=885553&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/JexlTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/JexlTest.java Mon Nov 30 19:28:40 2009
@@ -61,9 +61,9 @@
*/
Expression e = JEXL.createExpression("foo.bar");
- JexlContext jc = new JexlContext.Mapped();
+ JexlContext jc = new MapContext();
- jc.setJexlVariable("foo", new Foo() );
+ jc.set("foo", new Foo() );
Object o = e.evaluate(jc);
assertTrue("o not instanceof String", o instanceof String);
@@ -73,10 +73,10 @@
public void testBoolean()
throws Exception
{
- JexlContext jc = new JexlContext.Mapped();
- jc.setJexlVariable("foo", new Foo() );
- jc.setJexlVariable("a", Boolean.TRUE);
- jc.setJexlVariable("b", Boolean.FALSE);
+ JexlContext jc = new MapContext();
+ jc.set("foo", new Foo() );
+ jc.set("a", Boolean.TRUE);
+ jc.set("b", Boolean.FALSE);
assertExpression(jc, "foo.convertBoolean(a==b)", "Boolean : false");
assertExpression(jc, "foo.convertBoolean(a==true)", "Boolean : true");
@@ -92,24 +92,24 @@
/*
* tests a simple property expression
*/
- JexlContext jc = new JexlContext.Mapped();
- jc.setJexlVariable("foo", new Foo() );
+ JexlContext jc = new MapContext();
+ jc.set("foo", new Foo() );
assertExpression(jc, "foo.get(\"woogie\")", "Repeat : woogie");
}
public void testExpression()
throws Exception
{
- JexlContext jc = new JexlContext.Mapped();
- jc.setJexlVariable("foo", new Foo() );
- jc.setJexlVariable("a", Boolean.TRUE);
- jc.setJexlVariable("b", Boolean.FALSE);
- jc.setJexlVariable("num", new Integer(5));
- jc.setJexlVariable("now", Calendar.getInstance().getTime());
+ JexlContext jc = new MapContext();
+ jc.set("foo", new Foo() );
+ jc.set("a", Boolean.TRUE);
+ jc.set("b", Boolean.FALSE);
+ jc.set("num", new Integer(5));
+ jc.set("now", Calendar.getInstance().getTime());
GregorianCalendar gc = new GregorianCalendar(5000, 11, 20);
- jc.setJexlVariable("now2", gc.getTime());
- jc.setJexlVariable("bdec", new BigDecimal("7"));
- jc.setJexlVariable("bint", new BigInteger("7"));
+ jc.set("now2", gc.getTime());
+ jc.set("bdec", new BigDecimal("7"));
+ jc.set("bint", new BigInteger("7"));
assertExpression(jc, "a == b", Boolean.FALSE);
assertExpression(jc, "a==true", Boolean.TRUE);
@@ -161,13 +161,13 @@
public void testEmpty()
throws Exception
{
- JexlContext jc = new JexlContext.Mapped();
- jc.setJexlVariable("string", "");
- jc.setJexlVariable("array", new Object[0]);
- jc.setJexlVariable("map", new HashMap<Object, Object>());
- jc.setJexlVariable("list", new ArrayList<Object>());
- jc.setJexlVariable("set", (new HashMap<Object, Object>()).keySet());
- jc.setJexlVariable("longstring", "thingthing");
+ JexlContext jc = new MapContext();
+ jc.set("string", "");
+ jc.set("array", new Object[0]);
+ jc.set("map", new HashMap<Object, Object>());
+ jc.set("list", new ArrayList<Object>());
+ jc.set("set", (new HashMap<Object, Object>()).keySet());
+ jc.set("longstring", "thingthing");
/*
* I can't believe anyone thinks this is a syntax.. :)
@@ -185,9 +185,9 @@
public void testSize()
throws Exception
{
- JexlContext jc = new JexlContext.Mapped();
- jc.setJexlVariable("s", "five!");
- jc.setJexlVariable("array", new Object[5]);
+ JexlContext jc = new MapContext();
+ jc.set("s", "five!");
+ jc.set("array", new Object[5]);
Map<String, Integer> map = new HashMap<String, Integer>();
@@ -197,7 +197,7 @@
map.put("4", new Integer(4));
map.put("5", new Integer(5));
- jc.setJexlVariable("map", map);
+ jc.set("map", map);
List<String> list = new ArrayList<String>();
@@ -207,18 +207,18 @@
list.add("4");
list.add("5");
- jc.setJexlVariable("list", list);
+ jc.set("list", list);
// 30652 - support for set
Set<String> set = new HashSet<String>();
set.addAll(list);
set.add("1");
- jc.setJexlVariable("set", set);
+ jc.set("set", set);
// support generic int size() method
BitSet bitset = new BitSet(5);
- jc.setJexlVariable("bitset", bitset);
+ jc.set("bitset", bitset);
assertExpression(jc, "size(s)", new Integer(5));
assertExpression(jc, "size(array)", new Integer(5));
@@ -238,11 +238,11 @@
public void testSizeAsProperty() throws Exception
{
- JexlContext jc = new JexlContext.Mapped();
+ JexlContext jc = new MapContext();
Map<String, Object> map = new HashMap<String, Object>();
map.put("size", "cheese");
- jc.setJexlVariable("map", map);
- jc.setJexlVariable("foo", new Foo());
+ jc.set("map", map);
+ jc.set("foo", new Foo());
assertExpression(jc, "map['size']", "cheese");
// PR - unsure whether or not we should support map.size or force usage of the above 'escaped' version
@@ -256,9 +256,9 @@
* test the new function e.g constructor invocation
*/
public void testNew() throws Exception {
- JexlContext jc = new JexlContext.Mapped();
- jc.setJexlVariable("double", Double.class);
- jc.setJexlVariable("foo", "org.apache.commons.jexl2.Foo");
+ JexlContext jc = new MapContext();
+ jc.set("double", Double.class);
+ jc.set("foo", "org.apache.commons.jexl2.Foo");
Expression expr;
Object value;
expr = JEXL.createExpression("new(double, 1)");
@@ -278,23 +278,23 @@
public void testCalculations()
throws Exception
{
- JexlContext jc = new JexlContext.Mapped();
+ JexlContext jc = new MapContext();
/*
* test to ensure new string cat works
*/
- jc.setJexlVariable("stringy", "thingy" );
+ jc.set("stringy", "thingy" );
assertExpression(jc, "stringy + 2", "thingy2");
/*
* test new null coersion
*/
- jc.setJexlVariable("imanull", null );
+ jc.set("imanull", null );
assertExpression(jc, "imanull + 2", new Integer(2));
assertExpression(jc, "imanull + imanull", new Integer(0));
/* test for bugzilla 31577 */
- jc.setJexlVariable("n", new Integer(0));
+ jc.set("n", new Integer(0));
assertExpression(jc, "n != null && n != 0", Boolean.FALSE);
}
@@ -304,18 +304,18 @@
public void testConditions()
throws Exception
{
- JexlContext jc = new JexlContext.Mapped();
- jc.setJexlVariable("foo", new Integer(2) );
- jc.setJexlVariable("aFloat", new Float(1));
- jc.setJexlVariable("aDouble", new Double(2));
- jc.setJexlVariable("aChar", new Character('A'));
- jc.setJexlVariable("aBool", Boolean.TRUE);
+ JexlContext jc = new MapContext();
+ jc.set("foo", new Integer(2) );
+ jc.set("aFloat", new Float(1));
+ jc.set("aDouble", new Double(2));
+ jc.set("aChar", new Character('A'));
+ jc.set("aBool", Boolean.TRUE);
StringBuffer buffer = new StringBuffer("abc");
List<Object> list = new ArrayList<Object>();
List<Object> list2 = new LinkedList<Object>();
- jc.setJexlVariable("aBuffer", buffer);
- jc.setJexlVariable("aList", list);
- jc.setJexlVariable("bList", list2);
+ jc.set("aBuffer", buffer);
+ jc.set("aList", list);
+ jc.set("bList", list2);
assertExpression(jc, "foo == 2", Boolean.TRUE);
assertExpression(jc, "2 == 3", Boolean.FALSE);
@@ -351,12 +351,12 @@
public void testNotConditions()
throws Exception
{
- JexlContext jc = new JexlContext.Mapped();
+ JexlContext jc = new MapContext();
Foo foo = new Foo();
- jc.setJexlVariable("x", Boolean.TRUE );
- jc.setJexlVariable("foo", foo );
- jc.setJexlVariable("bar", "true" );
+ jc.set("x", Boolean.TRUE );
+ jc.set("foo", foo );
+ jc.set("bar", "true" );
assertExpression(jc, "!x", Boolean.FALSE);
assertExpression(jc, "x", Boolean.TRUE);
@@ -368,7 +368,7 @@
assertExpression(jc, "foo.getCheeseList().size() == 3", Boolean.TRUE);
assertExpression(jc, "foo.cheeseList.size() == 3", Boolean.TRUE);
- jc.setJexlVariable("string", "");
+ jc.set("string", "");
assertExpression(jc, "not empty string", Boolean.FALSE);
assertExpression(jc, "not(empty string)", Boolean.FALSE);
assertExpression(jc, "not empty(string)", Boolean.FALSE);
@@ -385,10 +385,10 @@
public void testNotConditionsWithDots()
throws Exception
{
- JexlContext jc = new JexlContext.Mapped();
+ JexlContext jc = new MapContext();
- jc.setJexlVariable("x.a", Boolean.TRUE );
- jc.setJexlVariable("x.b", Boolean.FALSE );
+ jc.set("x.a", Boolean.TRUE );
+ jc.set("x.b", Boolean.FALSE );
assertExpression(jc, "x.a", Boolean.TRUE);
assertExpression(jc, "!x.a", Boolean.FALSE);
@@ -401,8 +401,8 @@
public void testComparisons()
throws Exception
{
- JexlContext jc = new JexlContext.Mapped();
- jc.setJexlVariable("foo", "the quick and lazy fox" );
+ JexlContext jc = new MapContext();
+ jc.set("foo", "the quick and lazy fox" );
assertExpression(jc, "foo.indexOf('quick') > 0", Boolean.TRUE);
assertExpression(jc, "foo.indexOf('bar') >= 0", Boolean.FALSE);
@@ -415,8 +415,8 @@
public void testNull()
throws Exception
{
- JexlContext jc = new JexlContext.Mapped();
- jc.setJexlVariable("bar", new Integer(2) );
+ JexlContext jc = new MapContext();
+ jc.set("bar", new Integer(2) );
assertExpression(jc, "empty foo", Boolean.TRUE);
assertExpression(jc, "bar == null", Boolean.FALSE);
@@ -431,7 +431,7 @@
* test quoting in strings
*/
public void testStringQuoting() throws Exception {
- JexlContext jc = new JexlContext.Mapped();
+ JexlContext jc = new MapContext();
assertExpression(jc, "'\"Hello\"'", "\"Hello\"");
assertExpression(jc, "\"I'm testing\"", "I'm testing");
}
@@ -442,8 +442,8 @@
public void testBlankStrings()
throws Exception
{
- JexlContext jc = new JexlContext.Mapped();
- jc.setJexlVariable("bar", "" );
+ JexlContext jc = new MapContext();
+ jc.set("bar", "" );
assertExpression(jc, "foo == ''", Boolean.FALSE);
assertExpression(jc, "bar == ''", Boolean.TRUE);
@@ -459,9 +459,9 @@
public void testLogicExpressions()
throws Exception
{
- JexlContext jc = new JexlContext.Mapped();
- jc.setJexlVariable("foo", "abc" );
- jc.setJexlVariable("bar", "def" );
+ JexlContext jc = new MapContext();
+ jc.set("foo", "abc" );
+ jc.set("bar", "def" );
assertExpression(jc, "foo == 'abc' || bar == 'abc'", Boolean.TRUE);
assertExpression(jc, "foo == 'abc' or bar == 'abc'", Boolean.TRUE);
@@ -481,8 +481,8 @@
public void testVariableNames()
throws Exception
{
- JexlContext jc = new JexlContext.Mapped();
- jc.setJexlVariable("foo_bar", "123" );
+ JexlContext jc = new MapContext();
+ jc.set("foo_bar", "123" );
assertExpression(jc, "foo_bar", "123");
}
@@ -496,8 +496,8 @@
Map<String, String> foo = new HashMap<String, String>();
foo.put( "bar", "123" );
- JexlContext jc = new JexlContext.Mapped();
- jc.setJexlVariable("foo", foo );
+ JexlContext jc = new MapContext();
+ jc.set("foo", foo );
assertExpression(jc, "foo.bar", "123");
}
@@ -508,8 +508,8 @@
public void testStringLiterals()
throws Exception
{
- JexlContext jc = new JexlContext.Mapped();
- jc.setJexlVariable("foo", "bar" );
+ JexlContext jc = new MapContext();
+ jc.set("foo", "bar" );
assertExpression(jc, "foo == \"bar\"", Boolean.TRUE);
assertExpression(jc, "foo == 'bar'", Boolean.TRUE);
@@ -527,8 +527,8 @@
assertEquals(4, foo.square(2));
assertEquals(4, foo.square(-2));
- JexlContext jc = new JexlContext.Mapped();
- jc.setJexlVariable("foo", foo );
+ JexlContext jc = new MapContext();
+ jc.set("foo", foo );
assertExpression(jc, "foo.count", new Integer(5));
assertExpression(jc, "foo.square(2)", new Integer(4));
@@ -541,9 +541,9 @@
public void testNegativeIntComparison()
throws Exception
{
- JexlContext jc = new JexlContext.Mapped();
+ JexlContext jc = new MapContext();
Foo foo = new Foo();
- jc.setJexlVariable("foo", foo );
+ jc.set("foo", foo );
assertExpression(jc, "foo.count != -1", Boolean.TRUE);
assertExpression(jc, "foo.count == 5", Boolean.TRUE);
@@ -556,9 +556,9 @@
public void testCharAtBug()
throws Exception
{
- JexlContext jc = new JexlContext.Mapped();
+ JexlContext jc = new MapContext();
- jc.setJexlVariable("foo", "abcdef");
+ jc.set("foo", "abcdef");
assertExpression(jc, "foo.substring(2,4)", "cd");
assertExpression(jc, "foo.charAt(2)", new Character('c'));
@@ -568,20 +568,20 @@
public void testEmptyDottedVariableName() throws Exception
{
- JexlContext jc = new JexlContext.Mapped();
+ JexlContext jc = new MapContext();
- jc.setJexlVariable( "this.is.a.test", "");
+ jc.set( "this.is.a.test", "");
assertExpression(jc, "empty(this.is.a.test)", Boolean.TRUE);
}
public void testEmptySubListOfMap() throws Exception
{
- JexlContext jc = new JexlContext.Mapped();
+ JexlContext jc = new MapContext();
Map<String, ArrayList<?>> m = new HashMap<String, ArrayList<?>>();
m.put("aList", new ArrayList<Object>());
- jc.setJexlVariable( "aMap", m );
+ jc.set( "aMap", m );
assertExpression( jc, "empty( aMap.aList )", Boolean.TRUE );
}
@@ -589,7 +589,7 @@
public void testCoercionWithComparisionOperators()
throws Exception
{
- JexlContext jc = new JexlContext.Mapped();
+ JexlContext jc = new MapContext();
assertExpression(jc, "'2' > 1", Boolean.TRUE);
assertExpression(jc, "'2' >= 1", Boolean.TRUE);
@@ -614,16 +614,16 @@
{
// handle false for the left arg of 'and'
Foo tester = new Foo();
- JexlContext jc = new JexlContext.Mapped();
- jc.setJexlVariable("first", Boolean.FALSE);
- jc.setJexlVariable("foo", tester);
+ JexlContext jc = new MapContext();
+ jc.set("first", Boolean.FALSE);
+ jc.set("foo", tester);
Expression expr = JEXL.createExpression("first and foo.trueAndModify");
expr.evaluate(jc);
assertTrue("Short circuit failure: rhs evaluated when lhs FALSE", !tester.getModified());
// handle true for the left arg of 'and'
tester = new Foo();
- jc.setJexlVariable("first", Boolean.TRUE);
- jc.setJexlVariable("foo", tester);
+ jc.set("first", Boolean.TRUE);
+ jc.set("foo", tester);
expr.evaluate(jc);
assertTrue("Short circuit failure: rhs not evaluated when lhs TRUE", tester.getModified());
}
@@ -636,16 +636,16 @@
{
// handle false for the left arg of 'or'
Foo tester = new Foo();
- JexlContext jc = new JexlContext.Mapped();
- jc.setJexlVariable("first", Boolean.FALSE);
- jc.setJexlVariable("foo", tester);
+ JexlContext jc = new MapContext();
+ jc.set("first", Boolean.FALSE);
+ jc.set("foo", tester);
Expression expr = JEXL.createExpression("first or foo.trueAndModify");
expr.evaluate(jc);
assertTrue("Short circuit failure: rhs not evaluated when lhs FALSE", tester.getModified());
// handle true for the left arg of 'or'
tester = new Foo();
- jc.setJexlVariable("first", Boolean.TRUE);
- jc.setJexlVariable("foo", tester);
+ jc.set("first", Boolean.TRUE);
+ jc.set("foo", tester);
expr.evaluate(jc);
assertTrue("Short circuit failure: rhs evaluated when lhs TRUE", !tester.getModified());
}
@@ -656,9 +656,9 @@
*/
public void testStringConcatenation() throws Exception
{
- JexlContext jc = new JexlContext.Mapped();
- jc.setJexlVariable("first", "Hello");
- jc.setJexlVariable("second", "World");
+ JexlContext jc = new MapContext();
+ jc.set("first", "Hello");
+ jc.set("second", "World");
assertExpression(jc, "first + ' ' + second", "Hello World");
}
@@ -676,7 +676,7 @@
{
try
{
- assertExpression(new JexlContext.Mapped(), "empty()", null);
+ assertExpression(new MapContext(), "empty()", null);
fail("Bad expression didn't throw ParseException");
}
catch (JexlException pe)
@@ -691,7 +691,7 @@
*/
public void testComment() throws Exception
{
- assertExpression(new JexlContext.Mapped(), "## double or nothing\n 1 + 1", Integer.valueOf("2"));
+ assertExpression(new MapContext(), "## double or nothing\n 1 + 1", Integer.valueOf("2"));
}
/**
@@ -700,17 +700,17 @@
*/
public void testAssignment() throws Exception
{
- JexlContext jc = new JexlContext.Mapped();
- jc.setJexlVariable("aString", "Hello");
+ JexlContext jc = new MapContext();
+ jc.set("aString", "Hello");
Foo foo = new Foo();
- jc.setJexlVariable("foo", foo);
+ jc.set("foo", foo);
Parser parser = new Parser(new StringReader(";"));
parser.parse(new StringReader("aString = 'World';"), null);
assertExpression(jc, "hello = 'world'", "world");
- assertEquals("hello variable not changed", "world", jc.getJexlVariable("hello"));
+ assertEquals("hello variable not changed", "world", jc.get("hello"));
assertExpression(jc, "result = 1 + 1", new Integer(2));
- assertEquals("result variable not changed", new Integer(2), jc.getJexlVariable("result"));
+ assertEquals("result variable not changed", new Integer(2), jc.get("result"));
// todo: make sure properties can be assigned to, fall back to flat var if no property
// assertExpression(jc, "foo.property1 = '99'", "99");
// assertEquals("property not set", "99", foo.getProperty1());
@@ -718,9 +718,9 @@
public void testAntPropertiesWithMethods() throws Exception
{
- JexlContext jc = new JexlContext.Mapped();
+ JexlContext jc = new MapContext();
String value = "Stinky Cheese";
- jc.setJexlVariable("maven.bob.food", value);
+ jc.set("maven.bob.food", value);
assertExpression(jc, "maven.bob.food.length()", new Integer(value.length()));
assertExpression(jc, "empty(maven.bob.food)", Boolean.FALSE);
assertExpression(jc, "size(maven.bob.food)", new Integer(value.length()));
@@ -728,13 +728,13 @@
// DG: Note the following ant properties don't work
// String version = "1.0.3";
-// jc.setJexlVariable("commons-logging", version);
+// jc.set("commons-logging", version);
// assertExpression(jc, "commons-logging", version);
}
public void testUnicodeSupport() throws Exception
{
- JexlContext jc = new JexlContext.Mapped();
+ JexlContext jc = new MapContext();
assertExpression(jc, "myvar == 'Użytkownik'", Boolean.FALSE);
assertExpression(jc, "'c:\\some\\windows\\path'", "c:\\some\\windows\\path");
assertExpression(jc, "'foo\\u0020bar'", "foo\u0020bar");
@@ -770,8 +770,8 @@
@SuppressWarnings("boxing")
public void testDuck() throws Exception {
JexlEngine jexl = JEXL;
- JexlContext jc = new JexlContext.Mapped();
- jc.setJexlVariable("duck", new Duck());
+ JexlContext jc = new MapContext();
+ jc.set("duck", new Duck());
Expression expr;
Object result;
expr = jexl.createExpression("duck.zero");
@@ -797,8 +797,8 @@
public void testArray() throws Exception {
int[] array = { 100, 101 , 102 };
JexlEngine jexl = JEXL;
- JexlContext jc = new JexlContext.Mapped();
- jc.setJexlVariable("array", array);
+ JexlContext jc = new MapContext();
+ jc.set("array", array);
Expression expr;
Object result;
expr = jexl.createExpression("array.1");
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=885553&r1=885552&r2=885553&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 Mon Nov 30 19:28:40 2009
@@ -30,7 +30,7 @@
public void testLiteralWithStrings() throws Exception {
Expression e = JEXL.createExpression( "{ 'foo' : 'bar' }" );
- JexlContext jc = new JexlContext.Mapped();
+ JexlContext jc = new MapContext();
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 = new JexlContext.Mapped();
+ JexlContext jc = new MapContext();
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 = new JexlContext.Mapped();
+ JexlContext jc = new MapContext();
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.setJexlVariable("i", Integer.valueOf(5));
+ jc.set("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.setJexlVariable("k", Integer.valueOf(7));
+ jc.set("k", Integer.valueOf(7));
e = JEXL.createExpression("m[k]");
o = e.evaluate(jc);
assertEquals("SEVEN", o);
- jc.setJexlVariable("k", "7");
+ jc.set("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 = new JexlContext.Mapped();
+ JexlContext jc = new MapContext();
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 = new JexlContext.Mapped();
+ JexlContext jc = new MapContext();
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 = new JexlContext.Mapped();
+ JexlContext jc = new MapContext();
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 = new JexlContext.Mapped();
+ JexlContext jc = new MapContext();
Object o = e.evaluate( jc );
assertNotNull(o);
- jc.setJexlVariable("outer", o);
+ jc.set("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 = new JexlContext.Mapped();
+ JexlContext jc = new MapContext();
Object o = e.evaluate( jc );
assertNotNull(o);
- jc.setJexlVariable("outer", o);
+ jc.set("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=885553&r1=885552&r2=885553&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 Mon Nov 30 19:28:40 2009
@@ -132,7 +132,7 @@
funcs.put("math", new MyMath());
JEXL.setFunctions(funcs);
- JexlContext jc = new JexlContext.Mapped();
+ JexlContext jc = new MapContext();
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.setJexlVariable("pi", Math.PI);
+ jc.set("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 = new JexlContext.Mapped();
+ JexlContext jc = new MapContext();
Object o = e.evaluate(jc);
assertEquals("Result is not 10", new Integer(10), o);
e = JEXL.createExpression("func:plus10(10)");
- jc = new JexlContext.Mapped();
+ jc = new MapContext();
o = e.evaluate(jc);
assertEquals("Result is not 20", new Integer(20), o);
e = JEXL.createExpression("func:plus10(func:ten())");
- jc = new JexlContext.Mapped();
+ jc = new MapContext();
o = e.evaluate(jc);
assertEquals("Result is not 20", new Integer(20), o);
e = JEXL.createExpression("FUNC:PLUS20(10)");
- jc = new JexlContext.Mapped();
+ jc = new MapContext();
o = e.evaluate(jc);
assertEquals("Result is not 30", new Integer(30), o);
e = JEXL.createExpression("FUNC:PLUS20(FUNC:TWENTY())");
- jc = new JexlContext.Mapped();
+ jc = new MapContext();
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=885553&r1=885552&r2=885553&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 Mon Nov 30 19:28:40 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 = new JexlContext.Mapped();
- jc.setJexlVariable("x", new Integer(1));
+ JexlContext jc = new MapContext();
+ jc.set("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 = new JexlContext.Mapped();
- jc.setJexlVariable("out", System.out);
+ JexlContext jc = new MapContext();
+ jc.set("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 = new JexlContext.Mapped();
- jc.setJexlVariable("out", System.out);
+ JexlContext jc = new MapContext();
+ jc.set("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 = new JexlContext.Mapped();
- jc.setJexlVariable("resultat", resultatJexl);
+ JexlContext jc = new MapContext();
+ jc.set("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=885553&r1=885552&r2=885553&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 Mon Nov 30 19:28:40 2009
@@ -39,7 +39,7 @@
// ensure jul logging is only error
java.util.logging.Logger.getLogger(JexlEngine.class.getName()).setLevel(java.util.logging.Level.SEVERE);
vars = new HashMap<String,Object>();
- context = new JexlContext.Mapped(vars);
+ context = new MapContext(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=885553&r1=885552&r2=885553&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 Mon Nov 30 19:28:40 2009
@@ -30,7 +30,7 @@
public void testSimpleWhileFalse() throws Exception {
Expression e = JEXL.createExpression("while (false) ;");
- JexlContext jc = new JexlContext.Mapped();
+ JexlContext jc = new MapContext();
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 = new JexlContext.Mapped();
- jc.setJexlVariable("x", new Integer(1));
+ JexlContext jc = new MapContext();
+ jc.set("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 = new JexlContext.Mapped();
- jc.setJexlVariable("x", new Integer(1));
- jc.setJexlVariable("y", new Integer(1));
+ JexlContext jc = new MapContext();
+ jc.set("x", new Integer(1));
+ jc.set("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.getJexlVariable("x"));
- assertEquals("y is wrong", new Integer(512), jc.getJexlVariable("y"));
+ assertEquals("x is wrong", new Integer(10), jc.get("x"));
+ assertEquals("y is wrong", new Integer(512), jc.get("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=885553&r1=885552&r2=885553&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 Mon Nov 30 19:28:40 2009
@@ -42,13 +42,13 @@
/*
* Second make a jexlContext and put stuff in it
*/
- JexlContext jc = new JexlContext.Mapped();
+ JexlContext jc = new MapContext();
List<Object> l = new ArrayList<Object>();
l.add("Hello from location 0");
Integer two = new Integer(2);
l.add(two);
- jc.setJexlVariable("array", l);
+ jc.set("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=885553&r1=885552&r2=885553&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 Mon Nov 30 19:28:40 2009
@@ -40,7 +40,7 @@
/*
* Second make a jexlContext and put stuff in it
*/
- JexlContext jc = new JexlContext.Mapped();
+ JexlContext jc = new MapContext();
/**
* 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.setJexlVariable("foo", foo);
- jc.setJexlVariable("number", number);
+ jc.set("foo", foo);
+ jc.set("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=885553&r1=885552&r2=885553&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 Mon Nov 30 19:28:40 2009
@@ -24,6 +24,7 @@
import org.apache.commons.jexl2.Expression;
import org.apache.commons.jexl2.JexlContext;
+import org.apache.commons.jexl2.MapContext;
import org.apache.commons.jexl2.JexlEngine;
/**
@@ -39,7 +40,7 @@
/** variables used during asserts. */
private final Map<String, Object> variables = new HashMap<String, Object>();
/** context to use during asserts. */
- private final JexlContext context = new JexlContext.Mapped(variables);
+ private final JexlContext context = new MapContext(variables);
/** Jexl engine to use during Asserts. */
private final JexlEngine engine;
Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/util/introspection/DiscoveryTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/util/introspection/DiscoveryTest.java?rev=885553&r1=885552&r2=885553&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/util/introspection/DiscoveryTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/util/introspection/DiscoveryTest.java Mon Nov 30 19:28:40 2009
@@ -22,7 +22,10 @@
import java.util.Map;
+import org.apache.commons.jexl2.JexlEngine;
import org.apache.commons.jexl2.JexlTestCase;
+import org.apache.commons.jexl2.introspection.Uberspect;
+
import org.apache.commons.jexl2.util.Introspector;
import org.apache.commons.jexl2.util.AbstractExecutor;
import org.apache.commons.jexl2.util.PropertyGetExecutor;
@@ -97,7 +100,7 @@
public void testBeanIntrospection() throws Exception {
- Uberspect uber = Introspector.getUberspect();
+ Uberspect uber = JexlEngine.getUberspect(null);
Introspector intro = (Introspector) uber;
Bean bean = new Bean("JEXL", "LXEJ");
@@ -126,7 +129,7 @@
}
public void testDuckIntrospection() throws Exception {
- Uberspect uber = Introspector.getUberspect();
+ Uberspect uber = JexlEngine.getUberspect(null);
Introspector intro = (Introspector) uber;
Duck duck = new Duck("JEXL", "LXEJ");
@@ -154,7 +157,7 @@
}
public void testListIntrospection() throws Exception {
- Uberspect uber = Introspector.getUberspect();
+ Uberspect uber = JexlEngine.getUberspect(null);
Introspector intro = (Introspector) uber;
List<Object> list = new ArrayList<Object>();
list.add("LIST");
@@ -185,7 +188,7 @@
}
public void testMapIntrospection() throws Exception {
- Uberspect uber = Introspector.getUberspect();
+ Uberspect uber = JexlEngine.getUberspect(null);
Introspector intro = (Introspector) uber;
Map<String, Object> map = new HashMap<String, Object>();
map.put("value", "MAP");
Modified: commons/proper/jexl/trunk/xdocs/index.xml
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/xdocs/index.xml?rev=885553&r1=885552&r2=885553&view=diff
==============================================================================
--- commons/proper/jexl/trunk/xdocs/index.xml (original)
+++ commons/proper/jexl/trunk/xdocs/index.xml Mon Nov 30 19:28:40 2009
@@ -107,7 +107,7 @@
// Create a context and add data
JexlContext jc = new JexlContext.Mapped();
- jc.setJexlVariable("foo", new Foo() );
+ jc.set("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=885553&r1=885552&r2=885553&view=diff
==============================================================================
--- commons/proper/jexl/trunk/xdocs/reference/examples.xml (original)
+++ commons/proper/jexl/trunk/xdocs/reference/examples.xml Mon Nov 30 19:28:40 2009
@@ -79,10 +79,10 @@
// populate the context
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());
+ context.set("G1", businessObject.getTotalSales());
+ context.set("G2", taxManager.getTaxCredit(businessObject.getYear()));
+ context.set("G3", businessObject.getIntercompanyPayments());
+ context.set("G4", -taxManager.getAllowances());
// ...
// work it out