com.asdf.utils
Class XMLTools

java.lang.Object
  extended by com.asdf.utils.XMLTools

public class XMLTools
extends java.lang.Object

Tools for (un)marshalling XML data from objects to byte arrays and from byte array to objects.


Constructor Summary
XMLTools()
          Constructs XMLTools object.
XMLTools(java.lang.String jaxbContext, java.lang.String schemaLocation)
          Constructs XMLTools object.
 
Method Summary
 Message bytesToMessage(byte[] rawData)
          Converts byte array to Message instance
 Message loadMessageFromFile(java.lang.String path)
          Unmarshalls object from file and casts it to Message.
 java.lang.Object loadObjectFromFile(java.lang.String path)
          Unmarshalls object from file.
 byte[] marshallObject(java.lang.Object obj)
          Converts object into byte array
 org.w3c.dom.Element marshallObjectToElement(java.lang.Object obj)
           
 byte[] messageToBytes(Message msg)
          Converts Message to byte array.
 java.lang.Object unmarshallBytes(byte[] bytes)
          Converts byte array into Message object
 java.lang.Object unmarshallNode(org.w3c.dom.Node e)
          Convert given Node to object
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLTools

public XMLTools()
Constructs XMLTools object. Version of constructor that uses default XML schema file and JAXB context.


XMLTools

public XMLTools(java.lang.String jaxbContext,
                java.lang.String schemaLocation)
         throws org.xml.sax.SAXException,
                javax.xml.bind.JAXBException
Constructs XMLTools object. Version of constructor that lets user to define XML schema and JAXB context.

Parameters:
jaxbContext - Name of the JAXB context
schemaLocation - Path to the XML schema file
Throws:
org.xml.sax.SAXException - If schema is invalid
javax.xml.bind.JAXBException - If context can't be initialized
Method Detail

unmarshallBytes

public java.lang.Object unmarshallBytes(byte[] bytes)
                                 throws javax.xml.bind.JAXBException
Converts byte array into Message object

Parameters:
bytes - Byte array
Returns:
Unmarshalled object
Throws:
javax.xml.bind.JAXBException - In case of not conforming to schema or otherwise invalid data

unmarshallNode

public java.lang.Object unmarshallNode(org.w3c.dom.Node e)
                                throws javax.xml.bind.JAXBException
Convert given Node to object

Parameters:
e - Node to convert
Returns:
Converted object
Throws:
javax.xml.bind.JAXBException

marshallObject

public byte[] marshallObject(java.lang.Object obj)
                      throws javax.xml.bind.JAXBException
Converts object into byte array

Parameters:
obj - Object to convert
Returns:
Object converted to byte array
Throws:
javax.xml.bind.JAXBException - In case of not conforming to schema or otherwise invalid message

marshallObjectToElement

public org.w3c.dom.Element marshallObjectToElement(java.lang.Object obj)
                                            throws javax.xml.bind.JAXBException
Throws:
javax.xml.bind.JAXBException

loadMessageFromFile

public Message loadMessageFromFile(java.lang.String path)
                            throws javax.xml.bind.JAXBException
Unmarshalls object from file and casts it to Message.

Parameters:
path - Path to the file
Returns:
Unmarshalled Message
Throws:
javax.xml.bind.JAXBException - In case of not conforming to schema or otherwise invalid message

loadObjectFromFile

public java.lang.Object loadObjectFromFile(java.lang.String path)
                                    throws javax.xml.bind.JAXBException
Unmarshalls object from file.

Parameters:
path - Path to the file
Returns:
Unmarshalled object
Throws:
javax.xml.bind.JAXBException - In case of not conforming to schema or otherwise invalid data

bytesToMessage

public Message bytesToMessage(byte[] rawData)
                       throws javax.xml.bind.JAXBException
Converts byte array to Message instance

Parameters:
rawData - Raw data to convert
Returns:
Instance of Message
Throws:
javax.xml.bind.JAXBException - In case of not conforming to schema or otherwise invalid message

messageToBytes

public byte[] messageToBytes(Message msg)
                      throws javax.xml.bind.JAXBException
Converts Message to byte array.

Parameters:
msg - Message to convert
Returns:
Message marshalled to byte array
Throws:
javax.xml.bind.JAXBException - In case of not conforming to schema or otherwise invalid message