1 16 package org.apache.cocoon.forms.formmodel; 17 18 import java.util.ArrayList ; 19 import java.util.List ; 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 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 { 48 List parents = new ArrayList (); 49 parents.add(this); 50 resolve(parents, this); 51 52 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 , DuplicateIdException { 77 if ("submit".equals(definition.getId()) && StringUtils.isEmpty(this.getId())) { 80 throw new IllegalArgumentException ("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 |