001/* 002 * (C) Copyright 2006-2009 Nuxeo SAS (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * troger 016 */ 017package org.nuxeo.ecm.platform.annotations.repository.service; 018 019import java.util.List; 020 021import org.apache.commons.logging.Log; 022import org.apache.commons.logging.LogFactory; 023import org.nuxeo.ecm.core.event.Event; 024import org.nuxeo.ecm.core.event.EventBundle; 025import org.nuxeo.ecm.core.event.PostCommitEventListener; 026import org.nuxeo.runtime.api.Framework; 027 028/** 029 * @author <a href="mailto:troger@nuxeo.com">Thomas Roger</a> 030 */ 031public class VersionEventListener implements PostCommitEventListener { 032 033 private static final Log log = LogFactory.getLog(VersionEventListener.class); 034 035 public VersionEventListener() { 036 } 037 038 public void handleEvent(EventBundle events) { 039 AnnotationsRepositoryConfigurationService service = Framework.getLocalService(AnnotationsRepositoryConfigurationService.class); 040 GraphManagerEventListener manager = service.getGraphManagerEventListener(); 041 List<String> eventNames = service.getEventIds(); 042 043 boolean processEvents = false; 044 for (String eventName : eventNames) { 045 if (events.containsEventName(eventName)) { 046 processEvents = true; 047 break; 048 } 049 } 050 051 if (processEvents) { 052 for (Event event : events) { 053 if (eventNames.contains(event.getName())) { 054 log.debug("Handling " + event.getName() + " event"); 055 manager.manage(event); 056 } 057 } 058 } 059 } 060 061}