Class AbstractMarshaller

java.lang.Object
de.hsh.graja.util.marshal.AbstractMarshaller
Direct Known Subclasses:
JsonMarshaller, XmlMarshaller

public abstract class AbstractMarshaller extends Object
This is the abstract interface for marshallers. It is used for objects, that can be serialized as XML or JSON.
  • Constructor Details

    • AbstractMarshaller

      public AbstractMarshaller()
  • Method Details

    • read

      public <T> T read(String inFileName, Class<T> clazz) throws javax.xml.bind.JAXBException, IOException
      Read an object from inFileName and instantiate it as an object of class clazz.
      Parameters:
      inFileName - input file
      clazz - type of the new instance
      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 abstract <T> T read(InputStream input, Class<T> clazz) throws javax.xml.bind.JAXBException, IOException
      Read an object from input and instantiate it as an object of class clazz.
      Parameters:
      input - input stream
      clazz - type of the new instance
      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.
    • write

      public void write(Object o, String outFileName) throws javax.xml.bind.JAXBException, IOException
      Write an object {code o} to file outFileName.
      Parameters:
      o - the object to be written
      outFileName - the output file
      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 abstract void write(Object o, OutputStream output) throws javax.xml.bind.JAXBException, IOException
      Write an object {code o} to stream output.
      Parameters:
      o - the object to be written
      output - the output stream
      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.
    • create

      public static AbstractMarshaller create(String format)
      Create a subclass depending on the parameter.
      Parameters:
      format - allowed values: {"xml", "json"}.
      Returns:
      returns an instance of XmlMarshaller or JsonMarshaller.
    • isSupportedFormat

      public static boolean isSupportedFormat(String format)
      Parameters:
      format - a string
      Returns:
      true, if format is "xml" or "json" (case ignored).