saoj
Joined: 22/12/2007 07:20:02
Messages: 22
Offline
|
Mentawai has a very simple architecture following the KISS principle. The framework is all based on interfaces so it is extremely flexible. The basic concept is the notion of an Action that executes some task. An action has an Input and an Output. All the information from the web request is contained in the action input. The results produced by an action are placed in the action output so that it can be displayed in the view layer (JSP page, velocity, etc.). An action also has access to Contexts such as Session, Application and Cookies. After the execution, an action should return a Result. For each result you can configure a Consequence such as Forward, Redirect and Chain.
The core interfaces of the Mentawai framework are listed below with a brief explanation:
(Click in the interface to see its javadoc)
org.mentawai.core.Action: It just has setters and getters for the Input, Output, Session, Application, Cookies and Locale. It also defines some standard Results like SUCCESS, ERROR, INDEX, etc. The default implementation is BaseAction.
org.mentawai.core.Input: It provides methods to get values from the input as Object, int, float, double, boolean, etc. It performs the necessary conversions and also have versions that return a default value. It also has methods to return properties of a request (through reflection) and headers of a request. You can also use the method keys() to list all keys in the action input. The default implementation is RequestInput. Below are some examples:
org.mentawai.core.Output: It behaves pretty much like a Map<String, Object> where you can place values by a String key. You can also check if it is empty with the isEmpty() method and get all the keys with the keys() method. The default implementation is ResponseOutput. Below are some examples:
org.mentawai.core.Context: It behaves pretty much like a web application context where you can set attributes by name. A context also supports the reset() method (optional) and the keys() method. Some of its implementations are the SessionContext, ApplicationContext and CookieContext. Below are some examples:
org.mentawai.core.Consequence: A consequence is executed after the action has executed and returned a result. A consequence is an interface that has only the execute() method that receives the action, the HttpServletRequest and the HttpServletResponse. The main consequences implemented by the framework are: Forward (forwards to a JSP page), Redirect (redirects to a JSP), Chain (chains the action with another action) and StreamConsequence (returns a byte stream through the HttpServletResponse). You can implement your own consequences as well.
org.mentawai.core.Filter: A filter is the main building block of the framework. We will talk more about filters in the next chapter, but for now you should know that it is an interface with two methods: destroy() for cleanup and filter() that receives an InvocationChain as a parameter and returns a result. The signature of the filter() method is:
org.mentawai.core.AfterConsequenceFilter: This interface inherits from the Filter interface to add an extra method that is executed after the Consequence of the action is executed. The method signature is:
The big picture is more or less like this:
You don't need to fully understand the Mentawai architecture to start building web applications with it. However it does not hurt to have a good foundation and to really understand how things are working under the hood.
|