Package javaa.beans
Class PersistenceDelegate
java.lang.Object
javaa.beans.PersistenceDelegate
- Direct Known Subclasses:
DefaultPersistenceDelegate
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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected 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
Determines whether one object mutates to the other object.void
writeObject
(Object oldInstance, Encoder out) Writes a bean object to the given encoder.
-
Constructor Details
-
PersistenceDelegate
public PersistenceDelegate()Default constructor.
-
-
Method Details
-
initialize
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'sPersisteneceDelegate
instance.- Parameters:
type
- the type of the beanoldInstance
- the original bean object to be recordednewInstance
- the simmulating new bean object to be initializedenc
- the encoder to write the outputs to
-
instantiate
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 instanceenc
- 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
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 objecto2
- the other object- Returns:
- true if second object mutates to the first object, otherwise false
-
writeObject
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 writtenout
- the encoder that the old instance will be written to
-