001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.kernel.module.configuration;
016    
017    import com.liferay.portal.kernel.security.pacl.permission.PortalRuntimePermission;
018    import com.liferay.portal.kernel.settings.SettingsLocator;
019    import com.liferay.registry.collections.ServiceTrackerCollections;
020    import com.liferay.registry.collections.ServiceTrackerList;
021    
022    /**
023     * @author Jorge Ferrer
024     */
025    public class ConfigurationProviderUtil {
026    
027            public static <T> T getConfiguration(
028                            Class<T> clazz, SettingsLocator settingsLocator)
029                    throws ConfigurationException {
030    
031                    ConfigurationProvider configurationProvider =
032                            getConfigurationProvider();
033    
034                    return configurationProvider.getConfiguration(clazz, settingsLocator);
035            }
036    
037            public static String getConfigurationPid(Class clazz)
038                    throws ConfigurationException {
039    
040                    ConfigurationProvider configurationProvider =
041                            getConfigurationProvider();
042    
043                    return configurationProvider.getConfigurationPid(clazz);
044            }
045    
046            public static ConfigurationProvider getConfigurationProvider() {
047                    PortalRuntimePermission.checkGetBeanProperty(
048                            ConfigurationProviderUtil.class);
049    
050                    return _configurationProvider.get(0);
051            }
052    
053            private static final ServiceTrackerList<ConfigurationProvider>
054                    _configurationProvider = ServiceTrackerCollections.openList(
055                            ConfigurationProvider.class);
056    
057    }