Package de.hsh.graja.util.marshal
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 Summary
Constructors Constructor Description AbstractMarshaller()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static AbstractMarshaller
create(String format)
Create a subclass depending on the parameter.static boolean
isSupportedFormat(String format)
abstract <T> T
read(InputStream input, Class<T> clazz)
Read an object frominput
and instantiate it as an object of classclazz
.<T> T
read(String inFileName, Class<T> clazz)
Read an object frominFileName
and instantiate it as an object of classclazz
.abstract void
write(Object o, OutputStream output)
Write an object {code o} to streamoutput
.void
write(Object o, String outFileName)
Write an object {code o} to fileoutFileName
.
-
-
-
Method Detail
-
read
public <T> T read(String inFileName, Class<T> clazz) throws javax.xml.bind.JAXBException, IOException
Read an object frominFileName
and instantiate it as an object of classclazz
.- Parameters:
inFileName
- input fileclazz
- 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 frominput
and instantiate it as an object of classclazz
.- Parameters:
input
- input streamclazz
- 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 fileoutFileName
.- Parameters:
o
- the object to be writtenoutFileName
- 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 streamoutput
.- Parameters:
o
- the object to be writtenoutput
- 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
orJsonMarshaller
.
-
isSupportedFormat
public static boolean isSupportedFormat(String format)
- Parameters:
format
- a string- Returns:
- true, if format is "xml" or "json" (case ignored).
-
-