KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jmanage > webui > forms > MBeanConfigForm


1 /**
2  * Copyright 2004-2005 jManage.org
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 package org.jmanage.webui.forms;
17
18 import org.apache.struts.action.ActionErrors;
19 import org.apache.struts.action.ActionMapping;
20 import org.apache.struts.action.ActionError;
21 import org.apache.commons.validator.GenericValidator;
22 import org.jmanage.core.util.ErrorCodes;
23 import org.jmanage.webui.util.RequestParams;
24
25 import javax.servlet.http.HttpServletRequest JavaDoc;
26
27 /**
28  *
29  * date: Jul 21, 2004
30  * @author Rakesh Kalra, Shashank Bellary
31  */

32 public class MBeanConfigForm extends BaseForm {
33     //TODO: Usage of DynaForm should clean up this.
34
private String JavaDoc[] name;
35     private String JavaDoc objectName;
36     private boolean applicationCluster;
37
38     public final ActionErrors validate(ActionMapping mapping,
39                                        HttpServletRequest JavaDoc request) {
40         if(request.getParameter(RequestParams.MULTI_MBEAN_CONFIG) != null){
41             boolean validValue = false, invalidValue = false, nullValue = false;
42             final String JavaDoc[] objectNames = request.getParameterValues("name");
43             for(int mbeanCtr=0; mbeanCtr < objectNames.length; mbeanCtr++ ){
44                 final String JavaDoc configName = request.getParameter(objectNames[mbeanCtr]);
45                 if(GenericValidator.isBlankOrNull(configName)){
46                     nullValue = true;
47                 }else{
48                     if(configName.indexOf("/") != -1){
49                         invalidValue = true;
50                     }else{
51                         validValue = true;
52                     }
53                 }
54             }
55             ActionErrors errors = new ActionErrors();
56             if(invalidValue){
57                 errors.add(ActionErrors.GLOBAL_ERROR,
58                         new ActionError(ErrorCodes.INVALID_CHAR_APP_NAME));
59                 return errors;
60             }else if(nullValue && !validValue){
61                 errors.add(ActionErrors.GLOBAL_ERROR,
62                         new ActionError("errors.required", "application name"));
63                 return errors;
64             }
65             return null;
66         }else{
67             final String JavaDoc configName = request.getParameter("name");
68             ActionErrors errors = new ActionErrors();
69             if(GenericValidator.isBlankOrNull(configName)){
70                 errors.add(ActionErrors.GLOBAL_ERROR,
71                         new ActionError("errors.required", "application name"));
72                 return errors;
73             }else if(configName.indexOf("/") != -1){
74                 errors.add(ActionErrors.GLOBAL_ERROR,
75                         new ActionError(ErrorCodes.INVALID_CHAR_APP_NAME));
76                 return errors;
77             }else{
78                 return null;
79             }
80         }
81     }
82
83     public String JavaDoc[] getName() {
84         return name;
85     }
86
87     public void setName(String JavaDoc[] name) {
88         this.name = name;
89     }
90
91     public String JavaDoc getObjectName() {
92         return objectName;
93     }
94
95     public void setObjectName(String JavaDoc objectName) {
96         this.objectName = objectName;
97     }
98
99     public boolean isApplicationCluster(){
100         return applicationCluster;
101     }
102
103     public void setApplicationCluster(boolean applicationCluster){
104         this.applicationCluster = applicationCluster;
105     }
106 }
107
Popular Tags