Support python method invocation style on references, ref.func(...) in addition to ref('func', ...). Minor cleanup of the various samples, renamed gettotal to total and getcatalog to items, for consistency with the python sample.

git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1026939 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
jsdelfino 2010-10-25 03:18:16 +00:00
commit a2a2cb76e9
62 changed files with 307 additions and 218 deletions

View file

@ -50,7 +50,7 @@ const list<value> mkfruit(const string& name, const string& code, const string&
mklist<value>("name", name) + mklist<value>("currencyCode", code) + mklist<value>("currencySymbol", symbol) + mklist<value>("price", price);
}
const failable<value> getcatalog(const lambda<value(const list<value>&)> converter, const lambda<value(const list<value>&)> currencyCode) {
const failable<value> items(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));
@ -68,8 +68,8 @@ extern "C" {
const tuscany::value apply(const tuscany::list<tuscany::value>& params) {
const tuscany::value func(car(params));
if (func == "getcatalog")
return tuscany::store::getcatalog(cadr(params), caddr(params));
if (func == "items")
return tuscany::store::items(cadr(params), caddr(params));
return tuscany::mkfailure<tuscany::value>();
}

View file

@ -36,7 +36,7 @@ var shoppingTotal = new tuscany.sca.Reference("shoppingTotal");
var catalogItems;
function catalog_getcatalogResponse(items, exception) {
function catalog_itemsResponse(items, exception) {
if (exception){
alert(exception.message);
return;
@ -64,11 +64,11 @@ function shoppingCart_getResponse(feed) {
}
document.getElementById("shoppingCart").innerHTML = list;
shoppingTotal.apply("gettotal", shoppingTotal_gettotalResponse);
shoppingTotal.apply("total", shoppingTotal_totalResponse);
}
}
function shoppingTotal_gettotalResponse(total, exception) {
function shoppingTotal_totalResponse(total, exception) {
if (exception) {
alert(exception.message);
return;
@ -119,7 +119,7 @@ function deleteCart() {
function init() {
try {
catalog.apply("getcatalog", catalog_getcatalogResponse);
catalog.apply("items", catalog_itemsResponse);
shoppingCart.get("", shoppingCart_getResponse);
} catch(e){
alert(e);

View file

@ -1 +0,0 @@
{"id": 1, "method": "getcatalog", "params": []}

View file

@ -1 +0,0 @@
{"id":1,"result":[{"name":"Apple","currencyCode":"USD","currencySymbol":"$","price":2.99},{"name":"Orange","currencyCode":"USD","currencySymbol":"$","price":3.55},{"name":"Pear","currencyCode":"USD","currencySymbol":"$","price":1.55}]}

View file

@ -1 +1 @@
{"id":1,"result":[{"name":"Mango","currencyCode":"USD","currencySymbol":"$","price":2.99},{"name":"Passion","currencyCode":"USD","currencySymbol":"$","price":3.55},{"name":"Kiwi","currencyCode":"USD","currencySymbol":"$","price":1.55}]}
{"id":1,"result":[{"name":"Apple","currencyCode":"USD","currencySymbol":"$","price":2.99},{"name":"Orange","currencyCode":"USD","currencySymbol":"$","price":3.55},{"name":"Pear","currencyCode":"USD","currencySymbol":"$","price":1.55}]}

View file

@ -32,8 +32,8 @@ rc=$?
# Test Catalog
if [ "$rc" = "0" ]; then
$curl_prefix/bin/curl http://localhost:8090/references/Store/catalog -X POST -H "Content-type: application/json-rpc" --data @htdocs/test/getcatalog-request.txt >tmp/getcatalog-result.txt 2>/dev/null
diff tmp/getcatalog-result.txt htdocs/test/getcatalog-result.txt
$curl_prefix/bin/curl http://localhost:8090/references/Store/catalog -X POST -H "Content-type: application/json-rpc" --data @htdocs/test/items-request.txt >tmp/items-result.txt 2>/dev/null
diff tmp/items-result.txt htdocs/test/items-result.txt
rc=$?
fi

View file

@ -109,7 +109,7 @@ const double sum(const list<value>& items) {
/**
* Return the total price of the items in the cart.
*/
const failable<value> gettotal(const lambda<value(const list<value>&)> cache) {
const failable<value> total(const lambda<value(const list<value>&)> cache) {
const list<value> cart(getcart(cartId, cache));
return value(sum(cart));
}
@ -127,8 +127,8 @@ const tuscany::value apply(const tuscany::list<tuscany::value>& params) {
return tuscany::store::get(cadr(params), caddr(params));
if (func == "delete")
return tuscany::store::del(cadr(params), caddr(params));
if (func == "gettotal")
return tuscany::store::gettotal(cadr(params));
if (func == "total")
return tuscany::store::total(cadr(params));
return tuscany::mkfailure<tuscany::value>();
}