org.rhq.test
Class ObjectCollectionSerializer

java.lang.Object
  extended by org.rhq.test.ObjectCollectionSerializer

public class ObjectCollectionSerializer
extends Object

This class produces a JAXB serialized collection of objects and can convert such serialized data back to a list of objects.

The objects passed to this class must therefore be JAXB serializable.

This class is intended to be used in tests that need to persist the state of some object collection.

Author:
Lukas Krejci

Constructor Summary
ObjectCollectionSerializer()
           
 
Method Summary
 void addObject(Object o)
           
 void addObjects(Collection<?> objects)
           
 List<?> deserialize(InputStream inputStream)
           
 List<?> deserialize(Reader inputReader)
           
 List<?> deserialize(XMLStreamReader reader)
          This deserializes given input stream into a list of objects.
 Set<Class<?>> getClasses()
          Returns a set of classes of objects that are to be serialized.
 List<Object> getObjects()
          Returns a list of objects that are added to this serializer.
 void serialize(OutputStream output)
          Serializes the objects added to this serialize to the given output.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ObjectCollectionSerializer

public ObjectCollectionSerializer()
Method Detail

getObjects

@NotNull
public List<Object> getObjects()
Returns a list of objects that are added to this serializer. This list is NOT modifiable, use it only for inspection.

Returns:

addObject

public void addObject(@NotNull
                      Object o)

addObjects

public void addObjects(@NotNull
                       Collection<?> objects)

getClasses

@NotNull
public Set<Class<?>> getClasses()
Returns a set of classes of objects that are to be serialized. This set is not modifiable, use it only for informational purposes.

Returns:

serialize

public void serialize(OutputStream output)
               throws IOException,
                      JAXBException
Serializes the objects added to this serialize to the given output.

Parameters:
output - the output stream to serialize to
Throws:
IOException
JAXBException

deserialize

public List<?> deserialize(InputStream inputStream)
                    throws IOException,
                           XMLStreamException,
                           ClassNotFoundException,
                           JAXBException
Throws:
IOException
XMLStreamException
ClassNotFoundException
JAXBException
See Also:
deserialize(XMLStreamReader)

deserialize

public List<?> deserialize(Reader inputReader)
                    throws IOException,
                           XMLStreamException,
                           ClassNotFoundException,
                           JAXBException
Throws:
IOException
XMLStreamException
ClassNotFoundException
JAXBException
See Also:
deserialize(XMLStreamReader)

deserialize

public List<?> deserialize(XMLStreamReader reader)
                    throws IOException,
                           XMLStreamException,
                           ClassNotFoundException,
                           JAXBException
This deserializes given input stream into a list of objects.

This method uses the current thread's context classloader to resolve the classes of the objects to be deserialized if such classloader is set.

Parameters:
inputStream - the input stream to read the data from
Returns:
the list of deserialized objects
Throws:
XMLStreamException
ClassNotFoundException
JAXBException
IOException


Copyright © 2008-2012 Red Hat, Inc.. All Rights Reserved.