Author: jsdelfino
Date: Sat Jan 30 08:06:07 2010
New Revision: 904734

URL: http://svn.apache.org/viewvc?rev=904734&view=rev
Log:
Correctly pass property values to component implementations.

Modified:
    tuscany/sca-cpp/trunk/modules/java/eval.hpp
    tuscany/sca-cpp/trunk/modules/java/java-test.cpp
    tuscany/sca-cpp/trunk/modules/java/org/apache/tuscany/Service.java
    tuscany/sca-cpp/trunk/modules/java/test/CalcImpl.java
    tuscany/sca-cpp/trunk/test/store-cpp/fruits-catalog.cpp
    tuscany/sca-cpp/trunk/test/store-java/Makefile.am
    tuscany/sca-cpp/trunk/test/store-java/store/FruitsCatalogImpl.java
    tuscany/sca-cpp/trunk/test/store-java/store/ShoppingCartImpl.java
    tuscany/sca-cpp/trunk/test/store-python/fruits-catalog.py
    tuscany/sca-cpp/trunk/test/store-scheme/fruits-catalog.scm

Modified: tuscany/sca-cpp/trunk/modules/java/eval.hpp
URL: 
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/java/eval.hpp?rev=904734&r1=904733&r2=904734&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/java/eval.hpp (original)
+++ tuscany/sca-cpp/trunk/modules/java/eval.hpp Sat Jan 30 08:06:07 2010
@@ -211,17 +211,15 @@
 
     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 @@
     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 @@
         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));
 }
 

Modified: tuscany/sca-cpp/trunk/modules/java/java-test.cpp
URL: 
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/java/java-test.cpp?rev=904734&r1=904733&r2=904734&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/java/java-test.cpp (original)
+++ tuscany/sca-cpp/trunk/modules/java/java-test.cpp Sat Jan 30 08:06:07 2010
@@ -77,12 +77,22 @@
 
 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;
 }
 

Modified: tuscany/sca-cpp/trunk/modules/java/org/apache/tuscany/Service.java
URL: 
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/java/org/apache/tuscany/Service.java?rev=904734&r1=904733&r2=904734&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/java/org/apache/tuscany/Service.java 
(original)
+++ tuscany/sca-cpp/trunk/modules/java/org/apache/tuscany/Service.java Sat Jan 
30 08:06:07 2010
@@ -56,8 +56,8 @@
     boolean deleteall();
     
     /**
-     * Apply a function.
+     * Evaluate an expression.
      */
-    <T> T apply(Object... params);
+    <T> T eval(Object... params);
     
 }

Modified: tuscany/sca-cpp/trunk/modules/java/test/CalcImpl.java
URL: 
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/java/test/CalcImpl.java?rev=904734&r1=904733&r2=904734&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/java/test/CalcImpl.java (original)
+++ tuscany/sca-cpp/trunk/modules/java/test/CalcImpl.java Sat Jan 30 08:06:07 
2010
@@ -21,6 +21,7 @@
 
 import java.util.List;
 import java.util.ArrayList;
+import org.apache.tuscany.Service;
 
 public class CalcImpl {
     
@@ -28,6 +29,10 @@
         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;
     }

Modified: tuscany/sca-cpp/trunk/test/store-cpp/fruits-catalog.cpp
URL: 
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/test/store-cpp/fruits-catalog.cpp?rev=904734&r1=904733&r2=904734&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/test/store-cpp/fruits-catalog.cpp (original)
+++ tuscany/sca-cpp/trunk/test/store-cpp/fruits-catalog.cpp Sat Jan 30 08:06:07 
2010
@@ -50,8 +50,8 @@
         mklist<value>("javaClass", string("services.Item")) + 
mklist<value>("name", name) + mklist<value>("currencyCode", code) + 
mklist<value>("currencySymbol", symbol) + mklist<value>("price", price);
 }
 
-const failable<value> get(const lambda<value(const list<value>&)> converter) {
-    const string currency("USD");
+const failable<value> get(const lambda<value(const list<value>&)> converter, 
const lambda<value(const list<value>&)> currencyCode) {
+    const string currency(currencyCode(list<value>()));
     const string symbol(converter(mklist<value>("symbol", currency)));
     const lambda<value(const value&)> conv(convert(converter, currency));
 
@@ -64,7 +64,7 @@
 /**
  * TODO remove this JSON-RPC specific function.
  */
-const failable<value> listMethods(unused const lambda<value(const 
list<value>&)> converter) {
+const failable<value> listMethods(unused const lambda<value(const 
list<value>&)> converter, unused const lambda<value(const list<value>&)> 
currencyCode) {
     return value(mklist<value>(string("Service.get")));
 }
 
@@ -76,9 +76,9 @@
 const tuscany::value apply(const tuscany::list<tuscany::value>& 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::value>(tuscany::string("Function not 
supported: ") + func);
 }
 

Modified: tuscany/sca-cpp/trunk/test/store-java/Makefile.am
URL: 
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/test/store-java/Makefile.am?rev=904734&r1=904733&r2=904734&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/test/store-java/Makefile.am (original)
+++ tuscany/sca-cpp/trunk/test/store-java/Makefile.am Sat Jan 30 08:06:07 2010
@@ -19,7 +19,7 @@
 
 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
 

Modified: tuscany/sca-cpp/trunk/test/store-java/store/FruitsCatalogImpl.java
URL: 
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/test/store-java/store/FruitsCatalogImpl.java?rev=904734&r1=904733&r2=904734&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/test/store-java/store/FruitsCatalogImpl.java 
(original)
+++ tuscany/sca-cpp/trunk/test/store-java/store/FruitsCatalogImpl.java Sat Jan 
30 08:06:07 2010
@@ -19,6 +19,7 @@
 
 package store;
 
+import org.apache.tuscany.Service;
 import static org.apache.tuscany.IterableUtil.list;
 
 /**
@@ -29,15 +30,16 @@
     /**
      * 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 @@
     /**
      * 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");
     }
     

Modified: tuscany/sca-cpp/trunk/test/store-java/store/ShoppingCartImpl.java
URL: 
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/test/store-java/store/ShoppingCartImpl.java?rev=904734&r1=904733&r2=904734&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/test/store-java/store/ShoppingCartImpl.java (original)
+++ tuscany/sca-cpp/trunk/test/store-java/store/ShoppingCartImpl.java Sat Jan 
30 08:06:07 2010
@@ -123,7 +123,7 @@
     /**
      * TODO remove this JSON-RPC specific function.
      */
-    public Iterable<?> listMethods(final CurrencyConverter converter) {
+    public Iterable<?> listMethods(final Service cache) {
         return list("Service.gettotal");
     }
     

Modified: tuscany/sca-cpp/trunk/test/store-python/fruits-catalog.py
URL: 
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/test/store-python/fruits-catalog.py?rev=904734&r1=904733&r2=904734&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/test/store-python/fruits-catalog.py (original)
+++ tuscany/sca-cpp/trunk/test/store-python/fruits-catalog.py Sat Jan 30 
08:06:07 2010
@@ -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 @@
   )
 
 # TODO remove these JSON-RPC specific functions
-def listMethods(converter):
+def listMethods(converter, currencyCode):
     return ("Service.get",)
 

Modified: tuscany/sca-cpp/trunk/test/store-scheme/fruits-catalog.scm
URL: 
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/test/store-scheme/fruits-catalog.scm?rev=904734&r1=904733&r2=904734&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/test/store-scheme/fruits-catalog.scm (original)
+++ tuscany/sca-cpp/trunk/test/store-scheme/fruits-catalog.scm Sat Jan 30 
08:06:07 2010
@@ -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"))
 


Reply via email to