org.planx.xmlstore.io
Class PolymorphicStreamer<T>

java.lang.Object
  extended by org.planx.xmlstore.io.PolymorphicStreamer<T>
All Implemented Interfaces:
Streamer<T>

public class PolymorphicStreamer<T>
extends Object
implements Streamer<T>

A polymorphic Streamer that can handle multiple datatypes. A datatype is registered using addStreamer(byte, java.lang.Class, org.planx.xmlstore.io.Streamer). Each datatype must be given a unique id that is used to differentiate between the datatypes when reading data back-in. When writing data the class of the object is examined. If multiple Streamers are registered which can all handle a specific subclass, it is unspecified which Streamer is used. The most specific Streamer is not chosen. Thus, in general, registering a Streamer with a super class of a class of another registered Streamer should be avoided. Use the most specific class possible when registering Streamers.

Author:
Thomas Ambus

Constructor Summary
PolymorphicStreamer()
           
 
Method Summary
<E extends T>
void
addStreamer(byte id, Class<? extends E> cls, Streamer<E> streamer)
           
 T fromStream(DataInput in)
          Reads the internal state of the object from the input stream.
 void toStream(DataOutput out, T obj)
          Writes the internal state of the object to the output stream in a format that can later be read by the same Streamer using the fromStream method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PolymorphicStreamer

public PolymorphicStreamer()
Method Detail

addStreamer

public <E extends T> void addStreamer(byte id,
                                      Class<? extends E> cls,
                                      Streamer<E> streamer)

toStream

public void toStream(DataOutput out,
                     T obj)
              throws IOException
Description copied from interface: Streamer
Writes the internal state of the object to the output stream in a format that can later be read by the same Streamer using the fromStream method.

Specified by:
toStream in interface Streamer<T>
Throws:
IOException

fromStream

public T fromStream(DataInput in)
             throws IOException
Description copied from interface: Streamer
Reads the internal state of the object from the input stream.

Specified by:
fromStream in interface Streamer<T>
Throws:
IOException


Copyright © 2010. All Rights Reserved.