KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > soto > state > cocoon > util > Forms


1 package org.sapia.soto.state.cocoon.util;
2
3 import java.io.Serializable JavaDoc;
4
5 import java.util.Stack JavaDoc;
6
7
8 /**
9  * This class implements a stack of objects that act as data holders for forms.
10  * The objects are pushed onto the stack successively, if required (a form might
11  * need input that comes from a selection of another form's output).
12  * <p/>
13  * An instance of this class can be kept in a HTTP session. It holds the forms
14  * that are currently "active" for a given user.
15  * <p/>
16  * A form is pushed onto this instance when the corresponding form page is
17  * first displayed. Typically, the form object that is put onto
18  * the stack becomes a model that is displayed in the view.
19  * <p/>
20  * If the form is displayed again after submission (such as when required input data
21  * is missing), the current form object is used to display the data that has already been
22  * entered.
23  * <p/>
24  * Once submitted or cancelled, the current form object should be popped from
25  * the stack.
26  * <p/>
27  * Typically, instances of the <code>Form</code> class are used with an instance of this
28  * class.
29  *
30  * @see org.sapia.soto.state.cocoon.util.Form
31  * @see org.sapia.soto.state.util.FormStep
32  *
33  * @author Yanick Duchesne
34  *
35  * <dl>
36  * <dt><b>Copyright:</b><dd>Copyright &#169; 2002-2004 <a HREF="http://www.sapia-oss.org">Sapia Open Source Software</a>. All Rights Reserved.</dd></dt>
37  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
38  * <a HREF="http://www.sapia-oss.org/license.html">license page</a> at the Sapia OSS web site</dd></dt>
39  * </dl>
40  */

41 public class Forms implements Serializable JavaDoc {
42   private Stack JavaDoc _forms = new Stack JavaDoc();
43
44   /**
45    * @param form a <code>Object</code>.
46    */

47   public void pushForm(Object JavaDoc form) {
48     _forms.push(form);
49   }
50
51   /**
52    * @return the "current" form <code>Object</code>, or <code>null</code>
53    * if there is no form in this instance - the returned form is removed
54    * from this instance.
55    */

56   public Object JavaDoc popForm() {
57     if (_forms.size() == 0) {
58       return null;
59     }
60
61     return _forms.pop();
62   }
63
64   /**
65    * @return the "current" form <code>Object</code>, or <code>null</code>
66    * if there is no form in this instance.
67    */

68   public Object JavaDoc peekForm() {
69     if (_forms.size() == 0) {
70       return null;
71     }
72
73     return _forms.peek();
74   }
75
76   /**
77    * clears all form objects that this instance holds.
78    */

79   public void clear() {
80     _forms.clear();
81   }
82 }
83
Popular Tags