/** * Copyright (c) 2000-present Liferay, Inc. All rights reserved. * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. */ package com.liferay.application.list.adapter; import com.liferay.application.list.PanelApp; import com.liferay.osgi.util.ServiceTrackerFactory; import com.liferay.portal.kernel.log.Log; import com.liferay.portal.kernel.log.LogFactoryUtil; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import javax.portlet.Portlet; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; import org.osgi.framework.ServiceRegistration; import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Deactivate; import org.osgi.util.tracker.ServiceTracker; /** * @author Adolfo PĂ©rez */ @Component(immediate = true, service = Object.class) public class PortletPanelAppAdapterRegistry { @Activate protected void activate(BundleContext bundleContext) { _serviceTracker = ServiceTrackerFactory.open( bundleContext, Portlet.class, new PortletPanelAppAdapterServiceTrackerCustomizer( bundleContext, _serviceRegistrations)); } @Deactivate protected void deactivate() { _serviceTracker.close(); for (ServiceRegistration<PanelApp> serviceRegistration : _serviceRegistrations.values()) { try { serviceRegistration.unregister(); } catch (IllegalStateException ise) { _log.error(ise); } } _serviceRegistrations.clear(); } private static final Log _log = LogFactoryUtil.getLog( PortletPanelAppAdapterRegistry.class); private final Map<ServiceReference<Portlet>, ServiceRegistration<PanelApp>> _serviceRegistrations = new ConcurrentHashMap<>(); private ServiceTracker<Portlet, PanelApp> _serviceTracker; }