Class JaxbUtil

java.lang.Object
de.hsh.graja.util.marshal.JaxbUtil

public class JaxbUtil extends Object
This class can write or read an instance of a JAXB annotated class. It handles masking of illegal characters in an XML file and formatting issues.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    queryXsd(Scanner console, Class<?>[] domain, File destDir)
    Generates schema files for a given classes context
    static <T> T
    read(InputStream input, Class<T> clazz, Class<?>... contextClasses)
    Instantiate an object of a JAXB annotated type clazz by reading it from input while using the contextClasses as the class context.
    static <T> T
    read(InputStream input, Class<T> clazz, Schema schema, Class<?>... contextClasses)
    Instantiate an object of a JAXB annotated type clazz by reading it from input while using the contextClasses as the class context.
    static <T> T
    read(String inFileName, Class<T> clazz, Class<?>... contextClasses)
    Instantiate an object of a JAXB annotated type clazz by reading it from input file inFileName while using the contextClasses as the class context.
    static void
    write(Object o, OutputStream output, Class<?>... classesToBeBound)
    Write object o to output while using the classesToBebound as the class context.
    static void
    write(Object o, OutputStream output, Collection<Class<?>> classesToBeBound)
    Write object o to output while using the classesToBebound as the class context.
    static void
    write(Object o, String outFileName, Class<?>... classesToBeBound)
    Write object o to output file outFileName while using the classesToBebound as the class context.
    static void
    write(Object o, String outFileName, Collection<Class<?>> classesToBeBound)
    Write object o to output file outFileName while using the classesToBebound as the class context.

    Methods inherited from class java.lang.Object

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

    • JaxbUtil

      public JaxbUtil()
  • Method Details

    • write

      public static void write(Object o, OutputStream output, Class<?>... classesToBeBound) throws javax.xml.bind.JAXBException, IOException
      Write object o to output while using the classesToBebound as the class context.
      Parameters:
      o - the instance to be written
      output - output stream
      classesToBeBound - these classes define the class context
      Throws:
      javax.xml.bind.JAXBException - if an error was encountered while preparing the Marshaller object or the JAXBContext or while writing the object.
      IOException - if an I/O specific error was encountered.
    • write

      public static void write(Object o, String outFileName, Class<?>... classesToBeBound) throws javax.xml.bind.JAXBException, IOException
      Write object o to output file outFileName while using the classesToBebound as the class context.
      Parameters:
      o - the instance to be written
      outFileName - output file name
      classesToBeBound - these classes define the class context
      Throws:
      javax.xml.bind.JAXBException - if an error was encountered while preparing the Marshaller object or the JAXBContext or while writing the object.
      IOException - if an I/O specific error was encountered.
    • write

      public static void write(Object o, String outFileName, Collection<Class<?>> classesToBeBound) throws javax.xml.bind.JAXBException, IOException
      Write object o to output file outFileName while using the classesToBebound as the class context.
      Parameters:
      o - the instance to be written
      outFileName - output file name
      classesToBeBound - these classes define the class context
      Throws:
      javax.xml.bind.JAXBException - if an error was encountered while preparing the Marshaller object or the JAXBContext or while writing the object.
      IOException - if an I/O specific error was encountered.
    • write

      public static void write(Object o, OutputStream output, Collection<Class<?>> classesToBeBound) throws javax.xml.bind.JAXBException, IOException
      Write object o to output while using the classesToBebound as the class context.
      Parameters:
      o - the instance to be written
      output - output stream
      classesToBeBound - these classes define the class context
      Throws:
      javax.xml.bind.JAXBException - if an error was encountered while preparing the Marshaller object or the JAXBContext or while writing the object.
      IOException - if an I/O specific error was encountered.
    • read

      public static <T> T read(String inFileName, Class<T> clazz, Class<?>... contextClasses) throws javax.xml.bind.JAXBException, IOException
      Instantiate an object of a JAXB annotated type clazz by reading it from input file inFileName while using the contextClasses as the class context.
      Parameters:
      inFileName - the source file
      clazz - the type of the new object
      contextClasses - these classes define the class context
      Returns:
      the new instance
      Throws:
      javax.xml.bind.JAXBException - if an error was encountered while preparing the Marshaller object or the JAXBContext or while reading the object.
      IOException - if an I/O specific error was encountered.
    • read

      public static <T> T read(InputStream input, Class<T> clazz, Schema schema, Class<?>... contextClasses) throws javax.xml.bind.JAXBException, IOException
      Instantiate an object of a JAXB annotated type clazz by reading it from input while using the contextClasses as the class context.
      Parameters:
      input - the source stream
      clazz - the type of the new object
      schema -
      contextClasses - these classes define the class context
      Returns:
      the new instance
      Throws:
      javax.xml.bind.JAXBException - if an error was encountered while preparing the Marshaller object or the JAXBContext or while reading the object.
      IOException - if an I/O specific error was encountered.
    • read

      public static <T> T read(InputStream input, Class<T> clazz, Class<?>... contextClasses) throws javax.xml.bind.JAXBException, IOException
      Instantiate an object of a JAXB annotated type clazz by reading it from input while using the contextClasses as the class context.
      Parameters:
      input - the source stream
      clazz - the type of the new object
      contextClasses - these classes define the class context
      Returns:
      the new instance
      Throws:
      javax.xml.bind.JAXBException - if an error was encountered while preparing the Marshaller object or the JAXBContext or while reading the object.
      IOException - if an I/O specific error was encountered.
    • queryXsd

      public static void queryXsd(Scanner console, Class<?>[] domain, File destDir)
      Generates schema files for a given classes context
      Parameters:
      console - is used to get user input about filenames
      domain - these classes define the class context.
      destDir - destination directory. If null, the files are created in the current directory. The destination directory must be created by the caller, if it does not exist.