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