1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.struts2.s1;
19
20 import org.apache.struts.action.ActionMapping;
21 import org.apache.struts.action.ActionForward;
22 import org.apache.struts.config.ModuleConfig;
23 import org.apache.struts.config.ExceptionConfig;
24 import org.apache.struts.config.ForwardConfig;
25 import com.opensymphony.xwork2.config.entities.ActionConfig;
26 import com.opensymphony.xwork2.config.entities.ResultConfig;
27 import com.opensymphony.xwork2.config.entities.ExceptionMappingConfig;
28
29 import java.util.Iterator;
30 import java.util.Map;
31 import java.util.List;
32 import java.util.HashMap;
33
34 /***
35 * Wrapper for a Struts 1.x ActionMapping based on an XWork ActionConfig. Using a wrapper object
36 * allows us to be explicit about what is and isn't implemented.
37 */
38 class WrapperActionMapping extends ActionMapping {
39
40 private ActionConfig delegate;
41 private String actionPath;
42 private String attribute;
43 private Struts1Factory strutsFactory;
44
45 public WrapperActionMapping(Struts1Factory factory, ActionConfig delegate) {
46 this.delegate = delegate;
47 this.strutsFactory = factory;
48 forwards = null;
49 exceptions = null;
50 }
51
52 public WrapperActionMapping(Struts1Factory factory, ActionConfig delegate, String actionPath, ModuleConfig moduleConfig) {
53 this(factory, delegate);
54 this.moduleConfig = moduleConfig;
55 this.actionPath = actionPath;
56 }
57
58 /***
59 * Add Struts ForwardConfigs (from XWork ResultConfigs).
60 */
61 private void initActionForwards() {
62 if (forwards == null) {
63 forwards = new HashMap();
64 Map results = delegate.getResults();
65 for (Iterator i = results.entrySet().iterator(); i.hasNext();) {
66 Map.Entry entry = (Map.Entry) i.next();
67 ActionForward wrapper = strutsFactory.createActionForward((ResultConfig) entry.getValue());
68 forwards.put(wrapper.getName(), wrapper);
69 }
70 }
71 }
72
73 /***
74 * Add XWork ExceptionConfigs (from XWork ExceptionMappingConfigs)
75 */
76 private void initExceptionConfigs() {
77 if (exceptions == null) {
78 exceptions = new HashMap();
79 List exceptionMappings = delegate.getExceptionMappings();
80 for (Iterator i = exceptionMappings.iterator(); i.hasNext();) {
81 ExceptionConfig wrapper = strutsFactory.createExceptionConfig((ExceptionMappingConfig) i.next());
82 exceptions.put(wrapper.getType(), wrapper);
83 }
84 }
85 }
86
87 public ActionForward findForward(String name) {
88 initActionForwards();
89 return super.findForward(name);
90 }
91
92 public String[] findForwards() {
93 initActionForwards();
94 return super.findForwards();
95 }
96
97 public ForwardConfig findForwardConfig(String name) {
98 initActionForwards();
99 return super.findForwardConfig(name);
100 }
101
102 public ForwardConfig[] findForwardConfigs() {
103 initActionForwards();
104 return super.findForwardConfigs();
105 }
106
107 public ExceptionConfig findExceptionConfig(String type) {
108 initExceptionConfigs();
109 return super.findExceptionConfig(type);
110 }
111
112 public ExceptionConfig[] findExceptionConfigs() {
113 initExceptionConfigs();
114 return super.findExceptionConfigs();
115 }
116
117 public ExceptionConfig findException(Class type) {
118 initExceptionConfigs();
119 return super.findException(type);
120 }
121
122 public ActionForward getInputForward() {
123 throw new UnsupportedOperationException("NYI");
124 }
125
126 public ModuleConfig getModuleConfig() {
127 if (moduleConfig == null) {
128 moduleConfig = strutsFactory.createModuleConfig(delegate.getPackageName());
129 }
130
131 return moduleConfig;
132 }
133
134 public void setModuleConfig(ModuleConfig moduleConfig) {
135 throw new UnsupportedOperationException("Not implemented - immutable");
136 }
137
138 public String getAttribute() {
139 return attribute;
140 }
141
142 public void setAttribute(String attribute) {
143 this.attribute = attribute;
144 }
145
146 public String getForward() {
147 throw new UnsupportedOperationException("NYI");
148 }
149
150 public void setForward(String forward) {
151 throw new UnsupportedOperationException("Not implemented - immutable");
152 }
153
154 public String getInclude() {
155 throw new UnsupportedOperationException("NYI");
156 }
157
158 public void setInclude(String include) {
159 throw new UnsupportedOperationException("Not implemented - immutable");
160 }
161
162 public String getInput() {
163 throw new UnsupportedOperationException("NYI");
164 }
165
166 public void setInput(String input) {
167 throw new UnsupportedOperationException("Not implemented - immutable");
168 }
169
170 public String getMultipartClass() {
171 throw new UnsupportedOperationException("NYI");
172 }
173
174 public void setMultipartClass(String multipartClass) {
175 throw new UnsupportedOperationException("Not implemented - immutable");
176 }
177
178 public String getName() {
179
180 throw new UnsupportedOperationException("NYI");
181 }
182
183 public void setName(String name) {
184 throw new UnsupportedOperationException("Not implemented - immutable");
185 }
186
187 public String getParameter() {
188 throw new UnsupportedOperationException("NYI");
189 }
190
191 public void setParameter(String parameter) {
192 throw new UnsupportedOperationException("Not implemented - immutable");
193 }
194
195 public String getPath() {
196 return actionPath;
197 }
198
199 public void setPath(String path) {
200 throw new UnsupportedOperationException("Not implemented - immutable");
201 }
202
203 public String getPrefix() {
204 throw new UnsupportedOperationException("NYI");
205 }
206
207 public void setPrefix(String prefix) {
208 throw new UnsupportedOperationException("Not implemented - immutable");
209 }
210
211 public String getRoles() {
212 throw new UnsupportedOperationException("NYI");
213 }
214
215 public void setRoles(String roles) {
216 throw new UnsupportedOperationException("Not implemented - immutable");
217 }
218
219 public String[] getRoleNames() {
220 throw new UnsupportedOperationException("NYI");
221 }
222
223 public String getScope() {
224 throw new UnsupportedOperationException("Not implemented - immutable");
225 }
226
227 public void setScope(String scope) {
228 throw new UnsupportedOperationException("NYI");
229 }
230
231 public String getSuffix() {
232 throw new UnsupportedOperationException("NYI");
233 }
234
235 public void setSuffix(String suffix) {
236 throw new UnsupportedOperationException("Not implemented - immutable");
237 }
238
239 public String getType() {
240 throw new UnsupportedOperationException("NYI");
241 }
242
243 public void setType(String type) {
244 throw new UnsupportedOperationException("Not implemented - immutable");
245 }
246
247 public boolean getUnknown() {
248 throw new UnsupportedOperationException("NYI");
249 }
250
251 public void setUnknown(boolean unknown) {
252 throw new UnsupportedOperationException("Not implemented - immutable");
253 }
254
255 public boolean getValidate() {
256 throw new UnsupportedOperationException("NYI");
257 }
258
259 public void setValidate(boolean validate) {
260 throw new UnsupportedOperationException("Not implemented - immutable");
261 }
262
263 public void removeExceptionConfig(ExceptionConfig config) {
264 throw new UnsupportedOperationException("Not implemented - immutable");
265 }
266
267 public void removeForwardConfig(ForwardConfig config) {
268 throw new UnsupportedOperationException("Not implemented - immutable");
269 }
270
271 public void addExceptionConfig(ExceptionConfig config) {
272 throw new UnsupportedOperationException("Not implemented - immutable");
273 }
274
275 public void addForwardConfig(ForwardConfig config) {
276 throw new UnsupportedOperationException("Not implemented - immutable");
277 }
278
279 public String toString() {
280 return "wrapper -> " + delegate.toString();
281 }
282 }