org.mentawai.core
Class Controller

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by org.mentawai.core.Controller
All Implemented Interfaces:
java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig
Direct Known Subclasses:
PrettyURLController

public class Controller
extends javax.servlet.http.HttpServlet

The Mentawai central controller. Mentawai actions are intercepted and executed by this controller. The controller is also responsable for creating and starting the ApplicationManager.

Author:
Sergio Oliveira, Rubem Azenha (rubem.azenha@gmail.com)
See Also:
Serialized Form

Field Summary
protected static ApplicationContext appContext
           
 
Constructor Summary
Controller()
           
 
Method Summary
 void destroy()
          Destroy all filters defined in the ApplicationManager, call the destroy() method of ApplicationManager, then call super.destroy() to destroy this servlet (the Controller).
protected  java.lang.String getActionName(javax.servlet.http.HttpServletRequest req)
          From the http request, get the action name.
static javax.servlet.ServletContext getApplication()
          Returns the ServletContext of your web application.
protected  java.lang.String getInnerActionName(javax.servlet.http.HttpServletRequest req)
          The action name may include an Inner Action.
protected  java.lang.String getURI(javax.servlet.http.HttpServletRequest req)
          Returns the URI from this request.
 void init(javax.servlet.ServletConfig conf)
          Initialize the Controller, creating and starting the ApplicationManager.
static Consequence invokeAction(ActionConfig ac, Action action, java.lang.String innerAction, java.util.List<java.lang.Object> filters, java.lang.StringBuilder returnedResult)
          Invoke an action and return the consequence generated by this invocation.
protected  void prepareAction(Action action, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
          Subclasses of this controller may override this method to have a chance to prepare the action before it is executed.
protected  void service(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
           
static void setAppManager(ApplicationManager applicationManager)
           
static void setConsequenceProvider(ConsequenceProvider provider)
           
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doGet, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service
 
Methods inherited from class javax.servlet.GenericServlet
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

appContext

protected static ApplicationContext appContext
Constructor Detail

Controller

public Controller()
Method Detail

init

public void init(javax.servlet.ServletConfig conf)
          throws javax.servlet.ServletException
Initialize the Controller, creating and starting the ApplicationManager.

Specified by:
init in interface javax.servlet.Servlet
Overrides:
init in class javax.servlet.GenericServlet
Parameters:
conf - the ServletConfig.
Throws:
javax.servlet.ServletException

setConsequenceProvider

public static void setConsequenceProvider(ConsequenceProvider provider)

destroy

public void destroy()
Destroy all filters defined in the ApplicationManager, call the destroy() method of ApplicationManager, then call super.destroy() to destroy this servlet (the Controller).

Specified by:
destroy in interface javax.servlet.Servlet
Overrides:
destroy in class javax.servlet.GenericServlet

getApplication

public static javax.servlet.ServletContext getApplication()
Returns the ServletContext of your web application.

Returns:
The ServletContext of your web application.

getURI

protected java.lang.String getURI(javax.servlet.http.HttpServletRequest req)
Returns the URI from this request. URI = URI - context - extension. This method is used by getActionName and getInnerActionName. You may call this method in your own controller subclass. Ex: /myapp/UserAction.add.mtw will return UserAction.add

Parameters:
req -
Returns:
The URI

getActionName

protected java.lang.String getActionName(javax.servlet.http.HttpServletRequest req)
From the http request, get the action name. You may override this if you want to extract the action name through some other way.

Parameters:
req - The http request
Returns:
The action name

getInnerActionName

protected java.lang.String getInnerActionName(javax.servlet.http.HttpServletRequest req)
The action name may include an Inner Action. For example: for bookmanager.add.mtw the action name is "bookmanager" and the inneraction name is "add". If you want to extract the inner action through some other way you can override this method in your own controller.

Parameters:
req -
Returns:
The inner action name or null if there is no inneraction.

prepareAction

protected void prepareAction(Action action,
                             javax.servlet.http.HttpServletRequest req,
                             javax.servlet.http.HttpServletResponse res)
Subclasses of this controller may override this method to have a chance to prepare the action before it is executed. This method creates and injects in the action all contexts, input, output and locale.

Parameters:
action - The action to prepare for execution
req - The http request (input will need that)
res - The http response (output will need that)
Since:
1.2

service

protected void service(javax.servlet.http.HttpServletRequest req,
                       javax.servlet.http.HttpServletResponse res)
                throws javax.servlet.ServletException,
                       java.io.IOException
Overrides:
service in class javax.servlet.http.HttpServlet
Throws:
javax.servlet.ServletException
java.io.IOException

invokeAction

public static Consequence invokeAction(ActionConfig ac,
                                       Action action,
                                       java.lang.String innerAction,
                                       java.util.List<java.lang.Object> filters,
                                       java.lang.StringBuilder returnedResult)
                                throws java.lang.Exception
Invoke an action and return the consequence generated by this invocation. This method also return all filters that were executed together with the action inside the filters list parameter.

Parameters:
ac - The ActionConfig which contains the consequences for this action.
action - The action to invoke.
innerAction - The inner action to execute or null to execute the regular action (execute() method).
filters - The filters that were applied to the action. (You should pass an empty list here!)
Returns:
A consequence generated by this invocation.
Throws:
ActionException - if there was an exception executing the action.
FilterException - if there was an exception executing a filter for the action.
java.lang.Exception

setAppManager

public static void setAppManager(ApplicationManager applicationManager)


Copyright © 2005 Mentawai Team. All Rights Reserved.