|
Préférences
Moteurs de recherche
|
||||||||||||||||
JavaTM 2 Platform Std. Ed. v1.6.0
java.beans
|
Constructor Summary | |
---|---|
PersistenceDelegate()
|
Method Summary | |
---|---|
protected void |
initialize(Class<?> type,
Object oldInstance,
Object newInstance,
Encoder out)
Produce a series of statements with side effects on newInstance
so that the new instance becomes equivalent to oldInstance . |
protected abstract Expression |
instantiate(Object oldInstance,
Encoder out)
Returns an expression whose value is oldInstance . |
protected boolean |
mutatesTo(Object oldInstance,
Object newInstance)
Returns true if an equivalent copy of oldInstance may be
created by applying a series of statements to newInstance . |
void |
writeObject(Object oldInstance,
Encoder out)
The writeObject is a single entry point to the persistence
and is used by a Encoder in the traditional
mode of delegation. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public PersistenceDelegate()
Method Detail |
---|
public void writeObject(Object oldInstance, Encoder out)
writeObject
is a single entry point to the persistence
and is used by a Encoder
in the traditional
mode of delegation. Although this method is not final,
it should not need to be subclassed under normal circumstances.
This implementation first checks to see if the stream
has already encountered this object. Next the
mutatesTo
method is called to see if
that candidate returned from the stream can
be mutated into an accurate copy of oldInstance
.
If it can, the initialize
method is called to
perform the initialization. If not, the candidate is removed
from the stream, and the instantiate
method
is called to create a new candidate for this object.
oldInstance
- The instance that will be created by this expression.out
- The stream to which this expression will be written.protected boolean mutatesTo(Object oldInstance, Object newInstance)
oldInstance
may be
created by applying a series of statements to newInstance
.
In the specification of this method, we mean by equivalent that the modified instance
is indistinguishable from oldInstance
in the behavior
of the relevant methods in its public API. [Note: we use the
phrase relevant methods rather than all methods
here only because, to be strictly correct, methods like hashCode
and toString
prevent most classes from producing truly
indistinguishable copies of their instances].
The default behavior returns true
if the classes of the two instances are the same.
oldInstance
- The instance to be copied.newInstance
- The instance that is to be modified.
newInstance
may be
created by applying a series of mutations to oldInstance
.protected abstract Expression instantiate(Object oldInstance, Encoder out)
oldInstance
.
This method is used to characterize the constructor
or factory method that should be used to create the given object.
For example, the instantiate
method of the persistence
delegate for the Field
class could be defined as follows:
Field f = (Field)oldInstance; return new Expression(f, f.getDeclaringClass(), "getField", new Object[]{f.getName()});Note that we declare the value of the returned expression so that the value of the expression (as returned by
getValue
)
will be identical to oldInstance
.
oldInstance
- The instance that will be created by this expression.out
- The stream to which this expression will be written.
oldInstance
.protected void initialize(Class<?> type, Object oldInstance, Object newInstance, Encoder out)
newInstance
so that the new instance becomes equivalent to oldInstance
.
In the specification of this method, we mean by equivalent that, after the method
returns, the modified instance is indistinguishable from
newInstance
in the behavior of all methods in its
public API.
The implementation typically achieves this goal by producing a series of
"what happened" statements involving the oldInstance
and its publicly available state. These statements are sent
to the output stream using its writeExpression
method which returns an expression involving elements in
a cloned environment simulating the state of an input stream during
reading. Each statement returned will have had all instances
the old environment replaced with objects which exist in the new
one. In particular, references to the target of these statements,
which start out as references to oldInstance
are returned
as references to the newInstance
instead.
Executing these statements effects an incremental
alignment of the state of the two objects as a series of
modifications to the objects in the new environment.
By the time the initialize method returns it should be impossible
to tell the two instances apart by using their public APIs.
Most importantly, the sequence of steps that were used to make
these objects appear equivalent will have been recorded
by the output stream and will form the actual output when
the stream is flushed.
The default implementation, calls the initialize
method of the type's superclass.
oldInstance
- The instance to be copied.newInstance
- The instance that is to be modified.out
- The stream to which any initialization statements should be written.