1 16 package org.apache.cocoon.forms.binding; 17 18 import org.apache.cocoon.forms.formmodel.Union; 19 import org.apache.cocoon.forms.formmodel.Widget; 20 import org.apache.commons.jxpath.JXPathContext; 21 22 33 public class UnionJXPathBinding extends ComposedJXPathBindingBase { 34 35 private final String xpath; 36 37 private final String widgetId; 38 39 46 public UnionJXPathBinding(JXPathBindingBuilderBase.CommonAttributes commonAtts, String widgetId, String xpath, JXPathBindingBase[] childBindings) { 47 super(commonAtts, childBindings); 48 this.widgetId = widgetId; 49 this.xpath = xpath; 50 } 51 52 public String getXPath() { return xpath; } 53 public String getId() { return widgetId; } 54 55 60 public void doLoad(Widget frmModel, JXPathContext jxpc) throws BindingException { 61 Widget widget = selectWidget(frmModel, this.widgetId); 62 JXPathContext subContext = jxpc.getRelativeContext(jxpc.getPointer(this.xpath)); 63 if (!(widget instanceof Union)) 64 throw new RuntimeException ("Binding: Expected Union widget, but received class: \"" + 65 widget.getClass().getName() + "\"."); 66 Union unionWidget = (Union)widget; 67 Binding[] subBindings = getChildBindings(); 68 if (subBindings != null) { 69 int size = subBindings.length; 70 for (int i = 0; i < size; i++) { 71 subBindings[i].loadFormFromModel(unionWidget, subContext); 72 } 73 } 74 if (getLogger().isDebugEnabled()) { 75 getLogger().debug("done loading " + toString()); 76 } 77 } 78 79 84 public void doSave(Widget frmModel, JXPathContext jxpc) throws BindingException { 85 Union unionWidget = (Union)selectWidget(frmModel, this.widgetId); 86 JXPathContext subContext = jxpc.getRelativeContext(jxpc.getPointer(this.xpath)); 87 Binding[] subBindings = getChildBindings(); 88 if (subBindings != null) { 89 int size = subBindings.length; 90 for (int i = 0; i < size; i++) { 91 subBindings[i].saveFormToModel(unionWidget, subContext); 92 } 93 } 94 if (getLogger().isDebugEnabled()) { 95 getLogger().debug("done saving " + toString()); 96 } 97 } 98 99 public String toString() { 100 return "UnionJXPathBinding [widget=" + this.widgetId + ", xpath=" + this.xpath + "]"; 101 } 102 } 103 | Popular Tags |