Coverage Report - org.seasar.cubby.controller.impl.ActionProcessorImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
ActionProcessorImpl
29%
6/21
0%
0/6
2.667
 
 1  
 /*
 2  
  * Copyright 2004-2008 the Seasar Foundation and the Others.
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *     http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 13  
  * either express or implied. See the License for the specific language
 14  
  * governing permissions and limitations under the License.
 15  
  */
 16  
 package org.seasar.cubby.controller.impl;
 17  
 
 18  
 import javax.servlet.FilterChain;
 19  
 import javax.servlet.http.HttpServletRequest;
 20  
 import javax.servlet.http.HttpServletResponse;
 21  
 
 22  
 import org.seasar.cubby.action.ActionResult;
 23  
 import org.seasar.cubby.controller.ActionContext;
 24  
 import org.seasar.cubby.controller.ActionDef;
 25  
 import org.seasar.cubby.controller.ActionProcessor;
 26  
 import org.seasar.cubby.convention.CubbyConvention;
 27  
 import org.seasar.cubby.exception.ActionRuntimeException;
 28  
 import org.seasar.cubby.filter.CubbyHttpServletRequestWrapper;
 29  
 import org.seasar.framework.log.Logger;
 30  
 
 31  3
 public class ActionProcessorImpl implements ActionProcessor {
 32  
 
 33  1
         private static final Logger logger = Logger
 34  
                         .getLogger(ActionProcessorImpl.class);
 35  
 
 36  
         private ActionContext context;
 37  
 
 38  
         private CubbyConvention cubbyConvention;
 39  
 
 40  
         public void setActionContext(final ActionContext context) {
 41  1
                 this.context = context;
 42  1
         }
 43  
 
 44  
         public void setCubbyConvention(final CubbyConvention cubbyConvention) {
 45  1
                 this.cubbyConvention = cubbyConvention;
 46  1
         }
 47  
 
 48  
         public ActionResult process(final HttpServletRequest request,
 49  
                         final HttpServletResponse response, final FilterChain chain)
 50  
                         throws Exception {
 51  0
                 final ActionDef actionDef = cubbyConvention
 52  
                                 .fromPathToActionDef(request);
 53  0
                 if (actionDef != null) {
 54  0
                         context.initialize(actionDef);
 55  0
                         if (logger.isDebugEnabled()) {
 56  0
                                 logger
 57  
                                                 .log("DCUB0004",
 58  
                                                                 new Object[] { request.getRequestURI() });
 59  0
                                 logger.log("DCUB0005", new Object[] { context.getMethod() });
 60  
                         }
 61  0
                         final ActionResult result = context.invoke();
 62  0
                         if (result == null) {
 63  0
                                 throw new ActionRuntimeException("ECUB0001",
 64  
                                                 new Object[] { context.getMethod() });
 65  
                         }
 66  0
                         final HttpServletRequest wrappedRequest = new CubbyHttpServletRequestWrapper(
 67  
                                         request, context);
 68  0
                         result.execute(context, wrappedRequest, response);
 69  0
                         return result;
 70  
                 } else {
 71  0
                         final HttpServletRequest wrappedRequest = new CubbyHttpServletRequestWrapper(
 72  
                                         request, context);
 73  0
                         chain.doFilter(wrappedRequest, response);
 74  0
                         return null;
 75  
                 }
 76  
         }
 77  
 
 78  
 }