KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright 1999-2005 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.FormsConstants;
19 import org.apache.cocoon.forms.util.DomHelper;
20 import org.w3c.dom.Element JavaDoc;
21
22 /**
23  * Abstract base class for container widget builders.
24  *
25  * @version $Id: AbstractContainerDefinitionBuilder.java 327169 2005-10-21 13:04:31Z sylvain $
26  */

27
28 public abstract class AbstractContainerDefinitionBuilder extends AbstractWidgetDefinitionBuilder {
29
30     protected void setupContainer(Element JavaDoc element, String JavaDoc widgetsElementName, AbstractContainerDefinition definition) throws Exception JavaDoc {
31
32         Element JavaDoc widgetsElement = DomHelper.getChildElement(element, FormsConstants.DEFINITION_NS, widgetsElementName, false);
33
34         // if its not there, ignore it. Just means that there are no new widgets
35
if (widgetsElement == null)
36             return;
37
38         // All child elements of the widgets element are widgets
39
Element JavaDoc[] widgetElements = DomHelper.getChildElements(widgetsElement, FormsConstants.DEFINITION_NS);
40         WidgetDefinitionBuilderContext oldContext = this.context;
41
42         for (int i = 0; i < widgetElements.length; i++) {
43             Element JavaDoc widgetElement = widgetElements[i];
44
45             this.context = new WidgetDefinitionBuilderContext(oldContext);
46             this.context.setSuperDefinition(null);
47
48             String JavaDoc newId = DomHelper.getAttribute(widgetElement, "extends", null);
49             WidgetDefinition def = null;
50             if (newId != null) {
51                 if ((def = this.context.getLocalLibrary().getDefinition(newId)) != null)
52                     this.context.setSuperDefinition(def);
53                 else if ((def = definition.getWidgetDefinition(newId)) != null)
54                     this.context.setSuperDefinition(def);
55                 // throw new Exception("Widget to inherit from ("+newId+") not
56
// found! (at "+DomHelper.getLocation(element)+")");
57
}
58
59             WidgetDefinition widgetDefinition = buildAnotherWidgetDefinition(widgetElement);
60
61             if (widgetDefinition != null)
62                 definition.addWidgetDefinition(widgetDefinition);
63
64         }
65
66         this.context = oldContext;
67     }
68 }
69
Popular Tags