Java Doc for PersistenceDelegate.java in  » 6.0-JDK-Core » beans » java » beans » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Home
Java Source Code / Java Documentation
1.6.0 JDK Core
2.6.0 JDK Modules
3.6.0 JDK Modules com.sun
4.6.0 JDK Modules com.sun.java
5.6.0 JDK Modules sun
6.6.0 JDK Platform
7.Ajax
8.Apache Harmony Java SE
9.Aspect oriented
10.Authentication Authorization
11.Blogger System
12.Build
13.Byte Code
14.Cache
15.Chart
16.Chat
17.Code Analyzer
18.Collaboration
19.Content Management System
20.Database Client
21.Database DBMS
22.Database JDBC Connection Pool
23.Database ORM
24.Development
25.EJB Server
26.ERP CRM Financial
27.ESB
28.Forum
29.Game
30.GIS
31.Graphic 3D
32.Graphic Library
33.Groupware
34.HTML Parser
35.IDE
36.IDE Eclipse
37.IDE Netbeans
38.Installer
39.Internationalization Localization
40.Inversion of Control
41.Issue Tracking
42.J2EE
43.J2ME
44.JBoss
45.JMS
46.JMX
47.Library
48.Mail Clients
49.Music
50.Net
51.Parser
52.PDF
53.Portal
54.Profiler
55.Project Management
56.Report
57.RSS RDF
58.Rule Engine
59.Science
60.Scripting
61.Search Engine
62.Security
63.Sevlet Container
64.Source Control
65.Swing Library
66.Template Engine
67.Test Coverage
68.Testing
69.UML
70.Web Crawler
71.Web Framework
72.Web Mail
73.Web Server
74.Web Services
75.Web Services apache cxf 2.2.6
76.Web Services AXIS2
77.Wiki Engine
78.Workflow Engines
79.XML
80.XML UI
Java Source Code / Java Documentation » 6.0 JDK Core » beans » java.beans 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   java.beans.PersistenceDelegate

All known Subclasses:   java.beans.NullPersistenceDelegate,  java.beans.DefaultPersistenceDelegate,
PersistenceDelegate
abstract public class PersistenceDelegate (Code)
The PersistenceDelegate class takes the responsibility for expressing the state of an instance of a given class in terms of the methods in the class's public API. Instead of associating the responsibility of persistence with the class itself as is done, for example, by the 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:

  • Deciding whether or not an instance can be mutated into another instance of the same class.
  • Instantiating the object, either by calling a public constructor or a public factory method.
  • Performing the initialization of the object.

See Also:   XMLEncoder
since:
   1.4
version:
   1.19 05/05/07
author:
   Philip Milne




Method Summary
protected  voidinitialize(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. 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.

abstract protected  Expressioninstantiate(Object oldInstance, Encoder out)
     Returns an expression whose value is 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.
Parameters:
  oldInstance - The instance that will be created by this expression.
Parameters:
  out - The stream to which this expression will be written.
protected  booleanmutatesTo(Object oldInstance, Object newInstance)
     Returns true if an equivalent copy of 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.
public  voidwriteObject(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.



Method Detail
initialize
protected void initialize(Class type, Object oldInstance, Object newInstance, Encoder out)(Code)
Produce a series of statements with side effects on 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.
Parameters:
  oldInstance - The instance to be copied.
Parameters:
  newInstance - The instance that is to be modified.
Parameters:
  out - The stream to which any initialization statements should be written.




instantiate
abstract protected Expression instantiate(Object oldInstance, Encoder out)(Code)
Returns an expression whose value is 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.
Parameters:
  oldInstance - The instance that will be created by this expression.
Parameters:
  out - The stream to which this expression will be written. An expression whose value is oldInstance.



mutatesTo
protected boolean mutatesTo(Object oldInstance, Object newInstance)(Code)
Returns true if an equivalent copy of 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.
Parameters:
  oldInstance - The instance to be copied.
Parameters:
  newInstance - The instance that is to be modified. True if an equivalent copy of newInstance may becreated by applying a series of mutations to oldInstance.




writeObject
public void writeObject(Object oldInstance, Encoder out)(Code)
The 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.
Parameters:
  oldInstance - The instance that will be created by this expression.
Parameters:
  out - The stream to which this expression will be written.




Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.