1 16 17 package org.apache.struts.chain.legacy; 18 19 import javax.servlet.http.HttpServletRequest ; 20 import javax.servlet.http.HttpServletResponse ; 21 22 import org.apache.commons.chain.Catalog; 23 import org.apache.commons.chain.CatalogFactory; 24 import org.apache.commons.chain.Command; 25 import org.apache.commons.chain.Context; 26 import org.apache.commons.chain.web.servlet.ServletWebContext; 27 28 import org.apache.struts.action.Action; 29 import org.apache.struts.action.ActionForm; 30 import org.apache.struts.action.ActionForward; 31 import org.apache.struts.action.ActionMapping; 32 33 71 72 public class DispatchAction extends Action { 73 74 75 77 78 82 private Catalog catalog = null; 83 84 85 87 88 96 public ActionForward execute(ActionMapping mapping, 97 ActionForm form, 98 HttpServletRequest request, 99 HttpServletResponse response) 100 throws Exception { 101 102 Context context = new ServletWebContext 104 (getServlet().getServletContext(), request, response); 105 context.put("mapping", mapping); 106 context.put("form", form); 107 108 String name = mapping.getParameter(); 110 Command command = getCatalog().getCommand(request.getParameter(name)); 111 command.execute(context); 113 Exception exception = null; 115 try { 116 exception = (Exception ) context.get("exception"); 117 if (exception != null) { 118 throw exception; 119 } 120 } catch (ClassCastException e) { 121 ; } 123 ActionForward forward = null; 124 try { 125 forward = (ActionForward) context.get("forward"); 126 } catch (ClassCastException e) { 127 forward = null; } 129 return forward; 130 131 } 132 133 134 136 137 142 protected Catalog getCatalog() { 143 144 if (catalog == null) { 145 catalog = CatalogFactory.getInstance().getCatalog(); 146 } 147 return catalog; 148 149 } 150 151 152 } 153 | Popular Tags |