Class XmlHelper


  • public class XmlHelper
    extends java.lang.Object
    Internal use only The Class XmlHelper.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.Boolean CASE_INSENSITIVE
      This should never be set to false.
      static java.lang.Boolean FORMATTED_OUTPUT
      If set to true, the XML output will be formatted (line breaks + indent), otherwise ignorable whitespaces will be omitted.
      static java.lang.Boolean RAISE_EXCEPTIONS
      If 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> T deserialize​(byte[] data, java.lang.Class<T> clazz)
      Deserialize a piece of XML and return a CometCollection.
      static <T> T deserialize​(java.io.InputStream in, java.lang.Class<T> clazz)
      Deserialize a piece of XML and return a CometCollection
      static <T> T deserialize​(java.lang.String xml, java.lang.Class<T> clazz)
      Deserialize a piece of XML and return a CometCollection.
      static <T> T deserialize​(javax.activation.DataHandler data, java.lang.Class<T> clazz)
      Deserialize a piece of XML and return a CometCollection
      static java.io.OutputStream generateSchema​(java.lang.Class<?> clazz)
      Generate schema.
      static java.io.OutputStream generateSchema​(java.lang.Class<?>[] clazz)
      Generate schema.
      static <T> javax.activation.DataHandler getDataHandler​(java.util.List<T> list, java.lang.String rootElementName)
      Create a DataHandler from a CometCollection.
      static <T> java.io.OutputStream serialize​(java.lang.Object item, java.lang.String rootElement)
      Serialize an Object, use an arbitrary name for the root element.
      static <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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 xml
        clazz - 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 data
        clazz - 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 data
        clazz - 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 in
        clazz - 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 list
        rootElement - 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 item
        rootElement - 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 list
        rootElementName - the root element name
        Returns:
        DataHandler or null on any failure