Skip to content

Commit

Permalink
Added an invoke expression that will invoke a method on an object. Th…
Browse files Browse the repository at this point in the history
…is is ibeans specific and can be used to invoke WS from generated classes

git-svn-id: https://svn.codehaus.org/mule/branches/mule-3.x@19719 bf997673-6b11-0410-b953-e057580c5b09
  • Loading branch information
rossmason committed Sep 25, 2010
1 parent c1f88f5 commit 5dfd8fd
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* $Id$
* --------------------------------------------------------------------------------------
* Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
*
* The software in this package is published under the terms of the CPAL v1.0
* license, a copy of which has been included with this distribution in the
* LICENSE.txt file.
*/
package org.mule.module.ibeans.config;

import org.mule.api.MuleMessage;
import org.mule.api.expression.ExpressionEvaluator;
import org.mule.api.expression.ExpressionRuntimeException;
import org.mule.config.i18n.CoreMessages;

import java.util.Map;

import org.apache.commons.beanutils.MethodUtils;

/**
* TODO
*/
public class InvokeExpressionEvaluator implements ExpressionEvaluator
{
public Object evaluate(String expression, MuleMessage message)
{
int i = expression.indexOf(".");
String property;
String method;
if(i > -1)
{
property = expression.substring(0, i);
method = expression.substring(i+1);
}
else
{
throw new IllegalArgumentException();
}
Object[] args;

if(message.getPayload() instanceof Map)
{
args = ((Map)message.getPayload()).values().toArray(new Object[]{});
}
else if(message.getPayload().getClass().isArray())
{
args = (Object[]) message.getPayload();
}
else
{
args = new Object[]{message.getPayload()};
}
Object o = message.getInvocationProperty(property,null);
if(o!=null)
{
try
{
return MethodUtils.invokeMethod(o, method, args);
}
catch (Exception e)
{
throw new ExpressionRuntimeException(CoreMessages.failedToInvoke(expression), e);
}
}
else
{
throw new ExpressionRuntimeException(CoreMessages.expressionMalformed(expression, getName()));
}
}

public void setName(String name)
{
throw new UnsupportedOperationException("setName");
}

public String getName()
{
return "invoke";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ _integrationBeanProcessor=org.mule.module.ibeans.config.IntegrationBeanAnnotated
_mockIntegrationBeanProcessor=org.mule.module.ibeans.config.MockIntegrationBeansAnnotationProcessor
_callAnnotationParser=org.mule.module.ibeans.config.CallAnnotationParser
_ibeansLoader=org.mule.module.ibeans.config.IBeansLoader
_invokeExpressionEvaluator=org.mule.module.ibeans.config.InvokeExpressionEvaluator

0 comments on commit 5dfd8fd

Please sign in to comment.