if (resultType == null)
{
throw new IllegalArgumentException(CoreMessages.objectIsNull("resultType").getMessage());
}
DataType source = DataTypeFactory.createFromObject(this);
// If no conversion is necessary, just return the payload as-is
if (resultType.isCompatibleWith(source))
{
return (T) getPayload();
}
// The transformer to execute on this message
Transformer transformer = muleContext.getRegistry().lookupTransformer(source, resultType);
if (transformer == null)
{
throw new TransformerException(CoreMessages.noTransformerFoundForMessage(source, resultType));
}
// Pass in the message itself
Object result = transformer.transform(this, encoding);
// Unless we disallow Object.class as a valid return type we need to do this extra check
if (!resultType.getType().isAssignableFrom(result.getClass()))
{
throw new TransformerException(CoreMessages.transformOnObjectNotOfSpecifiedType(resultType, result));
}
// If the payload is a stream and we've consumed it, then we should set the payload on the
// message. This is the only time this method will alter the payload on the message
if (isPayloadConsumed(source.getType()))
{
setPayload(result);
}
return (T) result;