001/* 002 * (C) Copyright 2006-2009 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * troger 018 */ 019package org.nuxeo.ecm.platform.annotations.repository.service; 020 021import java.util.List; 022 023import org.apache.commons.logging.Log; 024import org.apache.commons.logging.LogFactory; 025import org.nuxeo.ecm.core.event.Event; 026import org.nuxeo.ecm.core.event.EventBundle; 027import org.nuxeo.ecm.core.event.PostCommitEventListener; 028import org.nuxeo.runtime.api.Framework; 029 030/** 031 * @author <a href="mailto:troger@nuxeo.com">Thomas Roger</a> 032 */ 033public class VersionEventListener implements PostCommitEventListener { 034 035 private static final Log log = LogFactory.getLog(VersionEventListener.class); 036 037 public VersionEventListener() { 038 } 039 040 public void handleEvent(EventBundle events) { 041 AnnotationsRepositoryConfigurationService service = Framework.getService(AnnotationsRepositoryConfigurationService.class); 042 GraphManagerEventListener manager = service.getGraphManagerEventListener(); 043 List<String> eventNames = service.getEventIds(); 044 045 boolean processEvents = false; 046 for (String eventName : eventNames) { 047 if (events.containsEventName(eventName)) { 048 processEvents = true; 049 break; 050 } 051 } 052 053 if (processEvents) { 054 for (Event event : events) { 055 if (eventNames.contains(event.getName())) { 056 log.debug("Handling " + event.getName() + " event"); 057 manager.manage(event); 058 } 059 } 060 } 061 } 062 063}