com.cedarsoft.serialization
Class AbstractSerializer<T,S,D,E extends java.lang.Throwable>

java.lang.Object
  extended by com.cedarsoft.serialization.AbstractSerializer<T,S,D,E>
Type Parameters:
T - the type
S - the object to serialize to
D - the object to deserialize from
E - the exception that might be thrown
All Implemented Interfaces:
ExtendedSerializer<T>, PluggableSerializer<T,S,D,E>, Serializer<T,Lookup>
Direct Known Subclasses:
AbstractJDomSerializer, AbstractStaxMateSerializer

public abstract class AbstractSerializer<T,S,D,E extends java.lang.Throwable>
extends java.lang.Object
implements PluggableSerializer<T,S,D,E>


Field Summary
 
Fields inherited from interface com.cedarsoft.serialization.Serializer
PI_TARGET_FORMAT
 
Constructor Summary
protected AbstractSerializer(java.lang.String defaultElementName, VersionRange formatVersionRange)
          Creates a new version range
 
Method Summary
 T deserialize(java.io.InputStream in)
          Deserializes the object
protected  java.lang.String getDefaultElementName()
           
 Version getFormatVersion()
          Returns the format version that is written
 VersionRange getFormatVersionRange()
           
 byte[] serialize(T object)
          Serializes the given object
 void serialize(T object, java.io.OutputStream out)
          Serializes the object to the output stream
protected  void verifyDelegatingSerializerVersion(Serializer<?,?> delegate, Version expectedFormatVersion)
          Helper method that can be used to ensure the right format version for each delegate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.cedarsoft.serialization.PluggableSerializer
deserialize, serialize
 
Methods inherited from interface com.cedarsoft.serialization.Serializer
deserialize, serialize
 

Constructor Detail

AbstractSerializer

protected AbstractSerializer(@NotNull@NonNls
                             java.lang.String defaultElementName,
                             @NotNull
                             VersionRange formatVersionRange)
Creates a new version range

Parameters:
defaultElementName - the default element name
formatVersionRange - the version range. The max value is used when written.
Method Detail

verifyDelegatingSerializerVersion

protected void verifyDelegatingSerializerVersion(@NotNull
                                                 Serializer<?,?> delegate,
                                                 @NotNull
                                                 Version expectedFormatVersion)
Helper method that can be used to ensure the right format version for each delegate

Parameters:
delegate - the delegate
expectedFormatVersion - the expected format version

getFormatVersion

@NotNull
public Version getFormatVersion()
Description copied from interface: Serializer
Returns the format version that is written

Specified by:
getFormatVersion in interface Serializer<T,Lookup>
Returns:
the format version that is written

getFormatVersionRange

@NotNull
public VersionRange getFormatVersionRange()

getDefaultElementName

@NotNull
@NonNls
protected java.lang.String getDefaultElementName()

serialize

@NotNull
public byte[] serialize(@NotNull
                                T object)
                 throws java.io.IOException
Description copied from interface: ExtendedSerializer
Serializes the given object

Specified by:
serialize in interface ExtendedSerializer<T>
Parameters:
object - the object
Returns:
the serialized object
Throws:
java.io.IOException

serialize

public void serialize(@NotNull
                      T object,
                      @NotNull
                      java.io.OutputStream out)
               throws java.io.IOException
Description copied from interface: ExtendedSerializer
Serializes the object to the output stream

Specified by:
serialize in interface ExtendedSerializer<T>
Parameters:
object - the object
out - the out stream
Throws:
java.io.IOException

deserialize

@NotNull
public T deserialize(@NotNull
                             java.io.InputStream in)
              throws java.io.IOException
Description copied from interface: ExtendedSerializer
Deserializes the object

Specified by:
deserialize in interface ExtendedSerializer<T>
Parameters:
in - the input stream
Returns:
the deserialized object
Throws:
java.io.IOException


Copyright © 2009 cedarsoft GmbH. All Rights Reserved.