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