KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > woody > formmodel > FieldDefinitionBuilder


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
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.apache.cocoon.woody.formmodel;
17
18 import java.util.Iterator JavaDoc;
19
20 import org.apache.cocoon.woody.Constants;
21 import org.apache.cocoon.woody.datatype.Datatype;
22 import org.apache.cocoon.woody.event.ValueChangedListener;
23 import org.apache.cocoon.woody.util.DomHelper;
24 import org.w3c.dom.Element JavaDoc;
25
26 /**
27  * Builds {FieldDefinition}s.
28  *
29  * @version $Id: FieldDefinitionBuilder.java 30932 2004-07-29 17:35:38Z vgritsenko $
30  */

31 public class FieldDefinitionBuilder extends AbstractDatatypeWidgetDefinitionBuilder {
32
33     public WidgetDefinition buildWidgetDefinition(Element JavaDoc widgetElement) throws Exception JavaDoc {
34         FieldDefinition fieldDefinition = new FieldDefinition();
35         buildWidgetDefinition(fieldDefinition, widgetElement);
36         return fieldDefinition;
37     }
38
39     protected void buildWidgetDefinition(FieldDefinition fieldDefinition, Element JavaDoc widgetElement) throws Exception JavaDoc {
40         setLocation(widgetElement, fieldDefinition);
41         setId(widgetElement, fieldDefinition);
42
43         Element JavaDoc datatypeElement = DomHelper.getChildElement(widgetElement, Constants.WD_NS, "datatype");
44         if (datatypeElement == null) {
45             throw new Exception JavaDoc("A nested datatype element is required for the widget at " +
46                                 DomHelper.getLocation(widgetElement));
47         }
48
49         Datatype datatype = datatypeManager.createDatatype(datatypeElement, false);
50         fieldDefinition.setDatatype(datatype);
51
52         buildSelectionList(widgetElement, fieldDefinition);
53
54         Iterator JavaDoc iter = buildEventListeners(widgetElement, "on-value-changed", ValueChangedListener.class).iterator();
55         while (iter.hasNext()) {
56             fieldDefinition.addValueChangedListener((ValueChangedListener)iter.next());
57         }
58
59         setDisplayData(widgetElement, fieldDefinition);
60         setValidators(widgetElement, fieldDefinition);
61
62         boolean required = DomHelper.getAttributeAsBoolean(widgetElement, "required", false);
63         fieldDefinition.setRequired(required);
64     }
65 }
66
Popular Tags