KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > verge > mvc > config > BaseFormConfig


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.config;
8
9
10 import java.util.ArrayList JavaDoc;
11 import java.util.Collection JavaDoc;
12 import java.util.HashMap JavaDoc;
13 import java.util.List JavaDoc;
14 import java.util.Map JavaDoc;
15
16 import com.inversoft.verge.util.WebBean;
17
18
19 /**
20  * This class is a simple JavaBean that holds information
21  * about a generic form configuration. The Form-Based MVC
22  * extends this functionality and other models use this as
23  * is.
24  *
25  * @author Brian Pontarelli
26  */

27 public class BaseFormConfig extends BaseConfig {
28
29     /**
30      * This is the WebBean that is the model for this form. This bean can either
31      * be a repository item, or a normal WebBean
32      */

33     private Map JavaDoc formBeans;
34     private List JavaDoc formBeanRIDs;
35     private List JavaDoc validators;
36     private boolean isValidating;
37
38
39     public BaseFormConfig(String JavaDoc name) {
40         super(name);
41         formBeans = new HashMap JavaDoc();
42         validators = new ArrayList JavaDoc();
43         formBeanRIDs = new ArrayList JavaDoc();
44         isValidating = false;
45     }
46
47     /**
48      * Copy constructor that does a deep copy of all the members of this class
49      * to the collection level but not to the collection element level.
50      *
51      * @param base The BaseFormConfig to copy
52      */

53     public BaseFormConfig(BaseFormConfig base) {
54         super(base.getName());
55         formBeans = base.formBeans;
56         validators = new ArrayList JavaDoc(base.validators);
57         formBeanRIDs = new ArrayList JavaDoc(base.formBeanRIDs);
58         isValidating = base.isValidating;
59     }
60
61
62     /**
63      * Gets the WebBean that is the model of this form, which has the given name
64      */

65     public WebBean getFormBean(String JavaDoc name) {
66         return (WebBean) formBeans.get(name);
67     }
68
69     /**
70      * Adds the WebBean to the list of WebBeans for this form
71      */

72     public void addFormBean(WebBean formBean) {
73         formBeans.put(formBean.getID(), formBean);
74     }
75
76     /**
77      * Returns a collection of all the form beans for this form
78      *
79      * @return A collection and never null
80      */

81     public Collection JavaDoc getFormBeans() {
82         return formBeans.values();
83     }
84
85     /**
86      * Gets the repository item id of the form beans. This list is not the live
87      * list of RIDs. This is a copy of the live list and contains the same objects
88      * that the live list does.
89      *
90      * @return Returns the repository item id of the form bean
91      */

92     public List JavaDoc getFormBeanRIDs() {
93         return new ArrayList JavaDoc(formBeanRIDs);
94     }
95
96     /**
97      * Sets the repository item id of the form bean
98      *
99      * @param formBeanRID the repository item id of the form bean
100      */

101     public void addFormBeanRID(String JavaDoc formBeanRID) {
102         this.formBeanRIDs.add(formBeanRID);
103     }
104
105     /**
106      * Returns whether or not the formBean is a repository item
107      *
108      * @return True if the formBean is a repository item, false otherwise
109      */

110     public boolean isFormBeanRepository(String JavaDoc name) {
111         return (formBeanRIDs.contains(name));
112     }
113
114     /**
115      * Returns whether or not this form is validating or not
116      */

117     public boolean isValidating() {
118         return isValidating;
119     }
120
121     /**
122      * Adds the given validator to the list of validators for this form.
123      *
124      * @param validator The validator to add
125      */

126     public void addValidatorConfig(BaseValidatorConfig validator) {
127         validators.add(validator);
128         isValidating |= validator.isValidating();
129     }
130
131     /**
132      * Returns the list of validators. This list is not the live list but instead
133      * is a copy of the live list that contains the same objects that the live
134      * list contains.
135      *
136      * @return The list of BaseValidatorConfig objects
137      */

138     public List JavaDoc getValidators() {
139         return new ArrayList JavaDoc(validators);
140     }
141 }
Popular Tags