KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > webapp > admin > realm > DataSourceRealmForm


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.realm;
18
19 import javax.servlet.http.HttpServletRequest JavaDoc;
20 import org.apache.struts.action.ActionError;
21 import org.apache.struts.action.ActionErrors;
22 import org.apache.struts.action.ActionForm;
23 import org.apache.struts.action.ActionMapping;
24 import java.net.InetAddress JavaDoc;
25 import java.util.List JavaDoc;
26
27 import org.apache.webapp.admin.ApplicationServlet;
28 import org.apache.webapp.admin.LabelValueBean;
29
30 /**
31  * Form bean for the datasource realm page.
32  *
33  * @author Amy Roh
34  * @version $Revision: 1.3 $ $Date: 2004/06/28 02:14:51 $
35  */

36
37 public final class DataSourceRealmForm extends RealmForm {
38     
39     // ----------------------------------------------------- Instance Variables
40

41     /**
42      * The text for the JNDI named JDBC DataSource for your database.
43      */

44     private String JavaDoc dataSourceName = null;
45       
46     /**
47      * The text for the digest.
48      */

49     private String JavaDoc digest = null;
50     
51     /**
52      * The text for if the DataSource is local to the webapp.
53      */

54     private String JavaDoc localDataSource = "false";
55     
56     /**
57      * The text for the roleNameCol.
58      */

59     private String JavaDoc roleNameCol = null;
60     
61     /**
62      * The text for the userCredCol.
63      */

64     private String JavaDoc userCredCol = null;
65     
66     /**
67      * The text for the userNameCol.
68      */

69     private String JavaDoc userNameCol = null;
70         
71     /**
72      * The text for the userRoleTable.
73      */

74     private String JavaDoc userRoleTable = null;
75     
76     /**
77      * The text for the user table.
78      */

79     private String JavaDoc userTable = null;
80         
81     /*
82      * Represent boolean (true, false) values for unpackWARs etc.
83      */

84     private List JavaDoc booleanVals = null;
85     
86     // ------------------------------------------------------------- Properties
87

88     
89     /**
90      * Return the dataSourceName.
91      */

92     public String JavaDoc getDataSourceName() {
93         
94         return this.dataSourceName;
95         
96     }
97     
98     /**
99      * Set the dataSourceName.
100      */

101     public void setDataSourceName(String JavaDoc dataSourceName) {
102         
103         this.dataSourceName = dataSourceName;
104         
105     }
106     
107     /**
108      * Return the digest.
109      */

110     public String JavaDoc getDigest() {
111         
112         return this.digest;
113         
114     }
115     
116     /**
117      * Set the digest.
118      */

119     public void setDigest(String JavaDoc digest) {
120         
121         this.digest = digest;
122         
123     }
124     
125     /**
126      * Return the localDataSource.
127      */

128     public String JavaDoc getLocalDataSource() {
129         
130         return this.localDataSource;
131         
132     }
133     
134     /**
135      * Set the localDataSource.
136      */

137     public void setLocalDataSource(String JavaDoc localDataSource) {
138         
139         this.localDataSource = localDataSource;
140         
141     }
142     
143     /**
144      * Return the roleNameCol.
145      */

146     public String JavaDoc getRoleNameCol() {
147         
148         return this.roleNameCol;
149         
150     }
151     
152     /**
153      * Set the roleNameCol.
154      */

155     public void setRoleNameCol(String JavaDoc roleNameCol) {
156         
157         this.roleNameCol = roleNameCol;
158         
159     }
160     
161     /**
162      * Return the userCredCol.
163      */

164     public String JavaDoc getUserCredCol() {
165         
166         return this.userCredCol;
167         
168     }
169     
170     /**
171      * Set the userCredCol.
172      */

173     public void setUserCredCol(String JavaDoc userCredCol) {
174         
175         this.userCredCol = userCredCol;
176         
177     }
178     
179     /**
180      * Return the userNameCol.
181      */

182     public String JavaDoc getUserNameCol() {
183         
184         return this.userNameCol;
185         
186     }
187     
188     /**
189      * Set the userNameCol.
190      */

191     public void setUserNameCol(String JavaDoc userNameCol) {
192         
193         this.userNameCol = userNameCol;
194         
195     }
196     
197     /**
198      * Return the user role table.
199      */

200     public String JavaDoc getUserRoleTable() {
201         
202         return this.userRoleTable;
203         
204     }
205     
206     /**
207      * Set the user role table.
208      */

209     public void setUserRoleTable(String JavaDoc userRoleTable) {
210         
211         this.userRoleTable = userRoleTable;
212         
213     }
214     
215     /**
216      * Return the user table.
217      */

218     public String JavaDoc getUserTable() {
219         
220         return this.userTable;
221         
222     }
223     
224     /**
225      * Set the user Table.
226      */

227     public void setUserTable(String JavaDoc userTable) {
228         
229         this.userTable = userTable;
230         
231     }
232     
233     /**
234      * Return the booleanVals.
235      */

236     public List JavaDoc getBooleanVals() {
237
238         return this.booleanVals;
239
240     }
241
242     /**
243      * Set the booleanVals.
244      */

245     public void setBooleanVals(List JavaDoc booleanVals) {
246
247         this.booleanVals = booleanVals;
248
249     }
250     
251     // --------------------------------------------------------- Public Methods
252

253     /**
254      * Reset all properties to their default values.
255      *
256      * @param mapping The mapping used to select this instance
257      * @param request The servlet request we are processing
258      */

259     public void reset(ActionMapping mapping, HttpServletRequest JavaDoc request) {
260         
261         super.reset(mapping, request);
262         this.dataSourceName = null;
263         this.digest = null;
264         this.localDataSource = "false";
265         
266         this.roleNameCol = null;
267         this.userCredCol = null;
268         this.userNameCol = null;
269         this.userTable = null;
270         this.userRoleTable = null;
271         
272     }
273     
274     /**
275      * Render this object as a String.
276      */

277     public String JavaDoc toString() {
278
279         StringBuffer JavaDoc sb = new StringBuffer JavaDoc("DataSourceRealmForm[adminAction=");
280         sb.append(getAdminAction());
281         sb.append(",dataSourceName=");
282         sb.append(dataSourceName);
283         sb.append(",digest=");
284         sb.append(digest);
285         sb.append("',localDataSource='");
286         sb.append(localDataSource);
287         sb.append("',roleNameCol=");
288         sb.append(roleNameCol);
289         sb.append("',userCredCol=");
290         sb.append(userCredCol);
291         sb.append("',userNameCol=");
292         sb.append(userNameCol);
293         sb.append("',userRoleTable=");
294         sb.append(userRoleTable);
295         sb.append("',userTable='");
296         sb.append(userTable);
297         sb.append("',objectName='");
298         sb.append(getObjectName());
299         sb.append("',realmType=");
300         sb.append(getRealmType());
301         sb.append("]");
302         return (sb.toString());
303
304     }
305     
306     /**
307      * Validate the properties that have been set from this HTTP request,
308      * and return an <code>ActionErrors</code> object that encapsulates any
309      * validation errors that have been found. If no errors are found, return
310      * <code>null</code> or an <code>ActionErrors</code> object with no
311      * recorded error messages.
312      *
313      * @param mapping The mapping used to select this instance
314      * @param request The servlet request we are processing
315      */

316     
317     public ActionErrors validate(ActionMapping mapping,
318     HttpServletRequest JavaDoc request) {
319         
320         ActionErrors errors = new ActionErrors();
321         
322         String JavaDoc submit = request.getParameter("submit");
323         //String type = request.getParameter("realmType");
324

325         // front end validation when save is clicked.
326
//if (submit != null) {
327
// the following fields are required.
328

329             if ((dataSourceName == null) || (dataSourceName.length() < 1)) {
330                 errors.add("dataSourceName",
331                 new ActionError("error.dataSourceName.required"));
332             }
333          
334             if ((roleNameCol == null) || (roleNameCol.length() < 1)) {
335                 errors.add("roleNameCol",
336                 new ActionError("error.roleNameCol.required"));
337             }
338
339             if ((userCredCol == null) || (userCredCol.length() < 1)) {
340                 errors.add("userCredCol",
341                 new ActionError("error.userCredCol.required"));
342             }
343         
344             if ((userNameCol == null) || (userNameCol.length() < 1)) {
345                 errors.add("userNameCol",
346                 new ActionError("error.userNameCol.required"));
347             }
348             
349             if ((userRoleTable == null) || (userRoleTable.length() < 1)) {
350                 errors.add("userRoleTable",
351                 new ActionError("error.userRoleTable.required"));
352             }
353         
354             if ((userTable == null) || (userTable.length() < 1)) {
355                 errors.add("userTable",
356                 new ActionError("error.userTable.required"));
357             }
358             
359         //}
360

361         return errors;
362     }
363 }
364
Popular Tags