001: /*
002: * Copyright (c) 2002-2006 by OpenSymphony
003: * All rights reserved.
004: */
005: package com.opensymphony.xwork;
006:
007: import com.opensymphony.xwork.util.OgnlValueStack;
008: import com.uwyn.rife.continuations.ContinuableObject;
009: import org.apache.commons.logging.Log;
010: import org.apache.commons.logging.LogFactory;
011:
012: import java.io.Serializable;
013: import java.util.*;
014:
015: /**
016: * Provides a default implementation for the most common actions.
017: * See the documentation for all the interfaces this class implements for more detailed information.
018: */
019: public class ActionSupport implements Action, Validateable,
020: ValidationAware, TextProvider, LocaleProvider, Serializable,
021: ContinuableObject {
022:
023: protected transient static final Log LOG = LogFactory
024: .getLog(ActionSupport.class);
025:
026: private transient final TextProvider textProvider = new TextProviderSupport(
027: getClass(), this );
028: private final ValidationAwareSupport validationAware = new ValidationAwareSupport();
029:
030: public void setActionErrors(Collection errorMessages) {
031: validationAware.setActionErrors(errorMessages);
032: }
033:
034: public Collection getActionErrors() {
035: return validationAware.getActionErrors();
036: }
037:
038: public void setActionMessages(Collection messages) {
039: validationAware.setActionMessages(messages);
040: }
041:
042: public Collection getActionMessages() {
043: return validationAware.getActionMessages();
044: }
045:
046: /**
047: * @deprecated Use {@link #getActionErrors()}.
048: */
049: public Collection getErrorMessages() {
050: return getActionErrors();
051: }
052:
053: /**
054: * @deprecated Use {@link #getFieldErrors()}.
055: */
056: public Map getErrors() {
057: return getFieldErrors();
058: }
059:
060: public void setFieldErrors(Map errorMap) {
061: validationAware.setFieldErrors(errorMap);
062: }
063:
064: public Map getFieldErrors() {
065: return validationAware.getFieldErrors();
066: }
067:
068: public Locale getLocale() {
069: return ActionContext.getContext().getLocale();
070: }
071:
072: public boolean hasKey(String key) {
073: return textProvider.hasKey(key);
074: }
075:
076: public String getText(String aTextName) {
077: return textProvider.getText(aTextName);
078: }
079:
080: public String getText(String aTextName, String defaultValue) {
081: return textProvider.getText(aTextName, defaultValue);
082: }
083:
084: public String getText(String aTextName, String defaultValue,
085: String obj) {
086: return textProvider.getText(aTextName, defaultValue, obj);
087: }
088:
089: public String getText(String aTextName, List args) {
090: return textProvider.getText(aTextName, args);
091: }
092:
093: public String getText(String key, String[] args) {
094: return textProvider.getText(key, args);
095: }
096:
097: public String getText(String aTextName, String defaultValue,
098: List args) {
099: return textProvider.getText(aTextName, defaultValue, args);
100: }
101:
102: public String getText(String key, String defaultValue, String[] args) {
103: return textProvider.getText(key, defaultValue, args);
104: }
105:
106: public String getText(String key, String defaultValue, List args,
107: OgnlValueStack stack) {
108: return textProvider.getText(key, defaultValue, args, stack);
109: }
110:
111: public String getText(String key, String defaultValue,
112: String[] args, OgnlValueStack stack) {
113: return textProvider.getText(key, defaultValue, args, stack);
114: }
115:
116: public ResourceBundle getTexts() {
117: return textProvider.getTexts();
118: }
119:
120: public ResourceBundle getTexts(String aBundleName) {
121: return textProvider.getTexts(aBundleName);
122: }
123:
124: public void addActionError(String anErrorMessage) {
125: validationAware.addActionError(anErrorMessage);
126: }
127:
128: public void addActionMessage(String aMessage) {
129: validationAware.addActionMessage(aMessage);
130: }
131:
132: public void addFieldError(String fieldName, String errorMessage) {
133: validationAware.addFieldError(fieldName, errorMessage);
134: }
135:
136: public String doInput() throws Exception {
137: return INPUT;
138: }
139:
140: public String doDefault() throws Exception {
141: return SUCCESS;
142: }
143:
144: /**
145: * A default implementation that does nothing an returns "success".
146: * <p/>
147: * Subclasses should override this method to provide their business logic.
148: * <p/>
149: * See also {@link com.opensymphony.xwork.Action#execute()}.
150: *
151: * @return returns {@link #SUCCESS}
152: * @throws Exception can be thrown by subclasses.
153: */
154: public String execute() throws Exception {
155: return SUCCESS;
156: }
157:
158: public boolean hasActionErrors() {
159: return validationAware.hasActionErrors();
160: }
161:
162: public boolean hasActionMessages() {
163: return validationAware.hasActionMessages();
164: }
165:
166: public boolean hasErrors() {
167: return validationAware.hasErrors();
168: }
169:
170: public boolean hasFieldErrors() {
171: return validationAware.hasFieldErrors();
172: }
173:
174: /**
175: * Clears all errors and messages. Useful for Continuations and other situations
176: * where you might want to clear parts of the state on the same action.
177: */
178: public void clearErrorsAndMessages() {
179: validationAware.clearErrorsAndMessages();
180: }
181:
182: /**
183: * A default implementation that validates nothing.
184: * Subclasses should override this method to provide validations.
185: */
186: public void validate() {
187: }
188:
189: public Object clone() throws CloneNotSupportedException {
190: return super .clone();
191: }
192:
193: /**
194: * <!-- START SNIPPET: pause-method -->
195: * Stops the action invocation immediately (by throwing a PauseException) and causes the action invocation to return
196: * the specified result, such as {@link #SUCCESS}, {@link #INPUT}, etc.
197: * <p/>
198: *
199: * The next time this action is invoked (and using the same continuation ID), the method will resume immediately
200: * after where this method was called, with the entire call stack in the execute method restored.
201: * <p/>
202: *
203: * Note: this method can <b>only</b> be called within the {@link #execute()} method.
204: * <!-- END SNIPPET: pause-method -->
205: *
206: * @param result the result to return - the same type of return value in the {@link #execute()} method.
207: */
208: public void pause(String result) {
209: }
210:
211: }
|