Class ProcessModelXMLExport


  • public class ProcessModelXMLExport
    extends Object
    The XMLExport class allows to export any template or instance data to an xml file, an DOM document, a string or a byte array (containing XML code). TODO Instance: export *histories elements in the histories-namespace?
    Author:
    Kevin Goeser
    • Constructor Detail

      • ProcessModelXMLExport

        public ProcessModelXMLExport()
    • Method Detail

      • writeTemplateToFile

        public void writeTemplateToFile​(Template template,
                                        File file)
                                 throws IOException,
                                        XMLFormatException
        Writes the given template to the given file.
        Parameters:
        file - The target file,
        template - The source template,
        Throws:
        IOException - Thrown if writing the XML to the file fails, e.g. if the provided file is read-only.
        XMLFormatException - Thrown if the validation of the document fails
      • writeTemplateToFile

        public void writeTemplateToFile​(Template template,
                                        File file,
                                        boolean intend)
                                 throws IOException,
                                        XMLFormatException
        Writes the given template to the given file.
        Parameters:
        file - The target file,
        template - The source template,
        intend - Whether to intend child nodes and text content. Use with care! Text content may contain whitespace and linebreaks afterwards!
        Throws:
        IOException - Thrown if writing the XML to the file fails, e.g. if the provided file is read-only.
        XMLFormatException - Thrown if the validation of the document fails
      • writeTemplateAndStatusToFile

        public void writeTemplateAndStatusToFile​(Template template,
                                                 TemplateStatus templateStatus,
                                                 File file)
                                          throws IOException,
                                                 XMLFormatException
        Writes the given template including its status to the given file.
        Parameters:
        file - The target file,
        template - The source template,
        templateStatus - The status of the template.
        Throws:
        IOException - Thrown if writing the XML to the file fails, e.g. if the provided file is read-only.
        XMLFormatException - Thrown if the validation of the document fails
      • writeTemplateAndStatusToFile

        public void writeTemplateAndStatusToFile​(Template template,
                                                 TemplateStatus templateStatus,
                                                 File file,
                                                 boolean intend)
                                          throws IOException,
                                                 XMLFormatException
        Writes the given template including its status to the given file.
        Parameters:
        file - The target file,
        template - The source template,
        templateStatus - The status of the template.
        intend - Whether to intend child nodes and text content. Use with care! Text content may contain whitespace and linebreaks afterwards!
        Throws:
        IOException - Thrown if writing the XML to the file fails, e.g. if the provided file is read-only.
        XMLFormatException - Thrown if the validation of the document fails
      • writeInstanceToFile

        public void writeInstanceToFile​(Instance instance,
                                        File file)
                                 throws IOException,
                                        XMLFormatException
        Writes the given instance to the given file.
        Parameters:
        file - The target file,
        instance - The source instance,
        Throws:
        IOException - Thrown if writing the XML to the file fails, e.g. if the provided file is read-only.
        XMLFormatException - Thrown if the validation of the document fails
      • writeInstanceToFile

        public void writeInstanceToFile​(Instance instance,
                                        File file,
                                        boolean intend)
                                 throws IOException,
                                        XMLFormatException
        Writes the given instance to the given file.
        Parameters:
        file - The target file,
        instance - The source instance,
        intend - Whether to intend child nodes and text content. Use with care! Text content may contain whitespace and linebreaks afterwards!
        Throws:
        IOException - Thrown if writing the XML to the file fails, e.g. if the provided file is read-only.
        XMLFormatException - Thrown if the validation of the document fails
      • writeInstanceAndStatusToFile

        public void writeInstanceAndStatusToFile​(Instance instance,
                                                 InstanceStatus instanceStatus,
                                                 File file,
                                                 boolean storeStructure)
                                          throws IOException,
                                                 XMLFormatException
        Writes the given instance including its status to the given file.
        Parameters:
        instance - The source instance,
        instanceStatus - The status object of the instance
        file - The target file,
        storeStructure - If set to true, the structure is stored to the file, else, only an ID reference will be stored.
        Throws:
        IOException - Thrown if writing the XML to the file fails, e.g. if the provided file is read-only.
        XMLFormatException - Thrown if the validation of the document fails
      • writeInstanceAndStatusToFile

        public void writeInstanceAndStatusToFile​(Instance instance,
                                                 InstanceStatus instanceStatus,
                                                 File file,
                                                 boolean storeStructure,
                                                 boolean intend)
                                          throws IOException,
                                                 XMLFormatException
        Writes the given instance including its status to the given file.
        Parameters:
        instance - The source instance,
        instanceStatus - The status object of the instance
        file - The target file,
        storeStructure - If set to true, the structure is stored to the file, else, only an ID reference will be stored.
        intend - Whether to intend child nodes and text content. Use with care! Text content may contain whitespace and linebreaks afterwards!
        Throws:
        IOException - Thrown if writing the XML to the file fails, e.g. if the provided file is read-only.
        XMLFormatException - Thrown if the validation of the document fails
      • writeExecutableInstanceAndStatusToFile

        public void writeExecutableInstanceAndStatusToFile​(ExecutableInstance instance,
                                                           InstanceStatus instanceStatus,
                                                           File file,
                                                           Template structure)
                                                    throws IOException,
                                                           XMLFormatException
        Writes the given instance including its status to the given file.
        Parameters:
        instance - The source instance,
        instanceStatus - The status object of the instance
        file - The target file,
        structure - If not null, the designated structure (template or instance delta layer) of the instance, will be stored inline.
        Throws:
        IOException - Thrown if writing the XML to the file fails, e.g. if the provided file is read-only.
        XMLFormatException - Thrown if the validation of the document fails
      • writeExecutableInstanceAndStatusToFile

        public void writeExecutableInstanceAndStatusToFile​(ExecutableInstance instance,
                                                           InstanceStatus instanceStatus,
                                                           File file,
                                                           Template structure,
                                                           boolean intend)
                                                    throws IOException,
                                                           XMLFormatException
        Writes the given instance including its status to the given file.
        Parameters:
        instance - The source instance,
        instanceStatus - The status object of the instance
        file - The target file,
        structure - If not null, the designated structure (template or instance delta layer) of the instance, will be stored inline.
        intend - Whether to intend child nodes and text content. Use with care! Text content may contain whitespace and linebreaks afterwards!
        Throws:
        IOException - Thrown if writing the XML to the file fails, e.g. if the provided file is read-only.
        XMLFormatException - Thrown if the validation of the document fails
      • getXMLStringForTemplate

        public String getXMLStringForTemplate​(Template template)
                                       throws XMLFormatException,
                                              IOException
        Returns the xml code of a given template as string.
        Parameters:
        template - The template which should be transformed.
        Returns:
        The xml code of the given process as string.
        Throws:
        XMLFormatException - Thrown if the validation of the document fails
        IOException - Thrown if an unrecoverable error occurs during the course of the transformation
      • getXMLStringForTemplate

        public String getXMLStringForTemplate​(Template template,
                                              boolean intend)
                                       throws XMLFormatException,
                                              IOException
        Returns the xml code of a given template as string.
        Parameters:
        template - The template which should be transformed.
        intend - Whether to intend child nodes and text content. Use with care! Text content may contain whitespace and linebreaks afterwards!
        Returns:
        The xml code of the given process as string.
        Throws:
        XMLFormatException - Thrown if the validation of the document fails
        IOException - Thrown if an unrecoverable error occurs during the course of the transformation
      • getXMLStringForInstance

        public String getXMLStringForInstance​(Instance instance)
                                       throws XMLFormatException,
                                              IOException
        Returns the xml code of a given instance as string.
        Parameters:
        instance - The instance which should be transformed.
        Returns:
        The xml code of the given process as string.
        Throws:
        XMLFormatException - Thrown if the validation of the document fails
        IOException - Thrown if an unrecoverable error occurs during the course of the transformation
      • getXMLStringForInstance

        public String getXMLStringForInstance​(Instance instance,
                                              boolean intend)
                                       throws XMLFormatException,
                                              IOException
        Returns the xml code of a given instance as string.
        Parameters:
        instance - The instance which should be transformed.
        intend - Whether to intend child nodes and text content. Use with care! Text content may contain whitespace and linebreaks afterwards!
        Returns:
        The xml code of the given process as string.
        Throws:
        XMLFormatException - Thrown if the validation of the document fails
        IOException - Thrown if an unrecoverable error occurs during the course of the transformation
      • getInputStreamForTemplate

        public InputStream getInputStreamForTemplate​(Template template)
                                              throws XMLFormatException,
                                                     IOException
        Returns The corresponding stream for a given template
        Parameters:
        template - The source template
        Returns:
        An input stream for the given template. The caller is responsible for closing.
        Throws:
        XMLFormatException - Thrown if the validation of the document fails
        IOException - Thrown if an unrecoverable error occurs during the course of the transformation
      • getInputStreamForTemplate

        public InputStream getInputStreamForTemplate​(Template template,
                                                     boolean intend)
                                              throws XMLFormatException,
                                                     IOException
        Returns The corresponding stream for a given template
        Parameters:
        template - The source template
        intend - Whether to intend child nodes and text content. Use with care! Text content may contain whitespace and linebreaks afterwards!
        Returns:
        An input stream for the given template. The caller is responsible for closing.
        Throws:
        XMLFormatException - Thrown if the validation of the document fails
        IOException - Thrown if an unrecoverable error occurs during the course of the transformation
      • getInputStreamForTemplateAndStatus

        public InputStream getInputStreamForTemplateAndStatus​(Template template,
                                                              TemplateStatus templateStatus)
                                                       throws XMLFormatException,
                                                              IOException
        Returns The corresponding stream for a given template and a given template status.
        Parameters:
        template - The source template
        templateStatus - The template status
        Returns:
        An input stream for the given template. The caller is responsible for closing.
        Throws:
        XMLFormatException - Thrown if the validation of the document fails
        IOException - Thrown if an unrecoverable error occurs during the course of the transformation
      • getInputStreamForTemplateAndStatus

        public InputStream getInputStreamForTemplateAndStatus​(Template template,
                                                              TemplateStatus templateStatus,
                                                              boolean intend)
                                                       throws XMLFormatException,
                                                              IOException
        Returns The corresponding stream for a given template and a given template status.
        Parameters:
        template - The source template
        templateStatus - The template status
        intend - Whether to intend child nodes and text content. Use with care! Text content may contain whitespace and linebreaks afterwards!
        Returns:
        An input stream for the given template. The caller is responsible for closing.
        Throws:
        XMLFormatException - Thrown if the validation of the document fails
        IOException - Thrown if an unrecoverable error occurs during the course of the transformation
      • getDocumentForTemplateAndStatus

        public Document getDocumentForTemplateAndStatus​(Template template,
                                                        TemplateStatus templateStatus)
                                                 throws XMLFormatException
        Returns The corresponding document for a given template and a given template status.
        Parameters:
        template - The source template
        templateStatus - The template status
        Returns:
        A document for the given template
        Throws:
        XMLFormatException - Thrown if the validation of the document fails
      • getInputStreamForInstance

        public InputStream getInputStreamForInstance​(Instance instance)
                                              throws XMLFormatException,
                                                     IOException
        Returns The corresponding stream for a given instance
        Parameters:
        instance - The source instance
        Returns:
        An input stream for the given instance. The caller is responsible for closing.
        Throws:
        XMLFormatException - Thrown if the validation of the document fails
        IOException - Thrown if an unrecoverable error occurs during the course of the transformation
      • getInputStreamForInstance

        public InputStream getInputStreamForInstance​(Instance instance,
                                                     boolean intend)
                                              throws XMLFormatException,
                                                     IOException
        Returns The corresponding stream for a given instance
        Parameters:
        instance - The source instance
        intend - Whether to intend child nodes and text content. Use with care! Text content may contain whitespace and linebreaks afterwards!
        Returns:
        An input stream for the given instance. The caller is responsible for closing.
        Throws:
        XMLFormatException - Thrown if the validation of the document fails
        IOException - Thrown if an unrecoverable error occurs during the course of the transformation
      • getDocumentForExecutableInstanceAndStatus

        public Document getDocumentForExecutableInstanceAndStatus​(ExecutableInstance instance,
                                                                  InstanceStatus instanceStatus,
                                                                  boolean storeStructure)
        Writes the given instance including its status to the given file.
        Parameters:
        instance - The source instance,
        instanceStatus - The status object of the instance
        storeStructure - If set to true, the structure is stored to the file, else, only an ID reference will be stored.
        Returns:
        The input stream
      • getDocumentForTemplate

        public Document getDocumentForTemplate​(Template template)
                                        throws XMLFormatException
        Creates a DOM document from the template.
        Parameters:
        template - The source template
        Returns:
        A DOM document
        Throws:
        XMLFormatException - Thrown if the validation of the document fails
      • getDocumentForInstance

        public Document getDocumentForInstance​(Instance instance)
                                        throws XMLFormatException
        Creates a DOM document from the instance.
        Parameters:
        instance - The source instance
        Returns:
        A DOM document
        Throws:
        XMLFormatException - Thrown if the validation of the document fails
      • getDocumentForParameter

        public Document getDocumentForParameter​(ProcessModelParameter parameter,
                                                boolean isInputParameter)
        TODO set namespace, schema location, check schema?
        Parameters:
        parameter - The source parameter
        isInputParameter - If true, an input parameter will be created, else an output parameter.
        Returns:
        A DOM/XML document for the given parameter.
      • getDocumentForParameterSet

        public Document getDocumentForParameterSet​(Collection<ProcessModelParameter> parameter,
                                                   boolean isInputParameter)
        TODO set namespace, schema location, check schema?
        Parameters:
        parameter - The source Parameterset.
        isInputParameter - If true, an input parameter set will be created, else an output parameter set.
        Returns:
        A DOM/XML document for the set of parameters.
      • getDocumentDataElementList

        public Document getDocumentDataElementList​(Set<DataElement> dataElements)
        Exports a set of data elements to a document.
        Parameters:
        dataElements - The data elements to be exported.
        Returns:
        A document with a list of data element XML elements.
      • getDocumentForEmbeddedTemplateMapping

        public Document getDocumentForEmbeddedTemplateMapping​(Map<UUID,​UUID> mapping)
                                                       throws XMLFormatException
        Generates and returns a Document representing the given embedded template id mapping
        Parameters:
        mapping - - the embedded IDs mapping to their parent IDs
        Returns:
        the generated document
        Throws:
        XMLFormatException
      • getDocumentForBaseTemplateMapping

        public Document getDocumentForBaseTemplateMapping​(Map<UUID,​UUID> mapping)
                                                   throws XMLFormatException
        Generates and returns a Document representing the given base template id mapping
        Parameters:
        mapping - - the template IDs mapping to their base template IDs
        Returns:
        the generated document
        Throws:
        XMLFormatException
      • getDocumentForAdhocTemplateMapping

        public Document getDocumentForAdhocTemplateMapping​(Map<UUID,​UUID> mapping)
                                                    throws XMLFormatException
        Generates and returns a Document representing the given adhoc template id mapping
        Parameters:
        mapping - - the adhoc template IDs mapping to their instance IDs
        Returns:
        the generated document
        Throws:
        XMLFormatException