1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
32
33
34
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
48
49
50
51
52 public ActionResultWrapperImpl(final ActionResult actionResult,
53 final ActionContext actionContext) {
54 super();
55 this.actionResult = actionResult;
56 this.actionContext = actionContext;
57 }
58
59
60
61
62 public void execute(final HttpServletRequest request,
63 final HttpServletResponse response) throws Exception {
64 final ActionResultInvocation actionResultInvocation = new ActionResultInvocationImpl(
65 request, response, actionContext, actionResult);
66 actionResultInvocation.proceed();
67 }
68
69
70
71
72 public ActionResult getActionResult() {
73 return actionResult;
74 }
75
76
77
78
79
80
81 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
102
103
104
105
106
107
108
109
110
111
112 public ActionResultInvocationImpl(final HttpServletRequest request,
113 final HttpServletResponse response,
114 final ActionContext actionContext,
115 final ActionResult actionResult) {
116 this.request = request;
117 this.response = response;
118 this.actionContext = actionContext;
119 this.actionResult = actionResult;
120
121 final PluginRegistry pluginRegistry = PluginRegistry.getInstance();
122 this.pluginsIterator = pluginRegistry.getPlugins().iterator();
123 }
124
125
126
127
128 public Void proceed() throws Exception {
129 if (pluginsIterator.hasNext()) {
130 final Plugin plugin = pluginsIterator.next();
131 plugin.invokeActionResult(this);
132 } else {
133 final ActionResult actionResult = getActionResult();
134 actionResult.execute(actionContext, request, response);
135 }
136 return null;
137 }
138
139
140
141
142 public HttpServletRequest getRequest() {
143 return request;
144 }
145
146
147
148
149 public HttpServletResponse getResponse() {
150 return response;
151 }
152
153
154
155
156 public ActionContext getActionContext() {
157 return actionContext;
158 }
159
160
161
162
163 public ActionResult getActionResult() {
164 return actionResult;
165 }
166 }
167
168 }