KickJava   Java API By Example, From Geeks To Geeks.

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


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.forms.formmodel;
17
18 import java.util.Collection JavaDoc;
19 import java.util.Iterator JavaDoc;
20 import java.util.List JavaDoc;
21
22 /**
23  * The {@link AbstractContainerDefinition} corresponding to an {@link AbstractContainerWidget}.
24  *
25  * @version $Id: AbstractContainerDefinition.java 289538 2005-09-16 13:46:22Z sylvain $
26  */

27 public abstract class AbstractContainerDefinition
28         extends AbstractWidgetDefinition implements ContainerDefinition {
29     protected WidgetDefinitionList definitions;
30
31     public AbstractContainerDefinition() {
32         definitions = new WidgetDefinitionList(this);
33     }
34
35     public void createWidget(Widget parent, String JavaDoc id) {
36         definitions.createWidget(parent, id);
37     }
38
39     public void createWidgets(Widget parent) {
40         definitions.createWidgets(parent);
41     }
42     
43     /**
44      * initialize this definition with the other, sort of like a copy constructor
45      */

46     public void initializeFrom(WidgetDefinition definition) throws Exception JavaDoc {
47         super.initializeFrom(definition);
48         
49         if(definition instanceof AbstractContainerDefinition) {
50             AbstractContainerDefinition other = (AbstractContainerDefinition)definition;
51             
52             Iterator JavaDoc otherwidgets = other.definitions.getWidgetDefinitions().iterator();
53             while(otherwidgets.hasNext()) {
54                 try {
55                     WidgetDefinition def = (WidgetDefinition)otherwidgets.next();
56                     this.definitions.addWidgetDefinition(def);
57                 } catch(DuplicateIdException ignore) {}
58             }
59         } else {
60             throw new Exception JavaDoc("Definition to inherit from is not of the right type! (at "+getLocation()+")");
61         }
62     }
63     
64     /**
65      * checks completeness of this definition
66      */

67     public void checkCompleteness() throws IncompletenessException {
68         super.checkCompleteness();
69         this.definitions.checkCompleteness();
70     }
71
72     public void addWidgetDefinition(WidgetDefinition definition) throws Exception JavaDoc, DuplicateIdException {
73         //FIXME: cannot enforce this check here as more children are added in the resolve() phase
74
//checkMutable();
75
definition.setParent(this);
76         definitions.addWidgetDefinition(definition);
77     }
78
79     public void resolve(List JavaDoc parents, WidgetDefinition parent) throws Exception JavaDoc {
80         definitions.resolve(parents, parent);
81     }
82
83     public boolean hasWidget(String JavaDoc id) {
84         return definitions.hasWidget(id);
85     }
86
87     public WidgetDefinition getWidgetDefinition(String JavaDoc id) {
88         return definitions.getWidgetDefinition(id);
89     }
90
91     public Collection JavaDoc getWidgetDefinitions() {
92         return definitions.getWidgetDefinitions();
93     }
94 }
95
Popular Tags