com.primix.tapestry.record
Class PageRecorder

java.lang.Object
  |
  +--com.primix.tapestry.record.PageRecorder
All Implemented Interfaces:
ChangeObserver, IPageRecorder, java.io.Serializable
Direct Known Subclasses:
SimplePageRecorder

public abstract class PageRecorder
extends java.lang.Object
implements IPageRecorder, java.io.Serializable

Tracks changes to components on a page, allowing changes to be persisted across request cycles, and restoring the state of a page and component when needed.

This is an abstract implementation; specific implementations can choose where and how to persist the data.

Implements Externalizable but does not have any state of its own. Subclasses must implement readExternal() and writeExternal().

Version:
$Id: PageRecorder.java,v 1.12 2001/05/02 14:15:16 hship Exp $
Author:
Howard Ship
See Also:
Serialized Form

Field Summary
protected  boolean dirty
           
protected  boolean locked
           
 
Constructor Summary
PageRecorder()
           
 
Method Summary
abstract  void commit()
          Invoked to persist all changes that have been accumulated.
abstract  java.util.Collection getChanges()
          Returns a Collection of IPageChange objects identifying changes to the page and its components.
 boolean isDirty()
          Returns true if the page has observed a change.
 boolean isLocked()
          Returns true if the recorder is locked.
 void observeChange(ObservedChangeEvent event)
          Observes the change.
protected  java.io.Serializable persistValue(java.lang.Object value)
          Invoked by subclasses to converts an object into a Serializable value for for persistent storage.
protected abstract  void recordChange(java.lang.String componentPath, java.lang.String propertyName, java.lang.Object newValue)
          Records a change to a particular component.
protected  java.lang.Object restoreValue(java.lang.Object value)
          Invoked by subclasses to restore a persisted value to its runtime value.
 void rollback(IPage page)
          Rolls back the page to the currently persisted state.
 void setLocked(boolean value)
          Invoked to lock or unlock the recorder.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.primix.tapestry.IPageRecorder
getHasChanges
 

Field Detail

dirty

protected transient boolean dirty

locked

protected transient boolean locked
Constructor Detail

PageRecorder

public PageRecorder()
Method Detail

commit

public abstract void commit()
                     throws PageRecorderCommitException
Invoked to persist all changes that have been accumulated. If the recorder saves change incrementally, this should ensure that all changes have been persisted.

Subclasses should check the dirty flag. If the recorder is dirty, changes should be recorded and the dirty flag cleared.

Specified by:
commit in interface IPageRecorder

getChanges

public abstract java.util.Collection getChanges()
Returns a Collection of IPageChange objects identifying changes to the page and its components.
Specified by:
getChanges in interface IPageRecorder

isDirty

public boolean isDirty()
Returns true if the page has observed a change. The dirty flag is cleared by commit().
Specified by:
isDirty in interface IPageRecorder

isLocked

public boolean isLocked()
Returns true if the recorder is locked. The locked flag is set by commit().
Specified by:
isLocked in interface IPageRecorder

setLocked

public void setLocked(boolean value)
Description copied from interface: IPageRecorder
Invoked to lock or unlock the recorder. Recoders are locked after they are commited, and stay locked until explicitly unlocked in a subsequent request cycle.
Specified by:
setLocked in interface IPageRecorder

observeChange

public void observeChange(ObservedChangeEvent event)
Observes the change. The object of the event is expected to be an IComponent. Ignores the change if not active, otherwise, sets invokes recordChange(String, String, Object).

If the property name in the event is null, then the recorder is marked dirty (but recordChange(String, String, Object) is not invoked. This is how a "distant" property changes are propogated to the page recorder (a distant property change is a change to a property of an object that is itself a property of the page).

If the recorder is not active (typically, when a page is being rewound), then the event is simply ignored.

Specified by:
observeChange in interface ChangeObserver

recordChange

protected abstract void recordChange(java.lang.String componentPath,
                                     java.lang.String propertyName,
                                     java.lang.Object newValue)
Records a change to a particular component. Subclasses may cache these in memory, or record them externally at this time.

This method is responsible for setting the dirty flag if the described change is real.

Parameters:
componentPath - the name of the component relative to the page which contains it. May be null if the change was to a property of the page itself.
propertyName - the name of the property which changed.
newValue - the new value for the property, which may also be null.
See Also:
IComponent.getIdPath()

rollback

public void rollback(IPage page)
Rolls back the page to the currently persisted state.
Specified by:
rollback in interface IPageRecorder

persistValue

protected java.io.Serializable persistValue(java.lang.Object value)
                                     throws java.io.IOException
Invoked by subclasses to converts an object into a Serializable value for for persistent storage.

This implementation implements a special case for converting an EJBObject into a Handle for storage.

Since:
0.2.9

restoreValue

protected java.lang.Object restoreValue(java.lang.Object value)
                                 throws java.io.IOException
Invoked by subclasses to restore a persisted value to its runtime value. This implementation converts Handles, stored persistently, back into EJBObjects.
Since:
0.2.9