View Javadoc

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