com.googlecode.openbeans
Class PersistenceDelegate

java.lang.Object
  extended by com.googlecode.openbeans.PersistenceDelegate
Direct Known Subclasses:
DefaultPersistenceDelegate

public abstract class PersistenceDelegate
extends Object

PersistenceDelegate instances write received bean objects to encoders in the form of expressions and statements, which can be evaluated or executed to reconstruct the recorded bean objects in a new environment during decoding. Expressions are usually used to instantiate bean objects in the new environment, and statements are used to initialize their properties if necessary. As a result, the reconstructed bean objects become equivalent to the original recorded ones in terms of their public states.


Constructor Summary
PersistenceDelegate()
          Default constructor.
 
Method Summary
protected  void initialize(Class<?> type, Object oldInstance, Object newInstance, Encoder enc)
          Produces a series of expressions and statements for the initialization of a bean object's properties.
protected abstract  Expression instantiate(Object oldInstance, Encoder enc)
          Constructs an expression for instantiating an object of the same type as the old instance.
protected  boolean mutatesTo(Object o1, Object o2)
          Determines whether one object mutates to the other object.
 void writeObject(Object oldInstance, Encoder out)
          Writes a bean object to the given encoder.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PersistenceDelegate

public PersistenceDelegate()
Default constructor.

Method Detail

initialize

protected void initialize(Class<?> type,
                          Object oldInstance,
                          Object newInstance,
                          Encoder enc)
Produces a series of expressions and statements for the initialization of a bean object's properties. The default implementation simply invokes the initialization provided by the super class's PersisteneceDelegate instance.

Parameters:
type - the type of the bean
oldInstance - the original bean object to be recorded
newInstance - the simmulating new bean object to be initialized
enc - the encoder to write the outputs to

instantiate

protected abstract Expression instantiate(Object oldInstance,
                                          Encoder enc)
Constructs an expression for instantiating an object of the same type as the old instance. Any exceptions occured during this process could be reported to the exception listener registered in the given encoder.

Parameters:
oldInstance - the old instance
enc - the encoder that wants to record the old instance
Returns:
an expression for instantiating an object of the same type as the old instance

mutatesTo

protected boolean mutatesTo(Object o1,
                            Object o2)
Determines whether one object mutates to the other object. One object is considered able to mutate to another object if they are indistinguishable in terms of behaviors of all public APIs. The default implementation here is to return true only if the two objects are instances of the same class.

Parameters:
o1 - one object
o2 - the other object
Returns:
true if second object mutates to the first object, otherwise false

writeObject

public void writeObject(Object oldInstance,
                        Encoder out)
Writes a bean object to the given encoder. First it is checked whether the simulating new object can be mutated to the old instance. If yes, it is initialized to produce a series of expressions and statements that can be used to restore the old instance. Otherwise, remove the new object in the simulating new environment and writes an expression that can instantiate a new instance of the same type as the old one to the given encoder.

Parameters:
oldInstance - the old instance to be written
out - the encoder that the old instance will be written to


Copyright © 2013. All Rights Reserved.