commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kukosa, Tomas" <tomas.kuk...@siemens-enterprise.com>
Subject RE: [jexl] Unexpected Integer -> Byte conversion
Date Mon, 09 Jul 2012 13:26:30 GMT
Hi Henrib,

please try it with code below.

The result is:
EXPR01 result=null ## NOT OK
EXPR02 result=22 ## OK

Is anywhere available built 3.0 SNAPSHOT jar file or do I need to build it myself from SVN
repository?

Best regards,
  Tomas

--------------------------
public class Test01 {

	private final static String SCR_INIT = "$TAB = { 1:11, 2:22, 3:33}; IDX=2;";
	private final static String[] SCR_FN01_PARS = { "idx" };
	private final static String SCR_FN01 = "var x = $TAB[idx]; return x;";
	private final static String SCR_EXPR01 = "fn01(IDX)";
	private final static String SCR_FN02 = "var x = $TAB[1*idx]; return x;";
	private final static String SCR_EXPR02 = "fn02(IDX)";
	
	public static void main(String[] args) {
		JexlEngine jexl = new JexlEngine();
		JexlContext jc = new MapContext();
		Script script;
		Expression expr;
		Object result;

		script = jexl.createScript(SCR_FN01, SCR_FN01_PARS);
		jc.set("fn01", script);
		script = jexl.createScript(SCR_FN02, SCR_FN01_PARS);
		jc.set("fn02", script);

		script = jexl.createScript(SCR_INIT);
		script.execute(jc);
		
		expr = jexl.createExpression(SCR_EXPR01);
		result = expr.evaluate(jc);
		System.out.print(String.format("EXPR01 result=%s\n", result));
		
		expr = jexl.createExpression(SCR_EXPR02);
		result = expr.evaluate(jc);
		System.out.print(String.format("EXPR02 result=%s\n", result));
		
	}
}

-----Original Message-----
From: henrib [mailto:henrib@apache.org] 
Sent: Thursday, July 05, 2012 11:33 AM
To: user@commons.apache.org
Subject: Re: [jexl] Unexpected Integer -> Byte conversion

Hi Tomas,
Your previous issue (JEXL-135) has been solved in the trunk (2.1.2 and 3.0).
Not sure about this one, I can't reproduce it on the trunk using the
following test:

{code}

    public void test135() throws Exception {
        JexlEngine jexl = new JexlEngine();
        JexlContext jc = new MapContext();
        Script script;
        Object result;
        Map<Integer, Object> foo = new HashMap<Integer, Object>();
        foo.put(3, 42);
        jc.set("state", foo);

        script = jexl.createScript("var y = state[3]; y");
        result = script.execute(jc, foo);
        assertEquals(42, result);

        jc.set("a", 3);
        script = jexl.createScript("var y = state[a]; y");
        result = script.execute(jc, foo);
        assertEquals(42, result);

        jc.set("a", 2);
        script = jexl.createScript("var y = state[a + 1]; y");
        result = script.execute(jc, foo);
        assertEquals(42, result);

        jc.set("a", 2);
        jc.set("b", 1);
        script = jexl.createScript("var y = state[a + b]; y");
        result = script.execute(jc, foo);
        assertEquals(42, result);

        script = jexl.createScript("var y = state[3]; y", "state");
        result = script.execute(null, foo, 3);
        assertEquals(42, result);

        script = jexl.createScript("var y = state[a]; y", "state", "a");
        result = script.execute(null, foo, 3);
        assertEquals(42, result);

        script = jexl.createScript("var y = state[a + 1]; y", "state", "a");
        result = script.execute(null, foo, 2);
        assertEquals(42, result);

        script = jexl.createScript("var y = state[a + b]; y", "state", "a",
"b");
        result = script.execute(null, foo, 2, 1);
        assertEquals(42, result);
    }
{code}
Let me know what I'm missing.
Regards
Henrib

PS: If you are starting/evaluating to use JEXL and if you can, I'd suggest
you use the 3.0 SNAPSHOT (published a new one today).


--
View this message in context: http://apache-commons.680414.n4.nabble.com/jexl-Unexpected-Integer-Byte-conversion-tp4635879p4635902.html
Sent from the Commons - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message