| 
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
T - The type to be externalized.public interface ExternalizableStrategyIfc<T>
This interface defines a strategy to serialize/deserialize an object. This interface is useful in scenarios where one may not want to subclass to ensure a class is serializable (that isn't already serializable) or the class to serialize cannot be subclassed (either abstract or final).
The following example illustrates a trivial implementation of a person and a anExternablizableStrategyIfc that can externalize the person.
    Note:  The person is declared final.
    
public final class Person
{
    private String _name;
    private int    _age;
    public Person ()
    {
    }
    public String getName () { return _name; }
    public void setName ( final String name ) { _name = name; }
    public int getAge () { return _age; }
    public void setAge ( final String age ) { _age = age; }
}
public final PersonExternalizableStrategy
    implements ExternablizableStrategyIfc <Person>
{
    public void writeExternal
        ( final Person person, final  ObjectOutput objectOutput )
            throws IOException
    {
        objectOutput.writeObject ( person.getName () );
        objectOutput.writInt     ( person.getAge  () );
    }
    public void readExternal
        ( final Person person, final ObjectInput objectInput )
            throws IOException, ClassNotFoundException
    {
        person.setName ( ( String ) objectInput.readObject () );
        person.setAge  (            objectInput.readInt    () );
    }
}
public final class PeopleCollection implements Externalizable
{
    private final List  _personList; = new LinkedList  ();
    private final ExternalizableStrategyIfc  _strategy;
    public PeopleCollection ( final ExternalizableStrategyIfc  strategy )
    {
        _strategy = strategy;
    }
    public PeopleCollection ()
    {
        this ( new PersonExternalizableStrategy () );
    }
    public void writeExternal ( final ObjectOutput out ) throws IOException
    {
        out.write
        for ( final Person person : _personList )
        {
            _strategy.writeExternal ( person, out );
        }
    }
    public void readExternal ( final ObjectInput in )
        throws IOException, ClassNotFoundException
    {
    }
}
        
    
Modifications:
    $Date: 2008-12-02 12:32:45 -0500 (Tue, 02 Dec 2008) $
    $Revision: 479 $
    $Author: sfloess $
    $HeadURL: https://jplate.svn.sourceforge.net/svnroot/jplate/trunk/src/dev/java/org/jplate/foundation/io/ExternalizableStrategyIfc.java $
    
| Method Summary | |
|---|---|
 void | 
readExternal(T externalizable,
             java.io.ObjectInput objectInput)
Deserialize externalizable from objectInput. | 
 void | 
writeExternal(T externalizable,
              java.io.ObjectOutput objectOutput)
Serialize externalizable to objectOutput. | 
| Method Detail | 
|---|
void writeExternal(T externalizable,
                   java.io.ObjectOutput objectOutput)
                   throws java.io.IOException
externalizable to objectOutput.
externalizable - The object to serialize to objectOutput.objectOutput - The stream to write externalizable to.
java.io.IOException - If any I/O exceptions arise.
void readExternal(T externalizable,
                  java.io.ObjectInput objectInput)
                  throws java.io.IOException,
                         java.lang.ClassNotFoundException
externalizable from objectInput.
externalizable - The object to deserialize from objectInput.objectInput - The stream to read externalizable from.
java.io.IOException - If any I/O exceptions arise.
java.lang.ClassNotFoundException
  | 
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||