summaryrefslogtreecommitdiffstats
path: root/sca-cpp/trunk/kernel
diff options
context:
space:
mode:
authorjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2010-01-24 09:27:52 +0000
committerjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2010-01-24 09:27:52 +0000
commit878131a50cf9651fc8de402420b8c94696328a3c (patch)
treed0112887a0204bbf6ad9e76ae062ca4b70bc094a /sca-cpp/trunk/kernel
parent1c21d758af81d880ad6e045d18f8bc62ad8be89e (diff)
Working Web service component using Axis2C 1.6. Some fixes to the JSON conversion functions to correctly handle all cases of nested objects and arrays. Added support for component properties, the Web service component has a URI property that can be configured to the address of the target Web service.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@902540 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-cpp/trunk/kernel')
-rw-r--r--sca-cpp/trunk/kernel/element.hpp10
-rw-r--r--sca-cpp/trunk/kernel/xml-test.cpp20
-rw-r--r--sca-cpp/trunk/kernel/xml.hpp30
3 files changed, 46 insertions, 14 deletions
diff --git a/sca-cpp/trunk/kernel/element.hpp b/sca-cpp/trunk/kernel/element.hpp
index 4570110e96..0d14acc4a3 100644
--- a/sca-cpp/trunk/kernel/element.hpp
+++ b/sca-cpp/trunk/kernel/element.hpp
@@ -37,6 +37,7 @@ namespace tuscany
*/
const value attribute("attribute");
const value element("element");
+const string atsign("@");
/**
* Returns true if a value is an element.
@@ -125,7 +126,7 @@ const value elementToValue(const value& t) {
// Convert an attribute
if (isTaggedList(t, attribute))
- return mklist(attributeName(t), attributeValue(t));
+ return mklist<value>(c_str(atsign + attributeName(t)), attributeValue(t));
// Convert an element
if (isTaggedList(t, element)) {
@@ -196,9 +197,12 @@ const value valueToElement(const value& t) {
const value n = car<value>(t);
const value v = cadr<value>(t);
- // Convert a single value
- if (!isList(v))
+ // Convert a single value to an attribute or an element
+ if (!isList(v)) {
+ if (substr(n, 0, 1) == atsign)
+ return mklist<value>(attribute, substr(n, 1), v);
return mklist(element, n, v);
+ }
// Convert a list value
if (isNil((list<value>)v) || !isSymbol(car<value>(v)))
diff --git a/sca-cpp/trunk/kernel/xml-test.cpp b/sca-cpp/trunk/kernel/xml-test.cpp
index 9e0cde597b..c83a65fd92 100644
--- a/sca-cpp/trunk/kernel/xml-test.cpp
+++ b/sca-cpp/trunk/kernel/xml-test.cpp
@@ -111,7 +111,7 @@ bool testWriteXML() {
return true;
}
-bool testElement() {
+bool testElements() {
{
const list<value> ad = mklist<value>(mklist<value>("city", string("san francisco")), mklist<value>("state", string("ca")));
const list<value> ac1 = mklist<value>(mklist<value>("id", string("1234")), mklist<value>("balance", 1000));
@@ -149,6 +149,21 @@ bool testElement() {
return true;
}
+bool testValues() {
+ {
+ const list<value> l = mklist<value>(list<value>() + "ns1:echoString" + (list<value>() + "@xmlns:ns1" + string("http://ws.apache.org/axis2/services/echo")) + (list<value>() + "text" + string("Hello World!")));
+ const list<value> e = valuesToElements(l);
+ const failable<list<string> > lx = writeXML(e);
+ ostringstream os;
+ write(content(lx), os);
+ istringstream is(str(os));
+ const list<value> x = readXML(streamList(is));
+ const list<value> v = elementsToValues(x);
+ assert(v == l);
+ }
+ return true;
+}
+
}
int main() {
@@ -156,7 +171,8 @@ int main() {
tuscany::testReadXML();
tuscany::testWriteXML();
- tuscany::testElement();
+ tuscany::testElements();
+ tuscany::testValues();
tuscany::cout << "OK" << tuscany::endl;
diff --git a/sca-cpp/trunk/kernel/xml.hpp b/sca-cpp/trunk/kernel/xml.hpp
index 9e903ea34d..fa1701d83a 100644
--- a/sca-cpp/trunk/kernel/xml.hpp
+++ b/sca-cpp/trunk/kernel/xml.hpp
@@ -290,16 +290,20 @@ const failable<bool> writeList(const list<value>& l, const xmlTextWriterPtr xml)
/**
* Write a list of values to a libxml2 XML writer.
*/
-const failable<bool> write(const list<value>& l, const xmlTextWriterPtr xml) {
- if (xmlTextWriterStartDocument(xml, NULL, encoding, NULL) < 0)
- return mkfailure<bool>(string("xmlTextWriterStartDocument failed"));
+const failable<bool> write(const list<value>& l, const xmlTextWriterPtr xml, bool xmlTag) {
+ if (xmlTag) {
+ if (xmlTextWriterStartDocument(xml, NULL, encoding, NULL) < 0)
+ return mkfailure<bool>(string("xmlTextWriterStartDocument failed"));
+ }
const failable<bool> w = writeList(l, xml);
if (!hasContent(w))
return w;
- if (xmlTextWriterEndDocument(xml) < 0)
- return mkfailure<bool>("xmlTextWriterEndDocument failed");
+ if (xmlTag) {
+ if (xmlTextWriterEndDocument(xml) < 0)
+ return mkfailure<bool>("xmlTextWriterEndDocument failed");
+ }
return true;
}
@@ -326,7 +330,7 @@ template<typename R> int writeCallback(void *context, const char* buffer, int le
/**
* Convert a list of values to an XML document.
*/
-template<typename R> const failable<R> writeXML(const lambda<R(const string&, const R)>& reduce, const R& initial, const list<value>& l) {
+template<typename R> const failable<R> writeXML(const lambda<R(const string&, const R)>& reduce, const R& initial, const list<value>& l, const bool xmlTag) {
XMLWriteContext<R> cx(reduce, initial);
xmlOutputBufferPtr out = xmlOutputBufferCreateIO(writeCallback<R>, NULL, &cx, NULL);
if (out == NULL)
@@ -335,7 +339,7 @@ template<typename R> const failable<R> writeXML(const lambda<R(const string&, co
if (xml == NULL)
return mkfailure<R>("xmlNewTextWriter failed");
- const failable<bool> w = write(l, xml);
+ const failable<bool> w = write(l, xml, xmlTag);
xmlFreeTextWriter(xml);
if (!hasContent(w)) {
return mkfailure<R>(reason(w));
@@ -343,15 +347,23 @@ template<typename R> const failable<R> writeXML(const lambda<R(const string&, co
return cx.accum;
}
+template<typename R> const failable<R> writeXML(const lambda<R(const string&, const R)>& reduce, const R& initial, const list<value>& l) {
+ return writeXML(reduce, initial, l, true);
+}
+
/**
* Convert a list of values to a list of strings representing an XML document.
*/
-const failable<list<string> > writeXML(const list<value>& l) {
- const failable<list<string> > ls = writeXML<list<string> >(rcons<string>, list<string>(), l);
+const failable<list<string> > writeXML(const list<value>& l, const bool xmlTag) {
+ const failable<list<string> > ls = writeXML<list<string> >(rcons<string>, list<string>(), l, xmlTag);
if (!hasContent(ls))
return ls;
return reverse(list<string>(content(ls)));
}
+const failable<list<string> > writeXML(const list<value>& l) {
+ return writeXML(l, true);
+}
+
}
#endif /* tuscany_xml_hpp */