}
}
for (Iterator iterator = listeners.iterator(); iterator.hasNext();)
{
ApplicationListener listener = (ApplicationListener) iterator.next();
if (muleEvent != null)
{
// As the asynchronous listener wraps the real listener we need
// to check the type of the wrapped listener, but invoke the Async
// listener
if (listener instanceof AsynchronousEventListener)
{
AsynchronousEventListener asyncListener = (AsynchronousEventListener) listener;
if (asyncListener.getListener() instanceof MuleSubscriptionEventListener)
{
if (isSubscriptionMatch(muleEvent.getEndpoint(),
((MuleSubscriptionEventListener) asyncListener.getListener()).getSubscriptions()))
{
asyncListener.onApplicationEvent(muleEvent);
}
}
else if (asyncListener.getListener() instanceof MuleEventListener)
{
asyncListener.onApplicationEvent(muleEvent);
}
else if (!(asyncListener.getListener() instanceof MuleEventListener))
{
asyncListener.onApplicationEvent(e);
}
// Synchronous MuleEvent listener Checks
}
else if (listener instanceof MuleSubscriptionEventListener)
{
if (isSubscriptionMatch(muleEvent.getEndpoint(),
((MuleSubscriptionEventListener) listener).getSubscriptions()))
{
listener.onApplicationEvent(muleEvent);
}
}
else if (listener instanceof MuleEventListener)
{
listener.onApplicationEvent(muleEvent);
}
}
else if (listener instanceof AsynchronousEventListener
&& !(((AsynchronousEventListener) listener).getListener() instanceof MuleEventListener))
{
listener.onApplicationEvent(e);
}
else if (!(listener instanceof MuleEventListener))
{
listener.onApplicationEvent(e);
}
else
{
// Finally only propagate the Application event if the
// ApplicationEvent interface is explicitly implemented
for (int i = 0; i < listener.getClass().getInterfaces().length; i++)
{
if (listener.getClass().getInterfaces()[i].equals(ApplicationListener.class))
{
listener.onApplicationEvent(e);
break;
}
}
}