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.forms.formmodel;
18:
19: import org.apache.cocoon.forms.FormsConstants;
20: import org.apache.cocoon.forms.util.DomHelper;
21: import org.w3c.dom.Element;
22:
23: /**
24: * Abstract base class for container widget builders.
25: *
26: * @version $Id: AbstractContainerDefinitionBuilder.java 449149 2006-09-23 03:58:05Z crossley $
27: */
28:
29: public abstract class AbstractContainerDefinitionBuilder extends
30: AbstractWidgetDefinitionBuilder {
31:
32: protected void setupContainer(Element element,
33: String widgetsElementName,
34: AbstractContainerDefinition definition) throws Exception {
35:
36: Element widgetsElement = DomHelper
37: .getChildElement(element, FormsConstants.DEFINITION_NS,
38: widgetsElementName, false);
39:
40: // if its not there, ignore it. Just means that there are no new widgets
41: if (widgetsElement == null) {
42: return;
43: }
44:
45: // All child elements of the widgets element are widgets
46: Element[] widgetElements = DomHelper.getChildElements(
47: widgetsElement, FormsConstants.DEFINITION_NS);
48: WidgetDefinitionBuilderContext oldContext = this .context;
49:
50: for (int i = 0; i < widgetElements.length; i++) {
51: Element widgetElement = widgetElements[i];
52:
53: this .context = new WidgetDefinitionBuilderContext(
54: oldContext);
55: this .context.setSuperDefinition(null);
56:
57: String newId = DomHelper.getAttribute(widgetElement,
58: "extends", null);
59: WidgetDefinition def;
60: if (newId != null) {
61: if ((def = this .context.getLocalLibrary()
62: .getDefinition(newId)) != null) {
63: this .context.setSuperDefinition(def);
64: } else if ((def = definition.getWidgetDefinition(newId)) != null) {
65: this .context.setSuperDefinition(def);
66: }
67: // throw new FormsException("Widget to inherit from ("+newId+") not
68: // found!", DomHelper.getLocationObject(element));
69: }
70:
71: WidgetDefinition widgetDefinition = buildAnotherWidgetDefinition(widgetElement);
72: if (widgetDefinition != null) {
73: definition.addWidgetDefinition(widgetDefinition);
74: }
75:
76: }
77:
78: this.context = oldContext;
79: }
80: }
|