001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.forms.formmodel;
018:
019: import java.util.Collection;
020: import java.util.Iterator;
021: import java.util.List;
022:
023: import org.apache.cocoon.forms.FormsException;
024:
025: /**
026: * The {@link AbstractContainerDefinition} corresponding to an {@link AbstractContainerWidget}.
027: *
028: * @version $Id: AbstractContainerDefinition.java 449149 2006-09-23 03:58:05Z crossley $
029: */
030: public abstract class AbstractContainerDefinition extends
031: AbstractWidgetDefinition implements ContainerDefinition {
032:
033: protected WidgetDefinitionList definitions;
034:
035: public AbstractContainerDefinition() {
036: definitions = new WidgetDefinitionList(this );
037: }
038:
039: public void createWidget(Widget parent, String id) {
040: definitions.createWidget(parent, id);
041: }
042:
043: public void createWidgets(Widget parent) {
044: definitions.createWidgets(parent);
045: }
046:
047: /**
048: * initialize this definition with the other, sort of like a copy constructor
049: */
050: public void initializeFrom(WidgetDefinition definition)
051: throws Exception {
052: super .initializeFrom(definition);
053:
054: if (!(definition instanceof AbstractContainerDefinition)) {
055: throw new FormsException("Parent definition "
056: + definition.getClass().getName()
057: + " is not an AbstractContainerDefinition.",
058: getLocation());
059: }
060:
061: AbstractContainerDefinition other = (AbstractContainerDefinition) definition;
062:
063: Iterator i = other.definitions.getWidgetDefinitions()
064: .iterator();
065: while (i.hasNext()) {
066: try {
067: WidgetDefinition def = (WidgetDefinition) i.next();
068: this .definitions.addWidgetDefinition(def);
069: } catch (DuplicateIdException e) { /* ignored */
070: }
071: }
072: }
073:
074: /**
075: * checks completeness of this definition
076: */
077: public void checkCompleteness() throws IncompletenessException {
078: super .checkCompleteness();
079: this .definitions.checkCompleteness();
080: }
081:
082: public void addWidgetDefinition(WidgetDefinition definition)
083: throws Exception, DuplicateIdException {
084: //FIXME: cannot enforce this check here as more children are added in the resolve() phase
085: //checkMutable();
086: definition.setParent(this );
087: definitions.addWidgetDefinition(definition);
088: }
089:
090: public void resolve(List parents, WidgetDefinition parent)
091: throws Exception {
092: definitions.resolve(parents, parent);
093: }
094:
095: public boolean hasWidget(String id) {
096: return definitions.hasWidget(id);
097: }
098:
099: public WidgetDefinition getWidgetDefinition(String id) {
100: return definitions.getWidgetDefinition(id);
101: }
102:
103: public Collection getWidgetDefinitions() {
104: return definitions.getWidgetDefinitions();
105: }
106: }
|