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

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

public abstract class AbstractSerializer<T,C,S,D,E extends java.lang.Throwable>
extends java.lang.Object
implements PluggableSerializer<T,C,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 without a context
protected  java.lang.String getDefaultElementName()
          Returns the default element name
 Version getFormatVersion()
          Returns the format version that is written
 VersionRange getFormatVersionRange()
          Returns the format version range that is supported for read
 void serialize(T object, java.io.OutputStream out)
          Serializes with a null context
 byte[] serializeToByteArray(T object, C context)
          Helper method that serializes to a byte array
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,C>
Returns:
the format version that is written

getFormatVersionRange

@NotNull
public VersionRange getFormatVersionRange()
Returns the format version range that is supported for read

Returns:
the format version range that is supported

getDefaultElementName

@NotNull
@NonNls
protected java.lang.String getDefaultElementName()
Returns the default element name

Returns:
the default element name

serializeToByteArray

@NotNull
public byte[] serializeToByteArray(@NotNull
                                           T object,
                                           @Nullable
                                           C context)
                            throws java.io.IOException
Helper method that serializes to a byte array

Parameters:
object - the object
context - the context
Returns:
the serialized object
Throws:
java.io.IOException

serialize

public void serialize(@NotNull
                      T object,
                      @NotNull
                      java.io.OutputStream out)
               throws java.io.IOException
Serializes with a null context

Parameters:
object - the object
out - the output stream
Throws:
java.io.IOException

deserialize

@NotNull
public T deserialize(@NotNull
                             java.io.InputStream in)
              throws java.io.IOException
Deserializes without a context

Parameters:
in - the input stream
Returns:
the deserialized object
Throws:
java.io.IOException


Copyright © 2009 cedarsoft GmbH. All Rights Reserved.