KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > webapp > jonasadmin > service > jtm > JtmServiceForm


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 2003-2004 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: JtmServiceForm.java,v 1.6 2005/04/21 08:59:54 kemlerp Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.webapp.jonasadmin.service.jtm;
27
28 import javax.servlet.http.HttpServletRequest JavaDoc;
29
30 import org.apache.struts.action.ActionMessage;
31 import org.apache.struts.action.ActionErrors;
32 import org.apache.struts.action.ActionForm;
33 import org.apache.struts.action.ActionMapping;
34
35 /**
36  * Form used to present the Transaction Manager properties
37  * @author Adriana Danes
38  */

39 public final class JtmServiceForm extends ActionForm {
40
41 // ------------------------------------------------------------- Properties Variables
42

43     private String JavaDoc action = null;
44     private String JavaDoc timeOutText = null;
45     private String JavaDoc jtmHost = null;
46     private String JavaDoc jtmLocation = null;
47     private String JavaDoc jtmPort = null;
48
49 // ------------------------------------------------------------- Properties Methods
50

51     public String JavaDoc getTimeOutText() {
52         return timeOutText;
53     }
54     public void setTimeOutText(String JavaDoc timeOutText) {
55         this.timeOutText = timeOutText;
56     }
57     public String JavaDoc getJtmHost() {
58         return jtmHost;
59     }
60     public void setJtmHost(String JavaDoc jtmHost) {
61         this.jtmHost = jtmHost;
62     }
63     public String JavaDoc getJtmLocation() {
64         return jtmLocation;
65     }
66     public void setJtmLocation(String JavaDoc jtmLocation) {
67         this.jtmLocation = jtmLocation;
68     }
69     public String JavaDoc getJtmPort() {
70         return jtmPort;
71     }
72     public void setJtmPort(String JavaDoc jtmPort) {
73         this.jtmPort = jtmPort;
74     }
75     public String JavaDoc getAction() {
76         return action;
77     }
78     public void setAction(String JavaDoc action) {
79         this.action = action;
80     }
81 // ------------------------------------------------------------- Public Methods
82

83     /**
84      * Reset all properties to their default values.
85      *
86      * @param mapping The mapping used to select this instance
87      * @param request The servlet request we are processing
88      */

89     public void reset(ActionMapping mapping, HttpServletRequest JavaDoc request) {
90         action = "apply";
91     }
92
93     /**
94      * Validate the properties that have been set from this HTTP request,
95      * and return an <code>ActionErrors</code> object that encapsulates any
96      * validation errors that have been found. If no errors are found, return
97      * <code>null</code> or an <code>ActionErrors</code> object with no
98      * recorded error messages.
99      *
100      * @param mapping The mapping used to select this instance
101      * @param request The servlet request we are processing
102      */

103     public ActionErrors validate(ActionMapping mapping, HttpServletRequest JavaDoc request) {
104         ActionErrors oErrors = new ActionErrors();
105         numberCheck(oErrors, "timeOut", timeOutText, false, 0, 0);
106         return oErrors;
107     }
108
109     /**
110      * Helper method to check that it is a required number and
111      * is a valid integer within the given range. (min, max).
112      *
113      * @param field The field name in the form for which this error occured.
114      * @param numText The string representation of the number.
115      * @param rangeCheck Boolean value set to true of reange check should be performed.
116      * @param min The lower limit of the range
117      * @param max The upper limit of the range
118      */

119     public void numberCheck(ActionErrors p_Errors, String JavaDoc field, String JavaDoc numText, boolean rangeCheck
120         , int min, int max) {
121         // Check for 'is required'
122
if ((numText == null) || (numText.length() < 1)) {
123             p_Errors.add(field, new ActionMessage("error.jtm." + field + ".required"));
124         } else {
125             // check for 'must be a number' in the 'valid range'
126
try {
127                 int num = Integer.parseInt(numText);
128                 // perform range check only if required
129
if (rangeCheck) {
130                     if ((num < min) || (num > max)) {
131                         p_Errors.add(field
132                             , new ActionMessage("error.jtm." + field + ".range"));
133                     }
134                 }
135             } catch (NumberFormatException JavaDoc e) {
136                 p_Errors.add(field, new ActionMessage("error.jtm." + field + ".format"));
137             }
138         }
139     }
140
141 }
142
Popular Tags