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