001: // THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
002: // CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
003: // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
004: // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
005: // OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
006: // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
007: // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
008: // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
009: // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
010: // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
011: // EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
012: // POSSIBILITY OF SUCH DAMAGE.
013: //
014: // Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
015: package com.metaboss.enterprise.xi.enhydrabarracuda;
016:
017: import org.apache.commons.logging.Log;
018: import org.apache.commons.logging.LogFactory;
019:
020: import com.metaboss.enterprise.ui.UIException;
021: import com.metaboss.enterprise.ui.UIInputValidationException;
022: import com.metaboss.enterprise.ui.UIUnexpectedProgramConditionException;
023:
024: /** This abstract represents the processing which should take place when user actions the form or anchor */
025: public abstract class Action {
026: // Static logging instance
027: private static final Log sLogger = LogFactory.getLog(Action.class);
028:
029: // Current navigation move
030: private Application.NavigationMove mNavigationMove;
031: // The Application which owns this instance
032: private Application mApplication = null;
033:
034: /** Package visibility only. This helper processes the action when user actions the form if there is one bound
035: * or just returns without complaining if action is not bound.
036: * @return alternative relative URI of the page where application should be redirected. If this equals null - the
037: * URI present in HTTP request will be used. */
038: static String processFormAction(String pPageResourceId,
039: String pFormResourceId, Application pApplication,
040: Application.NavigationMove pNavigationMove)
041: throws IllegalAccessException, InstantiationException,
042: UIException {
043: // Find out if we have action associated with this form
044: Class lFormActionClass = Page.getFormActionClass(
045: pPageResourceId, pFormResourceId);
046: if (lFormActionClass == null) {
047: sLogger
048: .debug("Form does not have an Action associated with it. PageId: "
049: + pPageResourceId
050: + ". FormId: "
051: + pFormResourceId);
052: return null;
053: }
054: // Create an instance of the action and execute it
055: Action lInstance = (Action) lFormActionClass.newInstance();
056: lInstance.mApplication = pApplication;
057: lInstance.mNavigationMove = pNavigationMove;
058: return lInstance.execute();
059: }
060:
061: /** Getter for the navigation move */
062: protected Application.NavigationMove getNavigationMove() {
063: return mNavigationMove;
064: }
065:
066: /** Getter for the application */
067: protected Application getApplication() {
068: return mApplication;
069: }
070:
071: /** Returns the value of a navigation parameter as a String, or throws exception if the specified parameter does not exist.
072: * This method should only be used if caller is sure that the parameter value is always a sinlge string.
073: * For array of strings getMandatoryParameters() method should be used */
074: protected String getMandatoryParameter(String pParameterName)
075: throws UIInputValidationException,
076: UIUnexpectedProgramConditionException {
077: return getNavigationMove()
078: .getMandatoryParameter(pParameterName);
079: }
080:
081: /** Returns the value of a navigation parameter as a String, or throws exception if the specified parameter does not exist. */
082: protected String[] getMandatoryParameters(String pParameterName)
083: throws UIInputValidationException {
084: return getNavigationMove().getMandatoryParameters(
085: pParameterName);
086: }
087:
088: /** Returns the value of a navigation parameter as a String, or specified default value if the parameter does not exist.
089: * This method should only be used if caller is sure that the parameter value is always a sinlge string.
090: * For array of strings getMandatoryParameters() method should be used */
091: protected String getParameter(String pParameterName,
092: String pDefaultValue)
093: throws UIUnexpectedProgramConditionException {
094: return getNavigationMove().getParameter(pParameterName,
095: pDefaultValue);
096: }
097:
098: /** Returns the value of a navigation parameter as a String, or specified default value if the parameter does not exist. */
099: protected String[] getParameters(String pParameterName,
100: String[] pDefaultValue) {
101: return getNavigationMove().getParameters(pParameterName,
102: pDefaultValue);
103: }
104:
105: /** Executes action.
106: * @return alternative relative URI of the page where application should be redirected. If this equals null - the
107: * URI present in HTTP request will be used. */
108: public abstract String execute() throws UIException;
109: }
|