1 package org.jbpm.instantiation; 2 3 import java.lang.reflect.*; 4 import org.apache.commons.logging.*; 5 import org.dom4j.*; 6 7 public class BeanInstantiator extends FieldInstantiator implements Instantiator { 8 9 protected void setPropertyValue(Class clazz, Object newInstance, String propertyName, Element propertyElement) { 10 try { 11 String setterMethodName = "set"+propertyName.substring(0,1).toUpperCase()+propertyName.substring(1); 13 14 Method[] methods = clazz.getDeclaredMethods(); 16 Method method = null; 17 Class propertyType = null; 18 for( int i=0; ( (i<methods.length) 19 && (method==null) ); i++) { 20 if ( (setterMethodName.equals(methods[i].getName())) 21 && (methods[i].getParameterTypes()!=null) 22 && (methods[i].getParameterTypes().length==1) ) { 23 method = methods[i]; 24 propertyType = methods[i].getParameterTypes()[0]; 25 } 26 } 27 28 if (method!=null) { 30 method.setAccessible(true); 32 method.invoke(newInstance, new Object []{ getValue(propertyType, propertyElement) }); 34 } else { 35 log.error( "couldn't set property '"+propertyName+"' to value '"+propertyElement.asXML()+"'" ); 36 } 37 } catch (Exception e) { 38 log.error( "couldn't parse property '"+propertyName+"' to value '"+propertyElement.asXML()+"'", e ); 39 } 40 } 41 42 private static final Log log = LogFactory.getLog(BeanInstantiator.class); 43 } 44 45 | Popular Tags |