A problem with condition evaluating
| Newsgroups | gmane.comp.java.enhydra.shark |
|---|---|
| Message-ID | <[email protected]> |
hi all,this problem maybe it's BeanShell's or Shark's.
When I set an evaluate-condition in xpdl file,the expression is:
--------------------------------------
isback && (backgroup=="billact_apply")
--------------------------------------
In the expression,isback is boolean type and backgroup is String type.
But I found that the return value was false when isback's value is true and backgroup's value equal "billact_apply",
so I download BeanShell's source code and debuging from the evaluateExpression method of the org.enhydra.shark.scripting.BshEvaluator.java.
I found BeanShell has some problem.
To affirm these,I test again. test code:
--------------------------------------
Interpreter interpreter1 = new Interpreter();
Interpreter interpreter2 = new Interpreter();
// >>>test 1: as basic type
interpreter1.set("isback", true);
interpreter1.set("backgroup", "billact_apply");
System.out.println(interpreter1.eval("isback && (backgroup==\"billact_apply\")"));
// >>>test 2: As Object type,like the org.enhydra.shark.scripting.BshEvaluator.prepareContext(Interpreter interpreter, Map context)
java.lang.Object value1 = new Boolean(true);
interpreter2.set("isback", value1);
java.lang.Object value2 = new String("billact_apply");// new StringBuffer("billact_apply");
interpreter2.set("backgroup", value2);
System.out.println(interpreter2.eval("isback && (backgroup==\"billact_apply\")"));
--------------------------------------
run test code,the return value is:
--------------------------------------
true
false
--------------------------------------
When I modified bsh.BSHBinaryExpression.java code:
...
switch (kind) {
case EQ:
return new Primitive((lhs == rhs));
case NE:
return new Primitive((lhs != rhs));
...
changed to:
...
switch (kind) {
case EQ:
if (lhs instanceof String || rhs instanceof String)
return new Primitive(lhs.equals(rhs));
else
return new Primitive((lhs == rhs));
case NE:
if (lhs instanceof String || rhs instanceof String)
return new Primitive(!lhs.equals(rhs));
else
return new Primitive((lhs != rhs));
...
And then run test code again,the return value is:
--------------------------------------
true
true
--------------------------------------
In addition,Can update the bsh.jar?Now Shark's is bsh-1.2b8.jar,the current release is bsh-2.0b4.jar.
message-footer.txt
(text/plain, 271 B)
-- You receive this message as a subscriber of the [email protected] mailing list. To unsubscribe: mailto:[email protected] For general help: mailto:[email protected]?subject=help ObjectWeb mailing lists service home page: http://www.objectweb.org/wws