Package com.priint.pubserver.comet.xml
Class XmlHelper
- java.lang.Object
-
- com.priint.pubserver.comet.xml.XmlHelper
-
public class XmlHelper extends java.lang.ObjectInternal use only The Class XmlHelper.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.BooleanCASE_INSENSITIVEThis should never be set to false.static java.lang.BooleanFORMATTED_OUTPUTIf set to true, the XML output will be formatted (line breaks + indent), otherwise ignorable whitespaces will be omitted.static java.lang.BooleanRAISE_EXCEPTIONSIf set to true, RuntimeExceptions will be raised upon error, otherwise the serialize / deserialize methods will just return null.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> Tdeserialize(byte[] data, java.lang.Class<T> clazz)Deserialize a piece of XML and return a CometCollection.static <T> Tdeserialize(java.io.InputStream in, java.lang.Class<T> clazz)Deserialize a piece of XML and return a CometCollectionstatic <T> Tdeserialize(java.lang.String xml, java.lang.Class<T> clazz)Deserialize a piece of XML and return a CometCollection.static <T> Tdeserialize(javax.activation.DataHandler data, java.lang.Class<T> clazz)Deserialize a piece of XML and return a CometCollectionstatic java.io.OutputStreamgenerateSchema(java.lang.Class<?> clazz)Generate schema.static java.io.OutputStreamgenerateSchema(java.lang.Class<?>[] clazz)Generate schema.static <T> javax.activation.DataHandlergetDataHandler(java.util.List<T> list, java.lang.String rootElementName)Create a DataHandler from a CometCollection.static <T> java.io.OutputStreamserialize(java.lang.Object item, java.lang.String rootElement)Serialize an Object, use an arbitrary name for the root element.static <T> java.io.OutputStreamserialize(java.util.List<T> list, java.lang.String rootElement)Serialize a List, use an arbitrary name for the root element.
-
-
-
Field Detail
-
FORMATTED_OUTPUT
public static final java.lang.Boolean FORMATTED_OUTPUT
If set to true, the XML output will be formatted (line breaks + indent), otherwise ignorable whitespaces will be omitted.
-
RAISE_EXCEPTIONS
public static final java.lang.Boolean RAISE_EXCEPTIONS
If set to true, RuntimeExceptions will be raised upon error, otherwise the serialize / deserialize methods will just return null.
-
CASE_INSENSITIVE
public static final java.lang.Boolean CASE_INSENSITIVE
This should never be set to false.
-
-
Method Detail
-
deserialize
public static final <T> T deserialize(java.lang.String xml, java.lang.Class<T> clazz)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
public static final <T> T deserialize(byte[] data, java.lang.Class<T> clazz)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
public static final <T> T deserialize(javax.activation.DataHandler data, java.lang.Class<T> clazz)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
public static final <T> T deserialize(java.io.InputStream in, java.lang.Class<T> clazz)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
public static final <T> java.io.OutputStream serialize(java.util.List<T> list, java.lang.String rootElement)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
public static final <T> java.io.OutputStream serialize(java.lang.Object item, java.lang.String rootElement)Serialize an Object, use an arbitrary name for the root element.- Type Parameters:
T- the generic type- Parameters:
item- the itemrootElement- the root element- Returns:
- XML (OutputStream) or null on failure
-
generateSchema
public static java.io.OutputStream generateSchema(java.lang.Class<?>[] clazz)
Generate schema.- Parameters:
clazz- the clazz- Returns:
- the output stream
-
generateSchema
public static java.io.OutputStream generateSchema(java.lang.Class<?> clazz)
Generate schema.- Parameters:
clazz- the clazz- Returns:
- the output stream
-
getDataHandler
public static final <T> javax.activation.DataHandler getDataHandler(java.util.List<T> list, java.lang.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
-
-