MuleEvent result;
boolean matchfound = false;
for (Iterator<MatchableMessageProcessor> iterator = matchableRoutes.iterator(); iterator.hasNext();)
{
MatchableMessageProcessor outboundRouter = iterator.next();
final MuleEvent eventToRoute;
boolean copyEvent = false;
// Create copy of message for router 1..n-1 if matchAll="true" or if
// routers require copy because it may mutate payload before match is
// chosen
if (iterator.hasNext())
{
if (isMatchAll())
{
copyEvent = true;
}
else if (outboundRouter instanceof TransformingMatchable)
{
copyEvent = ((TransformingMatchable) outboundRouter).isTransformBeforeMatch();
}
}
if (copyEvent)
{
if (((DefaultMuleMessage) message).isConsumable())
{
throw new MessagingException(CoreMessages.cannotCopyStreamPayload(message.getPayload().getClass().getName()), event, this);
}
eventToRoute = OptimizedRequestContext.criticalSetEvent(event);
}
else
{
eventToRoute = event;
}
if (outboundRouter.isMatch(eventToRoute.getMessage()))
{
matchfound = true;
result = outboundRouter.process(event);
if (!isMatchAll())
{
return result;
}
}