com.liferay.layouts.admin.kernel.util.SitemapURLProviderRegistryUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of com.liferay.portal.kernel Show documentation
Show all versions of com.liferay.portal.kernel Show documentation
Contains interfaces for the portal services. Interfaces are only loaded by the global class loader and are shared by all plugins.
/**
* 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.layouts.admin.kernel.util;
import aQute.bnd.annotation.ProviderType;
import com.liferay.portal.kernel.util.ListUtil;
import com.liferay.registry.Registry;
import com.liferay.registry.RegistryUtil;
import com.liferay.registry.ServiceReference;
import com.liferay.registry.ServiceRegistration;
import com.liferay.registry.ServiceTracker;
import com.liferay.registry.ServiceTrackerCustomizer;
import com.liferay.registry.collections.ServiceRegistrationMap;
import com.liferay.registry.collections.ServiceRegistrationMapImpl;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* @author Eduardo Garcia
*/
@ProviderType
public class SitemapURLProviderRegistryUtil {
public static SitemapURLProvider getSitemapURLProvider(String className) {
return _instance._getSitemapURLProvider(className);
}
public static List getSitemapURLProviders() {
return _instance._getSitemapURLProviders();
}
public static void register(SitemapURLProvider sitemapURLProvider) {
_instance._register(sitemapURLProvider);
}
public static void unregister(
List sitemapURLProviders) {
for (SitemapURLProvider sitemapURLProvider : sitemapURLProviders) {
unregister(sitemapURLProvider);
}
}
public static void unregister(SitemapURLProvider sitemapURLProvider) {
_instance._unregister(sitemapURLProvider);
}
private SitemapURLProviderRegistryUtil() {
Registry registry = RegistryUtil.getRegistry();
_serviceTracker = registry.trackServices(
SitemapURLProvider.class,
new SitemapURLProviderServiceTrackerCustomizer());
_serviceTracker.open();
}
private SitemapURLProvider _getSitemapURLProvider(String className) {
return _sitemapURLProviders.get(className);
}
private List _getSitemapURLProviders() {
Collection values = _sitemapURLProviders.values();
return ListUtil.fromCollection(values);
}
private void _register(SitemapURLProvider sitemapURLProvider) {
Registry registry = RegistryUtil.getRegistry();
ServiceRegistration serviceRegistration =
registry.registerService(
SitemapURLProvider.class, sitemapURLProvider);
_serviceRegistrations.put(sitemapURLProvider, serviceRegistration);
}
private void _unregister(SitemapURLProvider sitemapURLProvider) {
ServiceRegistration serviceRegistration =
_serviceRegistrations.remove(sitemapURLProvider);
if (serviceRegistration != null) {
serviceRegistration.unregister();
}
}
private static final SitemapURLProviderRegistryUtil _instance =
new SitemapURLProviderRegistryUtil();
private final ServiceRegistrationMap
_serviceRegistrations = new ServiceRegistrationMapImpl<>();
private final
ServiceTracker _serviceTracker;
private final Map _sitemapURLProviders =
new ConcurrentHashMap<>();
private class SitemapURLProviderServiceTrackerCustomizer
implements ServiceTrackerCustomizer
{
@Override
public SitemapURLProvider addingService(
ServiceReference serviceReference) {
Registry registry = RegistryUtil.getRegistry();
SitemapURLProvider sitemapURLProvider = registry.getService(
serviceReference);
_sitemapURLProviders.put(
sitemapURLProvider.getClassName(), sitemapURLProvider);
return sitemapURLProvider;
}
@Override
public void modifiedService(
ServiceReference serviceReference,
SitemapURLProvider sitemapURLProvider) {
}
@Override
public void removedService(
ServiceReference serviceReference,
SitemapURLProvider sitemapURLProvider) {
Registry registry = RegistryUtil.getRegistry();
registry.ungetService(serviceReference);
_sitemapURLProviders.remove(sitemapURLProvider.getClassName());
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy