summaryrefslogtreecommitdiffstats
path: root/sca-cpp/trunk
diff options
context:
space:
mode:
authorjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2010-02-22 06:08:34 +0000
committerjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2010-02-22 06:08:34 +0000
commit8c771c8ecd9bdc6b3ef0d5417db9bb9917b65fa9 (patch)
treea3671bc719d351a822b3728323e6456f163af2c3 /sca-cpp/trunk
parentd11cbfda813c7c6b32c06ddb33242fe3c82514eb (diff)
Moved component start calls from HTTPD postConfig to childInit, to give components an opportunity to start and setup connections and resources in each HTTPD child process. Adjusted utility components and test cases to this change. Minor code cleanup of Java components and integration tests.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@912491 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-cpp/trunk')
-rw-r--r--sca-cpp/trunk/components/cache/mcache.cpp2
-rw-r--r--sca-cpp/trunk/components/chat/chat.composite2
-rw-r--r--sca-cpp/trunk/components/chat/chatter.cpp4
-rw-r--r--sca-cpp/trunk/components/chat/xmpp.hpp3
-rw-r--r--sca-cpp/trunk/components/queue/queue-listener.cpp8
-rw-r--r--sca-cpp/trunk/components/webservice/webservice-client.cpp2
-rw-r--r--sca-cpp/trunk/kernel/value.hpp9
-rw-r--r--sca-cpp/trunk/modules/java/eval.hpp2
-rw-r--r--sca-cpp/trunk/modules/java/org/apache/tuscany/ClassLoader.java4
-rw-r--r--sca-cpp/trunk/modules/java/org/apache/tuscany/IterableUtil.java5
-rw-r--r--sca-cpp/trunk/modules/java/test/CalcImpl.java31
-rw-r--r--sca-cpp/trunk/modules/python/eval.hpp2
-rw-r--r--sca-cpp/trunk/modules/scheme/primitive.hpp10
-rw-r--r--sca-cpp/trunk/modules/server/impl-test.cpp2
-rw-r--r--sca-cpp/trunk/modules/server/mod-cpp.hpp4
-rw-r--r--sca-cpp/trunk/modules/server/mod-eval.hpp47
-rw-r--r--sca-cpp/trunk/modules/server/server-test.scm4
-rw-r--r--sca-cpp/trunk/test/store-cpp/shopping-cart.cpp39
-rw-r--r--sca-cpp/trunk/test/store-java/store/FruitsCatalogImpl.java25
-rw-r--r--sca-cpp/trunk/test/store-java/store/ShoppingCartImpl.java85
-rw-r--r--sca-cpp/trunk/test/store-python/shopping-cart.py26
-rw-r--r--sca-cpp/trunk/test/store-scheme/shopping-cart.scm33
22 files changed, 175 insertions, 174 deletions
diff --git a/sca-cpp/trunk/components/cache/mcache.cpp b/sca-cpp/trunk/components/cache/mcache.cpp
index 50b642106f..782de605c6 100644
--- a/sca-cpp/trunk/components/cache/mcache.cpp
+++ b/sca-cpp/trunk/components/cache/mcache.cpp
@@ -125,7 +125,7 @@ extern "C" {
const tuscany::value apply(const tuscany::list<tuscany::value>& params) {
const tuscany::value func(car(params));
- if (func == "start" || func == "restart")
+ if (func == "start")
return tuscany::mcache::start(cdr(params));
return tuscany::mkfailure<tuscany::value>();
}
diff --git a/sca-cpp/trunk/components/chat/chat.composite b/sca-cpp/trunk/components/chat/chat.composite
index f02eed1418..569dbfc4b2 100644
--- a/sca-cpp/trunk/components/chat/chat.composite
+++ b/sca-cpp/trunk/components/chat/chat.composite
@@ -46,7 +46,7 @@
<service name="print">
<t:binding.http uri="print"/>
</service>
- <reference name="report" target="print-sender"/>
+ <reference name="report" target="print-chatter"/>
</component>
</composite>
diff --git a/sca-cpp/trunk/components/chat/chatter.cpp b/sca-cpp/trunk/components/chat/chatter.cpp
index 5a6d4909df..95f2d40077 100644
--- a/sca-cpp/trunk/components/chat/chatter.cpp
+++ b/sca-cpp/trunk/components/chat/chatter.cpp
@@ -110,7 +110,7 @@ public:
// Disconnect and shutdown the worker thread
disconnect(const_cast<XMPPClient&>(xc));
- shutdown(const_cast<worker&>(w));
+ cancel(const_cast<worker&>(w));
debug("chat::chatter::stopped");
return failable<value>(value(lambda<value(const list<value>&)>()));
@@ -154,7 +154,7 @@ extern "C" {
const tuscany::value apply(const tuscany::list<tuscany::value>& params) {
const tuscany::value func(car(params));
- if (func == "start" || func == "restart")
+ if (func == "start")
return tuscany::chat::start(cdr(params));
return tuscany::mkfailure<tuscany::value>();
}
diff --git a/sca-cpp/trunk/components/chat/xmpp.hpp b/sca-cpp/trunk/components/chat/xmpp.hpp
index 0f84d5ec4a..34ab13ed98 100644
--- a/sca-cpp/trunk/components/chat/xmpp.hpp
+++ b/sca-cpp/trunk/components/chat/xmpp.hpp
@@ -318,7 +318,8 @@ const failable<bool> listen(const lambda<failable<bool>(const value&, const valu
debug("chat::listen");
xc.listener = listener;
xmpp_handler_add(xc.conn, messageHandler, NULL, "message", NULL, &xc);
- while(xc.connected && !isNil(xc.listener))
+ xc.ctx->loop_status = XMPP_LOOP_RUNNING;
+ while(xc.connected && !isNil(xc.listener) && xc.ctx->loop_status == XMPP_LOOP_RUNNING)
xmpp_run_once(xc.ctx, 1000L);
return true;
}
diff --git a/sca-cpp/trunk/components/queue/queue-listener.cpp b/sca-cpp/trunk/components/queue/queue-listener.cpp
index 57a63b620c..d714101583 100644
--- a/sca-cpp/trunk/components/queue/queue-listener.cpp
+++ b/sca-cpp/trunk/components/queue/queue-listener.cpp
@@ -100,9 +100,9 @@ public:
debug("queue::listener::stop");
// TODO check why stop() and close() hang in child processes
- //stop(const_cast<QpidSubscription&>(qsub));
- //close(const_cast<QpidSession&>(qs));
- //close(const_cast<QpidConnection&>(qc));
+ stop(const_cast<QpidSubscription&>(qsub));
+ close(const_cast<QpidSession&>(qs));
+ close(const_cast<QpidConnection&>(qc));
cancel(const_cast<worker&>(w));
debug("queue::listener::stopped");
@@ -150,7 +150,7 @@ extern "C" {
const tuscany::value apply(const tuscany::list<tuscany::value>& params) {
const tuscany::value func(car(params));
- if (func == "start" || func == "restart")
+ if (func == "start")
return tuscany::queue::start(cdr(params));
return tuscany::mkfailure<tuscany::value>();
}
diff --git a/sca-cpp/trunk/components/webservice/webservice-client.cpp b/sca-cpp/trunk/components/webservice/webservice-client.cpp
index cb756c015e..06db6c01b8 100644
--- a/sca-cpp/trunk/components/webservice/webservice-client.cpp
+++ b/sca-cpp/trunk/components/webservice/webservice-client.cpp
@@ -57,7 +57,7 @@ extern "C" {
const tuscany::value apply(const tuscany::list<tuscany::value>& params) {
const tuscany::value func(car(params));
- if (func == "start" || func == "restart")
+ if (func == "start")
return tuscany::mkfailure<tuscany::value>();
return tuscany::webservice::apply(func, cdr(params));
}
diff --git a/sca-cpp/trunk/kernel/value.hpp b/sca-cpp/trunk/kernel/value.hpp
index 1aafbe6d38..87d80a3e2a 100644
--- a/sca-cpp/trunk/kernel/value.hpp
+++ b/sca-cpp/trunk/kernel/value.hpp
@@ -557,6 +557,15 @@ template<typename T> const list<value> mkvalues(const list<T>& l) {
}
/**
+ * Convert a list of values to a list of other things.
+ */
+template<typename T> const list<T> convertValues(const list<value>& l) {
+ if (isNil(l))
+ return list<T>();
+ return cons<T>(car(l), convertValues<T>(cdr(l)));
+}
+
+/**
* Convert a path string value to a list of values.
*/
const list<string> pathTokens(const char* p) {
diff --git a/sca-cpp/trunk/modules/java/eval.hpp b/sca-cpp/trunk/modules/java/eval.hpp
index 58a1ab5ff9..741dda52ca 100644
--- a/sca-cpp/trunk/modules/java/eval.hpp
+++ b/sca-cpp/trunk/modules/java/eval.hpp
@@ -501,7 +501,7 @@ const failable<value> evalClass(const JavaRuntime& jr, const value& expr, const
// The start, stop, and restart functions are optional
const value fn = car<value>(expr);
- if (fn == "start" || fn == "restart" || "stop")
+ if (fn == "start" || fn == "stop")
return value(lambda<value(const list<value>&)>());
return mkfailure<value>(string("Couldn't find function: ") + car<value>(expr) + " : " + lastException(jr));
diff --git a/sca-cpp/trunk/modules/java/org/apache/tuscany/ClassLoader.java b/sca-cpp/trunk/modules/java/org/apache/tuscany/ClassLoader.java
index 78b9ec7d90..7fb6519472 100644
--- a/sca-cpp/trunk/modules/java/org/apache/tuscany/ClassLoader.java
+++ b/sca-cpp/trunk/modules/java/org/apache/tuscany/ClassLoader.java
@@ -19,8 +19,6 @@
package org.apache.tuscany;
-import static org.apache.tuscany.ClassLoader.Test.*;
-
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
@@ -36,7 +34,7 @@ class ClassLoader extends URLClassLoader {
}
/**
- * Create a class loader for an SCA contribution path.
+ * Create a class loader for an SCA contribution path.
*/
static java.lang.ClassLoader valueOf(final String path) throws MalformedURLException {
return new ClassLoader(new File(path).toURI().toURL());
diff --git a/sca-cpp/trunk/modules/java/org/apache/tuscany/IterableUtil.java b/sca-cpp/trunk/modules/java/org/apache/tuscany/IterableUtil.java
index ef18b856db..85872cba72 100644
--- a/sca-cpp/trunk/modules/java/org/apache/tuscany/IterableUtil.java
+++ b/sca-cpp/trunk/modules/java/org/apache/tuscany/IterableUtil.java
@@ -20,7 +20,6 @@
package org.apache.tuscany;
import static java.util.Arrays.*;
-import static org.apache.tuscany.IterableUtil.Test.*;
import java.util.AbstractList;
import java.util.ArrayList;
@@ -369,10 +368,10 @@ public class IterableUtil {
public static void main(final String[] args) {
System.out.println("Testing...");
-
+
Test.class.getClassLoader().setDefaultAssertionStatus(true);
new Test().testList();
-
+
System.out.println("OK");
}
diff --git a/sca-cpp/trunk/modules/java/test/CalcImpl.java b/sca-cpp/trunk/modules/java/test/CalcImpl.java
index 5337afe460..5bea01a43f 100644
--- a/sca-cpp/trunk/modules/java/test/CalcImpl.java
+++ b/sca-cpp/trunk/modules/java/test/CalcImpl.java
@@ -19,33 +19,34 @@
package test;
-import java.util.List;
import java.util.ArrayList;
+import java.util.List;
+
import org.apache.tuscany.Service;
public class CalcImpl {
-
- public Double add(Double x, Double y, Adder adder) {
+
+ public Double add(final Double x, final Double y, final Adder adder) {
return adder.add(x, y);
}
-
- public Double addEval(Double x, Double y, Service adder) {
+
+ public Double addEval(final Double x, final Double y, final Service adder) {
return adder.eval("add", x, y);
}
-
- public Double mult(Double x, Double y) {
+
+ public Double mult(final Double x, final Double y) {
return x * y;
}
-
- public Boolean even(Double x) {
- return (double)(((int)(double)x / 2) * 2) == (double)x;
+
+ public Boolean even(final Double x) {
+ return (double)((int)(double)x / 2 * 2) == (double)x;
}
-
- public Iterable<Double> square(Iterable<Double> l) {
- List r = new ArrayList();
- for (Double x: l)
+
+ public Iterable<Double> square(final Iterable<Double> l) {
+ final List<Double> r = new ArrayList<Double>();
+ for(final Double x : l)
r.add(x * x);
return r;
}
-
+
}
diff --git a/sca-cpp/trunk/modules/python/eval.hpp b/sca-cpp/trunk/modules/python/eval.hpp
index 136ecf6499..855804a5ae 100644
--- a/sca-cpp/trunk/modules/python/eval.hpp
+++ b/sca-cpp/trunk/modules/python/eval.hpp
@@ -241,7 +241,7 @@ const failable<value> evalScript(const value& expr, PyObject* script) {
// The start, stop, and restart functions are optional
const value fn = car<value>(expr);
- if (fn == "start" || fn == "restart" || fn == "stop") {
+ if (fn == "start" || fn == "stop") {
PyErr_Clear();
return value(lambda<value(const list<value>&)>());
}
diff --git a/sca-cpp/trunk/modules/scheme/primitive.hpp b/sca-cpp/trunk/modules/scheme/primitive.hpp
index e911c76f6c..fd5f3e9755 100644
--- a/sca-cpp/trunk/modules/scheme/primitive.hpp
+++ b/sca-cpp/trunk/modules/scheme/primitive.hpp
@@ -179,10 +179,6 @@ const value stopProc(unused const list<value>& args) {
return lambda<value(const list<value>&)>();
}
-const value restartProc(unused const list<value>& args) {
- return lambda<value(const list<value>&)>();
-}
-
const value applyPrimitiveProcedure(const value& proc, list<value>& args) {
const lambda<value(const list<value>&)> func(cadr((list<value>)proc));
return func(args);
@@ -236,8 +232,7 @@ const list<value> primitiveProcedureNames() {
+ "log"
+ "uuid"
+ "start"
- + "stop"
- + "restart";
+ + "stop";
}
const list<value> primitiveProcedureObjects() {
@@ -262,8 +257,7 @@ const list<value> primitiveProcedureObjects() {
+ primitiveProcedure(logProc)
+ primitiveProcedure(uuidProc)
+ primitiveProcedure(startProc)
- + primitiveProcedure(stopProc)
- + primitiveProcedure(restartProc);
+ + primitiveProcedure(stopProc);
}
const bool isFalse(const value& exp) {
diff --git a/sca-cpp/trunk/modules/server/impl-test.cpp b/sca-cpp/trunk/modules/server/impl-test.cpp
index 3fa1d65323..1bd0843745 100644
--- a/sca-cpp/trunk/modules/server/impl-test.cpp
+++ b/sca-cpp/trunk/modules/server/impl-test.cpp
@@ -34,7 +34,7 @@ namespace tuscany {
namespace server {
const failable<value> get(unused const list<value>& params) {
- return value(string("Hey"));
+ return value(mklist<value>("text/html", mklist<value>("Hey")));
}
const failable<value> post(unused const list<value>& params) {
diff --git a/sca-cpp/trunk/modules/server/mod-cpp.hpp b/sca-cpp/trunk/modules/server/mod-cpp.hpp
index 23b4941c26..b3828dd7d2 100644
--- a/sca-cpp/trunk/modules/server/mod-cpp.hpp
+++ b/sca-cpp/trunk/modules/server/mod-cpp.hpp
@@ -50,10 +50,10 @@ const list<value> failableResult(const value& func, const list<value>& v) {
return v;
// Report a failure with an empty reason as 'function not supported'
- // Except for the start, stop, and restart functions, which are optional
+ // Except for the start, and stop functions, which are optional
const value reason = cadr(v);
if (length(reason) == 0) {
- if (func == "start" || func == "restart" || func == "stop")
+ if (func == "start" || func == "stop")
return mklist<value>(lambda<value(const list<value>&)>());
return mklist<value>(value(), string("Function not supported: ") + func);
}
diff --git a/sca-cpp/trunk/modules/server/mod-eval.hpp b/sca-cpp/trunk/modules/server/mod-eval.hpp
index 03cce5aeb4..f319942f8d 100644
--- a/sca-cpp/trunk/modules/server/mod-eval.hpp
+++ b/sca-cpp/trunk/modules/server/mod-eval.hpp
@@ -104,15 +104,22 @@ const failable<int> get(request_rec* r, const lambda<value(const list<value>&)>&
return httpd::writeResult(json::jsonResult(id, content(val), cx), "application/json-rpc", r);
}
- // Evaluate the GET expression and return an ATOM entry or feed representing a resource
+ // Evaluate the GET expression
const list<value> path(pathValues(r->uri));
const failable<value> val = failableResult(impl(cons<value>("get", mklist<value>(cddr(path)))));
if (!hasContent(val))
return mkfailure<int>(reason(val));
+ const value c = content(val);
+
+ // Write returned content-type / content-list pair
+ if (isList(cadr<value>(c)))
+ return httpd::writeResult(convertValues<string>(cadr<value>(c)), car<value>(c), r);
+
+ // Write returned ATOM feed or entry
if (isNil(cddr(path)))
- return httpd::writeResult(atom::writeATOMFeed(atom::feedValuesToElements(content(val))), "application/atom+xml;type=feed", r);
+ return httpd::writeResult(atom::writeATOMFeed(atom::feedValuesToElements(c)), "application/atom+xml;type=feed", r);
else
- return httpd::writeResult(atom::writeATOMEntry(atom::entryValuesToElements(content(val))), "application/atom+xml;type=entry", r);
+ return httpd::writeResult(atom::writeATOMEntry(atom::entryValuesToElements(c)), "application/atom+xml;type=entry", r);
}
/**
@@ -375,7 +382,7 @@ const failable<list<value> > applyLifecycleExpr(const list<value>& impls, const
/**
* Configure the components declared in the deployed composite.
*/
-const failable<bool> confComponents(const string& lifecycle, ServerConf& sc, server_rec& server) {
+const failable<bool> confComponents(ServerConf& sc, server_rec& server) {
if (sc.contributionPath == "" || sc.compositeName == "")
return false;
@@ -383,20 +390,29 @@ const failable<bool> confComponents(const string& lifecycle, ServerConf& sc, ser
const failable<list<value> > comps = readComponents(sc.contributionPath + sc.compositeName);
if (!hasContent(comps))
return mkfailure<bool>(reason(comps));
- const list<value> starts = componentToImplementationAssoc(sc, server, content(comps));
+ sc.implementations = componentToImplementationAssoc(sc, server, content(comps));
+ debug(sc.implementations, "modeval::confComponents::implementations");
+
+ // Store the implementation lambda functions in a tree for fast retrieval
+ sc.implTree = mkbtree(sort(sc.implementations));
+ return true;
+}
+
+/**
+ * Start the components declared in the deployed composite.
+ */
+const failable<bool> startComponents(ServerConf& sc) {
- // Start or restart the component implementations
- // Record the returned lambda functions
- debug(starts, "modeval::confComponents::start");
- const failable<list<value> > impls = applyLifecycleExpr(starts, mklist<value>(c_str(lifecycle)));
+ // Start the components and record the returned implementation lambda functions
+ debug(sc.implementations, "modeval::startComponents::start");
+ const failable<list<value> > impls = applyLifecycleExpr(sc.implementations, mklist<value>("start"));
if (!hasContent(impls))
return mkfailure<bool>(reason(impls));
sc.implementations = content(impls);
- debug(sc.implementations, "modeval::confComponents::implementations");
+ debug(sc.implementations, "modeval::startComponents::implementations");
// Store the implementation lambda functions in a tree for fast retrieval
sc.implTree = mkbtree(sort(sc.implementations));
-
return true;
}
@@ -458,7 +474,7 @@ int postConfig(apr_pool_t *p, unused apr_pool_t *plog, unused apr_pool_t *ptemp,
debug(sc.wiringServerName, "modeval::postConfig::wiringServerName");
debug(sc.contributionPath, "modeval::postConfig::contributionPath");
debug(sc.compositeName, "modeval::postConfig::compositeName");
- const failable<bool> res = confComponents(count > 1? "restart" : "start", sc, *s);
+ const failable<bool> res = confComponents(sc, *s);
if (!hasContent(res)) {
cerr << "[Tuscany] Due to one or more errors mod_tuscany_eval loading failed. Causing apache to stop loading." << endl;
return -1;
@@ -481,6 +497,13 @@ void childInit(apr_pool_t* p, server_rec* s) {
exit(APEXIT_CHILDFATAL);
}
+ // Start the components in the child process
+ const failable<bool> res = startComponents(*sc);
+ if (!hasContent(res)) {
+ cerr << "[Tuscany] Due to one or more errors mod_tuscany_eval loading failed. Causing apache to stop loading." << endl;
+ exit(APEXIT_CHILDFATAL);
+ }
+
// Register a cleanup callback, called when the child is stopped or restarted
apr_pool_pre_cleanup_register(p, (void*)sc, serverCleanup);
}
diff --git a/sca-cpp/trunk/modules/server/server-test.scm b/sca-cpp/trunk/modules/server/server-test.scm
index 490f168170..7efb6ffeed 100644
--- a/sca-cpp/trunk/modules/server/server-test.scm
+++ b/sca-cpp/trunk/modules/server/server-test.scm
@@ -31,11 +31,11 @@
'("Item" "111" ((javaClass "services.Item") (name "Apple") (currencyCode "USD") (currencySymbol "$") (price 2.99))))
)
-(define (post coll entry)
+(define (post collection item)
'("123456789")
)
-(define (put id entry)
+(define (put id item)
true
)
diff --git a/sca-cpp/trunk/test/store-cpp/shopping-cart.cpp b/sca-cpp/trunk/test/store-cpp/shopping-cart.cpp
index 5dcbc88ee9..eaad0d3c77 100644
--- a/sca-cpp/trunk/test/store-cpp/shopping-cart.cpp
+++ b/sca-cpp/trunk/test/store-cpp/shopping-cart.cpp
@@ -41,7 +41,7 @@ const string cartId("1234");
* cart if not found.
*/
const list<value> getcart(const value& id, const lambda<value(const list<value>&)> cache) {
- const value cart = cache(mklist<value>("get", id));
+ const value cart = cache(mklist<value>("get", mklist<value>(id)));
if (isNil(cart))
return value(list<value>());
return (list<value>)cart;
@@ -61,19 +61,12 @@ const value uuid() {
/**
* Post a new item to the cart. Create a new cart if necessary.
*/
-const failable<value> post(const value& item, const lambda<value(const list<value>&)> cache) {
+const failable<value> post(unused const list<value>& collection, const value& item, const lambda<value(const list<value>&)> cache) {
const value id(uuid());
const list<value> newItem(mklist<value>(car<value>(item), id, caddr<value>(item)));
const list<value> cart(cons<value>(newItem, getcart(cartId, cache)));
- cache(mklist<value>("put", cartId, cart));
- return id;
-}
-
-/**
- * Return the contents of the cart.
- */
-const failable<value> getall(const lambda<value(const list<value>&)> cache) {
- return value(append(mklist<value>(string("Your Cart"), cartId), getcart(cartId, cache)));
+ cache(mklist<value>("put", mklist<value>(cartId), cart));
+ return value(mklist<value>(id));
}
/**
@@ -87,21 +80,21 @@ const value find(const value& id, const list<value>& cart) {
return find(id, cdr(cart));
}
-const failable<value> get(const value& id, const lambda<value(const list<value>&)> cache) {
- return find(id, getcart(cartId, cache));
-}
-
/**
- * Delete the whole cart.
+ * Return items from the cart.
*/
-const failable<value> delall(const lambda<value(const list<value>&)> cache) {
- return cache(mklist<value>("delete", cartId));
+const failable<value> get(const list<value>& id, const lambda<value(const list<value>&)> cache) {
+ if (isNil(id))
+ return value(append(mklist<value>(string("Your Cart"), cartId), getcart(cartId, cache)));
+ return find(car(id), getcart(cartId, cache));
}
/**
- * Delete an item from the cart.
+ * Delete items from the cart.
*/
-const failable<value> del(unused const value& id, unused const lambda<value(const list<value>&)> cache) {
+const failable<value> del(const list<value>& id, unused const lambda<value(const list<value>&)> cache) {
+ if (isNil(id))
+ return cache(mklist<value>("delete", mklist<value>(cartId)));
return value(true);
}
@@ -144,13 +137,9 @@ extern "C" {
const tuscany::value apply(const tuscany::list<tuscany::value>& params) {
const tuscany::value func(car(params));
if (func == "post")
- return tuscany::store::post(cadr(params), caddr(params));
- if (func == "getall")
- return tuscany::store::getall(cadr(params));
+ return tuscany::store::post(cadr(params), caddr(params), cadddr(params));
if (func == "get")
return tuscany::store::get(cadr(params), caddr(params));
- if (func == "deleteall")
- return tuscany::store::delall(cadr(params));
if (func == "delete")
return tuscany::store::del(cadr(params), caddr(params));
if (func == "gettotal")
diff --git a/sca-cpp/trunk/test/store-java/store/FruitsCatalogImpl.java b/sca-cpp/trunk/test/store-java/store/FruitsCatalogImpl.java
index bb75926b1f..2904bbd8a1 100644
--- a/sca-cpp/trunk/test/store-java/store/FruitsCatalogImpl.java
+++ b/sca-cpp/trunk/test/store-java/store/FruitsCatalogImpl.java
@@ -19,34 +19,33 @@
package store;
+import static org.apache.tuscany.IterableUtil.*;
+
import org.apache.tuscany.Service;
-import static org.apache.tuscany.IterableUtil.list;
/**
* Catalog component implementation.
*/
public class FruitsCatalogImpl {
-
+
/**
* Returns the catalog.
*/
public Iterable<?> get(final CurrencyConverter converter, final Service currencyCode) {
final String code = currencyCode.eval();
-
+
class Converter {
- Double convert(Double price) {
+ Double convert(final Double price) {
return converter.convert(code, "USD", price);
}
- };
+ }
- Converter c = new Converter();
- String symbol = converter.symbol(code);
-
- return list(
- list(list("'javaClass", "services.Item"), list("'name", "Apple"), list("'currencyCode", code), list("'currencySymbol", symbol), list("'price", c.convert(2.99))),
+ final Converter c = new Converter();
+ final String symbol = converter.symbol(code);
+
+ return list(list(list("'javaClass", "services.Item"), list("'name", "Apple"), list("'currencyCode", code), list("'currencySymbol", symbol), list("'price", c.convert(2.99))),
list(list("'javaClass", "services.Item"), list("'name", "Orange"), list("'currencyCode", code), list("'currencySymbol", symbol), list("'price", c.convert(3.55))),
- list(list("'javaClass", "services.Item"), list("'name", "Pear"), list("'currencyCode", code), list("'currencySymbol", symbol), list("'price", c.convert(1.55)))
- );
+ list(list("'javaClass", "services.Item"), list("'name", "Pear"), list("'currencyCode", code), list("'currencySymbol", symbol), list("'price", c.convert(1.55))));
}
/**
@@ -55,5 +54,5 @@ public class FruitsCatalogImpl {
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 7937b097ce..6620cbbbb0 100644
--- a/sca-cpp/trunk/test/store-java/store/ShoppingCartImpl.java
+++ b/sca-cpp/trunk/test/store-java/store/ShoppingCartImpl.java
@@ -19,25 +19,26 @@
package store;
-import org.apache.tuscany.Service;
-import java.lang.System;
-import java.util.UUID;
import static org.apache.tuscany.IterableUtil.*;
+import java.util.UUID;
+
+import org.apache.tuscany.Service;
+
/**
* Shopping cart component implementation.
*/
public class ShoppingCartImpl {
-
+
static String cartId = "1234";
-
+
/**
- * Get the shopping cart from the cache. Return an empty
- * cart if not found.
+ * Get the shopping cart from the cache. Return an empty cart if not found.
*/
- public Iterable<?> getcart(String id, Service cache) {
- Iterable<?> cart = cache.get(id);
- if (cart == null)
+ public Iterable<?> getcart(final String id, final Service cache) {
+ final Iterable<String> iid = list(id);
+ final Iterable<?> cart = cache.get(iid);
+ if(cart == null)
return list();
return cart;
}
@@ -52,72 +53,68 @@ public class ShoppingCartImpl {
/**
* Post a new item to the cart. Create a new cart if necessary.
*/
- public String post(Iterable<?> item, Service cache) {
- String id = uuid();
- Iterable<?> newItem = list(car(item), id, caddr(item));
- Iterable<?> cart = cons(newItem, getcart(cartId, cache));
- cache.put(cartId, cart);
- return id;
- }
-
- /**
- * Return the contents of the cart.
- */
- public Iterable<?> getall(Service cache) {
- return cons("Your Cart", cons(cartId, getcart(cartId, cache)));
+ public Iterable<String> post(final Iterable<String> collection, final Iterable<?> item, final Service cache) {
+ final String id = this.uuid();
+ final Iterable<?> newItem = list(car(item), id, caddr(item));
+ final Iterable<?> cart = cons(newItem, this.getcart(cartId, cache));
+ final Iterable<String> iid = list(cartId);
+ cache.put(iid, cart);
+ return list(id);
}
/**
* Find an item in the cart.
*/
- public Iterable<?> find(String id, Iterable<?> cart) {
- if (isNil(cart))
+ public Iterable<?> find(final String id, final Iterable<?> cart) {
+ if(isNil(cart))
return cons("Item", list("0", list()));
- if (id.equals(cadr(car(cart))))
+ if(id.equals(cadr(car(cart))))
return car(cart);
- return find(id, cdr(cart));
- }
-
- public Iterable<?> get(String id, Service cache) {
- return find(id, getcart(cartId, cache));
+ return this.find(id, cdr(cart));
}
/**
- * Delete the whole cart.
+ * Return items from the cart.
*/
- public Boolean deleteall(Service cache) {
- return cache.delete(cartId);
+ public Iterable<?> get(final Iterable<String> id, final Service cache) {
+ if(isNil(id))
+ return cons("Your Cart", cons(cartId, this.getcart(cartId, cache)));
+ return this.find((String)car(id), this.getcart(cartId, cache));
}
/**
- * Delete an item from the cart.
+ * Delete items from the cart.
*/
- public Boolean delete(String id, Service cache) {
+ public Boolean delete(final Iterable<String> id, final Service cache) {
+ if(isNil(id)) {
+ final Iterable<String> iid = list(cartId);
+ return cache.delete(iid);
+ }
return true;
}
/**
* Return the price of an item.
*/
- Double price(Iterable<?> item) {
+ Double price(final Iterable<?> item) {
return Double.valueOf((String)cadr(assoc("'price", caddr(item))));
}
/**
* Sum the prices of a list of items.
*/
- Double sum(Iterable<?> items) {
- if (isNil(items))
+ Double sum(final Iterable<?> items) {
+ if(isNil(items))
return 0.0;
- return price((Iterable<?>)car(items)) + sum(cdr(items));
+ return this.price((Iterable<?>)car(items)) + this.sum(cdr(items));
}
/**
* Return the total price of the items in the cart.
*/
- public Double gettotal(Service cache) {
- Iterable<?> cart = getcart(cartId, cache);
- return sum(cart);
+ public Double gettotal(final Service cache) {
+ final Iterable<?> cart = this.getcart(cartId, cache);
+ return this.sum(cart);
}
/**
@@ -126,5 +123,5 @@ public class ShoppingCartImpl {
public Iterable<?> listMethods(final Service cache) {
return list("Service.gettotal");
}
-
+
}
diff --git a/sca-cpp/trunk/test/store-python/shopping-cart.py b/sca-cpp/trunk/test/store-python/shopping-cart.py
index 083cd94fe0..988fe7bea6 100644
--- a/sca-cpp/trunk/test/store-python/shopping-cart.py
+++ b/sca-cpp/trunk/test/store-python/shopping-cart.py
@@ -24,21 +24,18 @@ cartId = "1234"
# Get the shopping cart from the cache
# Return an empty cart if not found
def getcart(id, cache):
- cart = cache("get", id)
+ cart = cache("get", (id,))
if cart is None:
return ()
return cart
# Post a new item to the cart, create a new cart if necessary
-def post(item, cache):
+def post(collection, item, cache):
id = str(uuid.uuid1())
cart = ((item[0], id, item[2]),) + getcart(cartId, cache)
- cache("put", cartId, cart)
- return id
+ cache("put", (cartId,), cart)
+ return (id,)
-# Return the content of the cart
-def getall(cache):
- return ("Your Cart", cartId) + getcart(cartId, cache)
# Find an item in the cart
def find(id, cart):
@@ -49,16 +46,16 @@ def find(id, cart):
else:
return find(id, cart[1:])
-# Get an item from the cart
+# Get items from the cart
def get(id, cache):
- return find(id, getcart(cartId, cache))
+ if id == ():
+ return ("Your Cart", cartId) + getcart(cartId, cache)
+ return find(id[0], getcart(cartId, cache))
-# Delete the whole cart
-def deleteall(cache):
- return cache("delete", cartId)
-
-# Delete an item from the cart
+# Delete items from the cart
def delete(id, cache):
+ if id == ():
+ return cache("delete", (cartId,))
return true
# Return the price of an item
@@ -79,4 +76,3 @@ def gettotal(cache):
# TODO remove these JSON-RPC specific functions
def listMethods(cache):
return ("Service.gettotal",)
-
diff --git a/sca-cpp/trunk/test/store-scheme/shopping-cart.scm b/sca-cpp/trunk/test/store-scheme/shopping-cart.scm
index f6a4cd3cfa..484044d420 100644
--- a/sca-cpp/trunk/test/store-scheme/shopping-cart.scm
+++ b/sca-cpp/trunk/test/store-scheme/shopping-cart.scm
@@ -22,24 +22,19 @@
; Get the shopping cart from the cache
; Return an empty cart if not found
(define (getcart id cache)
- (define cart (cache "get" id))
+ (define cart (cache "get" (list id)))
(if (nul cart)
(list)
cart)
)
; Post a new item to the cart, create a new cart if necessary
-(define (post item cache)
+(define (post collection item cache)
(define id (uuid))
(define newItem (list (car item) id (caddr item)))
(define cart (cons newItem (getcart cartId cache)))
- (cache "put" cartId cart)
- id
-)
-
-; Return the content of the cart
-(define (getall cache)
- (cons "Your Cart" (cons cartId (getcart cartId cache)))
+ (cache "put" (list cartId) cart)
+ (list id)
)
; Find an item in the cart
@@ -51,19 +46,20 @@
(find id (cdr cart))))
)
-; Get an item from the cart
+; Get items from the cart
(define (get id cache)
- (find id (getcart cartId cache))
+ (if (nul id)
+ (cons "Your Cart" (cons cartId (getcart cartId cache)))
+ (find (car id) (getcart cartId cache))
+ )
)
-; Delete the whole cart
-(define (deleteall cache)
- (cache "delete" cartId)
-)
-
-; Delete an item from the cart
+; Delete items from the cart
(define (delete id cache)
- true
+ (if (nul id)
+ (cache "delete" (list cartId))
+ true
+ )
)
; Return the price of an item
@@ -86,4 +82,3 @@
; TODO remove these JSON-RPC specific functions
(define (listMethods cache) (list "Service.gettotal"))
-