Package de.hsh.graja.util.marshal
Class JaxbUtil
java.lang.Object
de.hsh.graja.util.marshal.JaxbUtil
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 -
Method Summary
Modifier and TypeMethodDescriptionstatic voidGenerates schema files for a given classes contextstatic <T> Tread(InputStream input, Class<T> clazz, Class<?>... contextClasses) Instantiate an object of a JAXB annotated typeclazzby reading it frominputwhile using thecontextClassesas the class context.static <T> Tread(InputStream input, Class<T> clazz, Schema schema, Class<?>... contextClasses) Instantiate an object of a JAXB annotated typeclazzby reading it frominputwhile using thecontextClassesas the class context.static <T> TInstantiate an object of a JAXB annotated typeclazzby reading it from input fileinFileNamewhile using thecontextClassesas the class context.static voidwrite(Object o, OutputStream output, Class<?>... classesToBeBound) Write objectotooutputwhile using theclassesToBeboundas the class context.static voidwrite(Object o, OutputStream output, Collection<Class<?>> classesToBeBound) Write objectotooutputwhile using theclassesToBeboundas the class context.static voidWrite objectoto output fileoutFileNamewhile using theclassesToBeboundas the class context.static voidwrite(Object o, String outFileName, Collection<Class<?>> classesToBeBound) Write objectoto output fileoutFileNamewhile using theclassesToBeboundas the class context.
-
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 objectotooutputwhile using theclassesToBeboundas the class context.- Parameters:
o- the instance to be writtenoutput- output streamclassesToBeBound- 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 objectoto output fileoutFileNamewhile using theclassesToBeboundas the class context.- Parameters:
o- the instance to be writtenoutFileName- output file nameclassesToBeBound- 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 objectoto output fileoutFileNamewhile using theclassesToBeboundas the class context.- Parameters:
o- the instance to be writtenoutFileName- output file nameclassesToBeBound- 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 objectotooutputwhile using theclassesToBeboundas the class context.- Parameters:
o- the instance to be writtenoutput- output streamclassesToBeBound- 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 typeclazzby reading it from input fileinFileNamewhile using thecontextClassesas the class context.- Parameters:
inFileName- the source fileclazz- the type of the new objectcontextClasses- 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 typeclazzby reading it frominputwhile using thecontextClassesas the class context.- Parameters:
input- the source streamclazz- the type of the new objectschema-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 typeclazzby reading it frominputwhile using thecontextClassesas the class context.- Parameters:
input- the source streamclazz- the type of the new objectcontextClasses- 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
Generates schema files for a given classes context- Parameters:
console- is used to get user input about filenamesdomain- 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.
-