KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hero > struts > forms > HookForm


1 package hero.struts.forms;
2
3 import javax.servlet.http.HttpServletRequest JavaDoc;
4 import org.apache.struts.action.ActionError;
5 import org.apache.struts.action.ActionErrors;
6 import org.apache.struts.action.ActionForm;
7 import org.apache.struts.action.ActionMapping;
8
9
10 /**
11  * Form bean for the Hook. This form has the following fields,
12  * with default values in square brackets:
13  * <ul>
14  * <li><b>name</b> - The name of the hook. [REQUIRED]
15  * <li><b>event</b> - The event for this hook. [REQUIRED]
16  * <li><b>type</b> - The hook type [REQUIRED]
17  * </ul>
18  *
19  * @author Miguel Valdes Faura
20  * @version $Revision: 1.1 $ $Date: 2004/07/30 14:57:57 $
21  */

22
23 public final class HookForm extends ActionForm {
24
25
26 // =================================================== Instance Variables
27

28
29     /**
30      * The hook name
31      */

32     private String JavaDoc name = null;
33
34
35     /**
36      * The hook event
37      */

38
39     private String JavaDoc event = null;
40
41     /**
42      * The hook type
43      */

44
45          private String JavaDoc type = null;
46
47     /**
48      * The hook value
49      */

50     private String JavaDoc value = null;
51
52
53     // =========================================================== Properties
54

55
56     /**
57      * Return the hook name
58      */

59     public String JavaDoc getName() {
60
61     return (this.name);
62
63     }
64
65     /**
66      * Set the hook name
67      *
68      */

69     public void setName(String JavaDoc name) {
70
71     this.name = name;
72
73     }
74
75     /**
76      * Return the hook event
77      */

78     public String JavaDoc getEvent() {
79
80     return (this.event);
81
82     }
83
84     /**
85      * Set the hook event
86      *
87      */

88     public void setEvent(String JavaDoc event) {
89
90     this.event = event;
91
92     }
93
94     /**
95      * Return the hook type
96      */

97     public String JavaDoc getType() {
98
99     return (this.type);
100
101     }
102
103     /**
104      * Set the hook type
105      *
106      */

107     public void setType(String JavaDoc type) {
108
109     this.type = type;
110
111     }
112
113     /**
114      * Return the hook value
115      */

116     public String JavaDoc getValue() {
117
118     return (this.value);
119
120     }
121
122     /**
123      * Set the hook value
124      *
125      */

126     public void setValue(String JavaDoc value) {
127
128     this.value = value;
129     }
130
131
132     // --------------------------------------------------------- Public Methods
133

134
135     /**
136      * Reset all properties to their default values.
137      *
138      * @param mapping The mapping used to select this instance
139      * @param request The servlet request we are processing
140      */

141     public void reset(ActionMapping mapping, HttpServletRequest JavaDoc request) {
142
143         this.name = null;
144         this.event = null;
145         this.type = null;
146         this.value = null;
147     }
148
149     /**
150      * Validate the properties that have been set from this HTTP request,
151      * and return an <code>ActionErrors</code> object that encapsulates any
152      * validation errors that have been found. If no errors are found, return
153      * <code>null</code> or an <code>ActionErrors</code> object with no
154      * recorded error messages.
155      *
156      * @param mapping The mapping used to select this instance
157      * @param request The servlet request we are processing
158      */

159     public ActionErrors validate(ActionMapping mapping, HttpServletRequest JavaDoc request) {
160
161         ActionErrors errors = new ActionErrors();
162
163         if (name == null || name.length()==0)
164             errors.add("name",
165                    new ActionError("error.name.required"));
166         if (event == null || event.length()==0)
167         errors.add("event",
168                new ActionError("error.event.required"));
169         if (type == null || type.length()==0)
170         errors.add("type",
171         new ActionError("error.type.required"));
172
173     return (errors);
174
175     }
176 }
177
Popular Tags