Coverage Report - org.mule.module.ibeans.config.InvokeExpressionEvaluator
 
Classes in this File Line Coverage Branch Coverage Complexity
InvokeExpressionEvaluator
0%
0/19
0%
0/8
4.333
 
 1  
 /*
 2  
  * $Id: InvokeExpressionEvaluator.java 20320 2010-11-24 15:03:31Z dfeist $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 9  
  */
 10  
 package org.mule.module.ibeans.config;
 11  
 
 12  
 import org.mule.api.MuleMessage;
 13  
 import org.mule.api.expression.ExpressionEvaluator;
 14  
 import org.mule.api.expression.ExpressionRuntimeException;
 15  
 import org.mule.config.i18n.CoreMessages;
 16  
 
 17  
 import java.util.Map;
 18  
 
 19  
 import org.apache.commons.beanutils.MethodUtils;
 20  
 
 21  
 /**
 22  
  * TODO
 23  
  */
 24  0
 public class InvokeExpressionEvaluator implements ExpressionEvaluator
 25  
 {
 26  
     public Object evaluate(String expression, MuleMessage message)
 27  
     {
 28  0
         int i = expression.indexOf(".");
 29  
         String property;
 30  
         String method;
 31  0
         if(i > -1)
 32  
         {
 33  0
             property = expression.substring(0, i);
 34  0
             method = expression.substring(i+1);
 35  
         }
 36  
         else
 37  
         {
 38  0
             throw new IllegalArgumentException();
 39  
         }
 40  
         Object[] args;
 41  
 
 42  0
         if(message.getPayload() instanceof Map)
 43  
         {
 44  0
             args = ((Map)message.getPayload()).values().toArray(new Object[]{});
 45  
         }
 46  0
         else if(message.getPayload().getClass().isArray())
 47  
         {
 48  0
             args = (Object[]) message.getPayload();
 49  
         }
 50  
         else
 51  
         {
 52  0
             args = new Object[]{message.getPayload()};
 53  
         }
 54  0
         Object o = message.getInvocationProperty(property,null);
 55  0
         if(o!=null)
 56  
         {
 57  
             try
 58  
             {
 59  0
                 return MethodUtils.invokeMethod(o, method, args);
 60  
             }
 61  0
             catch (Exception e)
 62  
             {
 63  0
                 throw new ExpressionRuntimeException(CoreMessages.failedToInvoke(expression), e);
 64  
             }
 65  
         }
 66  
         else
 67  
         {
 68  0
             throw new ExpressionRuntimeException(CoreMessages.expressionMalformed(expression, getName()));
 69  
         }
 70  
     }
 71  
 
 72  
     public void setName(String name)
 73  
     {
 74  0
         throw new UnsupportedOperationException("setName");
 75  
     }
 76  
 
 77  
     public String getName()
 78  
     {
 79  0
         return "invoke";
 80  
     }
 81  
 }