Package de.hsh.graja.util.marshal
Class JaxbUtil
- java.lang.Object
-
- de.hsh.graja.util.marshal.JaxbUtil
-
public class JaxbUtil extends Object
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 Constructor Description JaxbUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
queryXsd(Scanner console, Class<?>[] domain, File destDir)
Generates schema files for a given classes contextstatic <T> T
read(InputStream input, Class<T> clazz, Class<?>... contextClasses)
Instantiate an object of a JAXB annotated typeclazz
by reading it frominput
while using thecontextClasses
as the class context.static <T> T
read(InputStream input, Class<T> clazz, Schema schema, Class<?>... contextClasses)
Instantiate an object of a JAXB annotated typeclazz
by reading it frominput
while using thecontextClasses
as the class context.static <T> T
read(String inFileName, Class<T> clazz, Class<?>... contextClasses)
Instantiate an object of a JAXB annotated typeclazz
by reading it from input fileinFileName
while using thecontextClasses
as the class context.static void
write(Object o, OutputStream output, Class<?>... classesToBeBound)
Write objecto
tooutput
while using theclassesToBebound
as the class context.static void
write(Object o, OutputStream output, Collection<Class<?>> classesToBeBound)
Write objecto
tooutput
while using theclassesToBebound
as the class context.static void
write(Object o, String outFileName, Class<?>... classesToBeBound)
Write objecto
to output fileoutFileName
while using theclassesToBebound
as the class context.static void
write(Object o, String outFileName, Collection<Class<?>> classesToBeBound)
Write objecto
to output fileoutFileName
while using theclassesToBebound
as the class context.
-
-
-
Method Detail
-
write
public static void write(Object o, OutputStream output, Class<?>... classesToBeBound) throws javax.xml.bind.JAXBException, IOException
Write objecto
tooutput
while using theclassesToBebound
as 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 objecto
to output fileoutFileName
while using theclassesToBebound
as 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 objecto
to output fileoutFileName
while using theclassesToBebound
as 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 objecto
tooutput
while using theclassesToBebound
as 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 typeclazz
by reading it from input fileinFileName
while using thecontextClasses
as 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 typeclazz
by reading it frominput
while using thecontextClasses
as 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 typeclazz
by reading it frominput
while using thecontextClasses
as 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
public static void queryXsd(Scanner console, Class<?>[] domain, File destDir)
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.
-
-