Package com.priint.pubserver.comet.xml
Class XmlHelper
java.lang.Object
com.priint.pubserver.comet.xml.XmlHelper
Internal use only
The Class XmlHelper.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final BooleanIf set to true, the XML output will be formatted (line breaks + indent), otherwise ignorable whitespaces will be omitted.static final BooleanIf set to true, RuntimeExceptions will be raised upon error, otherwise the serialize / deserialize methods will just return null. -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Tdeserialize(byte[] data, Class<T> clazz) Deserialize a piece of XML and return a CometCollection.static <T> Tdeserialize(jakarta.activation.DataHandler data, Class<T> clazz) Deserialize a piece of XML and return a CometCollectionstatic <T> Tdeserialize(InputStream in, Class<T> clazz) Deserialize a piece of XML and return a CometCollectionstatic <T> Tdeserialize(String xml, Class<T> clazz) Deserialize a piece of XML and return a CometCollection.static OutputStreamgenerateSchema(Class<?> clazz) Generate schema.static OutputStreamgenerateSchema(Class<?>[] clazz) Generate schema.static <T> jakarta.activation.DataHandlergetDataHandler(List<T> list, String rootElementName) Create a DataHandler from a CometCollection.static <T> InputStreamgetInputStream(List<T> list, String rootElementName) static ByteArrayOutputStreamSerialize an Object, use an arbitrary name for the root element.static <T> ByteArrayOutputStreamSerialize a List, use an arbitrary name for the root element.
-
Field Details
-
FORMATTED_OUTPUT
If set to true, the XML output will be formatted (line breaks + indent), otherwise ignorable whitespaces will be omitted. -
RAISE_EXCEPTIONS
If set to true, RuntimeExceptions will be raised upon error, otherwise the serialize / deserialize methods will just return null.
-
-
Method Details
-
deserialize
Deserialize a piece of XML and return a CometCollection.- Type Parameters:
T- the generic type- Parameters:
xml- the xmlclazz- target class (CometCollection<T>, e.g. com.priint.comet.configuration.entities.Actions)- Returns:
- CometCollection list of the requested target class or null on any failure
-
deserialize
Deserialize a piece of XML and return a CometCollection.- Type Parameters:
T- the generic type- Parameters:
data- the dataclazz- target class (CometCollection<T>, e.g. com.priint.comet.configuration.entities.Actions)- Returns:
- CometCollection list of the requested target class or null on any failure
-
deserialize
Deserialize a piece of XML and return a CometCollection- Type Parameters:
T- the generic type- Parameters:
data- the dataclazz- target class (CometCollection<T>, e.g. com.priint.comet.configuration.entities.Actions)- Returns:
- CometCollection list of the requested target class or null on any failure
-
deserialize
Deserialize a piece of XML and return a CometCollection- Type Parameters:
T- the generic type- Parameters:
in- the inclazz- target class (CometCollection<T>, e.g. com.priint.comet.configuration.entities.Actions)- Returns:
- CometCollection list of the requested target class or null on any failure
-
serialize
Serialize a List, use an arbitrary name for the root element.- Type Parameters:
T- the generic type- Parameters:
list- the listrootElement- the root element- Returns:
- XML (OutputStream) or null on failure
-
serialize
Serialize an Object, use an arbitrary name for the root element.- Parameters:
item- the itemrootElement- the root element- Returns:
- XML (OutputStream) or null on failure
-
generateSchema
Generate schema.- Parameters:
clazz- the clazz- Returns:
- the output stream
-
generateSchema
Generate schema.- Parameters:
clazz- the clazz- Returns:
- the output stream
-
getDataHandler
public static <T> jakarta.activation.DataHandler getDataHandler(List<T> list, String rootElementName) Create a DataHandler from a CometCollection.
This is just a shortcut for
DataHandler data = new DataHandler (new DataSource () { @Override public String getContentType() { return "application/xml"; } @Override public InputStream getInputStream() throws IOException { return null; } @Override public String getName() { return list.getXmlFileName (); } @Override public OutputStream getOutputStream() throws IOException { return XmlUtils.serialize (list); } });- Type Parameters:
T- the generic type- Parameters:
list- the listrootElementName- the root element name- Returns:
- DataHandler or null on any failure
-
getInputStream
-