java.lang.Objectjava.beans.PersistenceDelegate
Direct Known Subclasses:
java_util_AbstractCollection_PersistenceDelegate, java_awt_Container_PersistenceDelegate, CheckedCollection_PersistenceDelegate, CheckedList_PersistenceDelegate, javax_swing_Box_PersistenceDelegate, CheckedSortedMap_PersistenceDelegate, java_util_Collection_PersistenceDelegate, SynchronizedCollection_PersistenceDelegate, javax_swing_tree_DefaultMutableTreeNode_PersistenceDelegate, java_util_Map_PersistenceDelegate, SynchronizedSortedMap_PersistenceDelegate, ProxyPersistenceDelegate, UnmodifiableMap_PersistenceDelegate, NullPersistenceDelegate, UnmodifiableSet_PersistenceDelegate, javax_swing_DefaultListModel_PersistenceDelegate, CheckedSortedSet_PersistenceDelegate, java_util_Collections, SynchronizedRandomAccessList_PersistenceDelegate, PrimitivePersistenceDelegate, java_awt_Component_PersistenceDelegate, java_awt_GridBagLayout_PersistenceDelegate, java_util_EnumMap_PersistenceDelegate, UnmodifiableCollection_PersistenceDelegate, SingletonMap_PersistenceDelegate, java_awt_CardLayout_PersistenceDelegate, UnmodifiableRandomAccessList_PersistenceDelegate, CheckedMap_PersistenceDelegate, SingletonList_PersistenceDelegate, javax_swing_border_MatteBorder_PersistenceDelegate, java_sql_Timestamp_PersistenceDelegate, java_awt_AWTKeyStroke_PersistenceDelegate, EmptySet_PersistenceDelegate, CheckedSet_PersistenceDelegate, javax_swing_ToolTipManager_PersistenceDelegate, javax_swing_JFrame_PersistenceDelegate, java_awt_Rectangle_PersistenceDelegate, ArrayPersistenceDelegate, javax_swing_JMenu_PersistenceDelegate, java_util_Hashtable_PersistenceDelegate, java_awt_MenuShortcut_PersistenceDelegate, java_lang_String_PersistenceDelegate, EmptyList_PersistenceDelegate, EnumPersistenceDelegate, UnmodifiableSortedSet_PersistenceDelegate, java_util_EnumSet_PersistenceDelegate, UnmodifiableList_PersistenceDelegate, javax_swing_JTabbedPane_PersistenceDelegate, java_awt_Dimension_PersistenceDelegate, java_lang_Class_PersistenceDelegate, SynchronizedMap_PersistenceDelegate, java_util_AbstractList_PersistenceDelegate, SynchronizedSortedSet_PersistenceDelegate, EmptyMap_PersistenceDelegate, CheckedRandomAccessList_PersistenceDelegate, java_awt_Menu_PersistenceDelegate, SingletonSet_PersistenceDelegate, UnmodifiableSortedMap_PersistenceDelegate, java_awt_BorderLayout_PersistenceDelegate, java_util_AbstractMap_PersistenceDelegate, java_lang_reflect_Field_PersistenceDelegate, sun_swing_PrintColorUIResource_PersistenceDelegate, javax_swing_DefaultComboBoxModel_PersistenceDelegate, java_lang_reflect_Method_PersistenceDelegate, DefaultPersistenceDelegate, java_awt_Insets_PersistenceDelegate, java_util_Date_PersistenceDelegate, java_util_List_PersistenceDelegate, java_awt_GridBagConstraints_PersistenceDelegate, java_awt_MenuBar_PersistenceDelegate, java_beans_beancontext_BeanContextSupport_PersistenceDelegate, SynchronizedList_PersistenceDelegate, java_awt_font_TextAttribute_PersistenceDelegate, java_awt_Point_PersistenceDelegate, java_awt_SystemColor_PersistenceDelegate, java_awt_List_PersistenceDelegate, java_awt_Choice_PersistenceDelegate, StaticFieldsPersistenceDelegate, java_awt_Font_PersistenceDelegate, SynchronizedSet_PersistenceDelegate
readObject and writeObject
methods used by the ObjectOutputStream, streams like
the XMLEncoder which
use this delegation model can have their behavior controlled
independently of the classes themselves. Normally, the class
is the best place to put such information and conventions
can easily be expressed in this delegation scheme to do just that.
Sometimes however, it is the case that a minor problem
in a single class prevents an entire object graph from
being written and this can leave the application
developer with no recourse but to attempt to shadow
the problematic classes locally or use alternative
persistence techniques. In situations like these, the
delegation model gives a relatively clean mechanism for
the application developer to intervene in all parts of the
serialization process without requiring that modifications
be made to the implementation of classes which are not part
of the application itself.
In addition to using a delegation model, this persistence
scheme differs from traditional serialization schemes
in requiring an analog of the writeObject
method without a corresponding readObject
method. The writeObject analog encodes each
instance in terms of its public API and there is no need to
define a readObject analog
since the procedure for reading the serialized form
is defined by the semantics of method invocation as laid
out in the Java Language Specification.
Breaking the dependency between writeObject
and readObject implementations, which may
change from version to version, is the key factor
in making the archives produced by this technique immune
to changes in the private implementations of the classes
to which they refer.
A persistence delegate, may take control of all aspects of the persistence of an object including:
1.4 - Philip - Milne| Method from java.beans.PersistenceDelegate Summary: |
|---|
| initialize, instantiate, mutatesTo, writeObject |
| Methods from java.lang.Object: |
|---|
| clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method from java.beans.PersistenceDelegate Detail: |
|---|
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
The default implementation, calls the |
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 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 |
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
|