KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > riotfamily > forms > factory > DefaultFormFactory


1 /* ***** BEGIN LICENSE BLOCK *****
2  * Version: MPL 1.1
3  * The contents of this file are subject to the Mozilla Public License Version
4  * 1.1 (the "License"); you may not use this file except in compliance with
5  * the License. You may obtain a copy of the License at
6  * http://www.mozilla.org/MPL/
7  *
8  * Software distributed under the License is distributed on an "AS IS" basis,
9  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
10  * for the specific language governing rights and limitations under the
11  * License.
12  *
13  * The Original Code is Riot.
14  *
15  * The Initial Developer of the Original Code is
16  * Neteye GmbH.
17  * Portions created by the Initial Developer are Copyright (C) 2006
18  * the Initial Developer. All Rights Reserved.
19  *
20  * Contributor(s):
21  * Felix Gnass [fgnass at neteye dot de]
22  *
23  * ***** END LICENSE BLOCK ***** */

24 package org.riotfamily.forms.factory;
25
26 import java.util.Iterator JavaDoc;
27 import java.util.LinkedList JavaDoc;
28 import java.util.List JavaDoc;
29
30 import org.riotfamily.forms.Element;
31 import org.riotfamily.forms.ElementFactory;
32 import org.riotfamily.forms.Form;
33 import org.riotfamily.forms.FormInitializer;
34 import org.springframework.validation.Validator;
35
36
37 /**
38  * Form factory used by
39  * {@link org.riotfamily.forms.factory.xml.XmlFormRepositoryDigester}.
40  * Since there are no dependencies to the xml package this class
41  * could also be useful for other custom implementations.
42  */

43 public class DefaultFormFactory implements FormFactory {
44
45     /** Class to be edited by the form */
46     private Class JavaDoc beanClass;
47
48     /** List of factories to create child elements */
49     private List JavaDoc childFactories = new LinkedList JavaDoc();
50
51     private FormInitializer initializer;
52
53     private Validator validator;
54
55     public Class JavaDoc getBeanClass() {
56         return this.beanClass;
57     }
58
59     public void setBeanClass(Class JavaDoc beanClass) {
60         this.beanClass = beanClass;
61     }
62
63     /**
64      * Adds an ElementFactory to the list of child factories.
65      */

66     public void addChildFactory(ElementFactory factory) {
67         childFactories.add(factory);
68     }
69
70     public List JavaDoc getChildFactories() {
71         return this.childFactories;
72     }
73
74     public void setInitializer(FormInitializer initializer) {
75         this.initializer = initializer;
76     }
77
78     public void setValidator(Validator validator) {
79         this.validator = validator;
80     }
81
82     public Form createForm() {
83         Form form = new Form();
84         form.setBeanClass(beanClass);
85         form.setInitializer(initializer);
86         form.setValidator(validator);
87         Iterator JavaDoc it = childFactories.iterator();
88         while (it.hasNext()) {
89             ElementFactory factory = (ElementFactory) it.next();
90             Element child = factory.createElement(null, form);
91             form.addElement(child);
92         }
93         return form;
94     }
95
96 }
97
Popular Tags