org.infohazard.maverick.flow
Interface Shunt


public interface Shunt

The Shunt interface allows Maverick to automagically determine which of a set of views should be executed based on some arbitrary characteristic of the request. Views are associated with modes in the Maverick configuration, and the Shunt is responsible for identifying the proper mode based on the request.

The canonical example of a Shunt is the LanguageShunt, which uses the Accept-Language header to choose among views with modes like "en", "fr", etc. More complicated Shunts might allow regexes or other sophisticated expressions in the mode string.

Individual Shunt instances are associated with a particular view name, so there can be many modes for each of "success", "error", etc.

As the Maverick config file is loaded, Shunts are created and modes are defined with defineMode(). Then, during execution, getView() is called. Thus, defineMode() can be slow, but geView() should be fast.

Version:
$Revision: 1.5 $ $Date: 2002/06/06 12:23:53 $
Author:
Jeff Schnitzer

Method Summary
 void defineMode(java.lang.String mode, View v)
          As the Maverick config file is loaded, this method will be called to associate modes with particular views.
 View getView(javax.servlet.http.HttpServletRequest request)
          This is called during runtime to obtain a view based on some arbitrary characteristic of the request.
 

Method Detail

defineMode

public void defineMode(java.lang.String mode,
                       View v)
                throws ConfigException
As the Maverick config file is loaded, this method will be called to associate modes with particular views. If the configuration for a view did not specify a mode, the mode will be null. Shunts are free to interpret the mode in any way they choose.

Parameters:
mode - The mode associated with this view. Can be null.
Throws:
ConfigException - If modes clash (such as a duplicate mode).

getView

public View getView(javax.servlet.http.HttpServletRequest request)
             throws NoSuitableModeException
This is called during runtime to obtain a view based on some arbitrary characteristic of the request. All modes will already be defined.

Parameters:
request - The state of the request is used to determine the proper mode.
Returns:
A view appropriate for the request, based on mode.
Throws:
NoSuitableModeException - if the shunt could not pick a view from the modes which were defined.