org.apache.tapestry.record
Class PageRecorder

java.lang.Object
  extended by org.apache.tapestry.record.PageRecorder
All Implemented Interfaces:
IPageRecorder, ChangeObserver
Direct Known Subclasses:
SessionPageRecorder

public abstract class PageRecorder
extends Object
implements IPageRecorder

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.

Version:
$Id: PageRecorder.java 243791 2004-02-19 17:38:13Z hlship $
Author:
Howard Ship

Constructor Summary
PageRecorder()
           
 
Method Summary
abstract  void commit()
          Invoked to persist all changes that have been accumulated.
abstract  Collection getChanges()
          Returns a Collection of IPageChange objects identifying changes to the page and its components.
protected  boolean getDirty()
           
 boolean isDirty()
          Returns true if the page has observed a change.
 boolean isLocked()
          Returns true if the recorder is locked.
 boolean isMarkedForDiscard()
          Returns true if the recorder has been marked for discard.
 void markForDiscard()
          Invoked to mark the recorder for discarding at the end of the request cycle.
 void observeChange(ObservedChangeEvent event)
          Observes the change.
protected abstract  void recordChange(String componentPath, String propertyName, Object newValue)
          Records a change to a particular component.
 void rollback(IPage page)
          Rolls back the page to the currently persisted state.
protected  void setDirty(boolean dirty)
           
 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 org.apache.tapestry.engine.IPageRecorder
discard, getHasChanges, initialize
 

Constructor Detail

PageRecorder

public PageRecorder()
Method Detail

commit

public abstract void commit()
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 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(String componentPath,
                                     String propertyName,
                                     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

isMarkedForDiscard

public boolean isMarkedForDiscard()
Description copied from interface: IPageRecorder
Returns true if the recorder has been marked for discard.

Specified by:
isMarkedForDiscard in interface IPageRecorder
Since:
2.0.2

markForDiscard

public void markForDiscard()
Description copied from interface: IPageRecorder
Invoked to mark the recorder for discarding at the end of the request cycle.

Specified by:
markForDiscard in interface IPageRecorder
Since:
2.0.2

setDirty

protected void setDirty(boolean dirty)

getDirty

protected boolean getDirty()