|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.tapestry.engine.AbstractEngine
public abstract class AbstractEngine
Basis for building real Tapestry applications. Immediate subclasses provide different strategies for managing page state and other resources between request cycles.
Note: much of this description is in transition as part of Tapestry 4.0. All ad-hoc singletons and such are being replaced with HiveMind services.
Uses a shared instance of TemplateSource
,ISpecificationSource
,
IScriptSource
and ComponentMessagesSource
stored as attributes of the
ServletContext
(they will be shared by all sessions).
An engine is designed to be very lightweight. Particularily, it should never hold
references to any IPage
or IComponent
objects. The entire
system is based upon being able to quickly rebuild the state of any page(s).
Where possible, instance variables should be transient.
In practice, a subclass (usually BaseEngine
) is used without subclassing. Instead, a
visit object is specified. To facilitate this, the application specification may include a
property, org.apache.tapestry.visit-class
which is the class name to instantiate
when a visit object is first needed.
Some of the classes' behavior is controlled by JVM system properties (typically only used during development):
Property | Description |
---|---|
org.apache.tapestry.enable-reset-service | If true, enabled an additional service, reset, that allow page, specification and template caches to be cleared on demand. |
org.apache.tapestry.disable-caching | If true, then the page, specification, template and script caches will be cleared after each request. This slows things down, but ensures that the latest versions of such files are used. Care should be taken that the source directories for the files preceeds any versions of the files available in JARs or WARs. |
Field Summary | |
---|---|
static String |
VISIT_CLASS_PROPERTY_NAME
The name of the application specification property used to specify the class of the visit object. |
Constructor Summary | |
---|---|
AbstractEngine()
|
Method Summary | |
---|---|
protected void |
activateExceptionPage(IRequestCycle cycle,
Throwable cause)
|
protected void |
cleanupAfterRequest(IRequestCycle cycle)
Invoked at the end of the request cycle to release any resources specific to the request cycle. |
org.apache.hivemind.ClassResolver |
getClassResolver()
|
DataSqueezer |
getDataSqueezer()
|
boolean |
getHasVisit()
|
Infrastructure |
getInfrastructure()
Returns the Infrastructure object, a central
registry of key HiveMind services used by Tapestry. |
ListenerMap |
getListeners()
Allows subclasses to include listener methods easily. |
Locale |
getLocale()
Returns the locale for the engine. |
String |
getOutputEncoding()
Returns the encoding to be used to generate the responses and accept the requests. |
IPropertySource |
getPropertySource()
|
IScriptSource |
getScriptSource()
|
IEngineService |
getService(String name)
Returns a service with the given name. |
IApplicationSpecification |
getSpecification()
|
ISpecificationSource |
getSpecificationSource()
|
Object |
getVisit()
Gets the visit object from the ApplicationStateManager , creating it if it does not
already exist. |
Object |
getVisit(IRequestCycle cycle)
Gets the visit object from the ApplicationStateManager , which will create it as
necessary. |
protected void |
handlePageRedirectException(IRequestCycle cycle,
PageRedirectException exception)
Handles PageRedirectException which involves executing
IRequestCycle.activate(IPage) on the target page (of the exception), until either a
loop is found, or a page succesfully activates. |
protected void |
handleRedirectException(IRequestCycle cycle,
RedirectException redirectException)
Invoked when a RedirectException is thrown during the processing of a request. |
protected void |
handleStaleLinkException(IRequestCycle cycle,
StaleLinkException exception)
Invoked by service(WebRequest, WebResponse) if a StaleLinkException is
thrown by the service . |
protected void |
handleStaleSessionException(IRequestCycle cycle,
StaleSessionException exception)
Invoked by service(WebRequest, WebResponse) if a StaleSessionException is
thrown by the service . |
protected void |
redirect(String pageName,
IRequestCycle cycle,
org.apache.hivemind.ApplicationRuntimeException exception)
Invoked, typically, when an exception occurs while servicing the request. |
void |
renderResponse(IRequestCycle cycle)
Delegates to ResponseRenderer.renderResponse(IRequestCycle) . |
void |
reportException(String reportTitle,
Throwable ex)
Writes a detailed report of the exception to System.err . |
void |
service(WebRequest request,
WebResponse response)
Delegate method for the servlet. |
void |
setLocale(Locale value)
Changes the locale for the engine. |
void |
setVisit(Object visit)
|
String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final String VISIT_CLASS_PROPERTY_NAME
Constructor Detail |
---|
public AbstractEngine()
Method Detail |
---|
protected void activateExceptionPage(IRequestCycle cycle, Throwable cause)
ExceptionPresenter
public void reportException(String reportTitle, Throwable ex)
System.err
.
RequestExceptionReporter
protected void cleanupAfterRequest(IRequestCycle cycle)
public Locale getLocale()
ApplicationServlet
but may be updated by the application.
getLocale
in interface IEngine
public IEngineService getService(String name)
Infrastructure.getServiceMap()
,
ServiceMap
public IApplicationSpecification getSpecification()
Infrastructure.getApplicationSpecification()
public ISpecificationSource getSpecificationSource()
Infrastructure.getSpecificationSource()
protected void redirect(String pageName, IRequestCycle cycle, org.apache.hivemind.ApplicationRuntimeException exception) throws IOException
IOException
public void renderResponse(IRequestCycle cycle) throws IOException
ResponseRenderer.renderResponse(IRequestCycle)
.
IOException
public void service(WebRequest request, WebResponse response) throws IOException
service
in interface WebRequestServicer
IOException
protected void handlePageRedirectException(IRequestCycle cycle, PageRedirectException exception) throws IOException
PageRedirectException
which involves executing
IRequestCycle.activate(IPage)
on the target page (of the exception), until either a
loop is found, or a page succesfully activates.
This should generally not be overriden in subclasses.
IOException
protected void handleStaleLinkException(IRequestCycle cycle, StaleLinkException exception) throws IOException
service(WebRequest, WebResponse)
if a StaleLinkException
is
thrown by the service
. This implementation sets the message property
of the StaleLink page to the message provided in the exception, then invokes
redirect(String, IRequestCycle, ApplicationRuntimeException)
to render the StaleLink
page.
Subclasses may overide this method (without invoking this implementation). A better practice
is to contribute an alternative implementation of
StaleLinkExceptionPresenter
to the
tapestry.InfrastructureOverrides configuration point.
A common practice is to present an error message on the application's Home page. Alternately, the application may provide its own version of the StaleLink page, overriding the framework's implementation (probably a good idea, because the default page hints at "application errors" and isn't localized). The overriding StaleLink implementation must implement a message property of type String.
IOException
protected void handleStaleSessionException(IRequestCycle cycle, StaleSessionException exception) throws IOException
service(WebRequest, WebResponse)
if a StaleSessionException
is
thrown by the service
. This implementation uses the
StaleSessionExceptionPresenter
to render the StaleSession
page.
Subclasses may overide this method (without invoking this implementation), but it is better to override the tapestry.error.StaleSessionExceptionReporter service instead (or contribute a replacement to the tapestry.InfrastructureOverrides configuration point).
IOException
public void setLocale(Locale value)
setLocale
in interface IEngine
public org.apache.hivemind.ClassResolver getClassResolver()
Infrastructure.getClassResolver()
public String toString()
toString
in class Object
public Object getVisit()
ApplicationStateManager
, creating it if it does not
already exist.
As of Tapestry 4.0, this will always create the visit object, possibly creating a new session in the process.
public void setVisit(Object visit)
public Object getVisit(IRequestCycle cycle)
ApplicationStateManager
, which will create it as
necessary.
public boolean getHasVisit()
public IScriptSource getScriptSource()
public ListenerMap getListeners()
protected void handleRedirectException(IRequestCycle cycle, RedirectException redirectException)
RedirectException
is thrown during the processing of a request.
org.apache.hivemind.ApplicationRuntimeException
- if an IOException
,ServletException
is thrown by the redirect,
or if no RequestDispatcher
can be found for local resource.public DataSqueezer getDataSqueezer()
Infrastructure.getDataSqueezer()
public IPropertySource getPropertySource()
public Infrastructure getInfrastructure()
IEngine
Infrastructure
object, a central
registry of key HiveMind services used by Tapestry.
getInfrastructure
in interface IEngine
public String getOutputEncoding()
IEngine
getOutputEncoding
in interface IEngine
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |