Package jadex.commons.beans
Class PersistenceDelegate
- java.lang.Object
-
- jadex.commons.beans.PersistenceDelegate
-
- Direct Known Subclasses:
DefaultPersistenceDelegate
public abstract class PersistenceDelegate extends java.lang.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
Constructors Constructor Description PersistenceDelegate()
Default constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
initialize(java.lang.Class<?> type, java.lang.Object oldInstance, java.lang.Object newInstance, Encoder enc)
Produces a series of expressions and statements for the initialization of a bean object's properties.protected abstract Expression
instantiate(java.lang.Object oldInstance, Encoder enc)
Constructs an expression for instantiating an object of the same type as the old instance.protected boolean
mutatesTo(java.lang.Object o1, java.lang.Object o2)
Determines whether one object mutates to the other object.void
writeObject(java.lang.Object oldInstance, Encoder out)
Writes a bean object to the given encoder.
-
-
-
Method Detail
-
initialize
protected void initialize(java.lang.Class<?> type, java.lang.Object oldInstance, java.lang.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'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
protected abstract Expression instantiate(java.lang.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 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
protected boolean mutatesTo(java.lang.Object o1, java.lang.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 objecto2
- the other object- Returns:
- true if second object mutates to the first object, otherwise false
-
writeObject
public void writeObject(java.lang.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 writtenout
- the encoder that the old instance will be written to
-
-