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