From 8c5172b8ab407b79db53ce46271d72d8a3f9c19f Mon Sep 17 00:00:00 2001 From: jsdelfino Date: Sat, 30 Jan 2010 08:06:07 +0000 Subject: Correctly pass property values to component implementations. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@904734 13f79535-47bb-0310-9956-ffa450edef68 --- sca-cpp/trunk/modules/java/eval.hpp | 19 ++++++++++--------- sca-cpp/trunk/modules/java/java-test.cpp | 22 ++++++++++++++++------ .../modules/java/org/apache/tuscany/Service.java | 4 ++-- sca-cpp/trunk/modules/java/test/CalcImpl.java | 5 +++++ sca-cpp/trunk/test/store-cpp/fruits-catalog.cpp | 10 +++++----- sca-cpp/trunk/test/store-java/Makefile.am | 2 +- .../test/store-java/store/FruitsCatalogImpl.java | 12 +++++++----- .../test/store-java/store/ShoppingCartImpl.java | 2 +- sca-cpp/trunk/test/store-python/fruits-catalog.py | 8 ++++---- sca-cpp/trunk/test/store-scheme/fruits-catalog.scm | 8 ++++---- 10 files changed, 55 insertions(+), 37 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& 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 expr = cons(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 expr = func == "eval"? (list)car(jarrayToValues(jl.jr, args)) : cons(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&)>(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& args) { bool testEvalLambda() { gc_scoped_pool pool; - const failable obj = readClass(javaRuntime, ".", "test.CalcImpl"); - assert(hasContent(obj)); - const value tcel = mklist("add", 3, 4, lambda&)>(add)); - const failable r = evalClass(javaRuntime, tcel, content(obj)); - assert(hasContent(r)); - assert(content(r) == value(7)); + { + const failable obj = readClass(javaRuntime, ".", "test.CalcImpl"); + assert(hasContent(obj)); + const value tcel = mklist("add", 3, 4, lambda&)>(add)); + const failable r = evalClass(javaRuntime, tcel, content(obj)); + assert(hasContent(r)); + assert(content(r) == value(7)); + } + { + const failable obj = readClass(javaRuntime, ".", "test.CalcImpl"); + assert(hasContent(obj)); + const value tcel = mklist("addEval", 3, 4, lambda&)>(add)); + const failable 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 apply(Object... params); + 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; } diff --git a/sca-cpp/trunk/test/store-cpp/fruits-catalog.cpp b/sca-cpp/trunk/test/store-cpp/fruits-catalog.cpp index 4c93b2a58e..f0c9472177 100644 --- a/sca-cpp/trunk/test/store-cpp/fruits-catalog.cpp +++ b/sca-cpp/trunk/test/store-cpp/fruits-catalog.cpp @@ -50,8 +50,8 @@ const list mkfruit(const string& name, const string& code, const string& mklist("javaClass", string("services.Item")) + mklist("name", name) + mklist("currencyCode", code) + mklist("currencySymbol", symbol) + mklist("price", price); } -const failable get(const lambda&)> converter) { - const string currency("USD"); +const failable get(const lambda&)> converter, const lambda&)> currencyCode) { + const string currency(currencyCode(list())); const string symbol(converter(mklist("symbol", currency))); const lambda conv(convert(converter, currency)); @@ -64,7 +64,7 @@ const failable get(const lambda&)> converter) { /** * TODO remove this JSON-RPC specific function. */ -const failable listMethods(unused const lambda&)> converter) { +const failable listMethods(unused const lambda&)> converter, unused const lambda&)> currencyCode) { return value(mklist(string("Service.get"))); } @@ -76,9 +76,9 @@ extern "C" { const tuscany::value apply(const tuscany::list& params) { const tuscany::value func(car(params)); if (func == "get") - return tuscany::store::get(cadr(params)); + return tuscany::store::get(cadr(params), caddr(params)); if (func == "listMethods") - return tuscany::store::listMethods(cadr(params)); + return tuscany::store::listMethods(cadr(params), caddr(params)); return tuscany::mkfailure(tuscany::string("Function not supported: ") + func); } diff --git a/sca-cpp/trunk/test/store-java/Makefile.am b/sca-cpp/trunk/test/store-java/Makefile.am index a381f0a3fd..80972a0acc 100644 --- a/sca-cpp/trunk/test/store-java/Makefile.am +++ b/sca-cpp/trunk/test/store-java/Makefile.am @@ -19,7 +19,7 @@ JAVAROOT = ${top_builddir}/test/store-java if WANT_JAVA -AM_JAVACFLAGS = -classpath ${top_builddir}/modules/java/libmod-tuscany-java-${PACKAGE_VERSION}.jar +AM_JAVACFLAGS = -cp ${top_builddir}/modules/java/libmod-tuscany-java-${PACKAGE_VERSION}.jar:${JAVAROOT} noinst_JAVA = store/*.java diff --git a/sca-cpp/trunk/test/store-java/store/FruitsCatalogImpl.java b/sca-cpp/trunk/test/store-java/store/FruitsCatalogImpl.java index 3caa785416..bb75926b1f 100644 --- a/sca-cpp/trunk/test/store-java/store/FruitsCatalogImpl.java +++ b/sca-cpp/trunk/test/store-java/store/FruitsCatalogImpl.java @@ -19,6 +19,7 @@ package store; +import org.apache.tuscany.Service; import static org.apache.tuscany.IterableUtil.list; /** @@ -29,15 +30,16 @@ public class FruitsCatalogImpl { /** * Returns the catalog. */ - public Iterable get(final CurrencyConverter converter) { + public Iterable get(final CurrencyConverter converter, final Service currencyCode) { + final String code = currencyCode.eval(); + class Converter { Double convert(Double price) { - return converter.convert("USD", "USD", price); + return converter.convert(code, "USD", price); } }; + Converter c = new Converter(); - - String code = "USD"; String symbol = converter.symbol(code); return list( @@ -50,7 +52,7 @@ public class FruitsCatalogImpl { /** * TODO remove this JSON-RPC specific function. */ - public Iterable listMethods(final CurrencyConverter converter) { + public Iterable listMethods(final CurrencyConverter converter, final Service currencyCode) { return list("Service.get"); } diff --git a/sca-cpp/trunk/test/store-java/store/ShoppingCartImpl.java b/sca-cpp/trunk/test/store-java/store/ShoppingCartImpl.java index 30ee59932a..7937b097ce 100644 --- a/sca-cpp/trunk/test/store-java/store/ShoppingCartImpl.java +++ b/sca-cpp/trunk/test/store-java/store/ShoppingCartImpl.java @@ -123,7 +123,7 @@ public class ShoppingCartImpl { /** * TODO remove this JSON-RPC specific function. */ - public Iterable listMethods(final CurrencyConverter converter) { + public Iterable listMethods(final Service cache) { return list("Service.gettotal"); } diff --git a/sca-cpp/trunk/test/store-python/fruits-catalog.py b/sca-cpp/trunk/test/store-python/fruits-catalog.py index ea71e93b22..6bc0bca1d7 100644 --- a/sca-cpp/trunk/test/store-python/fruits-catalog.py +++ b/sca-cpp/trunk/test/store-python/fruits-catalog.py @@ -1,9 +1,9 @@ # Catalog implementation -def get(converter): +def get(converter, currencyCode): + code = currencyCode() def convert(price): - return converter("convert", "USD", "USD", price) - code = "USD" + return converter("convert", "USD", code, price) symbol = converter("symbol", code) return ( (("'javaClass", "services.Item"), ("'name", "Apple"), ("'currencyCode", code), ("'currencySymbol", symbol), ("'price", convert(2.99))), @@ -12,6 +12,6 @@ def get(converter): ) # TODO remove these JSON-RPC specific functions -def listMethods(converter): +def listMethods(converter, currencyCode): return ("Service.get",) diff --git a/sca-cpp/trunk/test/store-scheme/fruits-catalog.scm b/sca-cpp/trunk/test/store-scheme/fruits-catalog.scm index 173bcbe9c0..f299e14650 100644 --- a/sca-cpp/trunk/test/store-scheme/fruits-catalog.scm +++ b/sca-cpp/trunk/test/store-scheme/fruits-catalog.scm @@ -1,8 +1,8 @@ ; Catalog implementation -(define (get converter) - (define (convert price) (converter "convert" "USD" "USD" price)) - (define code "USD") +(define (get converter currencyCode) + (define code (currencyCode)) + (define (convert price) (converter "convert" "USD" code price)) (define symbol (converter "symbol" code)) (list (list (list 'javaClass "services.Item") (list 'name "Apple") (list 'currencyCode code) (list 'currencySymbol symbol) (list 'price (convert 2.99))) @@ -12,5 +12,5 @@ ) ; TODO remove these JSON-RPC specific functions -(define (listMethods converter) (list "Service.get")) +(define (listMethods converter currencyCode) (list "Service.get")) -- cgit v1.2.3