EventListenerIterator eventListeners = observationRegistry.getEventListeners();
while (eventListeners.hasNext())
{
EventListener listener = eventListeners.nextEventListener();
if (listener == null)
{
if (LOG.isDebugEnabled())
{
LOG.debug("The listener has probably been removed thus it will be skipped");
}
continue;
}
ListenerCriteria criteria = observationRegistry.getListenerFilter(listener);
if (criteria == null)
{
if (LOG.isDebugEnabled())
{
LOG.debug("The criteria of the listener could not be found thus it will be skipped");
}
continue;
}
EntityCollection events = new EntityCollection();
ChangesLogIterator logIterator = ((CompositeChangesLog)changesLog).getLogIterator();
while (logIterator.hasNextLog())
{
PlainChangesLog subLog = logIterator.nextLog();
String sessionId = subLog.getSessionId();
ExtendedSession userSession;
if (subLog.getSession() != null)
{
userSession = subLog.getSession();
}
else
{
userSession = sessionRegistry.getSession(sessionId);
}
if (userSession != null)
{
for (ItemState itemState : subLog.getAllStates())
{
if (itemState.isEventFire())
{
ItemData item = itemState.getData();
try
{
int eventType = eventType(itemState);
if (eventType != SKIP_EVENT && isTypeMatch(criteria, eventType)
&& isPathMatch(criteria, item, userSession) && isIdentifierMatch(criteria, item)
&& isNodeTypeMatch(criteria, item, userSession, subLog)
&& isSessionMatch(criteria, sessionId))
{
String path =
userSession.getLocationFactory().createJCRPath(item.getQPath()).getAsString(false);
if (eventType== ExtendedEvent.NODE_MOVED)
{
String oldPath =
userSession.getLocationFactory().createJCRPath(itemState.getOldPath()).getAsString(false);
Map<String, String> info = new HashMap<String, String>();
if(itemState.isMoved())
{
info.put(ExtendedEvent.SRC_ABS_PATH, oldPath);
info.put(ExtendedEvent.DEST_ABS_PATH, path);
}
else if (itemState.isOrdered())
{
info.put(ExtendedEvent.SRC_CHILD_REL_PATH, oldPath);
info.put(ExtendedEvent.DEST_CHILD_REL_PATH, path);
}
events.add(new EventImpl(eventType, path, userSession.getUserID(), info));
}
else
{
events.add(new EventImpl(eventType, path, userSession.getUserID()));
}
}
}
catch (RepositoryException e)
{
LOG.error("Can not fire ActionLauncher.onSaveItems() for " + item.getQPath().getAsString()
+ " reason: " + e.getMessage());
}
}
}
}
}
if (events.getSize() > 0)
{
// TCK says, no events - no onEvent() action
listener.onEvent(events);
}
}
}