001: /*
002: * Copyright (c) 2002-2006 by OpenSymphony
003: * All rights reserved.
004: */
005: package com.opensymphony.xwork.config.entities;
006:
007: import com.opensymphony.xwork.util.location.Located;
008: import java.io.Serializable;
009: import java.util.*;
010:
011: /**
012: * Contains everything needed to configure and execute an action:
013: * <ul>
014: * <li>methodName - the method name to execute on the action. If this is null, the Action will be cast to the Action
015: * Interface and the execute() method called</li>
016: * <li>clazz - the class name for the action</li>
017: * <li>params - the params to be set for this action just before execution</li>
018: * <li>results - the result map {String -> View class}</li>
019: * <li>resultParameters - params for results {String -> Map}</li>
020: * <li>typeConverter - the Ognl TypeConverter to use when getting/setting properties</li>
021: * </ul>
022: *
023: * @author Mike
024: * @author Rainer Hermanns
025: * @version $Revision: 1531 $
026: */
027: public class ActionConfig extends Located implements
028: InterceptorListHolder, Parameterizable, Serializable {
029:
030: private static final long serialVersionUID = -6785758611462211920L;
031:
032: protected List externalRefs;
033: protected List interceptors; // a list of interceptorMapping Objects eg. List<InterceptorMapping>
034: protected Map params;
035: protected Map results;
036: protected List exceptionMappings;
037: protected String className;
038: protected String methodName;
039: protected String packageName;
040:
041: public ActionConfig() {
042: params = new LinkedHashMap();
043: results = new LinkedHashMap();
044: interceptors = new ArrayList();
045: externalRefs = new ArrayList();
046: exceptionMappings = new ArrayList();
047: }
048:
049: //Helper constuctor to maintain backward compatibility with objects that create ActionConfigs
050: //TODO this should be removed if these changes are rolled in to xwork CVS
051: public ActionConfig(String methodName, Class clazz, Map parameters,
052: Map results, List interceptors) {
053: this (methodName, clazz.getName(), parameters, results,
054: interceptors);
055: }
056:
057: public ActionConfig(String methodName, Class clazz, Map parameters,
058: Map results, List interceptors, List exceptionMappings) {
059: this (methodName, clazz.getName(), parameters, results,
060: interceptors, exceptionMappings);
061: }
062:
063: public ActionConfig(String methodName, String className,
064: Map parameters, Map results, List interceptors) {
065: this (methodName, className, parameters, results, interceptors,
066: Collections.EMPTY_LIST, new String());
067: }
068:
069: public ActionConfig(String methodName, String className,
070: Map parameters, Map results, List interceptors,
071: List exceptionMappings) {
072: this (methodName, className, parameters, results, interceptors,
073: Collections.EMPTY_LIST, exceptionMappings, new String());
074: }
075:
076: //TODO If this is commited to CVS we should put the package arg at the front of the ctor and fix
077: //code that uses it
078: public ActionConfig(String methodName, String className,
079: Map parameters, Map results, List interceptors,
080: List externalRefs, String packageName) {
081: this (methodName, className, parameters, results, interceptors,
082: externalRefs, Collections.EMPTY_LIST, packageName);
083: }
084:
085: public ActionConfig(String methodName, String className,
086: Map parameters, Map results, List interceptors,
087: List externalRefs, List exceptionMappings,
088: String packageName) {
089: this .methodName = methodName;
090: this .interceptors = interceptors;
091: this .params = parameters;
092: this .results = results;
093: this .className = className;
094: this .externalRefs = externalRefs;
095: this .exceptionMappings = exceptionMappings;
096: this .packageName = packageName;
097: }
098:
099: public void setClassName(String className) {
100: this .className = className;
101: }
102:
103: public String getClassName() {
104: return className;
105: }
106:
107: public List getExternalRefs() {
108: return externalRefs;
109: }
110:
111: public List getExceptionMappings() {
112: return exceptionMappings;
113: }
114:
115: public List getInterceptors() {
116: if (interceptors == null) {
117: interceptors = new ArrayList();
118: }
119:
120: return interceptors;
121: }
122:
123: public void setMethodName(String methodName) {
124: this .methodName = methodName;
125: }
126:
127: /**
128: * Returns name of the action method
129: *
130: * @return name of the method to execute
131: */
132: public String getMethodName() {
133: return methodName;
134: }
135:
136: /**
137: * @param packageName The packageName to set.
138: */
139: public void setPackageName(String packageName) {
140: this .packageName = packageName;
141: }
142:
143: /**
144: * @return Returns the packageName.
145: */
146: public String getPackageName() {
147: return packageName;
148: }
149:
150: public void setParams(Map params) {
151: this .params = params;
152: }
153:
154: public Map getParams() {
155: if (params == null) {
156: params = new LinkedHashMap();
157: }
158:
159: return params;
160: }
161:
162: public void setResults(Map results) {
163: this .results = results;
164: }
165:
166: public Map getResults() {
167: if (results == null) {
168: results = new LinkedHashMap();
169: }
170:
171: return results;
172: }
173:
174: public void addExternalRef(ExternalReference reference) {
175: getExternalRefs().add(reference);
176: }
177:
178: public void addExternalRefs(List externalRefs) {
179: getExternalRefs().addAll(externalRefs);
180: }
181:
182: public void addExceptionMapping(
183: ExceptionMappingConfig exceptionMapping) {
184: getExceptionMappings().add(exceptionMapping);
185: }
186:
187: public void addExceptionMappings(List exceptionMappings) {
188: getExceptionMappings().addAll(exceptionMappings);
189: }
190:
191: public void addInterceptor(InterceptorMapping interceptor) {
192: getInterceptors().add(interceptor);
193: }
194:
195: public void addInterceptors(List interceptors) {
196: getInterceptors().addAll(interceptors);
197: }
198:
199: public void addParam(String name, Object value) {
200: getParams().put(name, value);
201: }
202:
203: public void addResultConfig(ResultConfig resultConfig) {
204: getResults().put(resultConfig.getName(), resultConfig);
205: }
206:
207: public boolean equals(Object o) {
208: if (this == o) {
209: return true;
210: }
211:
212: if (!(o instanceof ActionConfig)) {
213: return false;
214: }
215:
216: final ActionConfig actionConfig = (ActionConfig) o;
217:
218: if ((className != null) ? (!className
219: .equals(actionConfig.className))
220: : (actionConfig.className != null)) {
221: return false;
222: }
223:
224: if ((interceptors != null) ? (!interceptors
225: .equals(actionConfig.interceptors))
226: : (actionConfig.interceptors != null)) {
227: return false;
228: }
229:
230: if ((methodName != null) ? (!methodName
231: .equals(actionConfig.methodName))
232: : (actionConfig.methodName != null)) {
233: return false;
234: }
235:
236: if ((params != null) ? (!params.equals(actionConfig.params))
237: : (actionConfig.params != null)) {
238: return false;
239: }
240:
241: if ((results != null) ? (!results.equals(actionConfig.results))
242: : (actionConfig.results != null)) {
243: return false;
244: }
245:
246: return true;
247: }
248:
249: public int hashCode() {
250: int result;
251: result = ((interceptors != null) ? interceptors.hashCode() : 0);
252: result = (29 * result)
253: + ((params != null) ? params.hashCode() : 0);
254: result = (29 * result)
255: + ((results != null) ? results.hashCode() : 0);
256: result = (29 * result)
257: + ((methodName != null) ? methodName.hashCode() : 0);
258:
259: return result;
260: }
261:
262: public String toString() {
263: StringBuffer sb = new StringBuffer();
264: sb.append("{ActionConfig ");
265: sb.append(className);
266: if (methodName != null) {
267: sb.append(".").append(methodName).append("()");
268: }
269: sb.append(" - ").append(location);
270: sb.append("}");
271: return sb.toString();
272: }
273: }
|