KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > forms > formmodel > BooleanFieldDefinitionBuilder


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 java.util.Iterator JavaDoc;
19
20 import org.apache.cocoon.forms.FormsConstants;
21 import org.apache.cocoon.forms.event.ValueChangedListener;
22 import org.apache.cocoon.forms.util.DomHelper;
23 import org.w3c.dom.Element JavaDoc;
24
25 /**
26  * Builds {@link BooleanFieldDefinition}s.
27  *
28  * @version $Id: BooleanFieldDefinitionBuilder.java 326838 2005-10-20 06:26:53Z sylvain $
29  */

30 public final class BooleanFieldDefinitionBuilder extends AbstractWidgetDefinitionBuilder {
31     public WidgetDefinition buildWidgetDefinition(Element JavaDoc widgetElement) throws Exception JavaDoc {
32         
33         BooleanFieldDefinition definition = new BooleanFieldDefinition();
34         
35         setupDefinition(widgetElement, definition);
36         setDisplayData(widgetElement, definition);
37         Iterator JavaDoc iter = buildEventListeners(widgetElement, "on-value-changed", ValueChangedListener.class).iterator();
38         while (iter.hasNext()) {
39             definition.addValueChangedListener((ValueChangedListener)iter.next());
40         }
41
42         // Initial value
43
Element JavaDoc initialValueElement = DomHelper.getChildElement(widgetElement, FormsConstants.DEFINITION_NS, "initial-value", false);
44         if (initialValueElement != null) {
45             Boolean JavaDoc initialValue = Boolean.valueOf(DomHelper.getElementText(initialValueElement));
46             definition.setInitialValue(initialValue);
47         }
48         
49         // Parameter value for true
50
Element JavaDoc trueParamElement = DomHelper.getChildElement(widgetElement, FormsConstants.DEFINITION_NS, "true-param-value", false);
51         if (trueParamElement != null) {
52             definition.setTrueParamValue(DomHelper.getElementText(trueParamElement));
53         }
54
55         definition.makeImmutable();
56         return definition;
57     }
58 }
59
Popular Tags