diff options
Diffstat (limited to '')
-rw-r--r-- | sca-cpp/trunk/modules/java/eval.hpp | 19 | ||||
-rw-r--r-- | sca-cpp/trunk/modules/java/java-test.cpp | 22 | ||||
-rw-r--r-- | sca-cpp/trunk/modules/java/org/apache/tuscany/Service.java | 4 | ||||
-rw-r--r-- | sca-cpp/trunk/modules/java/test/CalcImpl.java | 5 |
4 files changed, 33 insertions, 17 deletions
diff --git a/sca-cpp/trunk/modules/java/eval.hpp b/sca-cpp/trunk/modules/java/eval.hpp index 9dbb50abb5..4272543506 100644 --- a/sca-cpp/trunk/modules/java/eval.hpp +++ b/sca-cpp/trunk/modules/java/eval.hpp @@ -211,17 +211,15 @@ public: const value operator()(const list<value>& expr) const { const value& op(car(expr)); + if (op == "equals") + return value(cadr(expr) == this); + if (op == "hashCode") + return value((double)(long)this); if (op == "toString") { ostringstream os; os << this; return value(string("org.apache.tuscany.InvocationHandler@") + (c_str(str(os)) + 2)); } - if (op == "hashCode") { - return value((double)(long)this); - } - if (op == "equals") { - return value(cadr(expr) == this); - } return func(expr); } @@ -247,8 +245,9 @@ jobject JNICALL nativeInvoke(JNIEnv* env, jobject self, unused jobject proxy, jo const value func(c); env->ReleaseStringUTFChars(s, c); - // Build the expression to evaluate - const list<value> expr = cons<value>(func, jarrayToValues(jl.jr, args)); + // Build the expression to evaluate, either (func, args[0], args[1], args[2]...) + // or just args[0] for the special eval(...) function + const list<value> expr = func == "eval"? (list<value>)car<value>(jarrayToValues(jl.jr, args)) : cons<value>(func, jarrayToValues(jl.jr, args)); debug(expr, "java::nativeInvoke::expr"); // Invoke the lambda function @@ -401,8 +400,10 @@ const value jobjectToValue(const JavaRuntime& jr, const jobject o) { return value((bool)jr.env->CallBooleanMethod(o, jr.booleanValue)); if (jr.env->IsSameObject(clazz, jr.doubleClass)) return value((double)jr.env->CallDoubleMethod(o, jr.doubleValue)); - if ((jr.env->IsAssignableFrom(clazz, jr.iterableClass))) + if (jr.env->IsAssignableFrom(clazz, jr.iterableClass)) return jiterableToValues(jr, o); + if (jr.env->IsAssignableFrom(clazz, jr.objectArrayClass)) + return jarrayToValues(jr, (jobjectArray)o); return lambda<value(const list<value>&)>(javaCallable(jr, o)); } diff --git a/sca-cpp/trunk/modules/java/java-test.cpp b/sca-cpp/trunk/modules/java/java-test.cpp index da73602f12..d050180be8 100644 --- a/sca-cpp/trunk/modules/java/java-test.cpp +++ b/sca-cpp/trunk/modules/java/java-test.cpp @@ -77,12 +77,22 @@ const value add(const list<value>& args) { bool testEvalLambda() { gc_scoped_pool pool; - const failable<JavaClass> obj = readClass(javaRuntime, ".", "test.CalcImpl"); - assert(hasContent(obj)); - const value tcel = mklist<value>("add", 3, 4, lambda<value(const list<value>&)>(add)); - const failable<value> r = evalClass(javaRuntime, tcel, content(obj)); - assert(hasContent(r)); - assert(content(r) == value(7)); + { + const failable<JavaClass> obj = readClass(javaRuntime, ".", "test.CalcImpl"); + assert(hasContent(obj)); + const value tcel = mklist<value>("add", 3, 4, lambda<value(const list<value>&)>(add)); + const failable<value> r = evalClass(javaRuntime, tcel, content(obj)); + assert(hasContent(r)); + assert(content(r) == value(7)); + } + { + const failable<JavaClass> obj = readClass(javaRuntime, ".", "test.CalcImpl"); + assert(hasContent(obj)); + const value tcel = mklist<value>("addEval", 3, 4, lambda<value(const list<value>&)>(add)); + const failable<value> r = evalClass(javaRuntime, tcel, content(obj)); + assert(hasContent(r)); + assert(content(r) == value(7)); + } return true; } diff --git a/sca-cpp/trunk/modules/java/org/apache/tuscany/Service.java b/sca-cpp/trunk/modules/java/org/apache/tuscany/Service.java index 6150b7d1cd..eedba5f46f 100644 --- a/sca-cpp/trunk/modules/java/org/apache/tuscany/Service.java +++ b/sca-cpp/trunk/modules/java/org/apache/tuscany/Service.java @@ -56,8 +56,8 @@ public interface Service { boolean deleteall(); /** - * Apply a function. + * Evaluate an expression. */ - <T> T apply(Object... params); + <T> T eval(Object... params); } diff --git a/sca-cpp/trunk/modules/java/test/CalcImpl.java b/sca-cpp/trunk/modules/java/test/CalcImpl.java index 37dc642e75..5337afe460 100644 --- a/sca-cpp/trunk/modules/java/test/CalcImpl.java +++ b/sca-cpp/trunk/modules/java/test/CalcImpl.java @@ -21,6 +21,7 @@ package test; import java.util.List; import java.util.ArrayList; +import org.apache.tuscany.Service; public class CalcImpl { @@ -28,6 +29,10 @@ public class CalcImpl { return adder.add(x, y); } + public Double addEval(Double x, Double y, Service adder) { + return adder.eval("add", x, y); + } + public Double mult(Double x, Double y) { return x * y; } |