org.dellroad.stuff.pobj
Interface PersistentObjectDelegate<T>

Type Parameters:
T - type of the root persistent object
All Known Implementing Classes:
AbstractDelegate, FilterDelegate, SpringDelegate

public interface PersistentObjectDelegate<T>

Delegate interface required for PersistentObjects. Instances provide methods for converting to/from XML, validation, etc.

See Also:
PersistentObject

Method Summary
 T copy(T original)
          Make a deep copy of the given object.
 T deserialize(Source source)
          Deserialize a root object from XML.
 void handleWritebackException(PersistentObject<T> pobj, Throwable t)
          Handle an exception thrown during a delayed write-back attempt.
 boolean isSameGraph(T root1, T root2)
          Attempt to determine whether two object graphs are identical.
 void serialize(T obj, Result result)
          Serialize a root object into XML.
 Set<ConstraintViolation<T>> validate(T obj)
          Validate the given object.
 

Method Detail

serialize

void serialize(T obj,
               Result result)
               throws IOException
Serialize a root object into XML.

Note that this method effectively defines what is contained in the object graph rooted at obj.

This method must not modify obj or any other object in its object graph.

Parameters:
obj - object to serialize; must not be modified
result - XML destination
Throws:
PersistentObjectException - if an error occurs
IOException

deserialize

T deserialize(Source source)
              throws IOException
Deserialize a root object from XML.

Parameters:
source - XML source
Returns:
deserialized object
Throws:
PersistentObjectException - if an error occurs
IOException

copy

T copy(T original)
Make a deep copy of the given object.

For correct behavior, this behavior of this method should be equivalent to a serialization followed by a deserialization.

This method must not modify original or any other object in its object graph.

Throws:
IllegalArgumentException - if original is null
PersistentObjectException - if an error occurs

isSameGraph

boolean isSameGraph(T root1,
                    T root2)
Attempt to determine whether two object graphs are identical.

This optional method is an optimization to detect invocations to PersistentObject.setRoot() where the new object graph and the old object graph are identical. In such cases, no change is applied, the version number does not increase, and no notifications are sent.

It is always safe and correct for this method to return false. If it returns true, then it must be the case that the two object graphs are identical.

This method must not modify oldRoot or newRoot or any other object in their object respective graphs.

Parameters:
root1 - root of first object graph
root2 - root of second object graph
Throws:
IllegalArgumentException - if oldRoot or newRoot is null
PersistentObjectException - if an error occurs

validate

Set<ConstraintViolation<T>> validate(T obj)
Validate the given object.

This method must not modify obj or any other object in its object graph.

Returns:
set of zero or more constraint violations
Throws:
IllegalArgumentException - if obj is null

handleWritebackException

void handleWritebackException(PersistentObject<T> pobj,
                              Throwable t)
Handle an exception thrown during a delayed write-back attempt. ThreadDeath exceptions are not passed to this method, but all others are.

Parameters:
pobj - the instance that encountered the exception
t - the exception thrown