Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ActionResultWrapperImpl |
|
| 0.0;0 | ||||
ActionResultWrapperImpl$ActionResultInvocationImpl |
|
| 0.0;0 |
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 | * @since 1.1.0 | |
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 | 2 | super(); |
55 | 2 | this.actionResult = actionResult; |
56 | 2 | this.actionContext = actionContext; |
57 | 2 | } |
58 | ||
59 | /** | |
60 | * {@inheritDoc} | |
61 | */ | |
62 | public void execute(final HttpServletRequest request, | |
63 | final HttpServletResponse response) throws Exception { | |
64 | 2 | final ActionResultInvocation actionResultInvocation = new ActionResultInvocationImpl( |
65 | request, response, actionContext, actionResult); | |
66 | 2 | actionResultInvocation.proceed(); |
67 | 2 | } |
68 | ||
69 | /** | |
70 | * {@inheritDoc} | |
71 | */ | |
72 | public ActionResult getActionResult() { | |
73 | 1 | return actionResult; |
74 | } | |
75 | ||
76 | /** | |
77 | * アクションの実行結果の実行情報の実装です。 | |
78 | * | |
79 | * @author baba | |
80 | */ | |
81 | 3 | 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 | * @param plugins | |
110 | * プラグインのコレクション | |
111 | */ | |
112 | public ActionResultInvocationImpl(final HttpServletRequest request, | |
113 | final HttpServletResponse response, | |
114 | final ActionContext actionContext, | |
115 | 2 | final ActionResult actionResult) { |
116 | 2 | this.request = request; |
117 | 2 | this.response = response; |
118 | 2 | this.actionContext = actionContext; |
119 | 2 | this.actionResult = actionResult; |
120 | ||
121 | 2 | final PluginRegistry pluginRegistry = PluginRegistry.getInstance(); |
122 | 2 | this.pluginsIterator = pluginRegistry.getPlugins().iterator(); |
123 | 2 | } |
124 | ||
125 | /** | |
126 | * {@inheritDoc} | |
127 | */ | |
128 | public Void proceed() throws Exception { | |
129 | 3 | if (pluginsIterator.hasNext()) { |
130 | 1 | final Plugin plugin = pluginsIterator.next(); |
131 | 1 | plugin.invokeActionResult(this); |
132 | 1 | } else { |
133 | 2 | final ActionResult actionResult = getActionResult(); |
134 | 2 | actionResult.execute(actionContext, request, response); |
135 | } | |
136 | 3 | return null; |
137 | } | |
138 | ||
139 | /** | |
140 | * {@inheritDoc} | |
141 | */ | |
142 | public HttpServletRequest getRequest() { | |
143 | 0 | return request; |
144 | } | |
145 | ||
146 | /** | |
147 | * {@inheritDoc} | |
148 | */ | |
149 | public HttpServletResponse getResponse() { | |
150 | 0 | return response; |
151 | } | |
152 | ||
153 | /** | |
154 | * {@inheritDoc} | |
155 | */ | |
156 | public ActionContext getActionContext() { | |
157 | 0 | return actionContext; |
158 | } | |
159 | ||
160 | /** | |
161 | * {@inheritDoc} | |
162 | */ | |
163 | public ActionResult getActionResult() { | |
164 | 2 | return actionResult; |
165 | } | |
166 | } | |
167 | ||
168 | } |