KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.apache.avalon.framework.service.ServiceSelector;
19 import org.apache.cocoon.woody.Constants;
20 import org.apache.cocoon.woody.datatype.SelectionList;
21 import org.apache.cocoon.woody.datatype.SelectionListBuilder;
22 import org.apache.cocoon.woody.util.DomHelper;
23 import org.w3c.dom.Element JavaDoc;
24
25 /**
26  * Abstract base class for WidgetDefinitionBuilders that build widgets that have datatypes/selection lists.
27  *
28  * @version $Id: AbstractDatatypeWidgetDefinitionBuilder.java 30932 2004-07-29 17:35:38Z vgritsenko $
29  */

30 public abstract class AbstractDatatypeWidgetDefinitionBuilder extends AbstractWidgetDefinitionBuilder {
31     
32     /**
33      * @return true if a selectionlist has actually been build.
34      */

35     protected boolean buildSelectionList(Element JavaDoc widgetElement, AbstractDatatypeWidgetDefinition widget) throws Exception JavaDoc {
36         // FIXME: pass the manager to the definition as a side effect. Should be removed
37
// when definition are managed like components.
38
widget.service(this.serviceManager);
39
40         Element JavaDoc selectionListElement = DomHelper.getChildElement(widgetElement, Constants.WD_NS, "selection-list");
41         if (selectionListElement != null) {
42             // Get an appropriate list builder
43
ServiceSelector builderSelector = (ServiceSelector)this.serviceManager.lookup(SelectionListBuilder.ROLE + "Selector");
44             SelectionListBuilder builder = null;
45             try {
46                 // listType can be null, meaning we will use the default selection list
47
String JavaDoc listType = selectionListElement.getAttribute("type");
48                 if ("".equals(listType)) {
49                     listType = null;
50                 }
51
52                 builder = (SelectionListBuilder)builderSelector.select(listType);
53                 SelectionList list = builder.build(selectionListElement, widget.getDatatype());
54                 widget.setSelectionList(list);
55             } finally {
56                 if (builder != null) {
57                     builderSelector.release(builder);
58                 }
59                 this.serviceManager.release(builderSelector);
60             }
61
62             return true;
63         } else {
64             return false;
65         }
66     }
67 }
68
Popular Tags