1 16 package org.apache.cocoon.woody.binding; 17 18 import java.lang.reflect.Method ; 19 20 import org.apache.avalon.framework.CascadingRuntimeException; 21 import org.apache.cocoon.woody.formmodel.Widget; 22 import org.apache.commons.jxpath.JXPathContext; 23 24 35 public class InsertBeanJXPathBinding extends JXPathBindingBase { 36 37 private final String className; 38 private final String addMethodName; 39 40 43 public InsertBeanJXPathBinding(JXPathBindingBuilderBase.CommonAttributes commonAtts, String className, String addMethod) { 44 super(commonAtts); 45 this.className = className; 46 this.addMethodName = addMethod; 47 } 48 49 52 public void doLoad(Widget frmModel, JXPathContext jxpc) { 53 } 55 56 62 public void doSave(Widget frmModel, JXPathContext jxpc) throws BindingException { 63 try { 64 Object parent = jxpc.getContextBean(); 65 Object [] args = new Object [1]; 66 Class [] argTypes = new Class [1]; 67 68 argTypes[0] = Class.forName(this.className); 70 args[0] = argTypes[0].newInstance(); 71 72 Method addMethod = 74 parent.getClass().getMethod(this.addMethodName, argTypes); 75 76 addMethod.invoke(parent, args); 78 79 if (getLogger().isDebugEnabled()) 80 getLogger().debug("InsertBean performed."); 81 } catch (Exception e) { 82 throw new CascadingRuntimeException("InsertBean failed.", e); 83 } 84 85 } 115 116 public String toString() { 117 return "InsertBeanJXPathBinding [for class " + this.className + " to addMethod " + this.addMethodName + "]"; 118 } 119 120 } 121 | Popular Tags |