org.dellroad.stuff.pobj
Class FilterDelegate<T>

java.lang.Object
  extended by org.dellroad.stuff.pobj.FilterDelegate<T>
Type Parameters:
T - type of the root persistent object
All Implemented Interfaces:
PersistentObjectDelegate<T>

public class FilterDelegate<T>
extends Object
implements PersistentObjectDelegate<T>

Adapter class for PersistentObjectDelegate implementations that wrap a nested delegate. All methods in this class forward to the nested delegate.


Field Summary
protected  PersistentObjectDelegate<T> nested
           
 
Constructor Summary
FilterDelegate(PersistentObjectDelegate<T> nested)
          Constructor.
 
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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

nested

protected final PersistentObjectDelegate<T> nested
Constructor Detail

FilterDelegate

public FilterDelegate(PersistentObjectDelegate<T> nested)
Constructor.

Parameters:
nested - nested delegate to wrap
Throws:
IllegalArgumentException - if nested is null
Method Detail

serialize

public void serialize(T obj,
                      Result result)
               throws IOException
Description copied from interface: PersistentObjectDelegate
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.

Specified by:
serialize in interface PersistentObjectDelegate<T>
Parameters:
obj - object to serialize; must not be modified
result - XML destination
Throws:
IOException

deserialize

public T deserialize(Source source)
              throws IOException
Description copied from interface: PersistentObjectDelegate
Deserialize a root object from XML.

Specified by:
deserialize in interface PersistentObjectDelegate<T>
Parameters:
source - XML source
Returns:
deserialized object
Throws:
IOException

copy

public T copy(T original)
Description copied from interface: PersistentObjectDelegate
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.

Specified by:
copy in interface PersistentObjectDelegate<T>

isSameGraph

public boolean isSameGraph(T root1,
                           T root2)
Description copied from interface: PersistentObjectDelegate
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.

Specified by:
isSameGraph in interface PersistentObjectDelegate<T>
Parameters:
root1 - root of first object graph
root2 - root of second object graph

validate

public Set<ConstraintViolation<T>> validate(T obj)
Description copied from interface: PersistentObjectDelegate
Validate the given object.

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

Specified by:
validate in interface PersistentObjectDelegate<T>
Returns:
set of zero or more constraint violations

handleWritebackException

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

Specified by:
handleWritebackException in interface PersistentObjectDelegate<T>
Parameters:
pobj - the instance that encountered the exception
t - the exception thrown