Class JAXBModifier


  • public class JAXBModifier
    extends java.lang.Object
    Reads an XML document using SAX and writes its content to the provided XMLWriter. Modifications must be provided by JAXBObjectModifier objects, which are called prior to writing the XML fragment they are registered for.
    See Also:
    SAXModifier
    • Constructor Summary

      Constructors 
      Constructor Description
      JAXBModifier(java.lang.String contextPath)
      Creates a new JAXBModifier for the given JAXB context path.
      JAXBModifier(java.lang.String contextPath, java.lang.ClassLoader classloader)
      Creates a new JAXBModifier for the given JAXB context path, using the given ClassLoader.
      JAXBModifier(java.lang.String contextPath, java.lang.ClassLoader classloader, OutputFormat outputFormat)
      Creates a new JAXBModifier for the given JAXB context path, using the specified ClassLoader.
      JAXBModifier(java.lang.String contextPath, OutputFormat outputFormat)
      Creates a new JAXBModifier for the given JAXB context path.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addObjectModifier(java.lang.String path, JAXBObjectModifier mod)
      Adds the JAXBObjectModifierto be called when the specified xml path is encounted while parsing the source.
      boolean isPruneElements()
      Returns true when the modified Documentis not kept in memory.
      protected Element marshal(javax.xml.bind.Element element)
      Marshals the given Elementin to its DOM4J counterpart.
      Document modify(java.io.File source)
      Parses the specified Filewith SAX
      Document modify(java.io.File source, java.nio.charset.Charset charset)
      Parses the specified Filewith SAX, using the given Charset.
      Document modify(java.io.InputStream source)
      Parses the specified InputStreamwith SAX.
      Document modify(java.io.InputStream source, java.lang.String systemId)
      Parses the specified InputStreamwith SAX.
      Document modify(java.io.Reader r)
      Parses the specified Readerwith SAX.
      Document modify(java.io.Reader source, java.lang.String systemId)
      Parses the specified Readerwith SAX.
      Document modify(java.lang.String url)
      Parses the the given URL or filename.
      Document modify(java.net.URL source)
      Parses the the given URL.
      Document modify(org.xml.sax.InputSource source)
      Parses the specified InputSourcewith SAX.
      void removeObjectModifier(java.lang.String path)
      Removes the JAXBObjectModifierfrom the event based processor, for the specified element path.
      void resetObjectModifiers()
      Removes all registered JAXBObjectModifierinstances from the event based processor.
      void setOutput(java.io.File file)
      Sets the Output to write the (modified) xml document to.
      void setOutput(java.io.OutputStream outputStream)
      Sets the Output to write the (modified) xml document to.
      void setOutput(java.io.Writer writer)
      Sets the Output to write the (modified) xml document to.
      void setPruneElements(boolean pruneElements)
      Define whether the modified Documentmust only be written to the output and pruned from the DOM4J tree.
      protected javax.xml.bind.Element unmarshal(Element element)
      Unmarshalls the specified DOM4J Elementinto a Element
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • JAXBModifier

        public JAXBModifier(java.lang.String contextPath)
        Creates a new JAXBModifier for the given JAXB context path. This is the Java package where JAXB can find the generated XML classes. This package MUST contain jaxb.properties!
        Parameters:
        contextPath - JAXB context path to be used
        See Also:
        JAXBContext
      • JAXBModifier

        public JAXBModifier(java.lang.String contextPath,
                            java.lang.ClassLoader classloader)
        Creates a new JAXBModifier for the given JAXB context path, using the given ClassLoader. This is the Java package where JAXB can find the generated XML classes. This package MUST contain jaxb.properties!
        Parameters:
        contextPath - JAXB context path to be used
        classloader - the classloader to use
        See Also:
        JAXBContext
      • JAXBModifier

        public JAXBModifier(java.lang.String contextPath,
                            OutputFormat outputFormat)
        Creates a new JAXBModifier for the given JAXB context path. The specified OutputFormatwill be used while writing the XML stream.
        Parameters:
        contextPath - JAXB context path to be used
        outputFormat - the DOM4J OutputFormatto be used
        See Also:
        JAXBContext
      • JAXBModifier

        public JAXBModifier(java.lang.String contextPath,
                            java.lang.ClassLoader classloader,
                            OutputFormat outputFormat)
        Creates a new JAXBModifier for the given JAXB context path, using the specified ClassLoader. The specified OutputFormat will be used while writing the XML stream.
        Parameters:
        contextPath - JAXB context path to be used
        classloader - the class loader to be used to load JAXB
        outputFormat - the DOM4J OutputFormatto be used
        See Also:
        JAXBContext
    • Method Detail

      • modify

        public Document modify(java.io.File source)
                        throws DocumentException,
                               java.io.IOException
        Parses the specified Filewith SAX
        Parameters:
        source - the file to parse
        Returns:
        the resulting DOM4J document
        Throws:
        DocumentException - when an error occurs while parsing
        java.io.IOException - when an error occurs while writing to the XMLWriter
      • modify

        public Document modify(java.io.File source,
                               java.nio.charset.Charset charset)
                        throws DocumentException,
                               java.io.IOException
        Parses the specified Filewith SAX, using the given Charset.
        Parameters:
        source - the file to parse
        charset - the character set to use
        Returns:
        the resulting DOM4J document
        Throws:
        DocumentException - when an error occurs while parsing
        java.io.IOException - when an error occurs while writing to the XMLWriter
      • modify

        public Document modify(org.xml.sax.InputSource source)
                        throws DocumentException,
                               java.io.IOException
        Parses the specified InputSourcewith SAX.
        Parameters:
        source - the input source to parse
        Returns:
        the resulting DOM4J document
        Throws:
        DocumentException - when an error occurs while parsing
        java.io.IOException - when an error occurs while writing to the XMLWriter
      • modify

        public Document modify(java.io.InputStream source)
                        throws DocumentException,
                               java.io.IOException
        Parses the specified InputStreamwith SAX.
        Parameters:
        source - the inputstream to parse
        Returns:
        the resulting DOM4J document
        Throws:
        DocumentException - when an error occurs while parsing
        java.io.IOException - when an error occurs while writing to the XMLWriter
      • modify

        public Document modify(java.io.InputStream source,
                               java.lang.String systemId)
                        throws DocumentException,
                               java.io.IOException
        Parses the specified InputStreamwith SAX.
        Parameters:
        source - the inputstream to parse
        systemId - the URI of the given inputstream
        Returns:
        the resulting DOM4J document
        Throws:
        DocumentException - when an error occurs while parsing
        java.io.IOException - when an error occurs while writing to the XMLWriter
      • modify

        public Document modify(java.io.Reader r)
                        throws DocumentException,
                               java.io.IOException
        Parses the specified Readerwith SAX.
        Parameters:
        r - the reader to use for parsing
        Returns:
        the resulting DOM4J document
        Throws:
        DocumentException - when an error occurs while parsing
        java.io.IOException - when an error occurs while writing to the XMLWriter
      • modify

        public Document modify(java.io.Reader source,
                               java.lang.String systemId)
                        throws DocumentException,
                               java.io.IOException
        Parses the specified Readerwith SAX.
        Parameters:
        source - the reader to parse
        systemId - the URI of the given reader
        Returns:
        the resulting DOM4J document
        Throws:
        DocumentException - when an error occurs while parsing
        java.io.IOException - when an error occurs while writing to the XMLWriter
      • modify

        public Document modify(java.lang.String url)
                        throws DocumentException,
                               java.io.IOException
        Parses the the given URL or filename.
        Parameters:
        url - the URL or filename to parse
        Returns:
        the resulting DOM4J document
        Throws:
        DocumentException - when an error occurs while parsing
        java.io.IOException - when an error occurs while writing to the XMLWriter
      • modify

        public Document modify(java.net.URL source)
                        throws DocumentException,
                               java.io.IOException
        Parses the the given URL.
        Parameters:
        source - the URL to parse
        Returns:
        the resulting DOM4J document
        Throws:
        DocumentException - when an error occurs while parsing
        java.io.IOException - when an error occurs while writing to the XMLWriter
      • setOutput

        public void setOutput(java.io.File file)
                       throws java.io.IOException
        Sets the Output to write the (modified) xml document to.
        Parameters:
        file - the Fileto write to
        Throws:
        java.io.IOException - when the file cannot be found or when the outputformat
      • setOutput

        public void setOutput(java.io.OutputStream outputStream)
                       throws java.io.IOException
        Sets the Output to write the (modified) xml document to.
        Parameters:
        outputStream - the OutputStreamto write to
        Throws:
        java.io.IOException - when an error occurs
      • setOutput

        public void setOutput(java.io.Writer writer)
                       throws java.io.IOException
        Sets the Output to write the (modified) xml document to.
        Parameters:
        writer - the Writerto write to
        Throws:
        java.io.IOException - when an error occurs
      • addObjectModifier

        public void addObjectModifier(java.lang.String path,
                                      JAXBObjectModifier mod)
        Adds the JAXBObjectModifierto be called when the specified xml path is encounted while parsing the source.
        Parameters:
        path - the element path to listen for
        mod - the modifier to register
      • removeObjectModifier

        public void removeObjectModifier(java.lang.String path)
        Removes the JAXBObjectModifierfrom the event based processor, for the specified element path.
        Parameters:
        path - the xml path to remove the modifier for
      • resetObjectModifiers

        public void resetObjectModifiers()
        Removes all registered JAXBObjectModifierinstances from the event based processor.
      • isPruneElements

        public boolean isPruneElements()
        Returns true when the modified Documentis not kept in memory.
        Returns:
        Returns true if elements are pruned.
      • setPruneElements

        public void setPruneElements(boolean pruneElements)
        Define whether the modified Documentmust only be written to the output and pruned from the DOM4J tree.
        Parameters:
        pruneElements - When true, elements will not be kept in memory
      • marshal

        protected Element marshal(javax.xml.bind.Element element)
                           throws javax.xml.bind.JAXBException
        Marshals the given Elementin to its DOM4J counterpart.
        Parameters:
        element - JAXB Element to be marshalled
        Returns:
        the marshalled DOM4J Element
        Throws:
        javax.xml.bind.JAXBException - when an error occurs
      • unmarshal

        protected javax.xml.bind.Element unmarshal(Element element)
                                            throws javax.xml.bind.JAXBException
        Unmarshalls the specified DOM4J Elementinto a Element
        Parameters:
        element - the DOM4J element to unmarshall
        Returns:
        the unmarshalled JAXB object
        Throws:
        javax.xml.bind.JAXBException - when an error occurs