View Javadoc

1   package org.seasar.cubby.controller.impl;
2   
3   import javax.servlet.FilterChain;
4   import javax.servlet.http.HttpServletRequest;
5   import javax.servlet.http.HttpServletResponse;
6   
7   import org.seasar.cubby.action.ActionResult;
8   import org.seasar.cubby.controller.ActionContext;
9   import org.seasar.cubby.controller.ActionDef;
10  import org.seasar.cubby.controller.ActionProcessor;
11  import org.seasar.cubby.convention.CubbyConvention;
12  import org.seasar.cubby.exception.ActionRuntimeException;
13  import org.seasar.cubby.util.CubbyUtils;
14  import org.seasar.framework.log.Logger;
15  
16  public class ActionProcessorImpl implements ActionProcessor {
17  
18  	private final Logger logger = Logger.getLogger(this.getClass());
19  
20  	private ActionContext context;
21  
22  	private CubbyConvention cubbyConvention;
23  
24  	public void setActionContext(final ActionContext context) {
25  		this.context = context;
26  	}
27  
28  	public void setCubbyConvention(final CubbyConvention cubbyConvention) {
29  		this.cubbyConvention = cubbyConvention;
30  	}
31  
32  	public void process(final HttpServletRequest request,
33  			final HttpServletResponse response, final FilterChain chain)
34  			throws Throwable {
35  		final String path = CubbyUtils.getPath(request);
36  
37  		final ActionDef actionDef = cubbyConvention.fromPathToActionDef(
38  				request, path);
39  		if (actionDef != null) {
40  			context.initialize(actionDef);
41  			if (logger.isDebugEnabled()) {
42  				logger.log("DCUB0004", new Object[] { path });
43  				logger.log("DCUB0005", new Object[] { context.getMethod() });
44  			}
45  			final ActionResult result = context.invoke();
46  			if (result == null) {
47  				throw new ActionRuntimeException("ECUB0001",
48  						new Object[] { context.getMethod() });
49  			}
50  			result.execute(context, request, response);
51  		} else {
52  			chain.doFilter(request, response);
53  		}
54  	}
55  
56  }