org.axonframework.eventstore
Class XStreamEventSerializer

java.lang.Object
  extended by org.axonframework.eventstore.XStreamEventSerializer
All Implemented Interfaces:
EventSerializer

public class XStreamEventSerializer
extends Object
implements EventSerializer

Implementation of the serializer that uses XStream as underlying serialization mechanism. Events are serialized to XML.

Since:
0.5
Author:
Allard Buijze

Constructor Summary
XStreamEventSerializer()
          Initialize an EventSerializer that uses XStream to serialize Events.
XStreamEventSerializer(Charset charset)
          Initialize an EventSerializer that uses XStream to serialize Events.
XStreamEventSerializer(String charsetName)
          Initialize an EventSerializer that uses XStream to serialize Events.
 
Method Summary
 void addAlias(String name, Class type)
          Adds an alias to use instead of the fully qualified class name.
 void addFieldAlias(String alias, Class definedIn, String fieldName)
          Adds an alias to use for a given field in the given class.
 void addPackageAlias(String alias, String pkgName)
          Add an alias for a package.
 DomainEvent deserialize(byte[] serializedEvent)
          Deserialize a DomainEvent using the given serializedEvents.
 com.thoughtworks.xstream.XStream getXStream()
          Returns a reference to the underlying XStream instance, that does the actual serialization.
 byte[] serialize(DomainEvent event)
          Serialize the given events into a byte[].
 void setEventUpcasters(List<EventUpcaster<org.dom4j.Document>> eventUpcasters)
          Sets the event upcasters the serializer may use.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XStreamEventSerializer

public XStreamEventSerializer()
Initialize an EventSerializer that uses XStream to serialize Events. The bytes are returned using UTF-8 encoding.


XStreamEventSerializer

public XStreamEventSerializer(String charsetName)
Initialize an EventSerializer that uses XStream to serialize Events. The bytes are returned using thy character set with the given name. If the character set is not supported by the JVM an UnsupportedCharsetException is thrown.

Parameters:
charsetName - The name of the character set to use.

XStreamEventSerializer

public XStreamEventSerializer(Charset charset)
Initialize an EventSerializer that uses XStream to serialize Events. The bytes are returned using given character set. If the character set is not supported by the JVM an UnsupportedCharsetException is thrown.

Parameters:
charset - The character set to use.
Method Detail

serialize

public byte[] serialize(DomainEvent event)
Serialize the given events into a byte[]. The actual encoding used depends on the implementation.

Specified by:
serialize in interface EventSerializer
Parameters:
event - The event to serialize
Returns:
the byte array representing the serialized domain event.

deserialize

public DomainEvent deserialize(byte[] serializedEvent)
Deserialize a DomainEvent using the given serializedEvents. Implementations are *not* allowed to change the given serializedEvent (byte array).

Specified by:
deserialize in interface EventSerializer
Parameters:
serializedEvent - The byte array containing the serialized domain event.
Returns:
The DomainEvent instance represented by the provided byte array

addAlias

public void addAlias(String name,
                     Class type)
Adds an alias to use instead of the fully qualified class name.

Parameters:
name - The alias to use
type - The Class to use the alias for
See Also:
XStream.alias(String, Class)

addPackageAlias

public void addPackageAlias(String alias,
                            String pkgName)
Add an alias for a package. This allows long package names to be shortened considerably. Will also use the alias for subpackages of the provided package.

E.g. an alias of "axoncore" for the package "org.axonframework.core" will use "axoncore.repository" for the package "org.axonframework.core.repository".

Parameters:
alias - The alias to use.
pkgName - The package to use the alias for
See Also:
XStream.aliasPackage(String, String)

addFieldAlias

public void addFieldAlias(String alias,
                          Class definedIn,
                          String fieldName)
Adds an alias to use for a given field in the given class.

Parameters:
alias - The alias to use instead of the original field name
definedIn - The class that defines the field.
fieldName - The name of the field to use the alias for
See Also:
XStream.aliasField(String, Class, String)

getXStream

public com.thoughtworks.xstream.XStream getXStream()
Returns a reference to the underlying XStream instance, that does the actual serialization.

Returns:
the XStream instance that does the actual (de)serialization.
See Also:
XStream

setEventUpcasters

public void setEventUpcasters(List<EventUpcaster<org.dom4j.Document>> eventUpcasters)
Sets the event upcasters the serializer may use. Note that this serializer only supports the dom4j Document representation of upcasters. This means they should all implement EventUpcaster<Document>.

Parameters:
eventUpcasters - The upcasters to assign to this serializer


Copyright © 2011. All Rights Reserved.