@SuppressWarnings("unchecked")
protected static <T> T getPropertyInternal(String expression, PropertyScope scope, boolean parseScope, MuleMessage msg, Class<T> 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<String, Object> props = new HashMap<String, Object>();
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<Object> values = new ArrayList<Object>();
for (String name : msg.getPropertyNames(scope))
{
if (filter.accept(name))
{
values.add(msg.getProperty(name, scope));
}
}
return (T) returnList(values, scope);
}
else
{
//TODO i18n
throw new IllegalArgumentException("Type specified is not a collection type but '" + ALL_ARGUMENT + "' was specified for all properties. Type is: " + type);
}
}
else if (Map.class.isAssignableFrom(type))
{
String[] names = expression.split(DELIM);
Map<String, Object> props = new HashMap<String, Object>();
for (String name : names)
{
boolean required = true;
name = name.trim();
PropertyScope entryScope = scope;
if (parseScope)
{
entryScope = getScope(name);
if (entryScope != null)
{
// cut-off leading scope and separator
name = name.substring(entryScope.getScopeName().length() + 1);
}
else
{
entryScope = scope;
}
}
if (name.endsWith(OPTIONAL_ARGUMENT))
{
name = name.substring(0, name.length() - OPTIONAL_ARGUMENT.length());
required = false;
}
Object value = msg.getProperty(name, entryScope);
if (value == null && required)
{
throw new RequiredValueException(CoreMessages.expressionEvaluatorReturnedNull("headers", entryScope.getScopeName() + ":" + name));
}
else if (value != null)
{
props.put(name, value);
}
}
return (T) returnMap(props, scope);
}
else if (List.class.isAssignableFrom(type))
{
String[] names = expression.split(DELIM);
List<Object> values = new ArrayList<Object>();
for (String name : names)
{
boolean required = true;
name = name.trim();
PropertyScope itemScope = scope;
if (parseScope)
{
itemScope = getScope(name);
if (itemScope != null)
{
// cut-off leading scope and separator
name = name.substring(itemScope.getScopeName().length() + 1);
}
else
{
itemScope = scope;
}
}
if (name.endsWith(OPTIONAL_ARGUMENT))
{
name = name.substring(0, name.length() - OPTIONAL_ARGUMENT.length());
required = false;
}
name = name.trim();
Object value = msg.getProperty(name, itemScope);
if (value == null && required)
{
throw new RequiredValueException(CoreMessages.expressionEvaluatorReturnedNull("headers-list", itemScope.getScopeName() + ":" + name));
}
else if (value != null)
{
values.add(value);
}