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.ActionDefBuilder;
 26  
 import org.seasar.cubby.controller.ActionProcessor;
 27  
 import org.seasar.cubby.exception.ActionRuntimeException;
 28  
 import org.seasar.cubby.filter.CubbyHttpServletRequestWrapper;
 29  
 import org.seasar.framework.log.Logger;
 30  
 
 31  
 /**
 32  
  * リクエストのパスを元にアクションメソッドを決定して実行するクラスの実装です。
 33  
  * 
 34  
  * @author baba
 35  
  * @since 1.0.0
 36  
  */
 37  3
 public class ActionProcessorImpl implements ActionProcessor {
 38  
 
 39  
         /** ロガー。 */
 40  1
         private static final Logger logger = Logger
 41  
                         .getLogger(ActionProcessorImpl.class);
 42  
 
 43  
         /** アクションのコンテキスト。 */
 44  
         private ActionContext context;
 45  
 
 46  
         /** アクションの定義を組み立てるビルダ。 */
 47  
         private ActionDefBuilder actionDefBuilder;
 48  
 
 49  
         /**
 50  
          * アクションのコンテキストを設定します。
 51  
          * 
 52  
          * @param context
 53  
          *            アクションのコンテキスト
 54  
          */
 55  
         public void setActionContext(final ActionContext context) {
 56  1
                 this.context = context;
 57  1
         }
 58  
 
 59  
         /**
 60  
          * アクションの定義を組み立てるビルダを設定します。
 61  
          * 
 62  
          * @param actionDefBuilder
 63  
          *            アクションの定義を組み立てるビルダ
 64  
          */
 65  
         public void setActionDefBuilder(final ActionDefBuilder actionDefBuilder) {
 66  1
                 this.actionDefBuilder = actionDefBuilder;
 67  1
         }
 68  
 
 69  
         /**
 70  
          * {@inheritDoc}
 71  
          */
 72  
         public ActionResult process(final HttpServletRequest request,
 73  
                         final HttpServletResponse response, final FilterChain chain)
 74  
                         throws Exception {
 75  0
                 final ActionDef actionDef = actionDefBuilder.build(request);
 76  0
                 if (actionDef != null) {
 77  0
                         context.initialize(actionDef);
 78  0
                         if (logger.isDebugEnabled()) {
 79  0
                                 logger
 80  
                                                 .log("DCUB0004",
 81  
                                                                 new Object[] { request.getRequestURI() });
 82  0
                                 logger.log("DCUB0005", new Object[] { context.getMethod() });
 83  
                         }
 84  0
                         final ActionResult result = context.invoke();
 85  0
                         if (result == null) {
 86  0
                                 throw new ActionRuntimeException("ECUB0101",
 87  
                                                 new Object[] { context.getMethod() });
 88  
                         }
 89  0
                         final HttpServletRequest wrappedRequest = new CubbyHttpServletRequestWrapper(
 90  
                                         request, context);
 91  0
                         result.execute(context, wrappedRequest, response);
 92  0
                         return result;
 93  
                 } else {
 94  0
                         final HttpServletRequest wrappedRequest = new CubbyHttpServletRequestWrapper(
 95  
                                         request, context);
 96  0
                         chain.doFilter(wrappedRequest, response);
 97  0
                         return null;
 98  
                 }
 99  
         }
 100  
 
 101  
 }