forked from genjosanzo/mule
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added an invoke expression that will invoke a method on an object. Th…
…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
Showing
2 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
modules/ibeans/src/main/java/org/mule/module/ibeans/config/InvokeExpressionEvaluator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters