KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infohazard > maverick > flow > Shunt


1 /*
2  * $Id: Shunt.java,v 1.6 2003/10/27 11:00:44 thusted Exp $
3  * $Source: /cvsroot/mav/maverick/src/java/org/infohazard/maverick/flow/Shunt.java,v $
4  */

5 package org.infohazard.maverick.flow;
6
7 import javax.servlet.http.HttpServletRequest JavaDoc;
8
9 /**
10  * <p>The Shunt interface allows Maverick to automagically determine which of a set of
11  * views should be executed based on some arbitrary characteristic of the request.
12  * Views are associated with modes in the Maverick configuration, and the Shunt
13  * is responsible for identifying the proper mode based on the request.</p>
14  *
15  * <p>The canonical example of a Shunt is the LanguageShunt, which uses the
16  * Accept-Language header to choose among views with modes like "en", "fr", etc.
17  * More complicated Shunts might allow regexes or other sophisticated expressions
18  * in the mode string.</p>
19  *
20  * <p>Individual Shunt instances are associated with a particular view name,
21  * so there can be many modes for each of "success", "error", etc.</p>
22  *
23  * <p>As the Maverick config file is loaded, Shunts are created and modes are
24  * defined with defineMode(). Then, during execution, getView() is called.
25  * Thus, defineMode() can be slow, but geView() should be fast.</p>
26  *
27  * @author Jeff Schnitzer
28  * @version $Revision: 1.6 $ $Date: 2003/10/27 11:00:44 $
29  */

30 public interface Shunt
31 {
32     /**
33      * As the Maverick config file is loaded, this method will be called to
34      * associate modes with particular views. If the configuration for a view
35      * did not specify a mode, the mode will be null. Shunts are free to
36      * interpret the mode in any way they choose.
37      *
38      * @param mode The mode associated with this view. Can be null.
39      * @param v The view which should be rendered when this mode is active.
40      * @exception ConfigException If modes clash (such as a duplicate mode).
41      */

42     public void defineMode(String JavaDoc mode, View v) throws ConfigException;
43
44     /**
45      * This is called during runtime to obtain a view based on some arbitrary
46      * characteristic of the request. All modes will already be defined.
47      *
48      * @param request The state of the request is used to determine the proper mode.
49      * @return A view appropriate for the request, based on mode.
50      * @exception NoSuitableModeException if the shunt could not pick a view from the
51      * modes which were defined.
52      */

53     public View getView(HttpServletRequest JavaDoc request) throws NoSuitableModeException;
54 }
55
56
Popular Tags