|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.dmdf.dmt.externalizers.ObjectExternalizer
public abstract class ObjectExternalizer
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 |
---|
public ObjectExternalizer()
Method Detail |
---|
public final java.lang.Object read(java.io.ObjectInput objectInput) throws java.io.IOException, java.lang.ClassNotFoundException
read
in interface Externalizer
java.io.IOException
java.lang.ClassNotFoundException
protected abstract java.lang.Object doRead(java.io.ObjectInput objectInput) throws java.io.IOException, java.lang.ClassNotFoundException
objectInput
-
java.io.IOException
java.lang.ClassNotFoundException
public void write(java.lang.Object obj, java.io.ObjectOutput objectOutput) throws java.io.IOException
write
in interface Externalizer
java.io.IOException
protected abstract void doWrite(java.lang.Object obj, java.io.ObjectOutput objectOutput) throws java.io.IOException
obj
- objectOutput
-
java.io.IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |