KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > verge > mvc > view > jsp > actionflow > FormTei


1 /*
2  * Copyright (c) 2003, Inversoft
3  *
4  * This software is distribuable under the GNU Lesser General Public License.
5  * For more information visit gnu.org.
6  */

7 package com.inversoft.verge.mvc.view.jsp.actionflow;
8
9
10 import java.util.Collection JavaDoc;
11 import java.util.Iterator JavaDoc;
12
13 import javax.servlet.jsp.tagext.TagData JavaDoc;
14 import javax.servlet.jsp.tagext.VariableInfo JavaDoc;
15
16 import org.apache.log4j.Logger;
17
18 import com.inversoft.util.StringTools;
19 import com.inversoft.verge.mvc.MVCException;
20 import com.inversoft.verge.mvc.config.BaseFormConfig;
21 import com.inversoft.verge.mvc.controller.actionflow.ActionFlowMetaData;
22 import com.inversoft.verge.util.WebBean;
23
24
25 /**
26  * Validates that the forms method attribute is either post
27  * or get (case-insensitive) and the form name
28  *
29  * @author Brian Pontarelli
30  */

31 public class FormTei extends com.inversoft.verge.mvc.view.jsp.html.FormTei {
32
33     /**
34      * This classes logger
35      */

36     private static final Logger logger = Logger.getLogger(FormTei.class);
37
38
39     /**
40      * Checks that the form name is valid
41      */

42     public boolean isValid(TagData JavaDoc data) {
43         boolean valid = true;
44         String JavaDoc form = data.getAttributeString("form");
45         if (form != null) {
46             String JavaDoc namespace = data.getAttributeString("namespace");
47             if (namespace == null) {
48                 valid = false;
49             } else {
50                 ActionFlowMetaData metaData = new ActionFlowMetaData(namespace, form);
51                 try {
52                     BaseFormConfig config = metaData.findFormConfig(null);
53                     Collection JavaDoc formBeans = config.getFormBeans();
54                     String JavaDoc var = data.getAttributeString("var");
55                     if (formBeans.size() > 1 && var != null) {
56                         logger.error("The var attribute of the form tag should " +
57                             "only be used when the form has a single form bean");
58                         valid = false;
59                     }
60                 } catch (MVCException mvce) {
61                     logger.error(mvce);
62                     valid = false;
63                 }
64             }
65         }
66
67         // Call the super isValid
68
valid &= super.isValid(data);
69         return valid;
70     }
71
72     /**
73      * Returns the variable info for the form bean
74      *
75      * @return A single VariableInfo instance for the form bean
76      */

77     public VariableInfo JavaDoc [] getVariableInfo(TagData JavaDoc data) {
78         VariableInfo JavaDoc[] infos = null;
79         String JavaDoc form = data.getAttributeString("form");
80         if (form != null) {
81             String JavaDoc namespace = data.getAttributeString("namespace");
82             ActionFlowMetaData metaData = new ActionFlowMetaData(namespace, form);
83
84             BaseFormConfig config = null;
85             try {
86                 config = metaData.findFormConfig(null);
87             } catch (MVCException mvce) {
88                 logger.fatal(mvce);
89                 throw new IllegalArgumentException JavaDoc("Invalid form name: " + form);
90             }
91
92             Collection JavaDoc formBeans = config.getFormBeans();
93             infos = new VariableInfo JavaDoc[formBeans.size()];
94             Iterator JavaDoc iter = formBeans.iterator();
95             WebBean webBean;
96             int count = 0;
97             String JavaDoc var = data.getAttributeString("var");
98             while (iter.hasNext()) {
99                 webBean = (WebBean) iter.next();
100
101                 if (StringTools.isEmpty(var)) {
102                     var = webBean.getID();
103                 }
104
105                 infos[count] = new VariableInfo JavaDoc(var, webBean.getClassName(), true,
106                     VariableInfo.NESTED);
107             }
108         }
109
110         return infos;
111     }
112 }
Popular Tags