java.beans
Class Encoder

java.lang.Object sample code for java.lang.Object definition code for java.lang.Object 
  extended by java.beans.Encoder
Direct Known Subclasses:
XMLEncoder sample code for java.beans.XMLEncoder definition code for java.beans.XMLEncoder

public class Encoder
extends Object sample code for java.lang.Object definition code for java.lang.Object

An Encoder is a class which can be used to create files or streams that encode the state of a collection of JavaBeans in terms of their public APIs. The Encoder, in conjunction with its persistence delegates, is responsible for breaking the object graph down into a series of Statementss and Expressions which can be used to create it. A subclass typically provides a syntax for these expressions using some human readable form - like Java source code or XML.

Since:
1.4

Constructor Summary
Encoder sample code for java.beans.Encoder.Encoder() definition code for java.beans.Encoder.Encoder() ()
           
 
Method Summary
 Object sample code for java.lang.Object definition code for java.lang.Object get sample code for java.beans.Encoder.get(java.lang.Object) definition code for java.beans.Encoder.get(java.lang.Object) (Object sample code for java.lang.Object definition code for java.lang.Object  oldInstance)
          Returns a tentative value for oldInstance in the environment created by this stream.
 ExceptionListener sample code for java.beans.ExceptionListener definition code for java.beans.ExceptionListener getExceptionListener sample code for java.beans.Encoder.getExceptionListener() definition code for java.beans.Encoder.getExceptionListener() ()
          Gets the exception handler for this stream.
 PersistenceDelegate sample code for java.beans.PersistenceDelegate definition code for java.beans.PersistenceDelegate getPersistenceDelegate sample code for java.beans.Encoder.getPersistenceDelegate(java.lang.Class) definition code for java.beans.Encoder.getPersistenceDelegate(java.lang.Class) (Class sample code for java.lang.Class definition code for java.lang.Class <?> type)
          Returns the persistence delegate for the given type.
 Object sample code for java.lang.Object definition code for java.lang.Object remove sample code for java.beans.Encoder.remove(java.lang.Object) definition code for java.beans.Encoder.remove(java.lang.Object) (Object sample code for java.lang.Object definition code for java.lang.Object  oldInstance)
          Removes the entry for this instance, returning the old entry.
 void setExceptionListener sample code for java.beans.Encoder.setExceptionListener(java.beans.ExceptionListener) definition code for java.beans.Encoder.setExceptionListener(java.beans.ExceptionListener) (ExceptionListener sample code for java.beans.ExceptionListener definition code for java.beans.ExceptionListener  exceptionListener)
          Sets the exception handler for this stream to exceptionListener.
 void setPersistenceDelegate sample code for java.beans.Encoder.setPersistenceDelegate(java.lang.Class, java.beans.PersistenceDelegate) definition code for java.beans.Encoder.setPersistenceDelegate(java.lang.Class, java.beans.PersistenceDelegate) (Class sample code for java.lang.Class definition code for java.lang.Class <?> type, PersistenceDelegate sample code for java.beans.PersistenceDelegate definition code for java.beans.PersistenceDelegate  persistenceDelegate)
          Sets the persistence delegate associated with this type to persistenceDelegate.
 void writeExpression sample code for java.beans.Encoder.writeExpression(java.beans.Expression) definition code for java.beans.Encoder.writeExpression(java.beans.Expression) (Expression sample code for java.beans.Expression definition code for java.beans.Expression  oldExp)
          The implementation first checks to see if an expression with this value has already been written.
protected  void writeObject sample code for java.beans.Encoder.writeObject(java.lang.Object) definition code for java.beans.Encoder.writeObject(java.lang.Object) (Object sample code for java.lang.Object definition code for java.lang.Object  o)
          Write the specified object to the output stream.
 void writeStatement sample code for java.beans.Encoder.writeStatement(java.beans.Statement) definition code for java.beans.Encoder.writeStatement(java.beans.Statement) (Statement sample code for java.beans.Statement definition code for java.beans.Statement  oldStm)
          Writes statement oldStm to the stream.
 
Methods inherited from class java.lang.Object sample code for java.lang.Object definition code for java.lang.Object
clone sample code for java.lang.Object.clone() definition code for java.lang.Object.clone() , equals sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object) , finalize sample code for java.lang.Object.finalize() definition code for java.lang.Object.finalize() , getClass sample code for java.lang.Object.getClass() definition code for java.lang.Object.getClass() , hashCode sample code for java.lang.Object.hashCode() definition code for java.lang.Object.hashCode() , notify sample code for java.lang.Object.notify() definition code for java.lang.Object.notify() , notifyAll sample code for java.lang.Object.notifyAll() definition code for java.lang.Object.notifyAll() , toString sample code for java.lang.Object.toString() definition code for java.lang.Object.toString() , wait sample code for java.lang.Object.wait() definition code for java.lang.Object.wait() , wait sample code for java.lang.Object.wait(long) definition code for java.lang.Object.wait(long) , wait sample code for java.lang.Object.wait(long, int) definition code for java.lang.Object.wait(long, int)
 

Constructor Detail

Encoder sample code for java.beans.Encoder() definition code for java.beans.Encoder()

public Encoder()
Method Detail

writeObject sample code for java.beans.Encoder.writeObject(java.lang.Object) definition code for java.beans.Encoder.writeObject(java.lang.Object)

protected void writeObject(Object sample code for java.lang.Object definition code for java.lang.Object  o)
Write the specified object to the output stream. The serialized form will denote a series of expressions, the combined effect of which will create an equivalent object when the input stream is read. By default, the object is assumed to be a JavaBean with a nullary constructor, whose state is defined by the matching pairs of "setter" and "getter" methods returned by the Introspector.

Parameters:
o - The object to be written to the stream.
See Also:
XMLDecoder.readObject() sample code for java.beans.XMLDecoder.readObject() definition code for java.beans.XMLDecoder.readObject()

setExceptionListener sample code for java.beans.Encoder.setExceptionListener(java.beans.ExceptionListener) definition code for java.beans.Encoder.setExceptionListener(java.beans.ExceptionListener)

public void setExceptionListener(ExceptionListener sample code for java.beans.ExceptionListener definition code for java.beans.ExceptionListener  exceptionListener)
Sets the exception handler for this stream to exceptionListener. The exception handler is notified when this stream catches recoverable exceptions.

Parameters:
exceptionListener - The exception handler for this stream; if null the default exception listener will be used.
See Also:
getExceptionListener() sample code for java.beans.Encoder.getExceptionListener() definition code for java.beans.Encoder.getExceptionListener()

getExceptionListener sample code for java.beans.Encoder.getExceptionListener() definition code for java.beans.Encoder.getExceptionListener()

public ExceptionListener sample code for java.beans.ExceptionListener definition code for java.beans.ExceptionListener  getExceptionListener()
Gets the exception handler for this stream.

Returns:
The exception handler for this stream; Will return the default exception listener if this has not explicitly been set.
See Also:
setExceptionListener(java.beans.ExceptionListener) sample code for java.beans.Encoder.setExceptionListener(java.beans.ExceptionListener) definition code for java.beans.Encoder.setExceptionListener(java.beans.ExceptionListener)

getPersistenceDelegate sample code for java.beans.Encoder.getPersistenceDelegate(java.lang.Class<?>) definition code for java.beans.Encoder.getPersistenceDelegate(java.lang.Class<?>)

public PersistenceDelegate sample code for java.beans.PersistenceDelegate definition code for java.beans.PersistenceDelegate  getPersistenceDelegate(Class sample code for java.lang.Class definition code for java.lang.Class <?> type)
Returns the persistence delegate for the given type. The persistence delegate is calculated by applying the following of rules in order:

Parameters:
type - The type of the object.
Returns:
The persistence delegate for this type of object.
See Also:
setPersistenceDelegate(java.lang.Class, java.beans.PersistenceDelegate) sample code for java.beans.Encoder.setPersistenceDelegate(java.lang.Class, java.beans.PersistenceDelegate) definition code for java.beans.Encoder.setPersistenceDelegate(java.lang.Class, java.beans.PersistenceDelegate) , Introspector.getBeanInfo(java.lang.Class) sample code for java.beans.Introspector.getBeanInfo(java.lang.Class) definition code for java.beans.Introspector.getBeanInfo(java.lang.Class) , BeanInfo.getBeanDescriptor() sample code for java.beans.BeanInfo.getBeanDescriptor() definition code for java.beans.BeanInfo.getBeanDescriptor()

setPersistenceDelegate sample code for java.beans.Encoder.setPersistenceDelegate(java.lang.Class<?>, java.beans.PersistenceDelegate) definition code for java.beans.Encoder.setPersistenceDelegate(java.lang.Class<?>, java.beans.PersistenceDelegate)

public void setPersistenceDelegate(Class sample code for java.lang.Class definition code for java.lang.Class <?> type,
                                   PersistenceDelegate sample code for java.beans.PersistenceDelegate definition code for java.beans.PersistenceDelegate  persistenceDelegate)
Sets the persistence delegate associated with this type to persistenceDelegate.

Parameters:
type - The class of objects that persistenceDelegate applies to.
persistenceDelegate - The persistence delegate for instances of type.
See Also:
getPersistenceDelegate(java.lang.Class) sample code for java.beans.Encoder.getPersistenceDelegate(java.lang.Class) definition code for java.beans.Encoder.getPersistenceDelegate(java.lang.Class) , Introspector.getBeanInfo(java.lang.Class) sample code for java.beans.Introspector.getBeanInfo(java.lang.Class) definition code for java.beans.Introspector.getBeanInfo(java.lang.Class) , BeanInfo.getBeanDescriptor() sample code for java.beans.BeanInfo.getBeanDescriptor() definition code for java.beans.BeanInfo.getBeanDescriptor()

remove sample code for java.beans.Encoder.remove(java.lang.Object) definition code for java.beans.Encoder.remove(java.lang.Object)

public Object sample code for java.lang.Object definition code for java.lang.Object  remove(Object sample code for java.lang.Object definition code for java.lang.Object  oldInstance)
Removes the entry for this instance, returning the old entry.

Parameters:
oldInstance - The entry that should be removed.
Returns:
The entry that was removed.
See Also:
get(java.lang.Object) sample code for java.beans.Encoder.get(java.lang.Object) definition code for java.beans.Encoder.get(java.lang.Object)

get sample code for java.beans.Encoder.get(java.lang.Object) definition code for java.beans.Encoder.get(java.lang.Object)

public Object sample code for java.lang.Object definition code for java.lang.Object  get(Object sample code for java.lang.Object definition code for java.lang.Object  oldInstance)
Returns a tentative value for oldInstance in the environment created by this stream. A persistence delegate can use its mutatesTo method to determine whether this value may be initialized to form the equivalent object at the output or whether a new object must be instantiated afresh. If the stream has not yet seen this value, null is returned.

Parameters:
oldInstance - The instance to be looked up.
Returns:
The object, null if the object has not been seen before.

writeStatement sample code for java.beans.Encoder.writeStatement(java.beans.Statement) definition code for java.beans.Encoder.writeStatement(java.beans.Statement)

public void writeStatement(Statement sample code for java.beans.Statement definition code for java.beans.Statement  oldStm)
Writes statement oldStm to the stream. The oldStm should be written entirely in terms of the callers environment, i.e. the target and all arguments should be part of the object graph being written. These expressions represent a series of "what happened" expressions which tell the output stream how to produce an object graph like the original.

The implementation of this method will produce a second expression to represent the same expression in an environment that will exist when the stream is read. This is achieved simply by calling writeObject on the target and all the arguments and building a new expression with the results.

Parameters:
oldStm - The expression to be written to the stream.

writeExpression sample code for java.beans.Encoder.writeExpression(java.beans.Expression) definition code for java.beans.Encoder.writeExpression(java.beans.Expression)

public void writeExpression(Expression sample code for java.beans.Expression definition code for java.beans.Expression  oldExp)
The implementation first checks to see if an expression with this value has already been written. If not, the expression is cloned, using the same procedure as writeStatement, and the value of this expression is reconciled with the value of the cloned expression by calling writeObject.

Parameters:
oldExp - The expression to be written to the stream.