net.sf.taverna.t2.util.beanable.jaxb
Class BeanSerialiser

java.lang.Object
  extended by net.sf.taverna.t2.util.beanable.jaxb.BeanSerialiser

public class BeanSerialiser
extends java.lang.Object

Serialise or deserialise a bean (normally produced by a Beanable) as XML. Code based on net.sf.taverna.t2.workflowmodel.impl.Tools#beanAsElement(Object). Currently beans are serialised to XML using JAXB.

Author:
Stian Soiland, Ian Dunlop

Nested Class Summary
 class BeanSerialiser.RefreshBindingsObserver
           
 
Method Summary
<Bean> Beanable<?>
beanableFromXMLElement(org.jdom.Element elem)
          Given an XML representation of a beanable entity (see beanableToXMLElement(Beanable)), use the BeanableFactory to return the beanable
<Bean> Beanable<?>
beanableFromXMLFile(java.io.File xmlFile)
          Given a File containing the XML representation of a Beanable entity, return the Beanable
<Bean> Beanable<?>
beanableFromXMLStream(java.io.InputStream inputStream)
          Given an InputStream containing an XML representation of a Beanable, return this Beanable
 org.jdom.Element beanableToXMLElement(Beanable<?> beanable)
          Given a beanable entity return as XML with the class name as an element
 void beanableToXMLFile(Beanable<?> beanable, java.io.File xmlFile)
          Given a Beanable entity store it in a file in XML format
 void beanableToXMLStream(Beanable<?> beanable, java.io.OutputStream outputStream)
          Given a Beanable entity store it in a stream in XML format
 java.lang.Object beanFromXMLFile(java.io.File xmlFile)
          Deserialise the bean from an XML file
static BeanSerialiser getInstance()
          Get BeanSerialiser singleton.
 void refreshBindings()
          Refresh the bindings from the BeanableFactoryRegistry, typically called after a plugin has modified the SPIRegistry.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static BeanSerialiser getInstance()
Get BeanSerialiser singleton.

Note that to avoid issues at initialisation time of the SPIRegistry it is not recommended to assign this instance as a static field in a class. The recommended usage is to assign the instance to a private field:

 public class MyClass {
     private BeanSerialiser beanSerialiser = BeanSerialiser.getInstance();
 ..
 }
 

Returns:
Throws:
javax.xml.bind.JAXBException

refreshBindings

public void refreshBindings()
                     throws javax.xml.bind.JAXBException
Refresh the bindings from the BeanableFactoryRegistry, typically called after a plugin has modified the SPIRegistry.

Throws:
javax.xml.bind.JAXBException

beanableFromXMLElement

public <Bean> Beanable<?> beanableFromXMLElement(org.jdom.Element elem)
Given an XML representation of a beanable entity (see beanableToXMLElement(Beanable)), use the BeanableFactory to return the beanable

Type Parameters:
Bean -
Parameters:
elem -
Returns:
The Beanable entity contained in the XML

beanableFromXMLFile

public <Bean> Beanable<?> beanableFromXMLFile(java.io.File xmlFile)
                                throws RetrievalException,
                                       java.io.FileNotFoundException
Given a File containing the XML representation of a Beanable entity, return the Beanable

Type Parameters:
Bean - the bean type used to create the Beanable
Parameters:
xmlFile - XML representation of the beanable entity
Returns:
the Beanable recreated from the XML
Throws:
RetrievalException
java.io.FileNotFoundException

beanableFromXMLStream

public <Bean> Beanable<?> beanableFromXMLStream(java.io.InputStream inputStream)
                                  throws RetrievalException
Given an InputStream containing an XML representation of a Beanable, return this Beanable

Type Parameters:
Bean - the bean type used to create the Beanable
Parameters:
inputStream -
Returns:
the Beanable recreated from the stream
Throws:
RetrievalException

beanableToXMLElement

public org.jdom.Element beanableToXMLElement(Beanable<?> beanable)
                                      throws StorageException
Given a beanable entity return as XML with the class name as an element

Parameters:
beanable -
Returns:
XML
Throws:
StorageException

beanableToXMLFile

public void beanableToXMLFile(Beanable<?> beanable,
                              java.io.File xmlFile)
                       throws StorageException,
                              java.io.IOException
Given a Beanable entity store it in a file in XML format

Parameters:
beanable - the Beanable entity
xmlFile - a file to serialise the Beanable out to
Throws:
StorageException
java.io.IOException

beanableToXMLStream

public void beanableToXMLStream(Beanable<?> beanable,
                                java.io.OutputStream outputStream)
                         throws StorageException
Given a Beanable entity store it in a stream in XML format

Parameters:
beanable - the Beanable entity
outputStream - a stream to serialise the Beanable out to
Throws:
StorageException

beanFromXMLFile

public java.lang.Object beanFromXMLFile(java.io.File xmlFile)
                                 throws RetrievalException,
                                        java.io.FileNotFoundException
Deserialise the bean from an XML file

Parameters:
xmlFile - file containing XML serialisation of bean
Returns:
Deserialised bean
Throws:
RetrievalException
java.io.FileNotFoundException