01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.woody.formmodel;
18:
19: import org.apache.avalon.framework.service.ServiceSelector;
20: import org.apache.cocoon.woody.Constants;
21: import org.apache.cocoon.woody.datatype.SelectionList;
22: import org.apache.cocoon.woody.datatype.SelectionListBuilder;
23: import org.apache.cocoon.woody.util.DomHelper;
24: import org.w3c.dom.Element;
25:
26: /**
27: * Abstract base class for WidgetDefinitionBuilders that build widgets that have datatypes/selection lists.
28: *
29: * @version $Id: AbstractDatatypeWidgetDefinitionBuilder.java 433543 2006-08-22 06:22:54Z crossley $
30: */
31: public abstract class AbstractDatatypeWidgetDefinitionBuilder extends
32: AbstractWidgetDefinitionBuilder {
33:
34: /**
35: * @return true if a selectionlist has actually been build.
36: */
37: protected boolean buildSelectionList(Element widgetElement,
38: AbstractDatatypeWidgetDefinition widget) throws Exception {
39: // FIXME: pass the manager to the definition as a side effect. Should be removed
40: // when definition are managed like components.
41: widget.service(this .serviceManager);
42:
43: Element selectionListElement = DomHelper.getChildElement(
44: widgetElement, Constants.WD_NS, "selection-list");
45: if (selectionListElement != null) {
46: // Get an appropriate list builder
47: ServiceSelector builderSelector = (ServiceSelector) this .serviceManager
48: .lookup(SelectionListBuilder.ROLE + "Selector");
49: SelectionListBuilder builder = null;
50: try {
51: // listType can be null, meaning we will use the default selection list
52: String listType = selectionListElement
53: .getAttribute("type");
54: if ("".equals(listType)) {
55: listType = null;
56: }
57:
58: builder = (SelectionListBuilder) builderSelector
59: .select(listType);
60: SelectionList list = builder.build(
61: selectionListElement, widget.getDatatype());
62: widget.setSelectionList(list);
63: } finally {
64: if (builder != null) {
65: builderSelector.release(builder);
66: }
67: this .serviceManager.release(builderSelector);
68: }
69:
70: return true;
71: } else {
72: return false;
73: }
74: }
75: }
|