Package de.hsh.graja.util.marshal
Class AbstractMarshaller
java.lang.Object
de.hsh.graja.util.marshal.AbstractMarshaller
- Direct Known Subclasses:
JsonMarshaller
,XmlMarshaller
This is the abstract interface for marshallers.
It is used for objects, that can be serialized as XML or JSON.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic AbstractMarshaller
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 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 an object {code o} to fileoutFileName
.
-
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 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
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
Create a subclass depending on the parameter.- Parameters:
format
- allowed values: {"xml", "json"}.- Returns:
- returns an instance of
XmlMarshaller
orJsonMarshaller
.
-
isSupportedFormat
- Parameters:
format
- a string- Returns:
- true, if format is "xml" or "json" (case ignored).
-