KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > forms > 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.forms.formmodel;
17
18 import org.apache.cocoon.forms.datatype.SelectionList;
19 import org.apache.cocoon.forms.util.DomHelper;
20 import org.w3c.dom.Element JavaDoc;
21
22 /**
23  * Builds {FieldDefinition}s.
24  *
25  * @version $Id: FieldDefinitionBuilder.java 327125 2005-10-21 08:52:51Z sylvain $
26  */

27 public class FieldDefinitionBuilder extends AbstractDatatypeWidgetDefinitionBuilder {
28
29     public WidgetDefinition buildWidgetDefinition(Element JavaDoc widgetElement) throws Exception JavaDoc {
30         FieldDefinition definition = new FieldDefinition();
31         setupDefinition(widgetElement, definition);
32         definition.makeImmutable();
33         return definition;
34     }
35
36     protected void setupDefinition(Element JavaDoc widgetElement, FieldDefinition definition) throws Exception JavaDoc {
37         super.setupDefinition(widgetElement, definition);
38         
39         // parse "@required"
40
if(widgetElement.hasAttribute("required"))
41             definition.setRequired(DomHelper.getAttributeAsBoolean(widgetElement, "required", false));
42         
43         SelectionList list = buildSelectionList(widgetElement, definition, "suggestion-list");
44         if (list != null) {
45             definition.setSuggestionList(list);
46         }
47     }
48 }
49
Popular Tags