Added: tuscany/sandbox/sebastien/java/dynamic/modules/implementation-python-runtime/src/main/resources/elemutil.py URL: http://svn.apache.org/viewvc/tuscany/sandbox/sebastien/java/dynamic/modules/implementation-python-runtime/src/main/resources/elemutil.py?rev=965360&view=auto ============================================================================== --- tuscany/sandbox/sebastien/java/dynamic/modules/implementation-python-runtime/src/main/resources/elemutil.py (added) +++ tuscany/sandbox/sebastien/java/dynamic/modules/implementation-python-runtime/src/main/resources/elemutil.py Mon Jul 19 06:12:11 2010 @@ -0,0 +1,168 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Functions to help represent data as lists of elements and attributes + +from util import * + +element = "'element" +attribute = "'attribute" +atsign = "'@" + +# Return true if a value is an element +def isElement(v): + if not isList(v) or isNil(v) or v == None or car(v) != element: + return False + return True + +# Return true if a value is an attribute +def isAttribute(v): + if not isList(v) or isNil(v) or v == None or car(v) != attribute: + return False + return True + +# Return the name of attribute +def attributeName(l): + return cadr(l) + +# Return the value of attribute +def attributeValue(l): + return caddr(l) + +# Return the name of an element +def elementName(l): + return cadr(l) + +# Return true if an element has children +def elementHasChildren(l): + return not isNil(cddr(l)) + +# Return the children of an element +def elementChildren(l): + return cddr(l) + +# Return true if an element has a value +def elementHasValue(l): + r = reverse(l) + if isSymbol(car(r)): + return False + if isList(car(r)) and not isNil(car(r)) and isSymbol(car(car(r))): + return False + return True + +# Return the value of an element +def elementValue(l): + return car(reverse(l)) + +# Convert an element to a value +def elementToValueIsList(v): + if not isList(v): + return False + return isNil(v) or not isSymbol(car(v)) + +def elementToValue(t): + if isTaggedList(t, attribute): + return (atsign + attributeName(t)[1:], attributeValue(t)) + if isTaggedList(t, element): + if elementHasValue(t): + if not elementToValueIsList(elementValue(t)): + return (elementName(t), elementValue(t)) + return cons(elementName(t), (elementsToValues(elementValue(t)),)) + return cons(elementName(t), elementsToValues(elementChildren(t))) + if not isList(t): + return t + return elementsToValues(t) + +# Convert a list of elements to a list of values +def elementToValueIsSymbol(v): + if not isList(v): + return False + if (isNil(v)): + return False + if not isSymbol(car(v)): + return False + return True + +def elementToValueGroupValues(v, l): + if isNil(l) or not elementToValueIsSymbol(v) or not elementToValueIsSymbol(car(l)): + return cons(v, l) + if car(car(l)) != car(v): + return cons(v, l) + if not elementToValueIsList(cadr(car(l))): + g = (car(v), (cdr(v), cdr(car(l)))) + return elementToValueGroupValues(g, cdr(l)) + g = (car(v), cons(cdr(v), cadr(car(l)))) + return elementToValueGroupValues(g, cdr(l)) + +def elementsToValues(e): + if isNil(e): + return e + return elementToValueGroupValues(elementToValue(car(e)), elementsToValues(cdr(e))) + +# Convert a value to an element +def valueToElement(t): + if isList(t) and not isNil(t) and isSymbol(car(t)): + n = car(t) + v = cadr(t) + if not isList(v): + if n[0:2] == atsign: + return (attribute, n[1:], v) + return (element, n, v) + if isNil(v) or not isSymbol(car(v)): + return cons(element, cons(n, (valuesToElements(v),))) + return cons(element, cons(n, valuesToElements(cdr(t)))) + if not isList(t): + return t + return valuesToElements(t) + +# Convert a list of values to a list of elements +def valuesToElements(l): + if isNil(l): + return l + return cons(valueToElement(car(l)), valuesToElements(cdr(l))) + +# Return a selector lambda function which can be used to filter elements +def evalSelect(s, v): + if isNil(s): + return True + if isNil(v): + return False + if car(s) != car(v): + return False + return evalSelect(cdr(s), cdr(v)) + +def selector(s): + return lambda v: evalSelect(s, v) + +# Return the value of the attribute with the given name +def namedAttributeValue(name, l): + f = filter(lambda v: isAttribute(v) and attributeName(v) == name, l) + if isNil(f): + return None + return caddr(car(f)) + +# Return child elements with the given name +def namedElementChildren(name, l): + return filter(lambda v: isElement(v) and elementName(v) == name, l) + +# Return the child element with the given name +def namedElementChild(name, l): + f = namedElementChildren(name, l) + if isNil(f): + return None + return car(f) +
Added: tuscany/sandbox/sebastien/java/dynamic/modules/implementation-python-runtime/src/main/resources/invoker.py URL: http://svn.apache.org/viewvc/tuscany/sandbox/sebastien/java/dynamic/modules/implementation-python-runtime/src/main/resources/invoker.py?rev=965360&view=auto ============================================================================== --- tuscany/sandbox/sebastien/java/dynamic/modules/implementation-python-runtime/src/main/resources/invoker.py (added) +++ tuscany/sandbox/sebastien/java/dynamic/modules/implementation-python-runtime/src/main/resources/invoker.py Mon Jul 19 06:12:11 2010 @@ -0,0 +1,89 @@ +#!/usr/bin/python +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Component invocation functions + +from sys import stderr, argv +from util import * +from jsonutil import * + +# JSON request id +id = 1 + +# Make a callable reference client +class proxy: + def __init__(self, jpx): + self.jpx = jpx + + def __call__(self, func, *args): + + # Create a JSON-RPC request + global id + req = StringIO() + writeStrings(jsonRequest(id, func, args), req) + id = id + 1 + + # Eval the Java proxy + res = self.jpx.eval(req.getvalue()) + + # Extract result from JSON-RPC response + return jsonResultValue((res,)) + + def __repr__(self): + return repr((jpx,)) + +def mkproxies(jpx): + if isNil(jpx): + return () + return cons(proxy(car(jpx)), mkproxies(cdr(jpx))) + +# Make a callable component +class component: + def __init__(self, name, impl, jpx): + self.name = name + self.impl = impl[0:len(impl) - 3] + self.mod = __import__(self.impl) + self.proxies = mkproxies(jpx) + + def __call__(self, func, *args): + return self.mod.__getattribute__(func)(*(args + self.proxies)) + + def __repr__(self): + return repr((self.name, self.impl, self.mod, self.svcs, self.refs, self.props, self.proxies)) + +# Converts the args received in a JSON request to a list of key value pairs +def jsonArgs(a): + if isNil(a): + return ((),) + l = car(a); + return cons(l, jsonArgs(cdr(a))) + +# Apply a JSON function request to a component +def apply(jsreq, comp): + json = elementsToValues(readJSON((jsreq,))) + args = jsonArgs(json) + jid = cadr(assoc("'id", args)) + func = funcName(cadr(assoc("'method", args))) + params = cadr(assoc("'params", args)) + v = comp(func, *params) + return jsonResult(jid, v)[0] + +# Make a component that can be called with a JSON function request +def mkcomponent(name, impl, jpx): + comp = component(name, impl, jpx) + return lambda jsreq: apply(jsreq, comp) Added: tuscany/sandbox/sebastien/java/dynamic/modules/implementation-python-runtime/src/main/resources/jsonutil.py URL: http://svn.apache.org/viewvc/tuscany/sandbox/sebastien/java/dynamic/modules/implementation-python-runtime/src/main/resources/jsonutil.py?rev=965360&view=auto ============================================================================== --- tuscany/sandbox/sebastien/java/dynamic/modules/implementation-python-runtime/src/main/resources/jsonutil.py (added) +++ tuscany/sandbox/sebastien/java/dynamic/modules/implementation-python-runtime/src/main/resources/jsonutil.py Mon Jul 19 06:12:11 2010 @@ -0,0 +1,142 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# JSON data conversion functions + +try: + import json +except: + from django.utils import simplejson as json + +from StringIO import StringIO +from util import * +from elemutil import * + +# Return true if a list represents a JS array +def isJSArray(l): + if isNil(l): + return True + v = car(l) + if isSymbol(v): + return False + if isList(v): + if not isNil(v) and isSymbol(car(v)): + return False + return True + +# Converts JSON properties to values +def jsPropertiesToValues(propertiesSoFar, o, i): + if isNil(i): + return propertiesSoFar + p = car(i) + jsv = o[p] + v = jsValToValue(jsv) + + if isinstance(p, basestring): + n = str(p) + if n[0:1] == "@": + return jsPropertiesToValues(cons((attribute, "'" + n[1:], v), propertiesSoFar), o, cdr(i)) + if isList(v) and not isJSArray(v): + return jsPropertiesToValues(cons(cons(element, cons("'" + n, v)), propertiesSoFar), o, cdr(i)) + return jsPropertiesToValues(cons((element, "'" + n, v), propertiesSoFar), o, cdr(i)) + return jsPropertiesToValues(cons(v, propertiesSoFar), o, cdr(i)) + +# Converts a JSON val to a value +def jsValToValue(jsv): + if isinstance(jsv, dict): + return jsPropertiesToValues((), jsv, tuple(jsv.keys())) + if isList(jsv): + return jsPropertiesToValues((), jsv, tuple(reversed(range(0, len(jsv))))) + if isinstance(jsv, basestring): + return str(jsv) + return jsv + +# Convert a list of strings representing a JSON document to a list of values +def readJSON(l): + s = StringIO() + writeStrings(l, s) + val = json.loads(s.getvalue()) + return jsValToValue(val) + +# Convert a list of values to JSON array elements +def valuesToJSElements(a, l, i): + if isNil(l): + return a + pv = valueToJSVal(car(l)) + a[i] = pv + return valuesToJSElements(a, cdr(l), i + 1) + +# Convert a value to a JSON value +def valueToJSVal(v): + if not isList(v): + return v + if isJSArray(v): + return valuesToJSElements(list(range(0, len(v))), v, 0) + return valuesToJSProperties({}, v) + +# Convert a list of values to JSON properties +def valuesToJSProperties(o, l): + if isNil(l): + return o + token = car(l) + if isTaggedList(token, attribute): + pv = valueToJSVal(attributeValue(token)) + o["@" + attributeName(token)[1:]] = pv + elif isTaggedList(token, element): + if elementHasValue(token): + pv = valueToJSVal(elementValue(token)) + o[elementName(token)[1:]] = pv + else: + child = {} + o[elementName(token)[1:]] = child + valuesToJSProperties(child, elementChildren(token)) + return valuesToJSProperties(o, cdr(l)) + +# Convert a list of values to a list of strings representing a JSON document +def writeJSON(l): + jsv = valuesToJSProperties({}, l) + s = json.dumps(jsv, separators=(',',':')) + return (s,) + +# Convert a list + params to a JSON-RPC request +def jsonRequest(id, func, params): + r = (("'id", id), ("'method", func), ("'params", params)) + return writeJSON(valuesToElements(r)) + +# Convert a value to a JSON-RPC result +def jsonResult(id, val): + return writeJSON(valuesToElements((("'id", id), ("'result", val)))) + +# Convert a JSON-RPC result to a value +def jsonResultValue(s): + jsres = readJSON(s) + res = elementsToValues(jsres) + val = cadr(assoc("'result", res)) + if isList(val) and not isJSArray(val): + return (val,) + return val + +# Return a portable function name from a JSON-RPC function name +def funcName(f): + if f.startswith("."): + return f[1:] + if f.startswith("system."): + return f[7:] + if f.startswith("Service."): + return f[8:] + return f + Added: tuscany/sandbox/sebastien/java/dynamic/modules/implementation-python-runtime/src/main/resources/rssutil.py URL: http://svn.apache.org/viewvc/tuscany/sandbox/sebastien/java/dynamic/modules/implementation-python-runtime/src/main/resources/rssutil.py?rev=965360&view=auto ============================================================================== --- tuscany/sandbox/sebastien/java/dynamic/modules/implementation-python-runtime/src/main/resources/rssutil.py (added) +++ tuscany/sandbox/sebastien/java/dynamic/modules/implementation-python-runtime/src/main/resources/rssutil.py Mon Jul 19 06:12:11 2010 @@ -0,0 +1,119 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# RSS data conversion functions + +from util import * +from elemutil import * +from xmlutil import * + +# Convert a list of elements to a list of values representing an RSS entry +def entryElementsToValues(e): + lt = filter(selector((element, "'title")), e) + t = "" if isNil(lt) else elementValue(car(lt)) + li = filter(selector((element, "'link")), e) + i = "" if isNil(li) else elementValue(car(li)) + lc = filter(selector((element, "'description")), e) + return (t, i, elementValue(car(lc))) + +# Convert a list of elements to a list of values representing RSS entries +def entriesElementsToValues(e): + if isNil(e): + return e + return cons(entryElementsToValues(car(e)), entriesElementsToValues(cdr(e))) + +# Convert a list of strings to a list of values representing an RSS entry +def readRSSEntry(l): + e = readXML(l) + if isNil(e): + return () + return entryElementsToValues(car(e)) + +# Convert a list of values representy an RSS entry to a value +def entryValue(e): + v = elementsToValues((caddr(e),)) + return cons(car(e), (cadr(e), cdr(car(v)))) + +# Return true if a list of strings represents an RSS feed +def isRSSFeed(l): + if isNil(l): + return False + if car(l)[0:5] != "<?xml": + return False + return contains(car(l), "<rss") + +# Convert a list of strings to a list of values representing an RSS feed +def readRSSFeed(l): + f = readXML(l) + if isNil(f): + return () + c = filter(selector((element, "'channel")), car(f)) + t = filter(selector((element, "'title")), car(c)) + i = filter(selector((element, "'link")), car(c)) + e = filter(selector((element, "'item")), car(c)) + if isNil(e): + return (elementValue(car(t)), elementValue(car(i))) + return cons(elementValue(car(t)), cons(elementValue(car(i)), entriesElementsToValues(e))) + +# Convert an RSS feed containing elements to an RSS feed containing values +def feedValuesLoop(e): + if (isNil(e)): + return e + return cons(entryValue(car(e)), feedValuesLoop(cdr(e))) + +def feedValues(e): + return cons(car(e), cons(cadr(e), feedValuesLoop(cddr(e)))) + +# Convert a list of values representy an RSS entry to a list of elements +def entryElement(l): + return (element, "'item", + (element, "'title", car(l)), + (element, "'link", cadr(l)), + (element, "'description", caddr(l))) + +# Convert a list of values representing RSS entries to a list of elements +def entriesElements(l): + if isNil(l): + return l + return cons(entryElement(car(l)), entriesElements(cdr(l))) + +# Convert a list of values representing an RSS entry to an RSS entry +def writeRSSEntry(l): + return writeXML((entryElement(l),), True) + +# Convert a list of values representing an RSS feed to an RSS feed +def writeRSSFeed(l): + c = ((element, "'title", car(l)), + (element, "'link", cadr(l)), + (element, "'description", car(l))) + ce = c if isNil(cddr(l)) else append(c, entriesElements(cddr(l))) + fe = (element, "'rss", (attribute, "'version", "2.0"), append((element, "'channel"), ce)) + return writeXML((fe,), True) + +# Convert an RSS entry containing a value to an RSS entry containing an item element +def entryValuesToElements(v): + return cons(car(v), cons(cadr(v), valuesToElements((cons("'item", caddr(v)),)))) + +# Convert an RSS feed containing values to an RSS feed containing elements +def feedValuesToElementsLoop(v): + if isNil(v): + return v + return cons(entryValuesToElements(car(v)), feedValuesToElementsLoop(cdr(v))) + +def feedValuesToElements(v): + return cons(car(v), cons(cadr(v), feedValuesToElementsLoop(cddr(v)))) + Added: tuscany/sandbox/sebastien/java/dynamic/modules/implementation-python-runtime/src/main/resources/util.py URL: http://svn.apache.org/viewvc/tuscany/sandbox/sebastien/java/dynamic/modules/implementation-python-runtime/src/main/resources/util.py?rev=965360&view=auto ============================================================================== --- tuscany/sandbox/sebastien/java/dynamic/modules/implementation-python-runtime/src/main/resources/util.py (added) +++ tuscany/sandbox/sebastien/java/dynamic/modules/implementation-python-runtime/src/main/resources/util.py Mon Jul 19 06:12:11 2010 @@ -0,0 +1,145 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Simple utility functions +from sys import maxint + +# Scheme-like lists +def cons(a, b): + return (a,) + b + +def car(l): + return l[0] + +def first(l): + return car(l) + +def cdr(l): + return l[1:] + +def rest(l): + return cdr(l) + +def cadr(l): + return car(cdr(l)) + +def cddr(l): + return cdr(cdr(l)) + +def caddr(l): + return car(cddr(l)) + +def append(a, b): + return a + b + +def reverse(l): + r = list(l) + r.reverse() + return tuple(r) + +def isNil(l): + if isinstance(l, streampair): + return l.isNil() + return l == () + +def isSymbol(v): + return isinstance(v, basestring) and v[0:1] == "'" + +def isList(v): + if getattr(v, '__iter__', False) == False: + return False + if isinstance(v, basestring) or isinstance(v, dict): + return False + return True + +def isTaggedList(v, t): + return isList(v) and not isNil(v) and car(v) == t + + +# Scheme-like streams +class streampair(object): + def __init__(self, car, cdr): + self.car = car + self.cdr = cdr + + def __repr__(self): + return repr(self[0:len(self)]) + + def isNil(self): + return self.cdr == () + + def __len__(self): + if self.cdr == (): + return 0 + return 1 + len(self.cdr()) + + def __getitem__(self, i): + if i == 0: + return self.car + return self.cdr()[i - 1] + + def __getslice__(self, i, j): + if isNil(self): + return () + if i > 0: + if j == maxint: + return self.cdr()[i - 1: j] + return self.cdr()[i - 1: j - 1] + if j == maxint: + return self + if j == 0: + return (self.car,) + return (self.car,) + self.cdr()[: j - 1] + + def __eq__(self, other): + sl = len(self) + ol = len(other) + if sl != ol: + return False + return self[0: sl] == other[0: ol] + + def __ne__(self, other): + return not self.__eq__(other) + +def cons_stream(car, cdr): + return streampair(car, cdr) + + +# Scheme-like associations +def assoc(k, l): + if l == (): + return None + + if k == car(car(l)): + return car(l) + return assoc(k, cdr(l)) + +# Currying / partial function application +def curry(f, *args): + return lambda *a: f(*(args + a)) + +# Split a path into a list of segments +def tokens(path): + return tuple(filter(lambda s: len(s) != 0, path.split("/"))) + +# Write a list of strings to a stream +def writeStrings(l, os): + if l == (): + return os + os.write(car(l)) + return writeStrings(cdr(l), os) + Added: tuscany/sandbox/sebastien/java/dynamic/modules/implementation-python-runtime/src/main/resources/xmlutil.py URL: http://svn.apache.org/viewvc/tuscany/sandbox/sebastien/java/dynamic/modules/implementation-python-runtime/src/main/resources/xmlutil.py?rev=965360&view=auto ============================================================================== --- tuscany/sandbox/sebastien/java/dynamic/modules/implementation-python-runtime/src/main/resources/xmlutil.py (added) +++ tuscany/sandbox/sebastien/java/dynamic/modules/implementation-python-runtime/src/main/resources/xmlutil.py Mon Jul 19 06:12:11 2010 @@ -0,0 +1,114 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# XML handling functions + +from StringIO import StringIO +from xml.parsers import expat +import xml.etree.ElementTree as et +from util import * +from elemutil import * + +# Read a list of XML attributes +def readAttributes(a): + if a == (): + return a + return cons((attribute, "'" + car(car(a)), cadr(car(a))), readAttributes(cdr(a))) + +# Read an XML element +def readElement(e): + l = (element, "'" + e.tag) + readAttributes(tuple(e.items())) + readElements(tuple(e.getchildren())) + if e.text == None: + return l + return l + (e.text,) + +# Read a list of XML elements +def readElements(l): + if l == (): + return l + return cons(readElement(car(l)), readElements(cdr(l))) + +# Parse a list of strings representing an XML document +class NamespaceParser(et.XMLTreeBuilder): + def __init__(self): + et.XMLTreeBuilder.__init__(self) + self._parser = parser = expat.ParserCreate(None) + parser.DefaultHandlerExpand = self._default + parser.StartElementHandler = self._start + parser.EndElementHandler = self._end + parser.CharacterDataHandler = self._data + try: + parser.buffer_text = 1 + except AttributeError: + pass + try: + parser.ordered_attributes = 1 + parser.specified_attributes = 1 + parser.StartElementHandler = self._start_list + except AttributeError: + pass + +def parseXML(l): + s = StringIO() + writeStrings(l, s) + parser = NamespaceParser() + parser.feed(s.getvalue()) + return parser.close() + +# Read a list of values from a list of strings representing an XML document +def readXML(l): + e = parseXML(l) + return (readElement(e),) + +# Write a list of XML element and attribute tokens +def expandElementValues(n, l): + if isNil(l): + return l + return cons(cons(element, cons(n, car(l))), expandElementValues(n, cdr(l))) + +def writeList(l, xml): + if isNil(l): + return xml + token = car(l) + if isTaggedList(token, attribute): + xml.attrib[attributeName(token)[1:]] = str(attributeValue(token)) + elif isTaggedList(token, element): + if elementHasValue(token): + v = elementValue(token) + if isList(v): + e = expandElementValues(elementName(token), v) + writeList(e, xml) + else: + child = et.Element(elementName(token)[1:]) + writeList(elementChildren(token), child) + xml.append(child) + else: + child = et.Element(elementName(token)[1:]) + writeList(elementChildren(token), child) + xml.append(child) + else: + xml.text = str(token) + writeList(cdr(l), xml) + return xml + +# Convert a list of values to a list of strings representing an XML document +def writeXML(l, xmlTag): + e = writeList(l, []) + if not xmlTag: + return (et.tostring(car(e)),) + return (et.tostring(car(e), "UTF-8") + "\n",) + Added: tuscany/sandbox/sebastien/java/dynamic/modules/implementation-python-runtime/src/test/java/org/apache/tuscany/sca/implementation/python/provider/ClientTest.java URL: http://svn.apache.org/viewvc/tuscany/sandbox/sebastien/java/dynamic/modules/implementation-python-runtime/src/test/java/org/apache/tuscany/sca/implementation/python/provider/ClientTest.java?rev=965360&view=auto ============================================================================== --- tuscany/sandbox/sebastien/java/dynamic/modules/implementation-python-runtime/src/test/java/org/apache/tuscany/sca/implementation/python/provider/ClientTest.java (added) +++ tuscany/sandbox/sebastien/java/dynamic/modules/implementation-python-runtime/src/test/java/org/apache/tuscany/sca/implementation/python/provider/ClientTest.java Mon Jul 19 06:12:11 2010 @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.implementation.python.provider; + +import org.oasisopen.sca.annotation.Reference; + + +/** + * Test Java component. + * + * @version $Rev$ $Date$ + */ +public class ClientTest implements EchoTest { + + @Reference + public EchoTest ref; + + public String echo(final String s) { + return ref.echo(s); + } +} Added: tuscany/sandbox/sebastien/java/dynamic/modules/implementation-python-runtime/src/test/java/org/apache/tuscany/sca/implementation/python/provider/EchoTest.java URL: http://svn.apache.org/viewvc/tuscany/sandbox/sebastien/java/dynamic/modules/implementation-python-runtime/src/test/java/org/apache/tuscany/sca/implementation/python/provider/EchoTest.java?rev=965360&view=auto ============================================================================== --- tuscany/sandbox/sebastien/java/dynamic/modules/implementation-python-runtime/src/test/java/org/apache/tuscany/sca/implementation/python/provider/EchoTest.java (added) +++ tuscany/sandbox/sebastien/java/dynamic/modules/implementation-python-runtime/src/test/java/org/apache/tuscany/sca/implementation/python/provider/EchoTest.java Mon Jul 19 06:12:11 2010 @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.implementation.python.provider; + +import org.oasisopen.sca.annotation.Remotable; + + +/** + * Test client interface. + * + * @version $Rev$ $Date$ + */ +...@remotable +public interface EchoTest { + + public String echo(String s); +} Added: tuscany/sandbox/sebastien/java/dynamic/modules/implementation-python-runtime/src/test/java/org/apache/tuscany/sca/implementation/python/provider/InvokeTestCase.java URL: http://svn.apache.org/viewvc/tuscany/sandbox/sebastien/java/dynamic/modules/implementation-python-runtime/src/test/java/org/apache/tuscany/sca/implementation/python/provider/InvokeTestCase.java?rev=965360&view=auto ============================================================================== --- tuscany/sandbox/sebastien/java/dynamic/modules/implementation-python-runtime/src/test/java/org/apache/tuscany/sca/implementation/python/provider/InvokeTestCase.java (added) +++ tuscany/sandbox/sebastien/java/dynamic/modules/implementation-python-runtime/src/test/java/org/apache/tuscany/sca/implementation/python/provider/InvokeTestCase.java Mon Jul 19 06:12:11 2010 @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.implementation.python.provider; + +import static org.apache.tuscany.sca.node.ContributionLocationHelper.getContributionLocation; +import static org.junit.Assert.assertEquals; + +import org.apache.tuscany.sca.node.Contribution; +import org.apache.tuscany.sca.node.Node; +import org.apache.tuscany.sca.node.NodeFactory; +import org.jabsorb.client.Client; +import org.jabsorb.client.Session; +import org.jabsorb.client.TransportRegistry; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * Tests the Python implementation provider. + * + * @version $Rev$ $Date$ + */ +public class InvokeTestCase { + static Node node; + + @BeforeClass + public static void setUp() throws Exception { + try { + final String loc = getContributionLocation("domain-test.composite"); + node = NodeFactory.newInstance().createNode("domain-test.composite", new Contribution("c", loc)); + node.start(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @AfterClass + public static void tearDown() throws Exception { + node.stop(); + } + + @Test + public void testService() throws Exception { + final Session s = TransportRegistry.i().createSession("http://localhost:8085/python"); + final Client c = new Client(s); + final Object px = c.openProxy("", EchoTest.class); + final Object r = c.invoke(px, EchoTest.class.getMethod("echo", String.class), new Object[]{"Hey"}); + c.closeProxy(px); + s.close(); + assertEquals("Hey", r); + } + + @Test + public void testReference() throws Exception { + final Session s = TransportRegistry.i().createSession("http://localhost:8085/client"); + final Client c = new Client(s); + final Object px = c.openProxy("", EchoTest.class); + final Object r = c.invoke(px, EchoTest.class.getMethod("echo", String.class), new Object[]{"Hey"}); + c.closeProxy(px); + s.close(); + assertEquals("Hey", r); + } + + //@Test Disabled for now as Java / JSON databinding transform doesn't seem + // to produce the right JSON + public void testLocal() throws Exception { + final EchoTest s = node.getService(EchoTest.class, "java-client-test"); + final String r = s.echo("Hey"); + assertEquals("Hey", r); + } + +} Added: tuscany/sandbox/sebastien/java/dynamic/modules/implementation-python-runtime/src/test/java/org/apache/tuscany/sca/implementation/python/provider/ServerTest.java URL: http://svn.apache.org/viewvc/tuscany/sandbox/sebastien/java/dynamic/modules/implementation-python-runtime/src/test/java/org/apache/tuscany/sca/implementation/python/provider/ServerTest.java?rev=965360&view=auto ============================================================================== --- tuscany/sandbox/sebastien/java/dynamic/modules/implementation-python-runtime/src/test/java/org/apache/tuscany/sca/implementation/python/provider/ServerTest.java (added) +++ tuscany/sandbox/sebastien/java/dynamic/modules/implementation-python-runtime/src/test/java/org/apache/tuscany/sca/implementation/python/provider/ServerTest.java Mon Jul 19 06:12:11 2010 @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.implementation.python.provider; + + +/** + * Test Java component. + * + * @version $Rev$ $Date$ + */ +public class ServerTest implements EchoTest { + + public String echo(final String s) { + return s; + } +} Added: tuscany/sandbox/sebastien/java/dynamic/modules/implementation-python-runtime/src/test/resources/client_test.py URL: http://svn.apache.org/viewvc/tuscany/sandbox/sebastien/java/dynamic/modules/implementation-python-runtime/src/test/resources/client_test.py?rev=965360&view=auto ============================================================================== --- tuscany/sandbox/sebastien/java/dynamic/modules/implementation-python-runtime/src/test/resources/client_test.py (added) +++ tuscany/sandbox/sebastien/java/dynamic/modules/implementation-python-runtime/src/test/resources/client_test.py Mon Jul 19 06:12:11 2010 @@ -0,0 +1,35 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# JSON-RPC test case + +def echo(x, ref): + return ref("echo", x) + +# ATOMPub test case + +def get(id, ref): + return ref("get", id) + +def post(collection, item, ref): + return ref("post", collection, item) + +def put(id, item, ref): + return ref("put", id, item) + +def delete(id, ref): + return ref("delete", id) Added: tuscany/sandbox/sebastien/java/dynamic/modules/implementation-python-runtime/src/test/resources/domain-test.composite URL: http://svn.apache.org/viewvc/tuscany/sandbox/sebastien/java/dynamic/modules/implementation-python-runtime/src/test/resources/domain-test.composite?rev=965360&view=auto ============================================================================== --- tuscany/sandbox/sebastien/java/dynamic/modules/implementation-python-runtime/src/test/resources/domain-test.composite (added) +++ tuscany/sandbox/sebastien/java/dynamic/modules/implementation-python-runtime/src/test/resources/domain-test.composite Mon Jul 19 06:12:11 2010 @@ -0,0 +1,57 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. +--> +<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912" + xmlns:t="http://tuscany.apache.org/xmlns/sca/1.1" + targetNamespace="http://domain/test" + name="domain-test"> + + <component name="python-test"> + <t:implementation.python script="server_test.py"/> + <service name="test"> + <t:binding.jsonrpc uri="http://localhost:8085/python"/> + </service> + </component> + + <component name="client-test"> + <t:implementation.python script="client_test.py"/> + <service name="client"> + <t:binding.jsonrpc uri="http://localhost:8085/client"/> + </service> + <reference name="ref" target="python-test"> + </reference> + </component> + + <component name="local-java-test"> + <implementation.java class="org.apache.tuscany.sca.implementation.python.provider.ServerTest"/> + </component> + + <component name="local-client-test"> + <t:implementation.python script="client_test.py"/> + <reference name="ref" target="local-java-test"> + </reference> + </component> + + <component name="java-client-test"> + <implementation.java class="org.apache.tuscany.sca.implementation.python.provider.ClientTest"/> + <reference name="ref" target="local-client-test"> + </reference> + </component> + +</composite> Added: tuscany/sandbox/sebastien/java/dynamic/modules/implementation-python-runtime/src/test/resources/server_test.py URL: http://svn.apache.org/viewvc/tuscany/sandbox/sebastien/java/dynamic/modules/implementation-python-runtime/src/test/resources/server_test.py?rev=965360&view=auto ============================================================================== --- tuscany/sandbox/sebastien/java/dynamic/modules/implementation-python-runtime/src/test/resources/server_test.py (added) +++ tuscany/sandbox/sebastien/java/dynamic/modules/implementation-python-runtime/src/test/resources/server_test.py Mon Jul 19 06:12:11 2010 @@ -0,0 +1,42 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# JSON-RPC test case + +def echo(x): + return x + +# ATOMPub test case + +def get(id): + if id == (): + return ("Sample Feed", "123456789", + ("Item", "111", (("'javaClass", "services.Item"), ("'name", "Apple"), ("'currencyCode", "USD"), ("'currencySymbol", "$"), ("'price", 2.99))), + ("Item", "222", (("'javaClass", "services.Item"), ("'name", "Orange"), ("'currencyCode", "USD"), ("'currencySymbol", "$"), ("'price", 3.55))), + ("Item", "333", (("'javaClass", "services.Item"), ("name", "Pear"), ("'currencyCode", "USD"), ("'currencySymbol", "$"), ("'price", 1.55)))) + + entry = (("'javaClass", "services.Item"), ("'name", "Apple"), ("'currencyCode", "USD"), ("'currencySymbol", "$"), ("'price", 2.99)) + return ("Item", id[0], entry) + +def post(collection, item): + return ("123456789",) + +def put(id, item): + return True + +def delete(id): + return True Modified: tuscany/sandbox/sebastien/java/dynamic/modules/pom.xml URL: http://svn.apache.org/viewvc/tuscany/sandbox/sebastien/java/dynamic/modules/pom.xml?rev=965360&r1=965359&r2=965360&view=diff ============================================================================== --- tuscany/sandbox/sebastien/java/dynamic/modules/pom.xml (original) +++ tuscany/sandbox/sebastien/java/dynamic/modules/pom.xml Mon Jul 19 06:12:11 2010 @@ -140,6 +140,9 @@ <module>binding-corba</module> <module>binding-corba-runtime</module> + <module>implementation-python</module> + <module>implementation-python-runtime</module> + <module>implementation-script</module> <module>implementation-script-runtime</module> <module>implementation-jaxrs</module>
