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

@ -15,21 +15,26 @@
# specific language governing permissions and limitations
# under the License.
import unittest
# JSON-RPC test case
def echo(x, ref):
return ref("echo", x)
e1 = ref("echo", x)
e2 = ref.echo(x)
assert e1 == e2
return e1
# ATOMPub test case
def get(id, ref):
return ref("get", id)
return ref.get(id);
def post(collection, item, ref):
return ref("post", collection, item)
return ref.post(collection, item)
def put(id, item, ref):
return ref("put", id, item)
return ref.put(id, item)
def delete(id, ref):
return ref("delete", id)
return ref.delete(id)

View file

@ -94,15 +94,54 @@ typedef struct {
lambda<value(const list<value>&)> func;
} pyLambda;
PyObject *mkPyLambda(const lambda<value(const list<value>&)>& l);
void pyLambda_dealloc(PyObject* self) {
PyMem_DEL(self);
}
const string pyRepr(PyObject * o) {
return PyString_AsString(PyObject_Repr(o));
}
PyObject* pyLambda_call(PyObject* self, PyObject* args, unused PyObject* kwds) {
debug("python::call");
const pyLambda* pyl = (pyLambda*)self;
const value result = pyl->func(pyTupleToValues(args));
debug(result, "python::call::result");
Py_DECREF(args);
PyObject *pyr = valueToPyObject(result);
Py_INCREF(pyr);
return pyr;
}
struct pyProxy {
const value name;
const lambda<value(const list<value>&)> func;
pyProxy(const value& name, const lambda<value(const list<value>&)>& func) : name(name), func(func) {
}
const value operator()(const list<value>& args) const {
debug(name, "python::proxy::name");
const value result = func(cons<value>(name, args));
debug(result, "python::proxy::result");
return result;
}
};
PyObject* pyLambda_getattr(PyObject *self, PyObject *attrname) {
const string name = PyString_AsString(attrname);
if (substr(name, 0, 1) == "_")
return PyObject_GenericGetAttr(self, attrname);
if (name == "eval")
return self;
const pyLambda* pyl = (pyLambda*)self;
debug(name, "python::getattr::name");
PyObject* pyr = mkPyLambda(pyProxy(name, pyl->func));
Py_INCREF(pyr);
return pyr;
}
@ -115,7 +154,9 @@ PyTypeObject pyLambda_type = {
(destructor)pyLambda_dealloc,
0, 0, 0, 0, 0, 0, 0, 0, 0,
(ternaryfunc)pyLambda_call,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0,
(binaryfunc)pyLambda_getattr,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0
@ -179,6 +220,7 @@ const list<value> pyTupleToValuesHelper(PyObject* o, const int i, const int size
}
const list<value> pyTupleToValues(PyObject* o) {
debug(pyRepr(o), "python::pyTupleToValues");
return pyTupleToValuesHelper(o, 0, PyTuple_Size(o));
}

View file

@ -15,21 +15,26 @@
# specific language governing permissions and limitations
# under the License.
import unittest
# JSON-RPC test case
def echo(x, ref):
return ref("echo", x)
e1 = ref("echo", x)
e2 = ref.echo(x)
assert e1 == e2
return e1
# ATOMPub test case
def get(id, ref):
return ref("get", id)
return ref.get(id)
def post(collection, item, ref):
return ref("post", collection, item)
return ref.post(collection, item)
def put(id, item, ref):
return ref("put", id, item)
return ref.put(id, item)
def delete(id, ref):
return ref("delete", id)
return ref.delete(id)

View file

@ -22,7 +22,7 @@ from httputil import *
def testClient():
c = mkclient("http://localhost:8090/wsgi")
assert c("echo", "Hey") == "Hey"
assert c.echo("Hey") == "Hey"
return True
if __name__ == "__main__":

View file

@ -56,6 +56,15 @@ class client:
return None
return jsonResultValue((res.read(),))
def __getattr__(self, name):
if name[0] == '_':
raise AttributeError()
if name == "eval":
return self
l = lambda *args: self.__call__(name, *args)
self.__dict__[name] = l
return l
def __repr__(self):
return repr((self.url,))

View file

@ -56,6 +56,15 @@ class component:
def __call__(self, func, *args):
return self.mod.__getattribute__(func)(*(args + self.proxies))
def __getattr__(self, name):
if name[0] == '_':
raise AttributeError()
if name == "eval":
return self
l = lambda *args: self.__call__(name, *args)
self.__dict__[name] = l
return l
def __repr__(self):
return repr((self.name, self.impl, self.mod, self.svcs, self.refs, self.props, self.proxies))
@ -186,19 +195,39 @@ def evalReference(r, comps):
return mkclient(t)
return nameToComponent(t, comps)
# Make a callable property
class property:
def __init__(self, name, l):
self.name = name
self.l = l
def __call__(self, *args):
return self.l(*args)
def __getattr__(self, name):
if name == "eval":
return self
raise AttributeError()
def __repr__(self):
return repr((self.name, self.l()))
def mkproperty(name, l):
return property(name, l)
# Evaluate a property, return a lambda function returning the property
# value. The host, user and email properties are configured with the
# values from the HTTP request, if any
def evalProperty(p):
if car(p) == "host":
return lambda: hostProperty(cadr(p), environ)
return mkproperty(car(p), lambda: hostProperty(cadr(p), environ))
if car(p) == "user":
return lambda: userProperty(cadr(p))
return mkproperty(car(p), lambda: userProperty(cadr(p)))
if car(p) == "nickname":
return lambda: nicknameProperty(cadr(p))
return mkproperty(car(p), lambda: nicknameProperty(cadr(p)))
if car(p) == "email":
return lambda: emailProperty(cadr(p))
return lambda: cadr(p)
return mkproperty(car(p), lambda: emailProperty(cadr(p)))
return mkproperty(car(p), lambda: cadr(p))
def currentUser():
try:

View file

@ -17,11 +17,11 @@
# Catalog implementation
def getcatalog(converter, currencyCode):
code = currencyCode()
def items(converter, currencyCode):
code = currencyCode.eval()
def convert(price):
return converter("convert", "USD", code, price)
symbol = converter("symbol", code)
return converter.convert("USD", code, price)
symbol = converter.symbol(code)
return (
(("'name", "Passion"), ("'currencyCode", code), ("'currencySymbol", symbol), ("'price", convert(2.99))),
(("'name", "Mango"), ("'currencyCode", code), ("'currencySymbol", symbol), ("'price", convert(3.55))),

View file

@ -21,12 +21,12 @@ import sys
# Convert a particular host and user email to a cart id
def cartid(host, email):
return ("cart", host(), email())
return ("cart", host.eval(), email.eval())
# 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
@ -35,7 +35,7 @@ def getcart(id, cache):
def post(collection, item, cache, host, email):
id = str(uuid.uuid1())
cart = ((item[0], id, item[2]),) + getcart(cartid(host, email), cache)
cache("put", cartid(host, email), cart)
cache.put(cartid(host, email), cart)
return (id,)
@ -51,13 +51,13 @@ def find(id, cart):
# Get items from the cart
def get(id, cache, host, email):
if id == ():
return ("Your Cart", email()) + getcart(cartid(host, email), cache)
return ("Your Cart", email.eval()) + getcart(cartid(host, email), cache)
return find(id[0], getcart(cartid(host, email), cache))
# Delete items from the cart
def delete(id, cache, host, email):
if id == ():
return cache("delete", cartid(host, email))
return cache.delete(cartid(host, email))
return True
# Return the price of an item
@ -71,6 +71,6 @@ def sum(items):
return price(items[0]) + sum(items[1:])
# Return the total price of the items in the cart
def gettotal(cache, host, email):
def total(cache, host, email):
return sum(getcart(cartid(host, email), cache))

View file

@ -18,23 +18,23 @@
# Store implementation
def post(item, catalog, shoppingCart, shoppingTotal):
return shoppingCart("post", item)
return shoppingCart.post(item)
def getall(catalog, shoppingCart, shoppingTotal):
return shoppingCart("getall")
return shoppingCart.getall()
def get(id, catalog, shoppingCart, shoppingTotal):
return shoppingCart("get", id)
return shoppingCart.get(id)
def getcatalog(catalog, shoppingCart, shoppingTotal):
return catalog("getcatalog")
def items(catalog, shoppingCart, shoppingTotal):
return catalog.items()
def gettotal(catalog, shoppingCart, shoppingTotal):
return shoppingCart("gettotal")
def total(catalog, shoppingCart, shoppingTotal):
return shoppingCart.total()
def deleteall(catalog, shoppingCart, shoppingTotal):
return shoppingCart("deleteall")
return shoppingCart.deleteall()
def delete(id, catalog, shoppingCart, shoppingTotal):
return shoppingCart("delete", id)
return shoppingCart.delete(id)

View file

@ -17,11 +17,11 @@
# Catalog implementation
def getcatalog(converter, currencyCode):
code = currencyCode()
def items(converter, currencyCode):
code = currencyCode.eval()
def convert(price):
return converter("convert", "USD", code, price)
symbol = converter("symbol", code)
return converter.convert("USD", code, price)
symbol = converter.symbol(code)
return (
(("'name", "Apple"), ("'currencyCode", code), ("'currencySymbol", symbol), ("'price", convert(2.99))),
(("'name", "Orange"), ("'currencyCode", code), ("'currencySymbol", symbol), ("'price", convert(3.55))),

View file

@ -21,12 +21,12 @@ import sys
# Convert a particular host and user email to a cart id
def cartid(host, email):
return ("cart", host(), email())
return ("cart", host.eval(), email.eval())
# 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
@ -35,7 +35,7 @@ def getcart(id, cache):
def post(collection, item, cache, host, email):
id = str(uuid.uuid1())
cart = ((item[0], id, item[2]),) + getcart(cartid(host, email), cache)
cache("put", cartid(host, email), cart)
cache.put(cartid(host, email), cart)
return (id,)
@ -51,13 +51,13 @@ def find(id, cart):
# Get items from the cart
def get(id, cache, host, email):
if id == ():
return ("Your Cart", email()) + getcart(cartid(host, email), cache)
return ("Your Cart", email.eval()) + getcart(cartid(host, email), cache)
return find(id[0], getcart(cartid(host, email), cache))
# Delete items from the cart
def delete(id, cache, host, email):
if id == ():
return cache("delete", cartid(host, email))
return cache.delete(cartid(host, email))
return True
# Return the price of an item
@ -71,6 +71,6 @@ def sum(items):
return price(items[0]) + sum(items[1:])
# Return the total price of the items in the cart
def gettotal(cache, host, email):
def total(cache, host, email):
return sum(getcart(cartid(host, email), cache))

View file

@ -18,23 +18,23 @@
# Store implementation
def post(item, catalog, shoppingCart, shoppingTotal):
return shoppingCart("post", item)
return shoppingCart.post(item)
def getall(catalog, shoppingCart, shoppingTotal):
return shoppingCart("getall")
return shoppingCart.getall()
def get(id, catalog, shoppingCart, shoppingTotal):
return shoppingCart("get", id)
return shoppingCart.get(id)
def getcatalog(catalog, shoppingCart, shoppingTotal):
return catalog("getcatalog")
def items(catalog, shoppingCart, shoppingTotal):
return catalog.items()
def gettotal(catalog, shoppingCart, shoppingTotal):
return shoppingCart("gettotal")
def total(catalog, shoppingCart, shoppingTotal):
return shoppingCart.total()
def deleteall(catalog, shoppingCart, shoppingTotal):
return shoppingCart("deleteall")
return shoppingCart.deletall()
def delete(id, catalog, shoppingCart, shoppingTotal):
return shoppingCart("delete", id)
return shoppingCart.delete(id)

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

@ -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

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

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>();
}

View file

@ -18,10 +18,10 @@
# Catalog implementation
def items(converter, currencyCode):
code = currencyCode()
code = currencyCode.eval()
def convert(price):
return converter("convert", "USD", code, price)
symbol = converter("symbol", code)
return converter.convert("USD", code, price)
symbol = converter.symbol(code)
return (
(("'name", "Platano"), ("'currencyCode", code), ("'currencySymbol", symbol), ("'price", convert(2.99))),
(("'name", "Banana"), ("'currencyCode", code), ("'currencySymbol", symbol), ("'price", convert(3.55))),

View file

@ -79,11 +79,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;

View file

@ -24,7 +24,7 @@ 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
@ -33,7 +33,7 @@ def getcart(id, cache):
def post(collection, item, cache, host, email):
id = str(uuid.uuid1())
cart = ((item[0], id, item[2]),) + getcart(cartId, cache)
cache("put", (cartId,), cart)
cache.put((cartId,), cart)
return (id,)
# Find an item in the cart
@ -54,7 +54,7 @@ def get(id, cache, host, email):
# Delete items from the cart
def delete(id, cache, host, email):
if id == ():
return cache("delete", (cartId,))
return cache.delete((cartId,))
return True
# Return the price of an item
@ -68,15 +68,15 @@ def sum(items):
return price(items[0]) + sum(items[1:])
# Return the total price of the items in the cart
def gettotal(cache, host, email):
def total(cache, host, email):
cart = getcart(cartId, cache)
return sum(cart)
# Return the email of the cart owner
def getemail(cache, host, email):
return email()
return email.eval()
# Return the host that the app is running on
def gethost(cache, host, email):
return host()
return host.eval()

View file

@ -18,23 +18,23 @@
# Store implementation
def post(item, catalog, shoppingCart, shoppingTotal):
return shoppingCart("post", item)
return shoppingCart.post(item)
def getall(catalog, shoppingCart, shoppingTotal):
return shoppingCart("getall")
return shoppingCart.getall()
def get(id, catalog, shoppingCart, shoppingTotal):
return shoppingCart("get", id)
return shoppingCart.get(id)
def items(catalog, shoppingCart, shoppingTotal):
return catalog("items")
return catalog.items()
def gettotal(catalog, shoppingCart, shoppingTotal):
return shoppingCart("gettotal")
def total(catalog, shoppingCart, shoppingTotal):
return shoppingCart.total()
def deleteall(catalog, shoppingCart, shoppingTotal):
return shoppingCart("deleteall")
return shoppingCart.deleteall()
def delete(id, catalog, shoppingCart, shoppingTotal):
return shoppingCart("delete", id)
return shoppingCart.delete(id)

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

@ -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 @../store-cpp/htdocs/test/getcatalog-request.txt >tmp/getcatalog-result.txt 2>/dev/null
diff tmp/getcatalog-result.txt ../store-cpp/htdocs/test/getcatalog-result.txt
$curl_prefix/bin/curl http://localhost:8090/references/Store/catalog -X POST -H "Content-type: application/json-rpc" --data @../store-cpp/htdocs/test/items-request.txt >tmp/items-result.txt 2>/dev/null
diff tmp/items-result.txt ../store-cpp/htdocs/test/items-result.txt
rc=$?
fi

View file

@ -31,7 +31,7 @@ public class FruitsCatalogImpl {
/**
* Returns the catalog.
*/
public Iterable<?> getcatalog(final CurrencyConverter converter, final Service currencyCode) {
public Iterable<?> items(final CurrencyConverter converter, final Service currencyCode) {
final String code = currencyCode.eval();
class Converter {

View file

@ -104,7 +104,7 @@ public class ShoppingCartImpl {
/**
* Return the total price of the items in the cart.
*/
public Double gettotal(final Service cache) {
public Double total(final Service cache) {
final Iterable<?> cart = this.getcart(cartId, cache);
return this.sum(cart);
}

View file

@ -17,7 +17,7 @@
; Catalog implementation
(define (getcatalog converter currencyCode)
(define (items converter currencyCode)
(define code (currencyCode))
(define (convert price) (converter "convert" "USD" code price))
(define symbol (converter "symbol" code))

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

@ -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 @../store-cpp/htdocs/test/getcatalog-request.txt >tmp/getcatalog-result.txt 2>/dev/null
diff tmp/getcatalog-result.txt ../store-cpp/htdocs/test/getcatalog-result.txt
$curl_prefix/bin/curl http://localhost:8090/references/Store/catalog -X POST -H "Content-type: application/json-rpc" --data @../store-cpp/htdocs/test/items-request.txt >tmp/items-result.txt 2>/dev/null
diff tmp/items-result.txt ../store-cpp/htdocs/test/items-result.txt
rc=$?
fi

View file

@ -75,7 +75,7 @@
)
; Return the total price of the items in the cart
(define (gettotal cache)
(define (total cache)
(define cart (getcart cartId cache))
(sum cart)
)

View file

@ -29,12 +29,12 @@
(shoppingCart "get" id)
)
(define (getcatalog catalog shoppingCart shoppingTotal)
(catalog "getcatalog")
(define (items catalog shoppingCart shoppingTotal)
(catalog "items")
)
(define (gettotal catalog shoppingCart shoppingTotal)
(shoppingCart "gettotal")
(define (total catalog shoppingCart shoppingTotal)
(shoppingCart "total")
)
(define (deleteall catalog shoppingCart shoppingTotal)

View file

@ -18,10 +18,10 @@
# Catalog implementation
def items(converter, currencyCode):
code = currencyCode()
code = currencyCode.eval()
def convert(price):
return converter("convert", "USD", code, price)
symbol = converter("symbol", code)
return converter.convert("USD", code, price)
symbol = converter.symbol(code)
return (
(("'name", "Mango"), ("'currencyCode", code), ("'currencySymbol", symbol), ("'price", convert(2.99))),
(("'name", "Passion"), ("'currencyCode", code), ("'currencySymbol", symbol), ("'price", convert(3.55))),

View file

@ -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;

View file

@ -0,0 +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}]}

View file

@ -33,7 +33,7 @@ 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 @../store-cpp/htdocs/test/items-request.txt >tmp/items-result.txt 2>/dev/null
diff tmp/items-result.txt ../store-cpp/htdocs/test/items-result.txt
diff tmp/items-result.txt htdocs/test/items-result.txt
rc=$?
fi

View file

@ -24,7 +24,7 @@ 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
@ -33,7 +33,7 @@ def getcart(id, cache):
def post(collection, item, cache):
id = str(uuid.uuid1())
cart = ((item[0], id, item[2]),) + getcart(cartId, cache)
cache("put", (cartId,), cart)
cache.put((cartId,), cart)
return (id,)
@ -55,7 +55,7 @@ def get(id, cache):
# Delete items from the cart
def delete(id, cache):
if id == ():
return cache("delete", (cartId,))
return cache.delete((cartId,))
return True
# Return the price of an item
@ -69,7 +69,7 @@ def sum(items):
return price(items[0]) + sum(items[1:])
# Return the total price of the items in the cart
def gettotal(cache):
def total(cache):
cart = getcart(cartId, cache)
return sum(cart)

View file

@ -18,23 +18,23 @@
# Store implementation
def post(item, catalog, shoppingCart, shoppingTotal):
return shoppingCart("post", item)
return shoppingCart.post(item)
def getall(catalog, shoppingCart, shoppingTotal):
return shoppingCart("getall")
return shoppingCart.getall()
def get(id, catalog, shoppingCart, shoppingTotal):
return shoppingCart("get", id)
return shoppingCart.get(id)
def items(catalog, shoppingCart, shoppingTotal):
return catalog("items")
return catalog.items()
def gettotal(catalog, shoppingCart, shoppingTotal):
return shoppingCart("gettotal")
def total(catalog, shoppingCart, shoppingTotal):
return shoppingCart.gettotal()
def deleteall(catalog, shoppingCart, shoppingTotal):
return shoppingCart("deleteall")
return shoppingCart.deleteall()
def delete(id, catalog, shoppingCart, shoppingTotal):
return shoppingCart("delete", id)
return shoppingCart.delete(id)

View file

@ -17,7 +17,7 @@
; Catalog implementation
(define (getcatalog converter currencyCode)
(define (items converter currencyCode)
(define code (currencyCode))
(define (convert price) (converter "convert" "USD" code price))
(define symbol (converter "symbol" code))

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

@ -56,7 +56,7 @@ bool testEval() {
ostringstream os;
scheme::setupDisplay(os);
scheme::Env globalEnv = scheme::setupEnvironment();
const value exp(mklist<value>("storeui_service", string("getcatalog")));
const value exp(mklist<value>("storeui_service", string("items")));
const value val = scheme::evalScript(exp, is, globalEnv);
ostringstream vs;
@ -71,7 +71,7 @@ bool testEval() {
scheme::setupDisplay(os);
scheme::Env globalEnv = scheme::setupEnvironment();
const value exp(mklist<value>("storeui_service", string("gettotal")));
const value exp(mklist<value>("storeui_service", string("total")));
const value res = scheme::evalScript(exp, is, globalEnv);
ostringstream rs;

View file

@ -53,7 +53,7 @@
(define (catalog_impl converter op args)
(cond
((equal? op "getcatalog") (apply catalog_get (cons converter args)))
((equal? op "items") (apply catalog_get (cons converter args)))
)
)
@ -76,7 +76,7 @@
(cons "Item" (list id entry))
)
(define (cart_gettotal)
(define (cart_total)
10.0
)
@ -85,7 +85,7 @@
((equal? op "post") (apply cart_post args))
((equal? op "getall") (apply cart_getall args))
((equal? op "getentry") (apply cart_getentry args))
((equal? op "gettotal") (apply cart_gettotal args))
((equal? op "total") (apply cart_total args))
)
)
@ -103,12 +103,12 @@
(cart "getentry" id)
)
(define (storeui_getcatalog catalog)
(catalog "getcatalog")
(define (storeui_items catalog)
(catalog "items")
)
(define (storeui_gettotal cart)
(cart "gettotal")
(define (storeui_total cart)
(cart "total")
)
(define (storeui_impl cart catalog op args)
@ -116,8 +116,8 @@
((equal? op "post") (apply storeui_post (cons cart args)))
((equal? op "getall") (apply storeui_getcart (cons cart args)))
((equal? op "getentry") (apply storeui_getentry (cons cart args)))
((equal? op "getcatalog") (apply storeui_getcatalog (cons catalog args)))
((equal? op "gettotal") (apply storeui_gettotal (cons cart args)))
((equal? op "items") (apply storeui_items (cons catalog args)))
((equal? op "total") (apply storeui_total (cons cart args)))
)
)
@ -129,12 +129,12 @@
; Store UI test case
(define catalog (storeui_service "getcatalog"))
(define catalog (storeui_service "items"))
(define empty (list))
(define apple (car catalog))
(define orange (car (cdr catalog)))
(define added1 (storeui_service "post" empty apple))
(define added2 (storeui_service "post" added1 orange))
(display (storeui_service "getall" added2))
(display (storeui_service "gettotal"))
(display (storeui_service "total"))

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 @../store-cpp/htdocs/test/getcatalog-request.txt >tmp/getcatalog-result.txt 2>/dev/null
diff tmp/getcatalog-result.txt ../store-cpp/htdocs/test/getcatalog-result.txt
$curl_prefix/bin/curl http://localhost:8090/references/Store/catalog -X POST -H "Content-type: application/json-rpc" --data @../store-cpp/htdocs/test/items-request.txt >tmp/items-result.txt 2>/dev/null
diff tmp/items-result.txt ../store-cpp/htdocs/test/items-result.txt
rc=$?
fi

View file

@ -75,7 +75,7 @@
)
; Return the total price of the items in the cart
(define (gettotal cache)
(define (total cache)
(define cart (getcart cartId cache))
(sum cart)
)

View file

@ -29,12 +29,12 @@
(shoppingCart "get" id)
)
(define (getcatalog catalog shoppingCart shoppingTotal)
(catalog "getcatalog")
(define (items catalog shoppingCart shoppingTotal)
(catalog "items")
)
(define (gettotal catalog shoppingCart shoppingTotal)
(shoppingCart "gettotal")
(define (total catalog shoppingCart shoppingTotal)
(shoppingCart "total")
)
(define (deleteall catalog shoppingCart shoppingTotal)

View file

@ -17,7 +17,7 @@
; Catalog implementation
(define (getcatalog converter currencyCode)
(define (items converter currencyCode)
(define code (currencyCode))
(define (convert price) (converter "convert" "USD" code price))
(define symbol (converter "symbol" code))

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

@ -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 @../store-cpp/htdocs/test/getcatalog-request.txt >tmp/getcatalog-result.txt 2>/dev/null
diff tmp/getcatalog-result.txt ../store-cpp/htdocs/test/getcatalog-result.txt
$curl_prefix/bin/curl http://localhost:8090/references/Store/catalog -X POST -H "Content-type: application/json-rpc" --data @../store-cpp/htdocs/test/items-request.txt >tmp/items-result.txt 2>/dev/null
diff tmp/items-result.txt ../store-cpp/htdocs/test/items-result.txt
rc=$?
fi

View file

@ -75,7 +75,7 @@
)
; Return the total price of the items in the cart
(define (gettotal cache)
(define (total cache)
(define cart (getcart cartId cache))
(sum cart)
)

View file

@ -29,12 +29,12 @@
(shoppingCart "get" id)
)
(define (getcatalog catalog shoppingCart shoppingTotal)
(catalog "getcatalog")
(define (items catalog shoppingCart shoppingTotal)
(catalog "items")
)
(define (gettotal catalog shoppingCart shoppingTotal)
(shoppingCart "gettotal")
(define (total catalog shoppingCart shoppingTotal)
(shoppingCart "total")
)
(define (deleteall catalog shoppingCart shoppingTotal)

View file

@ -17,11 +17,11 @@
# Catalog implementation
def getcatalog(converter, currencyCode):
code = currencyCode()
def items(converter, currencyCode):
code = currencyCode.eval()
def convert(price):
return converter("convert", "USD", code, price)
symbol = converter("symbol", code)
return converter.convert("USD", code, price)
symbol = converter.symbol(code)
return (
(("'name", "Passion"), ("'currencyCode", code), ("'currencySymbol", symbol), ("'price", convert(2.99))),
(("'name", "Mango"), ("'currencyCode", code), ("'currencySymbol", symbol), ("'price", convert(3.55))),

View file

@ -24,7 +24,7 @@ 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
@ -33,7 +33,7 @@ def getcart(id, cache):
def post(collection, item, cache):
id = str(uuid.uuid1())
cart = ((item[0], id, item[2]),) + getcart(cartId, cache)
cache("put", (cartId,), cart)
cache.put((cartId,), cart)
return (id,)
@ -55,7 +55,7 @@ def get(id, cache):
# Delete items from the cart
def delete(id, cache):
if id == ():
return cache("delete", (cartId,))
return cache.delete((cartId,))
return True
# Return the price of an item
@ -69,7 +69,7 @@ def sum(items):
return price(items[0]) + sum(items[1:])
# Return the total price of the items in the cart
def gettotal(cache):
def total(cache):
cart = getcart(cartId, cache)
return sum(cart)

View file

@ -18,23 +18,23 @@
# Store implementation
def post(item, catalog, shoppingCart, shoppingTotal):
return shoppingCart("post", item)
return shoppingCart.post(item)
def getall(catalog, shoppingCart, shoppingTotal):
return shoppingCart("getall")
return shoppingCart.getall()
def get(id, catalog, shoppingCart, shoppingTotal):
return shoppingCart("get", id)
return shoppingCart.get(id)
def getcatalog(catalog, shoppingCart, shoppingTotal):
return catalog("getcatalog")
def items(catalog, shoppingCart, shoppingTotal):
return catalog.items()
def gettotal(catalog, shoppingCart, shoppingTotal):
return shoppingCart("gettotal")
def total(catalog, shoppingCart, shoppingTotal):
return shoppingCart.total()
def deleteall(catalog, shoppingCart, shoppingTotal):
return shoppingCart("deleteall")
return shoppingCart.deleteall()
def delete(id, catalog, shoppingCart, shoppingTotal):
return shoppingCart("delete", id)
return shoppingCart.delete(id)

View file

@ -17,11 +17,11 @@
# Catalog implementation
def getcatalog(converter, currencyCode):
code = currencyCode()
def items(converter, currencyCode):
code = currencyCode.eval()
def convert(price):
return converter("convert", "USD", code, price)
symbol = converter("symbol", code)
return converter.convert("USD", code, price)
symbol = converter.symbol(code)
return (
(("'name", "Apple"), ("'currencyCode", code), ("'currencySymbol", symbol), ("'price", convert(2.99))),
(("'name", "Orange"), ("'currencyCode", code), ("'currencySymbol", symbol), ("'price", convert(3.55))),

View file

@ -24,7 +24,7 @@ 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
@ -33,7 +33,7 @@ def getcart(id, cache):
def post(collection, item, cache):
id = str(uuid.uuid1())
cart = ((item[0], id, item[2]),) + getcart(cartId, cache)
cache("put", (cartId,), cart)
cache.put((cartId,), cart)
return (id,)
@ -55,7 +55,7 @@ def get(id, cache):
# Delete items from the cart
def delete(id, cache):
if id == ():
return cache("delete", (cartId,))
return cache.delete((cartId,))
return True
# Return the price of an item
@ -69,7 +69,7 @@ def sum(items):
return price(items[0]) + sum(items[1:])
# Return the total price of the items in the cart
def gettotal(cache):
def total(cache):
cart = getcart(cartId, cache)
return sum(cart)

View file

@ -18,23 +18,23 @@
# Store implementation
def post(item, catalog, shoppingCart, shoppingTotal):
return shoppingCart("post", item)
return shoppingCart.post(item)
def getall(catalog, shoppingCart, shoppingTotal):
return shoppingCart("getall")
return shoppingCart.getall()
def get(id, catalog, shoppingCart, shoppingTotal):
return shoppingCart("get", id)
return shoppingCart.get(id)
def getcatalog(catalog, shoppingCart, shoppingTotal):
return catalog("getcatalog")
def items(catalog, shoppingCart, shoppingTotal):
return catalog.items()
def gettotal(catalog, shoppingCart, shoppingTotal):
return shoppingCart("gettotal")
def total(catalog, shoppingCart, shoppingTotal):
return shoppingCart.total()
def deleteall(catalog, shoppingCart, shoppingTotal):
return shoppingCart("deleteall")
return shoppingCart.deleteall()
def delete(id, catalog, shoppingCart, shoppingTotal):
return shoppingCart("delete", id)
return shoppingCart.delete(id)

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

@ -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

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