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 AbstractMarshallerCreate a subclass depending on the parameter.static booleanisSupportedFormat(String format) abstract <T> Tread(InputStream input, Class<T> clazz) Read an object frominputand instantiate it as an object of classclazz.<T> TRead an object frominFileNameand instantiate it as an object of classclazz.abstract voidwrite(Object o, OutputStream output) Write an object {code o} to streamoutput.voidWrite 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 frominFileNameand 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 frominputand 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
XmlMarshallerorJsonMarshaller.
-
isSupportedFormat
- Parameters:
format- a string- Returns:
- true, if format is "xml" or "json" (case ignored).
-