View Javadoc
1 2 package inklings.jgatms.action; 3 4 import javax.servlet.http.HttpServletRequest; 5 import javax.servlet.http.HttpServletResponse; 6 7 import org.apache.struts.action.Action; 8 import org.apache.struts.action.ActionForward; 9 import org.apache.struts.action.ActionForm; 10 import org.apache.struts.action.ActionMapping; 11 import org.apache.struts.config.FormBeanConfig; 12 13 /*** 14 * Base Action class. 15 * 16 * This class wraps basic Struts functionality that can be reused 17 * by the subclasses. To create a specific action, subclass this 18 * class and override the <code>executeLogic</code> method. 19 * 20 */ 21 public abstract class BaseAction extends Action 22 { 23 24 /*** 25 * Struts execute API. 26 * 27 * This method is called by Struts to execute the functionality 28 * of the action. 29 * 30 * @param mapping The Struts action mapping for the action. 31 * @param form. The ActionForm associated with the request. 32 * @param request. The <code>HttpServletRequest</code> object 33 * associated with the request. 34 * @param respone. The <code>HttpServletResponse</code> object 35 * that will render the HTTP response. 36 * @throws Exception if an error occurs within the action. 37 * @return An ActionForward indicating the next step in the workflow. 38 */ 39 public ActionForward execute(ActionMapping mapping, 40 ActionForm form, 41 HttpServletRequest request, 42 HttpServletResponse response) 43 throws Exception 44 { 45 if (form == null && mapping.getName() != null) 46 { 47 form = createFormInstance(mapping); 48 if (mapping.getScope().equals("session")) 49 request.getSession().setAttribute(mapping.getName(), form); 50 else 51 request.setAttribute(mapping.getName(), form); 52 } 53 54 return executeLogic(mapping, form, request, response); 55 } 56 57 /*** 58 * Executes the specific logic of the action. 59 * 60 * This abstract method is to be implemented by subclasses of 61 * BaseAction to provide the functionality specific to each 62 * action. 63 * 64 * @param mapping The Struts action mapping for the action. 65 * @param form. The ActionForm associated with the request. 66 * @param request. The <code>HttpServletRequest</code> object 67 * associated with the request. 68 * @param respone. The <code>HttpServletResponse</code> object 69 * that will render the HTTP response. 70 * @throws Exception if an error occurs within the action. 71 * @return An ActionForward indicating the next step in the workflow. 72 */ 73 public abstract ActionForward executeLogic(ActionMapping mapping, 74 ActionForm form, 75 HttpServletRequest request, 76 HttpServletResponse response) 77 throws Exception; 78 79 /*** 80 * Creates and returns the <code>ActionForm</code> instance for this action. 81 * 82 * This method reads the Form Bean configuration passed in and creates the 83 * Form bean instance. It should not be called to return an existing 84 * instance, but only to create a new instance. 85 * 86 * @param mapping. The ActionMapping that names the form bean to create. 87 * @throws Exception if the class cannot be created. 88 */ 89 protected ActionForm createFormInstance(ActionMapping mapping) 90 throws Exception 91 { 92 FormBeanConfig formConfig = 93 mapping.getModuleConfig().findFormBeanConfig(mapping.getName()); 94 95 String formClassName = formConfig.getType(); 96 97 Class formClass = Class.forName(formClassName); 98 Object o = formClass.newInstance(); 99 ActionForm form = (ActionForm) o; 100 return form; 101 } 102 } 103

This page was automatically generated by Maven