KickJava   Java API By Example, From Geeks To Geeks.

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


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.ArrayList JavaDoc;
19 import java.util.List JavaDoc;
20
21 import org.apache.cocoon.forms.event.ProcessingPhaseEvent;
22 import org.apache.cocoon.forms.event.ProcessingPhaseListener;
23 import org.apache.cocoon.forms.event.WidgetEventMulticaster;
24 import org.apache.cocoon.forms.formmodel.library.Library;
25 import org.apache.cocoon.forms.formmodel.library.LibraryManager;
26 import org.apache.commons.lang.StringUtils;
27
28 /**
29  * The {@link WidgetDefinition} part of a Form widget, see {@link Form} for more information.
30  *
31  * @version $Id: FormDefinition.java 291005 2005-09-22 19:08:29Z sylvain $
32  */

33 public class FormDefinition extends AbstractContainerDefinition {
34     private ProcessingPhaseListener listener;
35     
36     private Library localLibrary = null;
37
38     public FormDefinition(LibraryManager libraryManager) {
39         super();
40         localLibrary = libraryManager.getNewLibrary();
41     }
42     
43     public Library getLocalLibrary() {
44         return localLibrary;
45     }
46
47     public void resolve() throws Exception JavaDoc {
48         List JavaDoc parents = new ArrayList JavaDoc();
49         parents.add(this);
50         resolve(parents, this);
51         
52         // TODO: test if this actually gets called!
53
checkCompleteness();
54     }
55
56     public Widget createInstance() {
57         Form form = new Form(this);
58         createWidgets(form);
59         return form;
60     }
61     
62     public void addProcessingPhaseListener(ProcessingPhaseListener listener) {
63         this.listener = WidgetEventMulticaster.add(this.listener, listener);
64     }
65     
66     public boolean hasProcessingPhaseListeners() {
67         return this.listener != null;
68     }
69     
70     public void fireEvent(ProcessingPhaseEvent event) {
71         if (this.listener != null) {
72             this.listener.phaseEnded(event);
73         }
74     }
75     
76     public void addWidgetDefinition(WidgetDefinition definition) throws Exception JavaDoc, DuplicateIdException {
77         // Check that no child is named "submit" if this form has no id. This causes some weird behaviour
78
// in HTML as it collides with the submit() function on the <form> element...
79
if ("submit".equals(definition.getId()) && StringUtils.isEmpty(this.getId())) {
80             throw new IllegalArgumentException JavaDoc("Top-level widgets should not be named 'submit' to avoid problems "
81                     + " with HTML <form> elements, at " + definition.getLocation());
82         }
83
84         super.addWidgetDefinition(definition);
85     }
86 }
87
Popular Tags