Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* $Id: ExpressionUtils.java 20813 2010-12-21 11:37:48Z dirk.olmes $
* --------------------------------------------------------------------------------------
* Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.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.expression;
import org.mule.api.MuleMessage;
import org.mule.api.expression.RequiredValueException;
import org.mule.api.transport.PropertyScope;
import org.mule.config.i18n.CoreMessages;
import org.mule.routing.filters.WildcardFilter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.mule.expression.ExpressionConstants.ALL_ARGUMENT;
import static org.mule.expression.ExpressionConstants.DELIM;
import static org.mule.expression.ExpressionConstants.OPTIONAL_ARGUMENT;
/**
* Used by the different header expression evaluators to read message properties, honuouring scope and return type
*/
public final class ExpressionUtils
{
private ExpressionUtils()
{
// don't instantiate
}
/**
* Gets a property or map/list of properties specific by an expression supporting multiple return types as well as all and optional modifiers
*
* Handles scope-aware expressions like "#[header:INBOUND:foo]
* @param expression the header name to evaluate. this can be prefixed with a message scope such as INBOUND, OUTBOUND
* or INVOCATION scope. If no scope is defined the default scope is OUTBOUND
*
* @param msg the message to evaluate on
*/
public static Object getPropertyWithScope(String expression, MuleMessage msg)
{
return getPropertyWithScope(expression, msg, Object.class);
}
/**
* Gets a property or map/list of properties specific by an expression supporting multiple return types as well as all and optional modifiers
*
* Handles scope-aware expressions like "#[header:INBOUND:foo]
* @param expression the header name to evaluate. this can be prefixed with a message scope such as INBOUND, OUTBOUND
* or INVOCATION scope. If no scope is defined the default scope is OUTBOUND
*
* @param msg the message to evaluate on
* @param type the expected return type for this evaluation
* @return an object of type 'type' corresponding to the message header requested or null if the header was not on
* the message in the specified scope
*/
public static T getPropertyWithScope(String expression, MuleMessage msg, Class type)
{
return getPropertyInternal(expression, PropertyScope.OUTBOUND, true, msg, type);
}
/**
* Gets a property or map/list of properties specified by an expression supporting
* multiple return types as well as all and optional modifiers.
*/
public static Object getProperty(String expression, PropertyScope scope, MuleMessage msg)
{
return getProperty(expression, scope, msg, Object.class);
}
/**
* Gets a property or map/list of properties specific by an expression supporting multiple return types as well as all and optional modifiers
*
* @param msg the message to evaluate on
* @param type the expected return type for this evaluation
* @return an object of type 'type' corresponding to the message header requested or null if the header was not on
* the message in the specified scope
*/
public static T getProperty(String expression, PropertyScope scope, MuleMessage msg, Class type)
{
return getPropertyInternal(expression, scope, false, msg, type);
}
/**
* Obtains a property or map/list of properties from a message using an expression that specifies which property or properties to evaluate.
* This method can be used default scope
* @param expression the expression used to evaluator the message
* @param scope the scope to be used when obtaining a property. This is the default if parseScopes is true.
* @param parseScope should scope we parsed from expression string. When true the scope acts as a default.
* @param msg the message to be evaluated
* @param type return type expected
* @return property or list/map of evaluated property values
*/
@SuppressWarnings("unchecked")
protected static T getPropertyInternal(String expression, PropertyScope scope, boolean parseScope, MuleMessage msg, Class type)
{
if (parseScope)
{
PropertyScope tempScope = getScope(expression);
if (tempScope != null)
{
// cut-off leading scope and separator
expression = expression.substring(tempScope.getScopeName().length() + 1);
scope = tempScope;
}
}
if (expression.contains(ALL_ARGUMENT))
{
WildcardFilter filter = new WildcardFilter(expression);
if (Map.class.isAssignableFrom(type))
{
Map props = new HashMap();
for (String name : msg.getPropertyNames(scope))
{
if (filter.accept(name))
{
props.put(name, msg.getProperty(name, scope));
}
}
return (T) returnMap(props, scope);
}
else if (List.class.isAssignableFrom(type))
{
List