1 16 package org.apache.cocoon.woody.formmodel; 17 18 import java.util.Locale ; 19 20 import org.apache.cocoon.woody.FormContext; 21 import org.xml.sax.ContentHandler ; 22 import org.xml.sax.SAXException ; 23 24 34 public class Union extends AbstractContainerWidget { 35 private static final String ELEMENT = "field"; 36 private Widget caseWidget; 37 38 public Union(UnionDefinition definition) { 39 super(definition); 40 setLocation(definition.getLocation()); 41 } 44 45 48 public void setParent(Widget widget) { 49 super.setParent(widget); 50 resolve(); 51 } 52 53 public void resolve() { 57 String caseWidgetId = ((UnionDefinition)definition).getCaseWidgetId(); 58 caseWidget = getParent().getWidget(caseWidgetId); 59 } 60 61 public String getElementName() { 62 return ELEMENT; 63 } 64 65 public Object getValue() { 66 return caseWidget.getValue(); 67 } 68 69 public void readFromRequest(FormContext formContext) { 70 caseWidget.readFromRequest(formContext); 72 Widget widget; 73 String value = (String )getValue(); 75 if (value != null && !value.equals("")) 76 if ((widget = getWidget(value)) != null) 77 widget.readFromRequest(formContext); 78 79 } 82 83 public boolean validate(FormContext formContext) { 85 Widget widget; 86 boolean valid = true; 87 String value = (String )getValue(); 89 if (value != null && !value.equals("")) 90 if ((widget = getWidget(value)) != null) 91 valid = valid & widget.validate(formContext); 92 return valid; 93 } 94 95 public Widget getWidget(String id) { 96 if (!widgets.hasWidget(id) && ((ContainerDefinition)definition).hasWidget(id)) 97 ((ContainerDefinition)definition).createWidget(this, id); 98 return super.getWidget(id); 99 } 100 101 public void generateItemsSaxFragment(ContentHandler contentHandler, Locale locale) throws SAXException { 103 } 105 106 public void generateSaxFragment(ContentHandler contentHandler, Locale locale) throws SAXException { 107 generateSaxFragment(contentHandler, locale, ELEMENT); 108 } 109 } 110 | Popular Tags |