1 16 package org.apache.cocoon.forms.binding; 17 18 import java.lang.reflect.Method ; 19 20 import org.apache.avalon.framework.CascadingRuntimeException; 21 import org.apache.cocoon.forms.formmodel.Widget; 22 import org.apache.commons.jxpath.JXPathContext; 23 24 36 public class InsertBeanJXPathBinding extends JXPathBindingBase { 37 38 private final String className; 39 private final String addMethodName; 40 41 44 public InsertBeanJXPathBinding(JXPathBindingBuilderBase.CommonAttributes commonAtts, String className, String addMethod) { 45 super(commonAtts); 46 this.className = className; 47 this.addMethodName = addMethod; 48 } 49 50 public String getClassName() { return className; } 51 public String getAddMethodName() { return addMethodName; } 52 53 56 public void doLoad(Widget frmModel, JXPathContext jxpc) { 57 } 59 60 67 public void doSave(Widget frmModel, JXPathContext jxpc) throws BindingException { 68 try { 69 Object parent = jxpc.getContextBean(); 70 Object [] args = new Object [1]; 71 Class [] argTypes = new Class [1]; 72 73 if(this.className != null) { 75 argTypes[0] = Class.forName(this.className); 76 args[0] = argTypes[0].newInstance(); 77 } else { 78 argTypes = null; 79 args = null; 80 } 81 82 Method addMethod = 84 parent.getClass().getMethod(this.addMethodName, argTypes); 85 86 addMethod.invoke(parent, args); 88 89 if (getLogger().isDebugEnabled()) 90 getLogger().debug("InsertBean performed."); 91 } catch (Exception e) { 92 throw new CascadingRuntimeException("InsertBean failed.", e); 93 } 94 95 } 125 126 public String toString() { 127 return "InsertBeanJXPathBinding [for class " + this.className + " to addMethod " + this.addMethodName + "]"; 128 } 129 130 } 131 | Popular Tags |