messif.objects.nio
Class SingleClassSerializator<T>

java.lang.Object
  extended by messif.objects.nio.BinarySerializator
      extended by messif.objects.nio.SingleClassSerializator<T>
Type Parameters:
T - the class of objects created by this serializator during deserialization
All Implemented Interfaces:
java.io.Serializable

public class SingleClassSerializator<T>
extends BinarySerializator
implements java.io.Serializable

This is the simple serializator implementation for BinarySerializable objects. It can store and restore only one specified class or the standard Java-serialized objects.

See Also:
MultiClassSerializator, CachingSerializator, Serialized Form

Field Summary
protected  java.lang.reflect.Constructor<? extends T> constructor
          The constructor used to create instances of objects during deserialization
protected  java.lang.Class<? extends T> deserializationClass
          The class of objects created by this serializator during deserialization
protected  java.lang.reflect.Method factoryMethod
          The factory method used to create instances of objects during deserialization
 
Fields inherited from class messif.objects.nio.BinarySerializator
log
 
Constructor Summary
SingleClassSerializator(java.lang.Class<? extends T> baseClass)
          Create a new instance of BinarySerializator.
 
Method Summary
 boolean equals(java.lang.Object obj)
          Indicates whether some other object is "equal to" this serializator.
protected  int getBinarySize(BinarySerializable object)
          Returns the size of the binary-serialized object in bytes.
 java.lang.Class<? extends T> getDefaultClass()
          Returns a default class that is used for deserialization when a class is not specified.
 int hashCode()
          Returns a hash code value for this serializator.
 T readObject(BinaryInput input)
          Reads an instance from the input using this serializator.
protected
<E> E
readObjectImpl(BinaryInput input, java.lang.Class<E> expectedClass)
          Reads an instance using the proper constructor/factory method as specified by this serializator.
protected  int write(BinaryOutput output, BinarySerializable object)
          Writes object to this output buffer using binary serialization.
 
Methods inherited from class messif.objects.nio.BinarySerializator
getBinarySize, getBinarySize, getBinarySize, getBinarySize, getBinarySize, getBinarySize, getBinarySize, getBinarySize, getBinarySize, getBinarySize, getNativeSerializableConstructor, getNativeSerializableFactoryMethod, getSerialVersionUID, getSerialVersionUIDHash, readBoolean, readBooleanArray, readByte, readByteArray, readDouble, readDoubleArray, readFloat, readFloatArray, readChar, readCharArray, readInt, readIntArray, readLong, readLongArray, readObject, readObject, readObjectSize, readShort, readShortArray, readString, skipObject, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

deserializationClass

protected final java.lang.Class<? extends T> deserializationClass
The class of objects created by this serializator during deserialization


constructor

protected final transient java.lang.reflect.Constructor<? extends T> constructor
The constructor used to create instances of objects during deserialization


factoryMethod

protected final transient java.lang.reflect.Method factoryMethod
The factory method used to create instances of objects during deserialization

Constructor Detail

SingleClassSerializator

public SingleClassSerializator(java.lang.Class<? extends T> baseClass)
Create a new instance of BinarySerializator. If the baseClass implements the BinarySerializable interface, the constructor/factory method is extracted for deserializing. Otherwise a standard Java serialization will be used.

Parameters:
baseClass - the class of objects created by this serializator during deserialization
Method Detail

getDefaultClass

public java.lang.Class<? extends T> getDefaultClass()
Returns a default class that is used for deserialization when a class is not specified.

Returns:
a default class that is used for deserialization

hashCode

public int hashCode()
Returns a hash code value for this serializator. It is based on the deserializationClass name.

Overrides:
hashCode in class java.lang.Object
Returns:
a hash code value for this serializator

equals

public boolean equals(java.lang.Object obj)
Indicates whether some other object is "equal to" this serializator. It is based on the deserializationClass name.

Overrides:
equals in class java.lang.Object
Parameters:
obj - the reference object with which to compare
Returns:
true if this serializator is the same as the obj argument; false otherwise.

readObject

public T readObject(BinaryInput input)
             throws java.io.IOException,
                    java.lang.IllegalArgumentException
Reads an instance from the input using this serializator. The default class that is expected to be in the buffer.

Parameters:
input - the buffer to read the instance from
Returns:
an instance of the deserialized object
Throws:
java.io.IOException - if there was an I/O error
java.lang.IllegalArgumentException - if the constructor or the factory method has a wrong prototype

write

protected int write(BinaryOutput output,
                    BinarySerializable object)
             throws java.io.IOException
Description copied from class: BinarySerializator
Writes object to this output buffer using binary serialization. The following rules must hold:

Specified by:
write in class BinarySerializator
Parameters:
output - the buffer to write the object to
object - the object to write
Returns:
the number of bytes actually written
Throws:
java.io.IOException - if there was an error using flushChannel

readObjectImpl

protected <E> E readObjectImpl(BinaryInput input,
                               java.lang.Class<E> expectedClass)
                    throws java.io.IOException,
                           java.lang.IllegalArgumentException
Description copied from class: BinarySerializator
Reads an instance using the proper constructor/factory method as specified by this serializator. The following rules must hold:

Specified by:
readObjectImpl in class BinarySerializator
Type Parameters:
E - the class that is expected to be in the input
Parameters:
input - the buffer to read the instance from
expectedClass - the class that is expected to be in the input
Returns:
an instance of the deserialized object
Throws:
java.io.IOException - if there was an I/O error
java.lang.IllegalArgumentException - if the constructor or the factory method has a wrong prototype

getBinarySize

protected int getBinarySize(BinarySerializable object)
                     throws java.lang.IllegalArgumentException
Returns the size of the binary-serialized object in bytes.

Specified by:
getBinarySize in class BinarySerializator
Parameters:
object - the object to get the size for
Returns:
the size of the binary-serialized object
Throws:
java.lang.IllegalArgumentException - if there was an error using Java standard serialization on the object