Class JAXBModifier


  • public class JAXBModifier
    extends 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 Detail

      • JAXBModifier

        public JAXBModifier​(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​(String contextPath,
                            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​(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​(String contextPath,
                            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

      • setOutput

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

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

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

        public void addObjectModifier​(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​(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