org.dmdf.dmt.externalizers
Class ObjectExternalizer

java.lang.Object
  extended by org.dmdf.dmt.externalizers.ObjectExternalizer
All Implemented Interfaces:
Externalizer
Direct Known Subclasses:
ColorExternalizer, DateExternalizer, DoubleExternalizer, FloatExternalizer, FontExternalizer, IntegerExternalizer, LongExternalizer

public abstract class ObjectExternalizer
extends java.lang.Object
implements Externalizer

Author:
Steven Wang

A super class for all ObjectExternalizer implementation. All Externalizer handles non-primitive type shouold extend this class.

Since you are using DMTFramework, you don't need implement any of the externalizer for your Domain Model Object.

However, some case you might use this to make your Domain Model transportation more efficient - especially for those reference data, to client it is read only, and client have a cache to hold on it. For example:

      public class MyObjectExternalizer extends ObjectExternalizer {
                public Object doRead(ObjectInput objectInput) throws IOException, ClassNotFoundException {
                                Object id = objectInput.readObject();
                                //get MyObject from local cache
                                return getMyObjectFromLocalCache(id);
                }
    
                public void doWrite(Object obj, ObjectOutput objectOutput) throws IOException {
                        //we can only write the id for this object, and the client side can get it back from it's own cache
                        objectOutput.writeObject(((MyObject)obj).getId());
                }
       }
 

Another usage is if you can condense the data need to be streamlized. for Example:

 public class ColorExternalizer extends ObjectExternalizer {
 
        public Object doRead(ObjectInput objectInput) throws IOException {
                return new Color(objectInput.readInt());
        }
 
        public void doWrite(Object obj, ObjectOutput objectOutput) throws IOException {
                objectOutput.writeInt(((Color) obj).getRGB());
        }
 
 }
 

In the required method doRead() and doWrite(), the client object guarenteed not null.


Constructor Summary
ObjectExternalizer()
           
 
Method Summary
protected abstract  java.lang.Object doRead(java.io.ObjectInput objectInput)
          The subclass implementation responsible read the object back
protected abstract  void doWrite(java.lang.Object obj, java.io.ObjectOutput objectOutput)
          The subclass is responsible write the obj to objectOutput, the obj is guarenteed not null, subclass do not need do any null check on that
 java.lang.Object read(java.io.ObjectInput objectInput)
           
 void write(java.lang.Object obj, java.io.ObjectOutput objectOutput)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ObjectExternalizer

public ObjectExternalizer()
Method Detail

read

public final java.lang.Object read(java.io.ObjectInput objectInput)
                            throws java.io.IOException,
                                   java.lang.ClassNotFoundException
Specified by:
read in interface Externalizer
Throws:
java.io.IOException
java.lang.ClassNotFoundException

doRead

protected abstract java.lang.Object doRead(java.io.ObjectInput objectInput)
                                    throws java.io.IOException,
                                           java.lang.ClassNotFoundException
The subclass implementation responsible read the object back

Parameters:
objectInput -
Returns:
Object
Throws:
java.io.IOException
java.lang.ClassNotFoundException

write

public void write(java.lang.Object obj,
                  java.io.ObjectOutput objectOutput)
           throws java.io.IOException
Specified by:
write in interface Externalizer
Throws:
java.io.IOException

doWrite

protected abstract void doWrite(java.lang.Object obj,
                                java.io.ObjectOutput objectOutput)
                         throws java.io.IOException
The subclass is responsible write the obj to objectOutput, the obj is guarenteed not null, subclass do not need do any null check on that

Parameters:
obj -
objectOutput -
Throws:
java.io.IOException


Copyright © 2005 org.dmdt. All Rights Reserved.