View Javadoc

1   /*
2    * $Id: AbstractAction.java 121 2004-11-01 13:05:23Z josem $
3    *
4    * Tarsis
5    * Copyright (C) 2002 Talika Open Source Group
6    *
7    * This program is free software; you can redistribute it and/or modify
8    * it under the terms of the GNU General Public License as published by
9    * the Free Software Foundation; either version 2 of the License, or
10   * (at your option) any later version.
11   *
12   * This program is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   * GNU General Public License for more details.
16   *
17   * You should have received a copy of the GNU General Public License
18   * along with this program; if not, write to the Free Software
19   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20   *
21   */
22  
23  package org.talika.tarsis.command.action;
24  
25  import org.talika.tarsis.command.Request;
26  import org.talika.tarsis.command.Response;
27  import org.talika.tarsis.context.Context;
28  
29  /**
30   * Base implementation of <code>Action</code> interface.<br>
31   * <br>
32   * Defines all method except <code>validate</code> and <code>execute</code> method.
33   *
34   * @author  Jose M. Palomar
35   * @version $Revision: 121 $
36   */
37  public abstract class AbstractAction implements Action {
38  
39      // Fields
40      /**
41       * Tarsis context.
42       */
43      private Context context;
44  
45      /**
46       * Constructs a new <code>AbstractAction</code> object.
47       */
48      public AbstractAction() {
49      }
50  
51      /**
52       * Called by Tarsis MVC Framework to initialize action.<br>
53       * <br>
54       * This method should be used to initialize any static resource needed by action.<br>
55       * <br>
56       * This implementation simply saves context for later use.
57       *
58       * @param context Context contex of Tarsis MVC Framework.
59       * @throws ActionException if an exception has occurred that interferes with the
60       * action's normal operation.
61       * @see org.talika.tarsis.command.action.Action#init(Context)
62       */
63      public void init(Context context) throws ActionException {
64          this.context = context;
65      }
66  
67      /**
68       * Called by Tarsis MVC Framework to destroy action.<br>
69       * <br>
70       * This implementation do nothing.
71       *
72       * @see org.talika.tarsis.command.action.Action#destroy()
73       */
74      public void destroy() {
75      }
76  
77      /**
78       * Called by Tarsis MVC Framework to validate request everytime command is
79       * invoked.<br>
80       * <br>
81       * This method is called only if command is validable.
82       *
83       * @param request Request object representing client's request.
84       * @throws ActionException if an exception has occurred that interferes with the
85       * action's normal operation.
86       */
87      public abstract void validate(Request request) throws ActionException;
88  
89     /**
90       * Called by Tarsis MVC Framework to handle request everytime command is
91       * invoked.<br>
92       *
93       * @param request Request object representing client's request.
94       * @param response Response object representing client's reponse.
95       * @return String the name of view to be forwarded or <code>null</code> for
96       * default view.
97       * @throws ActionException if an exception has occurred that interferes with the
98       * action's normal operation.
99       * @see org.talika.tarsis.command.action.Action#execute(Request, Response)
100      */
101     public abstract String execute(Request request, Response response) throws ActionException;
102 
103     /**
104      * Returns the Tarsis context.
105      *
106      * @return Context the Tarsis context.
107      */
108     protected final Context getContext() {
109         return context;
110     }
111 
112 }