Coverage Report - org.seasar.cubby.internal.controller.impl.ActionResultWrapperImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
ActionResultWrapperImpl
100%
8/8
N/A
1.111
ActionResultWrapperImpl$ActionResultInvocationImpl
85%
17/20
100%
2/2
1.111
 
 1  
 /*
 2  
  * Copyright 2004-2010 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  
 
 17  
 package org.seasar.cubby.internal.controller.impl;
 18  
 
 19  
 import java.util.Iterator;
 20  
 
 21  
 import javax.servlet.http.HttpServletRequest;
 22  
 import javax.servlet.http.HttpServletResponse;
 23  
 
 24  
 import org.seasar.cubby.action.ActionContext;
 25  
 import org.seasar.cubby.action.ActionResult;
 26  
 import org.seasar.cubby.internal.controller.ActionResultWrapper;
 27  
 import org.seasar.cubby.plugin.ActionResultInvocation;
 28  
 import org.seasar.cubby.plugin.Plugin;
 29  
 import org.seasar.cubby.plugin.PluginRegistry;
 30  
 
 31  
 /**
 32  
  * {@link org.seasar.cubby.action.ActionResult} のラッパの実装です。
 33  
  * 
 34  
  * @author baba
 35  
  */
 36  
 class ActionResultWrapperImpl implements ActionResultWrapper {
 37  
 
 38  
         /** アクションの実行結果。 */
 39  
         private final ActionResult actionResult;
 40  
 
 41  
         /** アクションコンテキスト。 */
 42  
         private final ActionContext actionContext;
 43  
 
 44  
         /**
 45  
          * 指定されたアクションの実行結果をラップしたインスタンスを生成します。
 46  
          * 
 47  
          * @param actionResult
 48  
          *            アクションの実行結果
 49  
          * @param actionContext
 50  
          *            アクションコンテキスト
 51  
          */
 52  
         public ActionResultWrapperImpl(final ActionResult actionResult,
 53  
                         final ActionContext actionContext) {
 54  3
                 super();
 55  3
                 this.actionResult = actionResult;
 56  3
                 this.actionContext = actionContext;
 57  3
         }
 58  
 
 59  
         /**
 60  
          * {@inheritDoc}
 61  
          */
 62  
         public void execute(final HttpServletRequest request,
 63  
                         final HttpServletResponse response) throws Exception {
 64  3
                 final ActionResultInvocation actionResultInvocation = new ActionResultInvocationImpl(
 65  
                                 request, response, actionContext, actionResult);
 66  3
                 actionResultInvocation.proceed();
 67  3
         }
 68  
 
 69  
         /**
 70  
          * {@inheritDoc}
 71  
          */
 72  
         public ActionResult getActionResult() {
 73  1
                 return actionResult;
 74  
         }
 75  
 
 76  
         /**
 77  
          * アクションの実行結果の実行情報の実装です。
 78  
          * 
 79  
          * @author baba
 80  
          */
 81  6
         static class ActionResultInvocationImpl implements ActionResultInvocation {
 82  
 
 83  
                 /** 要求。 */
 84  
                 private final HttpServletRequest request;
 85  
 
 86  
                 /** 応答。 */
 87  
                 private final HttpServletResponse response;
 88  
 
 89  
                 /** アクションのコンテキスト。 */
 90  
                 private final ActionContext actionContext;
 91  
 
 92  
                 /** アクションの実行結果。 */
 93  
                 private final ActionResult actionResult;
 94  
 
 95  
                 /** プラグインのイテレータ。 */
 96  
                 private final Iterator<Plugin> pluginsIterator;
 97  
 
 98  
                 /**
 99  
                  * インスタンス化します。
 100  
                  * 
 101  
                  * @param request
 102  
                  *            要求
 103  
                  * @param response
 104  
                  *            応答
 105  
                  * @param actionContext
 106  
                  *            アクションのコンテキスト
 107  
                  * @param actionResult
 108  
                  *            アクションの実行結果
 109  
                  */
 110  
                 public ActionResultInvocationImpl(final HttpServletRequest request,
 111  
                                 final HttpServletResponse response,
 112  
                                 final ActionContext actionContext,
 113  3
                                 final ActionResult actionResult) {
 114  3
                         this.request = request;
 115  3
                         this.response = response;
 116  3
                         this.actionContext = actionContext;
 117  3
                         this.actionResult = actionResult;
 118  
 
 119  3
                         final PluginRegistry pluginRegistry = PluginRegistry.getInstance();
 120  3
                         this.pluginsIterator = pluginRegistry.getPlugins().iterator();
 121  3
                 }
 122  
 
 123  
                 /**
 124  
                  * {@inheritDoc}
 125  
                  */
 126  
                 public Void proceed() throws Exception {
 127  6
                         if (pluginsIterator.hasNext()) {
 128  3
                                 final Plugin plugin = pluginsIterator.next();
 129  3
                                 plugin.invokeActionResult(this);
 130  3
                         } else {
 131  3
                                 final ActionResult actionResult = getActionResult();
 132  3
                                 actionResult.execute(actionContext, request, response);
 133  
                         }
 134  6
                         return null;
 135  
                 }
 136  
 
 137  
                 /**
 138  
                  * {@inheritDoc}
 139  
                  */
 140  
                 public HttpServletRequest getRequest() {
 141  0
                         return request;
 142  
                 }
 143  
 
 144  
                 /**
 145  
                  * {@inheritDoc}
 146  
                  */
 147  
                 public HttpServletResponse getResponse() {
 148  0
                         return response;
 149  
                 }
 150  
 
 151  
                 /**
 152  
                  * {@inheritDoc}
 153  
                  */
 154  
                 public ActionContext getActionContext() {
 155  0
                         return actionContext;
 156  
                 }
 157  
 
 158  
                 /**
 159  
                  * {@inheritDoc}
 160  
                  */
 161  
                 public ActionResult getActionResult() {
 162  3
                         return actionResult;
 163  
                 }
 164  
         }
 165  
 
 166  
 }