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 72 73 public class ChainAction extends Action { 74 75 76 78 79 83 private Catalog catalog = null; 84 85 86 88 89 97 public ActionForward execute(ActionMapping mapping, 98 ActionForm form, 99 HttpServletRequest request, 100 HttpServletResponse response) 101 throws Exception { 102 103 Context context = new ServletWebContext 105 (getServlet().getServletContext(), request, response); 106 context.put("mapping", mapping); 107 context.put("form", form); 108 109 Command command = getCatalog().getCommand(mapping.getParameter()); 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 |