KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > webapp > admin > server > ServerForm


1 /*
2  * Copyright 2001,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.webapp.admin.server;
18
19
20 import javax.servlet.http.HttpServletRequest JavaDoc;
21 import org.apache.struts.action.ActionError;
22 import org.apache.struts.action.ActionErrors;
23 import org.apache.struts.action.ActionForm;
24 import org.apache.struts.action.ActionMapping;
25 import org.apache.webapp.admin.ApplicationServlet;
26 import org.apache.webapp.admin.TomcatTreeBuilder;
27
28 import java.util.List JavaDoc;
29
30 /**
31  * Form bean for the server form page.
32  * @author Patrick Luby
33  * @author Manveen Kaur
34  * @version $Revision: 1.5 $ $Date: 2004/06/28 02:14:51 $
35  */

36
37 public final class ServerForm extends ActionForm {
38     
39     // ----------------------------------------------------- Instance Variables
40

41     /**
42      * The text for the node label.
43      */

44     private String JavaDoc nodeLabel = null;
45     
46     /**
47      * The text for the port number.
48      */

49     private String JavaDoc portNumberText = "8080";
50     
51     /**
52      * The text for the shutdown text.
53      */

54     private String JavaDoc shutdownText = null;
55     
56     /**
57      * The object name of the Connector this bean refers to.
58      */

59     private String JavaDoc objectName = null;
60     
61     // ------------------------------------------------------------- Properties
62
/**
63      * Return the label of the node that was clicked.
64      */

65     public String JavaDoc getNodeLabel() {
66         
67         return this.nodeLabel;
68         
69     }
70     
71     /**
72      * Set the node label.
73      */

74     public void setNodeLabel(String JavaDoc nodeLabel) {
75         
76         this.nodeLabel = nodeLabel;
77         
78     }
79     
80     /**
81      * Return the portNumberText.
82      */

83     public String JavaDoc getPortNumberText() {
84         
85         return this.portNumberText;
86         
87     }
88     
89     /**
90      * Set the portNumberText.
91      */

92     public void setPortNumberText(String JavaDoc portNumberText) {
93         
94         this.portNumberText = portNumberText;
95         
96     }
97     
98     /**
99      * Return the Shutdown Text.
100      */

101     public String JavaDoc getShutdownText() {
102         
103         return this.shutdownText;
104         
105     }
106     
107     /**
108      * Set the Shut down Text.
109      */

110     public void setShutdownText(String JavaDoc shutdownText) {
111         
112         this.shutdownText = shutdownText;
113         
114     }
115     
116     /**
117      * Return the object name of the Connector this bean refers to.
118      */

119     public String JavaDoc getObjectName() {
120
121         return this.objectName;
122
123     }
124
125
126     /**
127      * Set the object name of the Connector this bean refers to.
128      */

129     public void setObjectName(String JavaDoc objectName) {
130
131         this.objectName = objectName;
132
133     }
134     
135     // --------------------------------------------------------- Public Methods
136

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

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

161     public ActionErrors validate(ActionMapping mapping,
162     HttpServletRequest JavaDoc request) {
163         
164         ActionErrors errors = new ActionErrors();
165         
166         String JavaDoc submit = request.getParameter("submit");
167         //if (submit != null) {
168

169             // check for portNumber -- must not be blank, must be in
170
// the range 1 to 65535.
171

172             if ((portNumberText == null) || (portNumberText.length() < 1)) {
173                 errors.add("portNumberText",
174                 new ActionError("error.portNumber.required"));
175             } else {
176                 try {
177                     int port = Integer.parseInt(portNumberText);
178                     if ((port <= 0) || (port >65535 ))
179                         errors.add("portNumberText",
180                             new ActionError("error.portNumber.range"));
181                 } catch (NumberFormatException JavaDoc e) {
182                     errors.add("portNumberText",
183                         new ActionError("error.portNumber.format"));
184                 }
185             }
186         
187             // shutdown text can be any non-empty string of atleast 6 characters.
188

189             if ((shutdownText == null) || (shutdownText.length() < 7))
190                 errors.add("shutdownText",
191                 new ActionError("error.shutdownText.length"));
192             
193         //}
194

195         return errors;
196         
197     }
198     
199 }
200
Popular Tags