1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
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 public ActionResultInvocationImpl(final HttpServletRequest request,
111 final HttpServletResponse response,
112 final ActionContext actionContext,
113 final ActionResult actionResult) {
114 this.request = request;
115 this.response = response;
116 this.actionContext = actionContext;
117 this.actionResult = actionResult;
118
119 final PluginRegistry pluginRegistry = PluginRegistry.getInstance();
120 this.pluginsIterator = pluginRegistry.getPlugins().iterator();
121 }
122
123
124
125
126 public Void proceed() throws Exception {
127 if (pluginsIterator.hasNext()) {
128 final Plugin plugin = pluginsIterator.next();
129 plugin.invokeActionResult(this);
130 } else {
131 final ActionResult actionResult = getActionResult();
132 actionResult.execute(actionContext, request, response);
133 }
134 return null;
135 }
136
137
138
139
140 public HttpServletRequest getRequest() {
141 return request;
142 }
143
144
145
146
147 public HttpServletResponse getResponse() {
148 return response;
149 }
150
151
152
153
154 public ActionContext getActionContext() {
155 return actionContext;
156 }
157
158
159
160
161 public ActionResult getActionResult() {
162 return actionResult;
163 }
164 }
165
166 }