Enterprise Java
Writing a Reusable Implementation of the MVC Design Pattern
by Prashant Sarode
Listing 1.

package com.framework;

import java.lang.reflect.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.framework.*;

public class RequestProcessor implements Serializable {

public RequestProcessor(){

RequestToEventTranslator eventTranslator
=new RequestToEventTranslator();

public void processRequest(HttpServletRequest request,
                             HttpServletResponse response,
                             ServletConfig servletConfig)
                       throws IOException,

//Step 1-Create a Business Event (abstract intent) from HTTP request.
Event businessEvent =eventTranslator.processRequest

//Step 2-Get the "functionality" Class name that is supposed to handle this event.
String functionalityClassName = businessEvent.getFunctionalityClass();

//Step 3-Get Reference to functionality from the servlet Context (i.e. application scope). If null then create
Instance and store the reference in servlet Context with class Name as the Key.
ClassName) == null){

//Create Instance Of the Functionality bean.
functionality = new Functionality(functionalityClassName);

ClassName,(Object) functionality);


functionality =(Functionality)

//Step 4-Call handleEvent(Event e) on appropriate functionality.
Result resultOfHandleEvent=functionality.handleEvent

//Step 5-Forward to appropriate View based on Event Success Or Failure.
if ( resultOfHandleEvent.wasSuccess() ){

//Get the Response View from event.
String responseView = businessEvent.getResponseView();

//Set the Result Object in Request Scope.

//Finally go to the Response view.
goToView(responseView, servletConfig , request , response);


//Get the Error View from event.
String errorView = businessEvent.getErrorView();

//Set the Result Object in Request Scope.

//Finally go to Error view.
goToView(errorView, servletConfig , request , response);