com.primix.tapestry.engine
Class RequestCycle

java.lang.Object
  |
  +--com.primix.tapestry.engine.RequestCycle
All Implemented Interfaces:
ChangeObserver, IRequestCycle

public class RequestCycle
extends java.lang.Object
implements IRequestCycle, ChangeObserver

Provides the logic for processing a single request cycle. Provides access to the engine and the RequestContext.

Version:
$Id: RequestCycle.java,v 1.16 2001/09/13 21:21:23 hship Exp $
Author:
Howard Ship

Constructor Summary
RequestCycle(IEngine engine, RequestContext requestContext, IMonitor monitor)
          Standard constructor used to render a response page.
 
Method Summary
 void cleanup()
          Called at the end of the request cycle (i.e., after all responses have been sent back to the client), to release all pages loaded during the request cycle.
 void commitPageChanges()
          Invokes IPageRecorder.commit() on each page recorder loaded during the request cycle.
 java.lang.String encodeURL(java.lang.String URL)
          Passes the String through HttpServletResponse.encodeURL(), which ensures that the session id is encoded in the URL (if necessary).
 java.lang.Object getAttribute(java.lang.String name)
          Retrieves a previously stored attribute, returning null if not found.
 IEngine getEngine()
          Returns the engine which is processing this request cycle.
 IMonitor getMonitor()
           
 java.lang.String getNextActionId()
          Returns the next action id.
 IPage getPage()
          Identifies the page being rendered.
 IPage getPage(java.lang.String name)
          Gets the page from the engines's IPageSource.
protected  IPageRecorder getPageRecorder(java.lang.String name)
          Returns the page recorder for the named page.
 RequestContext getRequestContext()
           
 IEngineService getService()
          Returns the service which initiated this request cycle.
 boolean isRewinding()
          Returns true if the context is being used to rewind a prior state of the page.
 boolean isRewound(IComponent component)
          Checks to see if the current action id matches the target action id.
 void observeChange(ObservedChangeEvent event)
          For pages without a page recorder, we're the change observer.
 void removeAttribute(java.lang.String name)
          Removes a previously stored attribute, if one with the given name exists.
 void renderPage(IResponseWriter writer)
          Renders the page by invoking IPage.renderPage(IResponseWriter, IRequestCycle).
 void rewindForm(IForm form, java.lang.String targetActionId)
          Rewinds an individual form by invoking IForm.rewind(IResponseWriter, IRequestCycle).
 void rewindPage(java.lang.String targetActionId, IComponent targetComponent)
          Rewinds the page by invoking IPage.renderPage(IResponseWriter, IRequestCycle).
 void setAttribute(java.lang.String name, java.lang.Object value)
          Allows a temporary object to be stored in the request cycle, which allows otherwise unrelated objects to communicate.
 void setPage(IPage value)
          Sets the page to be rendered.
 void setPage(java.lang.String name)
          Sets the page to be rendered.
 void setService(IEngineService value)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RequestCycle

public RequestCycle(IEngine engine,
                    RequestContext requestContext,
                    IMonitor monitor)
Standard constructor used to render a response page.
Method Detail

cleanup

public void cleanup()
Called at the end of the request cycle (i.e., after all responses have been sent back to the client), to release all pages loaded during the request cycle.
Specified by:
cleanup in interface IRequestCycle

getService

public IEngineService getService()
Description copied from interface: IRequestCycle
Returns the service which initiated this request cycle. This may return null (very early during the request cycle) if the service has not yet been determined.
Specified by:
getService in interface IRequestCycle

setService

public void setService(IEngineService value)
Since:
1.0.1

encodeURL

public java.lang.String encodeURL(java.lang.String URL)
Description copied from interface: IRequestCycle
Passes the String through HttpServletResponse.encodeURL(), which ensures that the session id is encoded in the URL (if necessary).
Specified by:
encodeURL in interface IRequestCycle

getEngine

public IEngine getEngine()
Description copied from interface: IRequestCycle
Returns the engine which is processing this request cycle.
Specified by:
getEngine in interface IRequestCycle

getAttribute

public java.lang.Object getAttribute(java.lang.String name)
Description copied from interface: IRequestCycle
Retrieves a previously stored attribute, returning null if not found. Attributes allow components to locate each other; primarily they allow a wrapped component to locate a component which wraps it.
Specified by:
getAttribute in interface IRequestCycle

getMonitor

public IMonitor getMonitor()
Specified by:
getMonitor in interface IRequestCycle

getNextActionId

public java.lang.String getNextActionId()
Description copied from interface: IRequestCycle
Returns the next action id. Action ids are used to identify different actions on a page (URLs that are related to dynamic page state).
Specified by:
getNextActionId in interface IRequestCycle

getPage

public IPage getPage()
Description copied from interface: IRequestCycle
Identifies the page being rendered.
Specified by:
getPage in interface IRequestCycle

getPage

public IPage getPage(java.lang.String name)
Gets the page from the engines's IPageSource.
Specified by:
getPage in interface IRequestCycle
Following copied from interface: com.primix.tapestry.IRequestCycle
See Also:
IEngine.getPageSource()

getPageRecorder

protected IPageRecorder getPageRecorder(java.lang.String name)
Returns the page recorder for the named page. This may come form the cycle's cache of page recorders or, if not yet encountered in this request cycle, the IEngine.getPageRecorder(String) is invoked to get the recorder, if it exists.

getRequestContext

public RequestContext getRequestContext()
Specified by:
getRequestContext in interface IRequestCycle

isRewinding

public boolean isRewinding()
Description copied from interface: IRequestCycle
Returns true if the context is being used to rewind a prior state of the page. This is only true when there is a target action id.
Specified by:
isRewinding in interface IRequestCycle

isRewound

public boolean isRewound(IComponent component)
                  throws StaleLinkException
Description copied from interface: IRequestCycle
Checks to see if the current action id matches the target action id. Returns true only if they match. Returns false if there is no target action id (that is, during page rendering).

If theres a match on action id, then the component is compared against the target component. If there's a mismatch then a StaleLinkException is thrown.

Specified by:
isRewound in interface IRequestCycle

removeAttribute

public void removeAttribute(java.lang.String name)
Description copied from interface: IRequestCycle
Removes a previously stored attribute, if one with the given name exists.
Specified by:
removeAttribute in interface IRequestCycle

renderPage

public void renderPage(IResponseWriter writer)
                throws RequestCycleException
Renders the page by invoking IPage.renderPage(IResponseWriter, IRequestCycle). This clears all attributes.
Specified by:
renderPage in interface IRequestCycle

rewindForm

public void rewindForm(IForm form,
                       java.lang.String targetActionId)
                throws RequestCycleException
Rewinds an individual form by invoking IForm.rewind(IResponseWriter, IRequestCycle).

The process is expected to end with a RenderRewoundException. If the entire page is renderred without this exception being thrown, it means that the target action id was not valid, and a RequestCycleException is thrown.

This clears all attributes.

Specified by:
rewindForm in interface IRequestCycle
Since:
1.0.2

rewindPage

public void rewindPage(java.lang.String targetActionId,
                       IComponent targetComponent)
                throws RequestCycleException
Rewinds the page by invoking IPage.renderPage(IResponseWriter, IRequestCycle).

The process is expected to end with a RenderRewoundException. If the entire page is renderred without this exception being thrown, it means that the target action id was not valid, and a RequestCycleException is thrown.

This clears all attributes.

Specified by:
rewindPage in interface IRequestCycle
Following copied from interface: com.primix.tapestry.IRequestCycle
See Also:
IAction

setAttribute

public void setAttribute(java.lang.String name,
                         java.lang.Object value)
Description copied from interface: IRequestCycle
Allows a temporary object to be stored in the request cycle, which allows otherwise unrelated objects to communicate. This is similar to HttpServletRequest.setAttribute(), except that values can be changed and removed as well.

This is used by components to locate each other. A component, such as Body, will write itself under a well-known name into the request cycle, and components it wraps can locate it by that name.

Specified by:
setAttribute in interface IRequestCycle

setPage

public void setPage(IPage value)
Description copied from interface: IRequestCycle
Sets the page to be rendered. This is called by a component during the rewind phase to specify an alternate page to render during the response phase.
Specified by:
setPage in interface IRequestCycle

setPage

public void setPage(java.lang.String name)
Description copied from interface: IRequestCycle
Sets the page to be rendered. This is called by a component during the rewind phase to specify an alternate page to render during the response phase.
Specified by:
setPage in interface IRequestCycle

commitPageChanges

public void commitPageChanges()
                       throws PageRecorderCommitException
Invokes IPageRecorder.commit() on each page recorder loaded during the request cycle.
Specified by:
commitPageChanges in interface IRequestCycle
Following copied from interface: com.primix.tapestry.IRequestCycle
See Also:
IPageRecorder.commit()

observeChange

public void observeChange(ObservedChangeEvent event)
For pages without a page recorder, we're the change observer. If such a page actually emits a change, then we'll obtain a new page recorder from the engine, set the recorder as the page's change observer, and forward the event to the newly created recorder. In addition, the new page recorder is remembered so that it will be committed by commitPageChanges().
Specified by:
observeChange in interface ChangeObserver