Index: .cvsignore
===================================================================
RCS file: /cvsroot/cashew-s-editor/cashews/.cvsignore,v
retrieving revision 1.1.1.1
diff -u -3 -p -u -r1.1.1.1 .cvsignore
--- .cvsignore 31 Jan 2005 04:02:18 -0000 1.1.1.1
+++ .cvsignore 9 May 2005 02:23:32 -0000
@@ -15,3 +15,4 @@ Makefile.in
stamp-h
stamp-h.in
autom4te*.cache
+plugin.xml
Index: configure.ac
===================================================================
RCS file: /cvsroot/cashew-s-editor/cashews/configure.ac,v
retrieving revision 1.2
diff -u -3 -p -u -r1.2 configure.ac
--- configure.ac 7 Feb 2005 01:59:19 -0000 1.2
+++ configure.ac 9 May 2005 02:23:32 -0000
@@ -36,6 +36,7 @@ AC_CONFIG_FILES([Makefile
scripts/Makefile
lib/Makefile
lib/gen-classlist.sh
- examples/Makefile])
+ examples/Makefile
+ src/nongnu/cashews/commons/Configuration.java])
AC_CONFIG_COMMANDS([gen-classlist],[chmod 755 lib/gen-classlist.sh])
AC_OUTPUT
Index: lib/Makefile.am
===================================================================
RCS file: /cvsroot/cashew-s-editor/cashews/lib/Makefile.am,v
retrieving revision 1.7
diff -u -3 -p -u -r1.7 Makefile.am
--- lib/Makefile.am 4 May 2005 14:30:27 -0000 1.7
+++ lib/Makefile.am 9 May 2005 02:23:32 -0000
@@ -52,13 +52,13 @@ JAVAH = $(USER_JAVAH) -jni -classpath .:
if INSTALL_GLIBJ_ZIP
if FOUND_ECLIPSE
-pkgdata_DATA = commons.jar xml.jar rdf.jar owls.jar cashews.jar services.jar eclipse.jar
+pkgdata_DATA = commons.jar xml.jar rdf.jar owls.jar cashews.jar services.jar soap.jar eclipse.jar
install-data-local: genclasses compile-classes eclipse.jar
if [ ! -e $(INSTALLDIR) ]; then mkdir $(INSTALLDIR); fi
cp eclipse.jar $(INSTALLDIR)
cp $(top_srcdir)/resource/plugin.xml $(INSTALLDIR)
else
-pkgdata_DATA = commons.jar xml.jar rdf.jar cashews.jar owls.jar services.jar
+pkgdata_DATA = commons.jar xml.jar rdf.jar cashews.jar owls.jar soap.jar services.jar
endif
endif # INSTALL_GLIBJ_ZIP
@@ -115,6 +115,12 @@ if FOUND_GCJ
$(GCJ) -shared -fjni -findirect-dispatch -o services.jar.so services.jar
endif
+soap.jar: classes compile-classes # resources
+ if test "$(JAR)" != ""; then rm soap.jar; $(JAR) cf soap.jar `find nongnu -path '*soap*' -name '*class'` > /dev/null; fi
+if FOUND_GCJ
+$(GCJ) -shared -fjni -findirect-dispatch -o soap.jar.so soap.jar
+endif
+
if FOUND_ECLIPSE
eclipse.jar: classes compile-classes # resources
Index: src/nongnu/cashews/commons/.cvsignore
===================================================================
RCS file: src/nongnu/cashews/commons/.cvsignore
diff -N src/nongnu/cashews/commons/.cvsignore
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/nongnu/cashews/commons/.cvsignore 9 May 2005 02:23:32 -0000
@@ -0,0 +1 @@
+Configuration.java
Index: src/nongnu/cashews/commons/Configuration.java.in
===================================================================
RCS file: src/nongnu/cashews/commons/Configuration.java.in
diff -N src/nongnu/cashews/commons/Configuration.java.in
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/nongnu/cashews/commons/Configuration.java.in 9 May 2005 02:23:32 -0000
@@ -0,0 +1,40 @@
+/* Configuration.java -- Local configuration details.
+ Copyright (C) 2005 The University of Sheffield.
+
+ This file is part of the CASheW-s editor.
+
+ The CASheW-s editor is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ The CASheW-s editor is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with The CASheW-s editor; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA.
+*/
+
+package nongnu.cashews.commons;
+
+/**
+ * This file defines compile-time constants that can be accessed by
+ * the Java code. It is pre-processed by configure
.
+ *
+ * @author Andrew John Hughes (address@hidden)
+ */
+public interface Configuration
+{
+
+ /**
+ * The release version number of CASheW-s.
+ * It is set according to the value of 'version' in the
+ * configure[.ac]
file.
+ */
+ String CASHEWS_VERSION = "@VERSION@";
+
+}
Index: src/nongnu/cashews/language/grounding/MessagePart.java
===================================================================
RCS file: /cvsroot/cashew-s-editor/cashews/src/nongnu/cashews/language/grounding/MessagePart.java,v
retrieving revision 1.2
diff -u -3 -p -u -r1.2 MessagePart.java
--- src/nongnu/cashews/language/grounding/MessagePart.java 7 May 2005 21:22:53 -0000 1.2
+++ src/nongnu/cashews/language/grounding/MessagePart.java 9 May 2005 02:23:32 -0000
@@ -164,7 +164,7 @@ public class MessagePart
}
/**
- * Sets the type of this SOAP message to that specified.
+ * Sets the type of this SOAP message part to that specified.
*
* @param type the type of this SOAP message.
*/
@@ -174,6 +174,16 @@ public class MessagePart
}
/**
+ * Returns the name of this SOAP message part.
+ *
+ * @return the name of this SOAP message part.
+ */
+ public QName getName()
+ {
+ return name;
+ }
+
+ /**
* Returns a String
representation of this SOAP message.
*
* @return a textual representation.
Index: src/nongnu/cashews/language/grounding/SoapMessage.java
===================================================================
RCS file: /cvsroot/cashew-s-editor/cashews/src/nongnu/cashews/language/grounding/SoapMessage.java,v
retrieving revision 1.2
diff -u -3 -p -u -r1.2 SoapMessage.java
--- src/nongnu/cashews/language/grounding/SoapMessage.java 7 May 2005 21:22:53 -0000 1.2
+++ src/nongnu/cashews/language/grounding/SoapMessage.java 9 May 2005 02:23:32 -0000
@@ -159,6 +159,16 @@ public class SoapMessage
}
/**
+ * Retrieves a shallow clone of the parts of this message.
+ *
+ * @return a shallow clone of the message parts.
+ */
+ public List getParts()
+ {
+ return new LinkedList(parts);
+ }
+
+ /**
* Returns a String
representation of this SOAP message.
*
* @return a textual representation.
Index: src/nongnu/cashews/language/grounding/SoapOperation.java
===================================================================
RCS file: /cvsroot/cashew-s-editor/cashews/src/nongnu/cashews/language/grounding/SoapOperation.java,v
retrieving revision 1.3
diff -u -3 -p -u -r1.3 SoapOperation.java
--- src/nongnu/cashews/language/grounding/SoapOperation.java 8 May 2005 12:03:41 -0000 1.3
+++ src/nongnu/cashews/language/grounding/SoapOperation.java 9 May 2005 02:23:32 -0000
@@ -176,6 +176,26 @@ public class SoapOperation
}
/**
+ * Retrieves the endpoint of this operation.
+ *
+ * @return the operation endpoint.
+ */
+ public URI getEndpoint()
+ {
+ return endpoint;
+ }
+
+ /**
+ * Retrieves the input message of this operation.
+ *
+ * @return the operation's input message.
+ */
+ public SoapMessage getInputMessage()
+ {
+ return inputMessage;
+ }
+
+ /**
* Returns a String
representation of this SOAP operation.
*
* @return a textual representation.
Index: src/nongnu/cashews/services/Processes.java
===================================================================
RCS file: src/nongnu/cashews/services/Processes.java
diff -N src/nongnu/cashews/services/Processes.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/nongnu/cashews/services/Processes.java 9 May 2005 02:23:32 -0000
@@ -0,0 +1,108 @@
+/* Processes.java -- Test service processes.
+ Copyright (C) 2005 The University of Sheffield.
+
+ This file is part of the CASheW-s editor.
+
+ The CASheW-s editor is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ The CASheW-s editor is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with The CASheW-s editor; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA.
+*/
+
+package nongnu.cashews.services;
+
+import java.net.URISyntaxException;
+
+import static javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI;
+
+import nongnu.cashews.language.grounding.MessagePart;
+import nongnu.cashews.language.grounding.SoapMessage;
+import nongnu.cashews.language.grounding.SoapOperation;
+
+import nongnu.cashews.language.process.AtomicProcess;
+import nongnu.cashews.language.process.CompositeProcess;
+import nongnu.cashews.language.process.Consume;
+import nongnu.cashews.language.process.Performance;
+import nongnu.cashews.language.process.Produce;
+import nongnu.cashews.language.process.Sequence;
+
+/**
+ * Test CASheW-s processes for use in service calls.
+ *
+ * @author Andrew John Hughes (address@hidden)
+ */
+public class Processes
+{
+
+ /**
+ * A test composite process using a sequence.
+ */
+ public static final CompositeProcess TEST_COMPOSITE_SEQUENCE;
+
+ /**
+ * Static initializer
+ */
+ static
+ {
+ try
+ {
+ CompositeProcess process = new CompositeProcess("MyProcess");
+ Sequence sequence = new Sequence();
+ Performance performance = new Performance("MyPerform");
+ AtomicProcess atomic1 = new AtomicProcess("MyAtomic");
+ SoapOperation operation1 = new
+ SoapOperation("http://soapclient.com/xml/soapresponder.wsdl");
+ SoapMessage method1 = new
+ SoapMessage("http://soapclient.com/xml/soapresponder.wsdl",
+ "Method1", "ns1");
+ MessagePart input1a = new MessagePart("input1");
+ input1a.setName(null, "bstrParam1");
+ input1a.setType(W3C_XML_SCHEMA_NS_URI, "string", "xsd");
+ method1.addPart(input1a);
+ MessagePart input1b = new MessagePart("input2");
+ input1b.setName(null, "bstrParam2");
+ input1b.setType(W3C_XML_SCHEMA_NS_URI, "string", "xsd");
+ method1.addPart(input1b);
+ SoapMessage method1Response = new
+ SoapMessage("http://soapclient.com/xml/soapresponder.wsdl",
+ "Method1Response","ns1");
+ MessagePart output1 = new MessagePart("output");
+ output1.setName(null, "bstrReturn");
+ output1.setType(W3C_XML_SCHEMA_NS_URI, "string", "xsd");
+ method1Response.addPart(output1);
+ operation1.setInputMessage(method1);
+ operation1.setOutputMessage(method1Response);
+ atomic1.setGrounding(operation1);
+ performance.setProcess(atomic1);
+ sequence.add(performance);
+ process.setControlStructure(sequence);
+ Consume consume = new Consume("in1","MyPerform","input1",0);
+ process.addConsumer(consume);
+ Produce produce = new Produce("out1","MyPerform","output");
+ process.addProducer(produce);
+ TEST_COMPOSITE_SEQUENCE = process;
+ }
+ catch (URISyntaxException e)
+ {
+ throw new IllegalStateException("Couldn't initialise process.", e);
+ }
+ }
+
+ /**
+ * Private constructor to prevent instantiation.
+ */
+ private Processes()
+ {
+ }
+
+}
Index: src/nongnu/cashews/soap/SoapClient.java
===================================================================
RCS file: src/nongnu/cashews/soap/SoapClient.java
diff -N src/nongnu/cashews/soap/SoapClient.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/nongnu/cashews/soap/SoapClient.java 9 May 2005 02:23:32 -0000
@@ -0,0 +1,177 @@
+/* SoapClient.java -- Handles calling SOAP services.
+ Copyright (C) 2005 The University of Sheffield.
+
+ This file is part of the CASheW-s editor.
+
+ The CASheW-s editor is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ The CASheW-s editor is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with The CASheW-s editor; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA.
+*/
+
+package nongnu.cashews.soap;
+
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.IOException;
+import java.io.OutputStream;
+
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.URISyntaxException;
+import java.net.URI;
+
+import java.util.List;
+
+import static javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI;
+
+import static nongnu.cashews.commons.Configuration.CASHEWS_VERSION;
+
+import nongnu.cashews.language.grounding.MessagePart;
+import nongnu.cashews.language.grounding.SoapMessage;
+import nongnu.cashews.language.grounding.SoapOperation;
+
+import static nongnu.cashews.services.Processes.TEST_COMPOSITE_SEQUENCE;
+
+import nongnu.cashews.xml.Serializer;
+import nongnu.cashews.xml.schema.TypeMapper;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ * Handles the calling of a SOAP service.
+ *
+ * @author Andrew John Hughes (address@hidden)
+ */
+public class SoapClient
+{
+
+ /**
+ * Performs the specified SOAP operation using the supplied
+ * arguments.
+ *
+ * @param operation the operation to perform.
+ * @param args the function arguments, if any.
+ * @return the return value from the call.
+ * @throws IOException if an I/O error occurs.
+ * @throws MalformedURLException if the endpoint URL is invalid.
+ * @throws InstantiationException if a needed class can't be instantiated.
+ * @throws IllegalAccessException if a needed class can't be accessed.
+ * @throws ClassNotFoundException if a needed class can't be found.
+ */
+ public Object call(SoapOperation operation, Object... args)
+ throws IOException, MalformedURLException,
+ InstantiationException, IllegalAccessException,
+ ClassNotFoundException
+ {
+ Document document = serializeOperation(operation, args);
+ HttpURLConnection connection =
+ (HttpURLConnection) operation.getEndpoint().toURL().openConnection();
+ connection.setRequestProperty("SOAPAction","");
+ connection.setRequestProperty("Content-Type",
+ "text/xml; charset=\"utf-8\"");
+ connection.setRequestProperty("User-Agent",
+ "CASheW-s " + CASHEWS_VERSION);
+ connection.setRequestMethod("POST");
+ connection.setDoOutput(true);
+ OutputStream ostream = connection.getOutputStream();
+ Serializer.serializeToStream(document, ostream);
+ connection.connect();
+ System.out.println(connection.getContent());
+ InputStream istream = connection.getInputStream();
+ BufferedReader reader = new BufferedReader(new InputStreamReader(istream));
+ String line = reader.readLine();
+ while (line != null)
+ {
+ System.out.println(line);
+ line = reader.readLine();
+ }
+ return null;
+ }
+
+ /**
+ * Serializes a SoapOperation
object as a SOAP
+ * envelope using the specified values.
+ *
+ * @param operation the operation to perform.
+ * @param args the function arguments, if any.
+ * @return the XML document containing the SOAP envelope.
+ * @throws InstantiationException if a needed class can't be instantiated.
+ * @throws IllegalAccessException if a needed class can't be accessed.
+ * @throws ClassNotFoundException if a needed class can't be found.
+ */
+ private Document serializeOperation(SoapOperation operation, Object... args)
+ throws InstantiationException, IllegalAccessException,
+ ClassNotFoundException
+ {
+ System.out.println("args: " + args);
+ SoapMessage input = operation.getInputMessage();
+ if (input == null)
+ throw new IllegalStateException("No input message specified.");
+ List parts = input.getParts();
+ if (args.length != parts.size())
+ throw new IllegalStateException("All inputs not supplied.");
+ Document document = Serializer.getXmlDocument();
+ Element env = document.createElement("Envelope");
+ Element body = document.createElement("Body");
+ Element inputMessage =
+ document.createElement(input.getName().getLocalPart());
+ int objectIndex = 0;
+ TypeMapper mapper = new TypeMapper();
+ for (MessagePart part : parts)
+ {
+ Serializer.serializeValue(part.getName().getLocalPart(),
+ args[objectIndex], mapper,
+ document, inputMessage);
+ ++objectIndex;
+ }
+ body.appendChild(inputMessage);
+ env.appendChild(body);
+ return Serializer.finalizeXmlDocument(document, env, null);
+ }
+
+ /**
+ * Test harness which performs a workflow request with a test
+ * composite process.
+ *
+ * @param args the command-line arguments.
+ * @throws IOException if an I/O error occurs.
+ * @throws URISyntaxException if one of the operation URIs is invalid.
+ * @throws MalformedURLException if the endpoint URL is invalid.
+ * @throws InstantiationException if a needed class can't be instantiated.
+ * @throws IllegalAccessException if a needed class can't be accessed.
+ * @throws ClassNotFoundException if a needed class can't be found.
+ */
+ public static void main(String[] args)
+ throws URISyntaxException, MalformedURLException, IOException,
+ InstantiationException, IllegalAccessException,
+ ClassNotFoundException
+ {
+ SoapClient client = new SoapClient();
+ SoapOperation operation = new SoapOperation
+ ("http://repton.no-ip.com:8080/workflowService");
+ SoapMessage input = new SoapMessage(null, "workflowRequest");
+ MessagePart part1 = new MessagePart("endpoint");
+ part1.setName(null, "endpoint");
+ part1.setType(W3C_XML_SCHEMA_NS_URI, "anyURI", "xsd");
+ MessagePart part2 = new MessagePart("process");
+ part2.setName(null, "process");
+ input.addPart(part1);
+ input.addPart(part2);
+ operation.setInputMessage(input);
+ client.call(operation, new URI("testWorkflow3"), TEST_COMPOSITE_SEQUENCE);
+ }
+
+}
Index: src/nongnu/cashews/xml/Serializer.java
===================================================================
RCS file: /cvsroot/cashew-s-editor/cashews/src/nongnu/cashews/xml/Serializer.java,v
retrieving revision 1.4
diff -u -3 -p -u -r1.4 Serializer.java
--- src/nongnu/cashews/xml/Serializer.java 8 May 2005 12:03:41 -0000 1.4
+++ src/nongnu/cashews/xml/Serializer.java 9 May 2005 02:23:32 -0000
@@ -22,6 +22,7 @@
package nongnu.cashews.xml;
import java.io.ObjectStreamField;
+import java.io.OutputStream;
import java.io.Serializable;
import java.lang.reflect.Field;
@@ -29,10 +30,7 @@ import java.lang.reflect.Modifier;
import java.net.URISyntaxException;
-import java.util.Arrays;
import java.util.Collection;
-import java.util.LinkedList;
-import java.util.List;
import static javax.xml.XMLConstants.XMLNS_ATTRIBUTE;
import static javax.xml.XMLConstants.XMLNS_ATTRIBUTE_NS_URI;
@@ -43,16 +41,7 @@ import javax.xml.namespace.QName;
import nongnu.cashews.commons.Pair;
import nongnu.cashews.commons.PairList;
-import nongnu.cashews.language.grounding.MessagePart;
-import nongnu.cashews.language.grounding.SoapMessage;
-import nongnu.cashews.language.grounding.SoapOperation;
-
-import nongnu.cashews.language.process.AtomicProcess;
-import nongnu.cashews.language.process.CompositeProcess;
-import nongnu.cashews.language.process.Consume;
-import nongnu.cashews.language.process.Performance;
-import nongnu.cashews.language.process.Produce;
-import nongnu.cashews.language.process.Sequence;
+import static nongnu.cashews.services.Processes.TEST_COMPOSITE_SEQUENCE;
import nongnu.cashews.xml.schema.TypeMapper;
import nongnu.cashews.xml.schema.XsdType;
@@ -60,9 +49,9 @@ import nongnu.cashews.xml.schema.XsdType
import org.w3c.dom.Document;
import org.w3c.dom.DOMImplementation;
import org.w3c.dom.Element;
-import org.w3c.dom.Node;
import org.w3c.dom.bootstrap.DOMImplementationRegistry;
import org.w3c.dom.ls.DOMImplementationLS;
+import org.w3c.dom.ls.LSOutput;
import org.w3c.dom.ls.LSSerializer;
/**
@@ -225,45 +214,10 @@ public class Serializer
Field field = pair.getRight();
if (Modifier.isTransient(field.getModifiers()))
continue;
- System.out.println("field: " + field);
- Object value = field.get(object);
- if (value == null)
- continue;
- Class valueClazz = value.getClass();
- System.out.println("value: " + value + ", " + valueClazz);
- XsdType schemaType = mapper.map(valueClazz);
- if (schemaType != null)
- {
- Element element = createElement(document, field.getName());
- element.appendChild(schemaType.translateValue(document, value));
- objRoot.appendChild(element);
- }
- else if (value instanceof Collection)
- {
- Collection collection = (Collection) value;
- for (Object obj : collection)
- if (obj instanceof Serializable)
- serialize((Serializable) obj, objRoot, document);
- }
- else if (value instanceof Serializable)
- {
- Element element;
- if (xField.isFieldNameSerialized())
- {
- element = createElement(document, field.getName());
- objRoot.appendChild(element);
- }
- else
- element = objRoot;
- serialize((Serializable) value, element, document,
- xField.isClassNameSerialized());
- }
- else
- {
- Element element = createElement(document, field.getName());
- element.appendChild(document.createTextNode(value.toString()));
- objRoot.appendChild(element);
- }
+ serializeValue(field.getName(), field.get(object),
+ xField.isFieldNameSerialized(),
+ xField.isClassNameSerialized(),
+ mapper, document, objRoot);
}
if (root != null)
{
@@ -277,6 +231,7 @@ public class Serializer
* Converts an XML document to a String
.
*
* @param document the document to convert.
+ * @return a String
containing the serialized document.
*/
public static String convertDocumentToString(Document document)
{
@@ -318,6 +273,120 @@ public class Serializer
}
/**
+ * Finalizes an XML document by adding the specified namespace
+ * declarations and root element.
+ *
+ * @param document the document to finalize.
+ * @param root the root element of the document.
+ * @param namespaces the namespaces to declare as part of the document.
+ * This may be null
if there are no
+ * namespaces to declare.
+ * @return the XML document.
+ */
+ public static Document finalizeXmlDocument(Document document, Element root,
+ QName[] namespaces)
+ {
+ addNamespaceDeclarations(namespaces, root);
+ document.appendChild(root);
+ return document;
+ }
+
+ /**
+ * Retrieves an empty XML document for content generation.
+ *
+ * @return a blank XML document.
+ * @throws InstantiationException if the implementation class couldn't
+ * be instantiated.
+ * @throws IllegalAccessException if the implementation class can't be
+ * accessed.
+ * @throws ClassNotFoundException if the implementation class can't be
+ * found.
+ */
+ public static Document getXmlDocument()
+ throws InstantiationException, IllegalAccessException,
+ ClassNotFoundException
+ {
+ initializeImpl();
+ return domImpl.createDocument(null,null,null);
+ }
+
+ /**
+ * Serializes an XML document to an OutputStream
.
+ *
+ * @param document the document to convert.
+ * @param stream the stream to serialize to.
+ * @return true if serialization was successful.
+ */
+ public static boolean serializeToStream(Document document,
+ OutputStream stream)
+ {
+ DOMImplementationLS loadAndSave = (DOMImplementationLS) domImpl;
+ LSSerializer serializer = loadAndSave.createLSSerializer();
+ LSOutput output = loadAndSave.createLSOutput();
+ output.setByteStream(stream);
+ output.setEncoding("utf-8");
+ return serializer.write(document, output);
+ }
+
+ public static void serializeValue(String name, Object value,
+ TypeMapper mapper, Document document,
+ Element objRoot)
+ throws IllegalAccessException
+ {
+ serializeValue(name, value, false, true, mapper, document, objRoot);
+ }
+
+ /**
+ * Serializes a value to XML.
+ *
+ */
+ public static void serializeValue(String name, Object value,
+ boolean includeFieldName,
+ boolean includeTypeName,
+ TypeMapper mapper, Document document,
+ Element objRoot)
+ throws IllegalAccessException
+ {
+ System.out.println("field: " + name);
+ if (value == null)
+ return;
+ Class valueClazz = value.getClass();
+ System.out.println("value: " + value + ", " + valueClazz);
+ XsdType schemaType = mapper.map(valueClazz);
+ if (schemaType != null)
+ {
+ Element element = createElement(document, name);
+ element.appendChild(schemaType.translateValue(document, value));
+ objRoot.appendChild(element);
+ }
+ else if (value instanceof Collection)
+ {
+ Collection collection = (Collection) value;
+ for (Object obj : collection)
+ if (obj instanceof Serializable)
+ serialize((Serializable) obj, objRoot, document);
+ }
+ else if (value instanceof Serializable)
+ {
+ Element element;
+ if (includeFieldName)
+ {
+ element = createElement(document, name);
+ objRoot.appendChild(element);
+ }
+ else
+ element = objRoot;
+ serialize((Serializable) value, element, document, includeTypeName);
+ }
+ else
+ {
+ Element element = createElement(document, name);
+ element.appendChild(document.createTextNode(value.toString()));
+ objRoot.appendChild(element);
+ }
+ }
+
+ /**
* A simple test harness to ensure that objects can be successfully
* converted to XML.
*
@@ -332,45 +401,10 @@ public class Serializer
throws InstantiationException, IllegalAccessException,
ClassNotFoundException, URISyntaxException
{
- CompositeProcess process = new CompositeProcess("MyProcess");
- Sequence sequence = new Sequence();
- Performance performance = new Performance("MyPerform");
- AtomicProcess atomic1 = new AtomicProcess("MyAtomic");
- SoapOperation operation1 = new
- SoapOperation("http://soapclient.com/xml/soapresponder.wsdl");
- SoapMessage method1 = new
- SoapMessage("http://soapclient.com/xml/soapresponder.wsdl", "Method1",
- "ns1");
- MessagePart input1a = new MessagePart("input1");
- input1a.setName(null, "bstrParam1");
- input1a.setType(W3C_XML_SCHEMA_NS_URI, "string", "xsd");
- method1.addPart(input1a);
- MessagePart input1b = new MessagePart("input2");
- input1b.setName(null, "bstrParam2");
- input1b.setType(W3C_XML_SCHEMA_NS_URI, "string", "xsd");
- method1.addPart(input1b);
- SoapMessage method1Response = new
- SoapMessage("http://soapclient.com/xml/soapresponder.wsdl",
- "Method1Response","ns1");
- MessagePart output1 = new MessagePart("output");
- output1.setName(null, "bstrReturn");
- output1.setType(W3C_XML_SCHEMA_NS_URI, "string", "xsd");
- method1Response.addPart(output1);
- operation1.setInputMessage(method1);
- operation1.setOutputMessage(method1Response);
- atomic1.setGrounding(operation1);
- performance.setProcess(atomic1);
- sequence.add(performance);
- process.setControlStructure(sequence);
- Consume consume = new Consume("in1","MyPerform","input1",0);
- process.addConsumer(consume);
- Produce produce = new Produce("out1","MyPerform","output");
- process.addProducer(produce);
- initializeImpl();
- Document document = domImpl.createDocument(null,null,null);
- Element root = Serializer.serialize(process, null, document);
- addNamespaceDeclarations(DOCUMENT_NAMESPACES, root);
- document.appendChild(root);
+ Document document = getXmlDocument();
+ Element root = Serializer.serialize(TEST_COMPOSITE_SEQUENCE, null,
+ document);
+ finalizeXmlDocument(document, root, DOCUMENT_NAMESPACES);
System.out.println(convertDocumentToString(document));
}