Package jadex.commons.beans
Class Encoder
- java.lang.Object
-
- jadex.commons.beans.Encoder
-
- Direct Known Subclasses:
XMLEncoder
public class Encoder extends java.lang.Object
TheEncoder
, together withPersistenceDelegate
s, can encode an object into a series of java statements. By executing these statements, a new object can be created and it will has the same state as the original object which has been passed to the encoder. Here "has the same state" means the two objects are indistinguishable from their public API.Encoder and
PersistenceDelegate
s do this by creating copies of the input object and all objects it references. The copy process continues recursively util every object in the object graph has its new copy and the new version has the same state as the old version. All statements used to create those new objects and executed on them during the process form the result of encoding.-
-
Constructor Summary
Constructors Constructor Description Encoder()
Construct a new encoder.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Object
get(java.lang.Object old)
Gets the new copy of the given old object.ExceptionListener
getExceptionListener()
Returns the exception listener of this encoder.PersistenceDelegate
getPersistenceDelegate(java.lang.Class<?> type)
Returns aPersistenceDelegate
for the given class type.java.lang.Object
remove(java.lang.Object old)
Remvoe the existing new copy of the given old object.void
setExceptionListener(ExceptionListener listener)
Sets the exception listener of this encoder.void
setPersistenceDelegate(java.lang.Class<?> type, PersistenceDelegate delegate)
Register thePersistenceDelegate
of the specified type.void
writeExpression(Expression oldExp)
Write an expression of old objects.protected void
writeObject(java.lang.Object o)
Encode the given object into a series of statements and expressions.void
writeStatement(Statement oldStat)
Write a statement of old objects.
-
-
-
Method Detail
-
get
public java.lang.Object get(java.lang.Object old)
Gets the new copy of the given old object.- Parameters:
old
- an old object- Returns:
- the new copy of the given old object, or null if there is not one.
-
getExceptionListener
public ExceptionListener getExceptionListener()
Returns the exception listener of this encoder.- Returns:
- the exception listener of this encoder
-
getPersistenceDelegate
public PersistenceDelegate getPersistenceDelegate(java.lang.Class<?> type)
Returns aPersistenceDelegate
for the given class type.PersistenceDelegate is determined as following:
- PersistenceDelegate has been registered by
calling
- Parameters:
type
- a class type- Returns:
- a
PersistenceDelegate
for the given class type -
remove
public java.lang.Object remove(java.lang.Object old)
Remvoe the existing new copy of the given old object.- Parameters:
old
- an old object- Returns:
- the removed new version of the old object, or null if there is not one
-
setExceptionListener
public void setExceptionListener(ExceptionListener listener)
Sets the exception listener of this encoder.- Parameters:
listener
- the exception listener to set
-
setPersistenceDelegate
public void setPersistenceDelegate(java.lang.Class<?> type, PersistenceDelegate delegate)
Register thePersistenceDelegate
of the specified type.- Parameters:
type
-delegate
-
-
writeExpression
public void writeExpression(Expression oldExp)
Write an expression of old objects.writeObject() is called to create the new version.
writeObject() with the old return value, so that more statements will be executed on its new version to change it into the same state as the old value.- Parameters:
oldExp
- the expression to write. The target, arguments, and return value of the expression are all old objects.
-
writeObject
protected void writeObject(java.lang.Object o)
Encode the given object into a series of statements and expressions.PersistenceDelegate responsible for the object's class, and delegate the call to it.
- Parameters:
o
- the object to encode
-
writeStatement
public void writeStatement(Statement oldStat)
Write a statement of old objects.writeObject() is called to create one.
- Parameters:
oldStat
- a statement of old objects
setPersistenceDelegate
for the given type, it is returned.PersistenceDelegate for array types is returned.PersistenceDelegate for proxy classes is returned.Introspector is used to check the bean descriptor value "persistenceDelegate". If one is set, it is returned.DefaultPersistenceDelegate is returned.
-
-