simple.template
Class Action

java.lang.Object
  extended by simple.http.serve.Component
      extended by simple.http.load.Service
          extended by simple.template.Controller
              extended by simple.template.Action
All Implemented Interfaces:
Resource

public abstract class Action
extends Controller

The Action object provides a service controller implementation for taking an action before delegating to other service implementations, which will handle the view. It is used to implement controllers that ultimately redirect to another service or site to complete the client request. Typically the execute method is implemented to perform some processing before being redirected.

The lookup and resolve methods are used to acquire the desired resource object. This must then be returned for the redirection to complete. If at any stage during processing and error occurs then an exception may be thrown to the calling method to indicate the problem.

Author:
Niall Gallagher

Field Summary
 
Fields inherited from class simple.template.Controller
data, system
 
Fields inherited from class simple.http.load.Service
engine
 
Fields inherited from class simple.http.serve.Component
context
 
Constructor Summary
Action(Context context)
          Constructor for the Action object.
 
Method Summary
abstract  Resource execute(Request req, Response resp)
          The execute method is used to perform various operations before a request and response is forwarded.
 Resource lookup(java.lang.String target)
          This method is used to retrieve services using the name for that service.
protected  void process(Request req, Response resp)
          This process method is used to drive the execute method.
 Resource resolve(java.lang.String target)
          This method is used to retrieve services using the path for that service.
 
Methods inherited from class simple.template.Controller
prepare, prepare
 
Methods inherited from class simple.http.load.Service
prepare
 
Methods inherited from class simple.http.serve.Component
handle, handle, handle, process, process
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Action

public Action(Context context)
Constructor for the Action object. This is used to create a service implementation that can be used as a controller. Any subclass of this can initialize itself using the prepare method.

Parameters:
context - the context this controller is rooted at
Method Detail

process

protected void process(Request req,
                       Response resp)
                throws java.lang.Exception
This process method is used to drive the execute method. This will simply invoke the method and forward the client request to the resulting Resource object, which completes the request.

Specified by:
process in class Component
Parameters:
req - the HTTP request object representing the client
resp - the HTTP response object to send a reply with
Throws:
java.lang.Exception - thrown if there is a problem processing

lookup

public Resource lookup(java.lang.String target)
                throws java.lang.Exception
This method is used to retrieve services using the name for that service. This method delegates directly to the LoaderEngine.lookup method implemented. This method can be subclassed to provide a naming scheme, such that resources can be acquired using aliases.

Parameters:
target - the target name referencing the resource
Returns:
the Resource that has been located
Throws:
java.lang.Exception

resolve

public Resource resolve(java.lang.String target)
                 throws java.lang.Exception
This method is used to retrieve services using the path for that service. This method delegates directly to the LoaderEngine.resolve method implemented. This method can be subclassed to provide a mapping scheme, such that resources can be acquired using pattern matches.

Parameters:
target - the target path referencing the resource
Returns:
the Resource that has been located
Throws:
java.lang.Exception

execute

public abstract Resource execute(Request req,
                                 Response resp)
                          throws java.lang.Exception
The execute method is used to perform various operations before a request and response is forwarded. This is useful when no specific view is associated with a target service or resource. It allows delegation to other resources, which can then render the view for the HTTP transaction.

Parameters:
req - the HTTP request object representing the client
resp - the HTTP response object to send a reply with
Returns:
returns the resource used to handle the request
Throws:
java.lang.Exception - thrown if there is a problem processing