KickJava   Java API By Example, From Geeks To Geeks.

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


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.TagExtraInfo JavaDoc;
15 import javax.servlet.jsp.tagext.VariableInfo JavaDoc;
16
17 import org.apache.log4j.Logger;
18
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 ATei extends TagExtraInfo JavaDoc {
32
33     /**
34      * This classes logger
35      */

36     private static final Logger logger = Logger.getLogger(ATei.class);
37
38
39     /**
40      * Returns whether or not the form (if specified) is valid.
41      *
42      * @return True if the form exists, false otherwise
43      */

44     public boolean isValid(TagData JavaDoc data) {
45         boolean valid = true;
46         String JavaDoc form = data.getAttributeString("form");
47         if (form != null) {
48             String JavaDoc namespace = data.getAttributeString("namespace");
49             ActionFlowMetaData metaData = new ActionFlowMetaData(namespace, form);
50
51             try {
52                 metaData.findFormConfig(null);
53             } catch (MVCException mvce) {
54                 logger.fatal(mvce);
55                 valid = false;
56             }
57         }
58
59         return valid;
60     }
61
62     /**
63      * Returns the variable info for the form bean
64      *
65      * @return A single VariableInfo instance for the form bean
66      */

67     public VariableInfo JavaDoc [] getVariableInfo(TagData JavaDoc data) {
68         VariableInfo JavaDoc[] infos = null;
69         String JavaDoc form = data.getAttributeString("form");
70         if (form != null) {
71             String JavaDoc namespace = data.getAttributeString("namespace");
72             ActionFlowMetaData metaData = new ActionFlowMetaData(namespace, form);
73
74             BaseFormConfig config = null;
75             try {
76                 config = metaData.findFormConfig(null);
77             } catch (MVCException mvce) {
78                 logger.fatal(mvce);
79                 throw new IllegalArgumentException JavaDoc("Invalid form name: " + form);
80             }
81
82             Collection JavaDoc formBeans = config.getFormBeans();
83             infos = new VariableInfo JavaDoc[formBeans.size()];
84             Iterator JavaDoc iter = formBeans.iterator();
85             WebBean webBean;
86             int count = 0;
87             while (iter.hasNext()) {
88                 webBean = (WebBean) iter.next();
89                 infos[count] = new VariableInfo JavaDoc(webBean.getID(), webBean.getClassName(),
90                     true, VariableInfo.NESTED);
91             }
92         }
93
94         return infos;
95     }
96 }
Popular Tags