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.1 diff -u -3 -p -u -r1.1 MessagePart.java --- src/nongnu/cashews/language/grounding/MessagePart.java 4 May 2005 11:05:53 -0000 1.1 +++ src/nongnu/cashews/language/grounding/MessagePart.java 7 May 2005 20:50:11 -0000 @@ -22,9 +22,12 @@ package nongnu.cashews.language.grounding; import java.net.URI; +import java.net.URISyntaxException; import javax.xml.namespace.QName; +import nongnu.cashews.xml.Xmlizable; + /** * Represents a single part of a SOAP message body. This specifies * the name and type of the element. @@ -32,6 +35,7 @@ import javax.xml.namespace.QName; * @author Andrew John Hughes (address@hidden) */ public class MessagePart + implements Xmlizable { /** @@ -55,6 +59,156 @@ public class MessagePart */ private QName type; + /** + * Constructs a new message part with the specified URI. + * + * @param uri the uri of this message part. + * @throws URISyntaxException if the supplied name is not a valid URI. + */ + public MessagePart(String uri) + throws URISyntaxException + { + setURI(uri); + } + + /** + * Constructs a new message part with the specified URI. + * + * @param uri the uri of this message part. + */ + public MessagePart(URI uri) + { + setURI(uri); + } + + /** + * Sets the URI of this message part to that specified. + * + * @param uri the uri of this message part. + * @throws URISyntaxException if the supplied name is not a valid URI. + */ + public void setURI(String uri) + throws URISyntaxException + { + setURI(new URI(uri)); + } + + /** + * Sets the URI of this message part to that specified. + * + * @param uri the uri of this message part. + */ + public void setURI(URI uri) + { + this.uri = uri; + } + + /** + * Sets the qualified name of this SOAP message to that constructed + * from the supplied namespace URI and local part. + * + * @param namespaceURI the namespace URI of this SOAP message's name. + * @param localPart the local part of this SOAP message's name. + */ + public void setName(String namespaceURI, String localPart) + { + setName(new QName(namespaceURI, localPart)); + } + + /** + * Sets the qualified name of this SOAP message to that constructed + * from the supplied namespace URI, local part and prefix. + * + * @param namespaceURI the namespace URI of this SOAP message's name. + * @param localPart the local part of this SOAP message's name. + * @param prefix the prefix of this SOAP message's name. + */ + public void setName(String namespaceURI, String localPart, String prefix) + { + setName(new QName(namespaceURI, localPart, prefix)); + } + + /** + * Sets the name of this SOAP message to that specified. + * + * @param name the name of this SOAP message. + */ + public void setName(QName name) + { + this.name = name; + } + + /** + * Sets the type of this SOAP message to that constructed + * from the supplied namespace URI and local part. + * + * @param namespaceURI the namespace URI of this SOAP message's type. + * @param localPart the local part of this SOAP message's type. + */ + public void setType(String namespaceURI, String localPart) + { + setType(new QName(namespaceURI, localPart)); + } + + /** + * Sets the qualified type of this SOAP message to that constructed + * from the supplied namespace URI, local part and prefix. + * + * @param namespaceURI the namespace URI of this SOAP message's type. + * @param localPart the local part of this SOAP message's type. + * @param prefix the prefix of this SOAP message's type. + */ + public void setType(String namespaceURI, String localPart, String prefix) + { + setType(new QName(namespaceURI, localPart, prefix)); + } + + /** + * Sets the type of this SOAP message to that specified. + * + * @param type the type of this SOAP message. + */ + public void setType(QName type) + { + this.type = type; + } + + /** + * Returns a String representation of this SOAP message. + * + * @return a textual representation. + */ + public String toString() + { + return getClass().getName() + + "[uri=" + + uri + + ",name=" + + name + + ",type=" + + type + + "]"; + } + + /** + * Returns "part" as the element name for XML serialization. + * + * @return part + */ + public String getElementName() + { + return "part"; + } + + /** + * Returns null as this class needs no further namespace declarations. + * + * @return null. + */ + public QName[] getDeclaredNamespaces() + { + return null; + } } 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.1 diff -u -3 -p -u -r1.1 SoapMessage.java --- src/nongnu/cashews/language/grounding/SoapMessage.java 4 May 2005 11:05:53 -0000 1.1 +++ src/nongnu/cashews/language/grounding/SoapMessage.java 7 May 2005 20:50:11 -0000 @@ -21,6 +21,9 @@ package nongnu.cashews.language.grounding; +import java.io.Serializable; + +import java.util.LinkedList; import java.util.List; import javax.xml.namespace.QName; @@ -32,6 +35,7 @@ import javax.xml.namespace.QName; * @author Andrew John Hughes (address@hidden) */ public class SoapMessage + implements Serializable { /** @@ -48,5 +52,126 @@ public class SoapMessage */ private List parts; + /** + * Constructs a new SOAP message. + */ + private SoapMessage() + { + parts = new LinkedList(); + } + + /** + * Constructs a new SOAP message with the specified qualified + * name, constructed from the supplied namespace URI and + * local part. + * + * @param namespaceURI the namespace URI of this SOAP message's name. + * @param localPart the local part of this SOAP message's name. + */ + public SoapMessage(String namespaceURI, String localPart) + { + this(); + setName(new QName(namespaceURI, localPart)); + } + + /** + * Constructs a new SOAP message with the specified qualified + * name, constructed from the supplied namespace URI, local part + * and prefix. + * + * @param namespaceURI the namespace URI of this SOAP message's name. + * @param localPart the local part of this SOAP message's name. + * @param prefix the prefix of this SOAP message's name. + */ + public SoapMessage(String namespaceURI, String localPart, String prefix) + { + this(); + setName(namespaceURI, localPart, prefix); + } + + /** + * Constructs a new SOAP message with the specified name. + * + * @param name the name of this SOAP message. + */ + public SoapMessage(QName name) + { + this(); + setName(name); + } + + /** + * Sets the qualified name of this SOAP message to that constructed + * from the supplied namespace URI and local part. + * + * @param namespaceURI the namespace URI of this SOAP message's name. + * @param localPart the local part of this SOAP message's name. + */ + public void setName(String namespaceURI, String localPart) + { + setName(new QName(namespaceURI, localPart)); + } + + /** + * Sets the qualified name of this SOAP message to that constructed + * from the supplied namespace URI, local part and prefix. + * + * @param namespaceURI the namespace URI of this SOAP message's name. + * @param localPart the local part of this SOAP message's name. + * @param prefix the prefix of this SOAP message's name. + */ + public void setName(String namespaceURI, String localPart, String prefix) + { + setName(new QName(namespaceURI, localPart, prefix)); + } + + /** + * Sets the name of this SOAP message to that specified. + * + * @param name the name of this SOAP message. + */ + public void setName(QName name) + { + this.name = name; + } + + /** + * Adds a new part to the SOAP message. + * + * @param part the new part to add. + */ + public boolean addPart(MessagePart part) + { + if (part == null) + return false; + parts.add(part); + return true; + } + + /** + * Retrieves the qualified name of this SOAP message. + * + * @return the qualified name of this SOAP message. + */ + public QName getName() + { + return name; + } + + /** + * Returns a String representation of this SOAP message. + * + * @return a textual representation. + */ + public String toString() + { + return getClass().getName() + + "[name=" + + name + + ",parts=" + + parts + + "]"; + } + } 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.1 diff -u -3 -p -u -r1.1 SoapOperation.java --- src/nongnu/cashews/language/grounding/SoapOperation.java 4 May 2005 11:05:53 -0000 1.1 +++ src/nongnu/cashews/language/grounding/SoapOperation.java 7 May 2005 20:50:11 -0000 @@ -22,6 +22,11 @@ package nongnu.cashews.language.grounding; import java.net.URI; +import java.net.URISyntaxException; + +import javax.xml.namespace.QName; + +import nongnu.cashews.xml.Xmlizable; /** * An implementation of Grounding for the Simple @@ -34,7 +39,7 @@ import java.net.URI; * @see Grounding */ public class SoapOperation - implements Grounding + implements Grounding, Xmlizable { /** @@ -65,5 +70,145 @@ public class SoapOperation */ private SoapMessage outputMessage; + /** + * Constructs a new operation using the specified endpoint. + * The endpoint is also used as the namespace of the operation. + * + * @param endpoint the endpoint of this SOAP operation. + * @throws URISyntaxException if the supplied endpoint is not a valid URI. + */ + public SoapOperation(String endpoint) + throws URISyntaxException + { + this(endpoint, endpoint); + } + + /** + * Constructs a new operation using the specified endpoint + * and namespace. + * + * @param endpoint the endpoint of this SOAP operation. + * @param namespace the namespace of this SOAP operation. + * @throws URISyntaxException if the supplied endpoint is not a valid URI. + */ + public SoapOperation(String endpoint, String namespace) + throws URISyntaxException + { + setEndpoint(endpoint); + setNamespace(namespace); + } + + /** + * Sets the endpoint of this SOAP operation to that specified. + * + * @param endpoint the endpoint of the operation. + * @throws URISyntaxException if the supplied endpoint is not a valid URI. + */ + public void setEndpoint(String endpoint) + throws URISyntaxException + { + setEndpoint(new URI(endpoint)); + } + + /** + * Sets the endpoint of this SOAP operation to that specified. + * + * @param endpoint the endpoint of the operation. + */ + public void setEndpoint(URI endpoint) + { + this.endpoint = endpoint; + } + + /** + * Sets the namespace of this SOAP operation to that specified. + * + * @param namespace the namespace of the operation. + * @throws URISyntaxException if the supplied namespace is not a valid URI. + */ + public void setNamespace(String namespace) + throws URISyntaxException + { + setNamespace(new URI(namespace)); + } + + /** + * Sets the namespace of this SOAP operation to that specified. + * + * @param namespace the namespace of the operation. + */ + public void setNamespace(URI namespace) + { + this.namespace = namespace; + } + + /** + * Sets the input message of this SOAP operation to that specified. + * + * @param inputMessage the input message of this operation. + */ + public void setInputMessage(SoapMessage inputMessage) + { + this.inputMessage = inputMessage; + } + + /** + * Sets the output message of this SOAP operation to that specified. + * + * @param outputMessage the output message of this operation. + */ + public void setOutputMessage(SoapMessage outputMessage) + { + this.outputMessage = outputMessage; + } + + /** + * Returns a String representation of this SOAP operation. + * + * @return a textual representation. + */ + public String toString() + { + return getClass().getName() + + "[endpoint=" + + endpoint + + ",namespace=" + + namespace + + ",inputMessage=" + + inputMessage + + ",outputMessage=" + + outputMessage + + "]"; + } + + /** + * Returns "soapOperation" as the element name. + * + * @return soapOperation + */ + public String getElementName() + { + return "soapOperation"; + } + + /** + * Retrieves an array of QNames which specifies the namespaces to + * declare when serializing this element as XML. + * + * @return an array of QNames for namespace declaration. + */ + public QName[] getDeclaredNamespaces() + { + if (inputMessage != null) + { + return new QName[] + { + inputMessage.getName() + }; + } + else + return null; + } + } Index: src/nongnu/cashews/language/process/CProcess.java =================================================================== RCS file: /cvsroot/cashew-s-editor/cashews/src/nongnu/cashews/language/process/CProcess.java,v retrieving revision 1.1 diff -u -3 -p -u -r1.1 CProcess.java --- src/nongnu/cashews/language/process/CProcess.java 4 May 2005 22:14:05 -0000 1.1 +++ src/nongnu/cashews/language/process/CProcess.java 7 May 2005 20:50:11 -0000 @@ -21,6 +21,8 @@ package nongnu.cashews.language.process; +import java.io.Serializable; + /** * Marks this class as a possible control construct for * CompositeProcesses. @@ -29,5 +31,6 @@ package nongnu.cashews.language.process; * @see CompositeProcess */ public interface CProcess + extends Serializable { } Index: src/nongnu/cashews/language/process/CompositeProcess.java =================================================================== RCS file: /cvsroot/cashew-s-editor/cashews/src/nongnu/cashews/language/process/CompositeProcess.java,v retrieving revision 1.3 diff -u -3 -p -u -r1.3 CompositeProcess.java --- src/nongnu/cashews/language/process/CompositeProcess.java 6 May 2005 10:26:51 -0000 1.3 +++ src/nongnu/cashews/language/process/CompositeProcess.java 7 May 2005 20:50:11 -0000 @@ -23,6 +23,8 @@ package nongnu.cashews.language.process; import java.net.URI; import java.net.URISyntaxException; + +import java.util.LinkedList; import java.util.List; /** @@ -78,6 +80,8 @@ public class CompositeProcess throws URISyntaxException { super(name); + consumers = new LinkedList(); + producers = new LinkedList(); } /** @@ -89,6 +93,8 @@ public class CompositeProcess public CompositeProcess(URI name) { super(name); + consumers = new LinkedList(); + producers = new LinkedList(); } /** @@ -102,6 +108,32 @@ public class CompositeProcess } /** + * Adds a consumer to this composite process. + * + * @param consumer the new consumer. + */ + public boolean addConsumer(Consume consumer) + { + if (consumer == null) + return false; + consumers.add(consumer); + return true; + } + + /** + * Adds a producer to this composite process. + * + * @param producer the new producer. + */ + public boolean addProducer(Produce producer) + { + if (producer == null) + return false; + producers.add(producer); + return true; + } + + /** * Returns a String representation of this process. * * @return a textual representation. Index: src/nongnu/cashews/language/process/Consume.java =================================================================== RCS file: /cvsroot/cashew-s-editor/cashews/src/nongnu/cashews/language/process/Consume.java,v retrieving revision 1.1 diff -u -3 -p -u -r1.1 Consume.java --- src/nongnu/cashews/language/process/Consume.java 4 May 2005 07:31:55 -0000 1.1 +++ src/nongnu/cashews/language/process/Consume.java 7 May 2005 20:50:11 -0000 @@ -21,7 +21,10 @@ package nongnu.cashews.language.process; +import java.io.Serializable; + import java.net.URI; +import java.net.URISyntaxException; /** * Consumes input for use in a CompositeProcess. @@ -32,6 +35,7 @@ import java.net.URI; * @see Performance */ public class Consume + implements Serializable { /** @@ -61,5 +65,142 @@ public class Consume * @serial the index of the destination input. */ private int toIndex; + + /** + * Construct a new Consume with the specified + * destination performance, source and destination inputs, + * along with the supplied index. + * + * @param fromInput the input on the composite process. + * @param toPerformance the performance to send the input to. + * @param toInput the input on the destination performance. + * @param toIndex the index on the input on the destination performance. + * @throws URISyntaxException if one of the supplied names is not a valid + * URI. + */ + public Consume(String fromInput, String toPerformance, String toInput, + int toIndex) + throws URISyntaxException + { + setFromInput(fromInput); + setToPerformance(toPerformance); + setToInput(toInput); + setToIndex(toIndex); + } + + /** + * Construct a new Consume with the specified + * destination performance, source and destination inputs, + * along with the supplied index. + * + * @param fromInput the input on the composite process. + * @param toPerformance the performance to send the input to. + * @param toInput the input on the destination performance. + * @param toIndex the index on the input on the destination performance. + */ + public Consume(URI fromInput, URI toPerformance, URI toInput, + int toIndex) + { + setFromInput(fromInput); + setToPerformance(toPerformance); + setToInput(toInput); + setToIndex(toIndex); + } + + /** + * Sets the source input on the composite process to that specified. + * + * @param fromInput the new source input on the composite process. + * @throws URISyntaxException if the supplied input is not a valid URI. + */ + public void setFromInput(String fromInput) + throws URISyntaxException + { + setFromInput(new URI(fromInput)); + } + + /** + * Sets the source input on the composite process to that specified. + * + * @param fromInput the new source input on the composite process. + */ + public void setFromInput(URI fromInput) + { + this.fromInput = fromInput; + } + + /** + * Sets the destination performance to that specified. + * + * @param toPerformance the new destination performance. + * @throws URISyntaxException if the supplied performance is not a valid URI. + */ + public void setToPerformance(String toPerformance) + throws URISyntaxException + { + setToPerformance(new URI(toPerformance)); + } + + /** + * Sets the destination performance to that specified. + * + * @param toPerformance the new destination performance. + */ + public void setToPerformance(URI toPerformance) + { + this.toPerformance = toPerformance; + } + + /** + * Sets the destination input on the performance to that specified. + * + * @param toInput the new destination input on the performance. + * @throws URISyntaxException if the supplied input is not a valid URI. + */ + public void setToInput(String toInput) + throws URISyntaxException + { + setToInput(new URI(toInput)); + } + + /** + * Sets the destination input on the performance to that specified. + * + * @param toInput the new destination input on the performance. + */ + public void setToInput(URI toInput) + { + this.toInput = toInput; + } + + /** + * Sets the index of the input on the performance to that specified. + * + * @param toIndex the new index of the input on the performance. + */ + public void setToIndex(int toIndex) + { + this.toIndex = toIndex; + } + + /** + * Returns a String representation of this performance. + * + * @return a textual representation. + */ + public String toString() + { + return getClass().getName() + + "[fromInput=" + + fromInput + + ",toPerformance=" + + toPerformance + + ",toInput=" + + toInput + + ",toIndex=" + + toIndex + + "]"; + } + } Index: src/nongnu/cashews/language/process/MultiPerform.java =================================================================== RCS file: /cvsroot/cashew-s-editor/cashews/src/nongnu/cashews/language/process/MultiPerform.java,v retrieving revision 1.3 diff -u -3 -p -u -r1.3 MultiPerform.java --- src/nongnu/cashews/language/process/MultiPerform.java 6 May 2005 10:26:51 -0000 1.3 +++ src/nongnu/cashews/language/process/MultiPerform.java 7 May 2005 20:50:11 -0000 @@ -24,8 +24,6 @@ package nongnu.cashews.language.process; import java.util.ArrayList; import java.util.List; -import nongnu.cashews.xml.Xmlizable; - /** * A generic superclass for composite processes which handle an arbitrary * length list of Performances, interleaved with @@ -36,7 +34,7 @@ import nongnu.cashews.xml.Xmlizable; * @see Connection */ public abstract class MultiPerform - implements CProcess, Xmlizable + implements CProcess { /** Index: src/nongnu/cashews/language/process/Performance.java =================================================================== RCS file: /cvsroot/cashew-s-editor/cashews/src/nongnu/cashews/language/process/Performance.java,v retrieving revision 1.3 diff -u -3 -p -u -r1.3 Performance.java --- src/nongnu/cashews/language/process/Performance.java 6 May 2005 10:26:51 -0000 1.3 +++ src/nongnu/cashews/language/process/Performance.java 7 May 2005 20:50:11 -0000 @@ -26,7 +26,9 @@ import java.net.URISyntaxException; import java.util.ArrayList; import java.util.List; -import nongnu.cashews.xml.CustomXmlizable; +import javax.xml.namespace.QName; + +import nongnu.cashews.xml.Xmlizable; /** * Represents an instance of an atomic or @@ -42,7 +44,7 @@ import nongnu.cashews.xml.CustomXmlizabl * @see ValueCollector */ public class Performance - implements MultiPerformElement, CustomXmlizable + implements MultiPerformElement, Xmlizable { /** @@ -229,7 +231,7 @@ public class Performance } /** - * Returns "perform" as the element name. + * Returns "perform" as the element name for XML serialization. * * @return perform */ @@ -238,4 +240,14 @@ public class Performance return "perform"; } + /** + * Returns null as this class needs no further namespace declarations. + * + * @return null. + */ + public QName[] getDeclaredNamespaces() + { + return null; + } + } Index: src/nongnu/cashews/language/process/Process.java =================================================================== RCS file: /cvsroot/cashew-s-editor/cashews/src/nongnu/cashews/language/process/Process.java,v retrieving revision 1.3 diff -u -3 -p -u -r1.3 Process.java --- src/nongnu/cashews/language/process/Process.java 6 May 2005 10:26:51 -0000 1.3 +++ src/nongnu/cashews/language/process/Process.java 7 May 2005 20:50:11 -0000 @@ -21,11 +21,11 @@ package nongnu.cashews.language.process; +import java.io.Serializable; + import java.net.URI; import java.net.URISyntaxException; -import nongnu.cashews.xml.Xmlizable; - /** * Takes a set of inputs, does some processing and returns a set of * outputs. The internal makeup of the process is split between @@ -43,7 +43,7 @@ import nongnu.cashews.xml.Xmlizable; * @see Grounding */ public abstract class Process - implements Cloneable, Xmlizable + implements Cloneable, Serializable { /** Index: src/nongnu/cashews/language/process/Produce.java =================================================================== RCS file: /cvsroot/cashew-s-editor/cashews/src/nongnu/cashews/language/process/Produce.java,v retrieving revision 1.1 diff -u -3 -p -u -r1.1 Produce.java --- src/nongnu/cashews/language/process/Produce.java 4 May 2005 07:31:55 -0000 1.1 +++ src/nongnu/cashews/language/process/Produce.java 7 May 2005 20:50:12 -0000 @@ -22,6 +22,9 @@ package nongnu.cashews.language.process; import java.net.URI; +import java.net.URISyntaxException; + +import java.io.Serializable; /** * Produces output for a CompositeProcess as a whole. @@ -32,14 +35,15 @@ import java.net.URI; * @see Performance */ public class Produce + implements Serializable { /** - * The output of the internal performance. + * The output of the composite process. * - * @serial the internal performance input. + * @serial the composite process output. */ - private URI fromOutput; + private URI toOutput; /** * The internal performance where the output comes from. @@ -49,11 +53,129 @@ public class Produce private URI fromPerformance; /** - * The output of the composite process. + * The output of the internal performance. * - * @serial the composite process output. + * @serial the internal performance input. */ - private URI toOutput; + private URI fromOutput; + + /** + * Construct a new Produce with the specified + * source performance and the supplied source and destination + * outputs. + * + * @param fromOutput the output on the composite process. + * @param fromPerformance the performance to retrieve the output from. + * @param toOutput the output on the destination performance. + * @throws URISyntaxException if one of the supplied names is not a valid + * URI. + */ + public Produce(String fromOutput, String fromPerformance, String toOutput) + throws URISyntaxException + { + setFromOutput(fromOutput); + setFromPerformance(fromPerformance); + setToOutput(toOutput); + } + + /** + * Construct a new Produce with the specified + * source performance and the supplied source and destination + * outputs. + * + * @param fromOutput the output on the composite process. + * @param fromPerformance the performance to retrieve the output from. + * @param toOutput the output on the destination performance. + */ + public Produce(URI fromOutput, URI fromPerformance, URI toOutput) + { + setFromOutput(fromOutput); + setFromPerformance(fromPerformance); + setToOutput(toOutput); + } + + /** + * Sets the source output on the performance to that specified. + * + * @param fromOutput the new source output on the performance. + * @throws URISyntaxException if the supplied output is not a valid URI. + */ + public void setFromOutput(String fromOutput) + throws URISyntaxException + { + setFromOutput(new URI(fromOutput)); + } + + /** + * Sets the source output on the performance to that specified. + * + * @param fromOutput the new source output on the performance. + */ + public void setFromOutput(URI fromOutput) + { + this.fromOutput = fromOutput; + } + + /** + * Sets the source performance to that specified. + * + * @param fromPerformance the new source performance. + * @throws URISyntaxException if the supplied performance is not a valid URI. + */ + public void setFromPerformance(String fromPerformance) + throws URISyntaxException + { + setFromPerformance(new URI(fromPerformance)); + } + + /** + * Sets the destination performance to that specified. + * + * @param fromPerformance the new destination performance. + */ + public void setFromPerformance(URI fromPerformance) + { + this.fromPerformance = fromPerformance; + } + + /** + * Sets the destination output on the composite process to that specified. + * + * @param toOutput the new destination output on the composite process. + * @throws URISyntaxException if the supplied output is not a valid URI. + */ + public void setToOutput(String toOutput) + throws URISyntaxException + { + setToOutput(new URI(toOutput)); + } + + /** + * Sets the destination output on the composite process to that specified. + * + * @param toOutput the new destination input on the composite process. + */ + public void setToOutput(URI toOutput) + { + this.toOutput = toOutput; + } + + /** + * Returns a String representation of this performance. + * + * @return a textual representation. + */ + public String toString() + { + return getClass().getName() + + "[fromOutput=" + + fromOutput + + ",fromPerformance=" + + fromPerformance + + ",toOutput=" + + toOutput + + "]"; + } } Index: src/nongnu/cashews/xml/CustomXmlizable.java =================================================================== RCS file: src/nongnu/cashews/xml/CustomXmlizable.java diff -N src/nongnu/cashews/xml/CustomXmlizable.java --- src/nongnu/cashews/xml/CustomXmlizable.java 6 May 2005 10:26:51 -0000 1.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,46 +0,0 @@ -/* CProcess.java -- Marks a class as a possible construct for composites. - 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.xml; - -/** - * Specifies that a class can be converted to an XML tree. The methods - * specified by this class allow additional information to be specified - * to the serializer. - * - * @author Andrew John Hughes (address@hidden) - * @see Serializer - */ -public interface CustomXmlizable - extends Xmlizable -{ - - /** - * Retrieves the name to use for the XML element that represents - * this class. If null is specified, the class name - * will be used with the first letter set to lowercase. - * - * @return the element name, or null if the class name - * should be used. - */ - String getElementName(); - -} Index: src/nongnu/cashews/xml/Serializer.java =================================================================== RCS file: /cvsroot/cashew-s-editor/cashews/src/nongnu/cashews/xml/Serializer.java,v retrieving revision 1.2 diff -u -3 -p -u -r1.2 Serializer.java --- src/nongnu/cashews/xml/Serializer.java 6 May 2005 10:26:51 -0000 1.2 +++ src/nongnu/cashews/xml/Serializer.java 7 May 2005 20:50:12 -0000 @@ -21,7 +21,11 @@ package nongnu.cashews.xml; +import java.io.ObjectStreamClass; +import java.io.Serializable; + import java.lang.reflect.Field; +import java.lang.reflect.Modifier; import java.net.URISyntaxException; @@ -30,11 +34,23 @@ 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; +import static javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI; + +import javax.xml.namespace.QName; + +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 nongnu.cashews.xml.schema.TypeMapper; import nongnu.cashews.xml.schema.XsdType; @@ -60,6 +76,14 @@ public class Serializer private static DOMImplementation domImpl; /** + * The document namespaces. + */ + private static final QName[] DOCUMENT_NAMESPACES = new QName[] + { + new QName(W3C_XML_SCHEMA_NS_URI, "", "xsd") + }; + + /** * Initialize the DOM implementation (one time operation only). * * @throws InstantiationException if the implementation class couldn't @@ -93,49 +117,60 @@ public class Serializer * @return the serialized object in XML form. * @throws IllegalAccessException if a field can't be accessed. */ - public static Node serialize(Xmlizable object, Node root, - Document document) + public static Element serialize(Serializable object, Element root, + Document document) throws IllegalAccessException { List fields = new LinkedList(); Class clazz = object.getClass(); String elementName = null; - CustomXmlizable customObject = null; - if (object instanceof CustomXmlizable) + Xmlizable customObject = null; + if (object instanceof Xmlizable) { - customObject = (CustomXmlizable) object; + customObject = (Xmlizable) object; elementName = customObject.getElementName(); } if (elementName == null) elementName = clazz.getSimpleName(); Element objRoot = createElement(document, elementName); + if (customObject != null) + addNamespaceDeclarations(customObject.getDeclaredNamespaces(), objRoot); while (clazz != null) { fields.addAll(0, Arrays.asList(clazz.getDeclaredFields())); clazz = clazz.getSuperclass(); } + TypeMapper mapper = new TypeMapper(); for (Field field: fields) { + if (Modifier.isTransient(field.getModifiers())) + continue; System.out.println("field: " + field); Object value = field.get(object); - System.out.println("value: " + value); if (value == null) continue; - if (value instanceof Collection) + 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 Xmlizable) - serialize((Xmlizable) obj, objRoot, document); - } + if (obj instanceof Serializable) + serialize((Serializable) obj, objRoot, document); } - else if (value instanceof Xmlizable) - serialize((Xmlizable) value, objRoot, document); + else if (value instanceof Serializable) + serialize((Serializable) value, objRoot, document); else { Element element = createElement(document, field.getName()); - serializeValue(document, element, value); + element.appendChild(document.createTextNode(value.toString())); objRoot.appendChild(element); } } @@ -160,29 +195,6 @@ public class Serializer } /** - * Serializes a reflected class field and its contents into an XML element. - * An XML schema datatype is searched for first, in order to provide - * the most appropriate translation. If this fails, the - * toString() content is used. - * - * @param document the document instance for creating further XML nodes. - * @param element the element to serialize to. - * @param value the value to serialize. - * @return the serialized element. - */ - private static void serializeValue(Document document, Element element, - Object value) - { - TypeMapper mapper = new TypeMapper(); - Class clazz = value.getClass(); - XsdType schemaType = mapper.map(clazz); - if (schemaType == null) - element.appendChild(document.createTextNode(value.toString())); - else - element.appendChild(schemaType.translateValue(document, value)); - } - - /** * Creates an element with the appropriate naming schema. * * @param document the document for creating elements. @@ -199,6 +211,22 @@ public class Serializer } /** + * Adds namespace declarations to an element. + * + * @param qnames the qualified names for which namespace declarations + * should be made. + * @param element the element to which to add declarations. + */ + private static void addNamespaceDeclarations(QName[] qnames, Element element) + { + if (qnames != null) + for (QName qname : qnames) + element.setAttributeNS(XMLNS_ATTRIBUTE_NS_URI, + XMLNS_ATTRIBUTE + ":" + qname.getPrefix(), + qname.getNamespaceURI()); + } + + /** * A simple test harness to ensure that objects can be successfully * converted to XML. * @@ -217,13 +245,41 @@ public class Serializer Sequence sequence = new Sequence(); Performance performance = new Performance("MyPerform"); AtomicProcess atomic1 = new AtomicProcess("MyAtomic"); - atomic1.setGrounding(new SoapOperation()); + 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); - document.appendChild(Serializer.serialize(process, null, document)); + Element root = Serializer.serialize(process, null, document); + addNamespaceDeclarations(DOCUMENT_NAMESPACES, root); + document.appendChild(root); System.out.println(convertDocumentToString(document)); } Index: src/nongnu/cashews/xml/Xmlizable.java =================================================================== RCS file: /cvsroot/cashew-s-editor/cashews/src/nongnu/cashews/xml/Xmlizable.java,v retrieving revision 1.2 diff -u -3 -p -u -r1.2 Xmlizable.java --- src/nongnu/cashews/xml/Xmlizable.java 6 May 2005 10:26:51 -0000 1.2 +++ src/nongnu/cashews/xml/Xmlizable.java 7 May 2005 20:50:12 -0000 @@ -1,4 +1,4 @@ -/* Xmlizable.java -- Marks a class as convertable to an XML tree. +/* Xmlizable.java -- Defines the XML serialization process for a class. Copyright (C) 2005 The University of Sheffield. This file is part of the CASheW-s editor. @@ -21,12 +21,40 @@ package nongnu.cashews.xml; +import java.io.Serializable; + +import javax.xml.namespace.QName; + /** - * Marks a class that can be converted to an XML tree. + * Specifies that a class can be converted to an XML tree. The methods + * specified by this class allow additional information to be specified + * to the serializer. * * @author Andrew John Hughes (address@hidden) * @see Serializer */ public interface Xmlizable + extends Serializable { + + /** + * Retrieves the name to use for the XML element that represents + * this class. If null is specified, the class name + * will be used with the first letter set to lowercase. + * + * @return the element name, or null if the class name + * should be used. + */ + String getElementName(); + + /** + * Retrieves an array of qualified names which specifies the + * namespaces to declare when serializing this element as XML. + * Specifying null or an empty array corresponds to no + * namespace declarations. + * + * @return an array of qualified names for namespace declaration. + */ + QName[] getDeclaredNamespaces(); + } Index: src/nongnu/cashews/xml/schema/TypeMapper.java =================================================================== RCS file: /cvsroot/cashew-s-editor/cashews/src/nongnu/cashews/xml/schema/TypeMapper.java,v retrieving revision 1.1 diff -u -3 -p -u -r1.1 TypeMapper.java --- src/nongnu/cashews/xml/schema/TypeMapper.java 4 May 2005 22:14:05 -0000 1.1 +++ src/nongnu/cashews/xml/schema/TypeMapper.java 7 May 2005 20:50:12 -0000 @@ -26,7 +26,11 @@ import java.net.URI; import java.util.HashMap; import java.util.Map; +import javax.xml.namespace.QName; + import nongnu.cashews.xml.schema.datatypes.AnyUri; +import nongnu.cashews.xml.schema.datatypes.Int; +import nongnu.cashews.xml.schema.datatypes.XsdQName; /** * Maps a Java data type to an XML schema data type. @@ -48,6 +52,8 @@ public class TypeMapper { builtInTypes = new HashMap>(); builtInTypes.put(URI.class, new AnyUri()); + builtInTypes.put(QName.class, new XsdQName()); + builtInTypes.put(Integer.class, new Int()); } /** Index: src/nongnu/cashews/xml/schema/datatypes/Int.java =================================================================== RCS file: src/nongnu/cashews/xml/schema/datatypes/Int.java diff -N src/nongnu/cashews/xml/schema/datatypes/Int.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/nongnu/cashews/xml/schema/datatypes/Int.java 7 May 2005 20:50:12 -0000 @@ -0,0 +1,50 @@ +/* Int.java -- Represents the XML schema type, xsd:int. + 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.xml.schema.datatypes; + +import nongnu.cashews.xml.schema.XsdType; + +import org.w3c.dom.Document; +import org.w3c.dom.Node; + +/** + * Represents the XML schema datatype, xsd:int. + * + * @author Andrew John Hughes (address@hidden) + */ +public class Int + implements XsdType +{ + + /** + * Translates the supplied Java Integer into a value + * of the XML schema datatype, xsd:int. + * @param document the XML document to use to create the XML tree. + * @param value the Integer value to translate. + * @return an XML tree node representing the type. + */ + public Node translateValue(Document document, Integer value) + { + return document.createTextNode(value.toString()); + } + +} Index: src/nongnu/cashews/xml/schema/datatypes/XsdQName.java =================================================================== RCS file: src/nongnu/cashews/xml/schema/datatypes/XsdQName.java diff -N src/nongnu/cashews/xml/schema/datatypes/XsdQName.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/nongnu/cashews/xml/schema/datatypes/XsdQName.java 7 May 2005 20:50:12 -0000 @@ -0,0 +1,58 @@ +/* XsdQName.java -- Represents the XML schema type, xsd:QName. + 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.xml.schema.datatypes; + +import javax.xml.namespace.QName; + +import nongnu.cashews.xml.schema.XsdType; + +import org.w3c.dom.Document; +import org.w3c.dom.Node; + +/** + * Represents the XML schema datatype, xsd:QName. + * + * @author Andrew John Hughes (address@hidden) + */ +public class XsdQName + implements XsdType +{ + + /** + * Translates the supplied Java QName into a value + * of the XML schema datatype, xsd:QName. + * @param document the XML document to use to create the XML tree. + * @param value the QName value to translate. + * @return an XML tree node representing the type. + */ + public Node translateValue(Document document, QName value) + { + String content; + String prefix = value.getPrefix(); + if (prefix.equals("")) + content = value.getLocalPart(); + else + content = prefix + ":" + value.getLocalPart(); + return document.createTextNode(content); + } + +}