public class JAXBFiles
extends java.lang.Object
Legal stuff
Copyright 2010-2020 Ekkart Kleinod ekleinod@edgesoft.de
This file is part of edgeutils.
edgeutils is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
edgeutils is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with edgeutils. If not, see http://www.gnu.org/licenses/.
- Since:
- 0.1
- Version:
- 0.13.0
- Author:
- Ekkart Kleinod
-
Constructor Summary
Constructors Constructor Description JAXBFiles() -
Method Summary
Modifier and Type Method Description static <T> voidmarshal(javax.xml.bind.JAXBElement<T> theDataElement, java.lang.String theFileName, java.lang.String theSchema)Writes an XML file from the given xml data object to a file.static <T> java.lang.StringmarshalToString(javax.xml.bind.JAXBElement<T> theDataElement, java.lang.String theSchema)Writes a given xml data object to a string.static voidsetEncoding(java.nio.charset.Charset newEncoding)Sets the file encoding.static <T> Tunmarshal(java.io.Reader theReader, java.lang.Class<T> theClass)Returns the xml data object saved in the supplied reader.static <T> Tunmarshal(java.lang.String theFileName, java.lang.Class<T> theClass)Returns the xml data object saved in the supplied file.static <T> TunmarshalInclude(java.lang.String theFileName, java.lang.Class<T> theClass)Returns the xml data object saved in the supplied file, uses includes.
-
Constructor Details
-
JAXBFiles
public JAXBFiles()
-
-
Method Details
-
setEncoding
public static void setEncoding(java.nio.charset.Charset newEncoding)Sets the file encoding.For the standard encodings see java.nio.charsets.StandardCharsets.
Use them as follows, example: UTF-8:
JAXBFiles.setEncoding(StandardCharsets.UTF_8);
- Parameters:
newEncoding- the file encoding
-
unmarshal
public static <T> T unmarshal(java.lang.String theFileName, java.lang.Class<T> theClass) throws EdgeUtilsExceptionReturns the xml data object saved in the supplied file.- Type Parameters:
T- xml data object type- Parameters:
theFileName- the filename of the file to unmarshaltheClass- class of return type (needed for package information)- Returns:
- xml data object
- Throws:
EdgeUtilsException- if some JAXB-error happened
-
unmarshalInclude
public static <T> T unmarshalInclude(java.lang.String theFileName, java.lang.Class<T> theClass) throws EdgeUtilsExceptionReturns the xml data object saved in the supplied file, uses includes.- Type Parameters:
T- xml data object type- Parameters:
theFileName- the filename of the file to unmarshaltheClass- class of return type (needed for package information)- Returns:
- xml data object
- Throws:
EdgeUtilsException- if some JAXB-error happened- Since:
- 0.2
-
unmarshal
public static <T> T unmarshal(java.io.Reader theReader, java.lang.Class<T> theClass) throws EdgeUtilsExceptionReturns the xml data object saved in the supplied reader.In order to unmarshal a String, use a StringReader:
String sXML = ...; JAXBFiles.unmarshal(new StringReader(sXML), XAZ.class);- Type Parameters:
T- xml data object type- Parameters:
theReader- the filename of the file to unmarshaltheClass- class of return type (needed for package information)- Returns:
- xml data object
- Throws:
EdgeUtilsException- if some JAXB-error happened
-
marshal
public static <T> void marshal(javax.xml.bind.JAXBElement<T> theDataElement, java.lang.String theFileName, java.lang.String theSchema) throws EdgeUtilsExceptionWrites an XML file from the given xml data object to a file.Call:
marshal(new ObjectFactory().create<T>(the<T>), file, schema)Example (<T> = IssuesType):
IssuesType theIssues = new IssuesType(); ... JAXBFiles.marshal(new ObjectFactory().createIssues(theIssues), "test.xml", null);- Type Parameters:
T- xml data object type- Parameters:
theDataElement- data modeltheFileName- filename of the file to write totheSchema- schema location (null allowed)- Throws:
EdgeUtilsException- if some JAXB-error happened
-
marshalToString
public static <T> java.lang.String marshalToString(javax.xml.bind.JAXBElement<T> theDataElement, java.lang.String theSchema) throws EdgeUtilsExceptionWrites a given xml data object to a string.Call:
marshal(new ObjectFactory().create<T>(the<T>), file, schema)Example (<T> = IssuesType):
IssuesType theIssues = new IssuesType(); ... String sXML = JAXBFiles.marshal(new ObjectFactory().createIssues(theIssues), "test.xml", null);- Type Parameters:
T- xml data object type- Parameters:
theDataElement- data modeltheSchema- schema location (null allowed)- Returns:
- string representation
- Throws:
EdgeUtilsException- if some JAXB-error happened
-