1 10 11 package org.mule.components.builder; 12 13 import org.mule.config.i18n.Message; 14 import org.mule.config.i18n.Messages; 15 import org.mule.umo.UMOMessage; 16 import org.mule.util.ClassUtils; 17 18 import java.lang.reflect.Method ; 19 import java.util.List ; 20 21 28 public class ReflectionMessageBuilder extends AbstractMessageBuilder 29 { 30 31 protected String [] ignoreMethods = new String []{"equals", "getInvocationHandler"}; 33 34 public Object buildMessage(UMOMessage request, UMOMessage response) throws MessageBuilderException 35 { 36 Object master = request.getPayload(); 37 Object property = response.getPayload(); 38 List methods = null; 39 try 40 { 41 methods = ClassUtils.getSatisfiableMethods(master.getClass(), new Class []{property.getClass()}, 42 true, false, ignoreMethods); 43 } 44 catch (Exception e) 45 { 46 throw new MessageBuilderException(request, e); 47 } 48 if (methods.size() == 0) 49 { 50 throw new MessageBuilderException(new Message(Messages.NO_MATCHING_METHODS_FOR_X_ON_X, 51 property.getClass().getName(), master.getClass().getName()), request); 52 } 53 else if (methods.size() > 1) 54 { 55 throw new MessageBuilderException(new Message(Messages.TOO_MANY_MATCHING_METHODS_FOR_X_ON_X, 56 property.getClass().getName(), master.getClass().getName()), request); 57 } 58 else 59 { 60 Method m = (Method )methods.get(0); 61 try 62 { 63 m.invoke(master, 64 (property.getClass().isArray() ? (Object [])property : new Object []{property})); 65 } 66 catch (Exception e) 67 { 68 throw new MessageBuilderException(new Message(Messages.FAILED_TO_INVOKE_X, 69 m.getName() + " on " + master.getClass().getName()), request); 70 71 } 72 } 73 return master; 74 } 75 } 76 | Popular Tags |