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.model.Layout;
018    import com.liferay.portal.kernel.model.PortletInstance;
019    import com.liferay.portal.kernel.security.pacl.permission.PortalRuntimePermission;
020    import com.liferay.portal.kernel.settings.SettingsLocator;
021    import com.liferay.registry.collections.ServiceTrackerCollections;
022    import com.liferay.registry.collections.ServiceTrackerList;
023    
024    /**
025     * @author Jorge Ferrer
026     */
027    public class ConfigurationProviderUtil {
028    
029            public static <T> T getCompanyConfiguration(Class<T> clazz, long companyId)
030                    throws ConfigurationException {
031    
032                    ConfigurationProvider configurationProvider =
033                            getConfigurationProvider();
034    
035                    return configurationProvider.getCompanyConfiguration(clazz, companyId);
036            }
037    
038            public static <T> T getConfiguration(
039                            Class<T> clazz, SettingsLocator settingsLocator)
040                    throws ConfigurationException {
041    
042                    ConfigurationProvider configurationProvider =
043                            getConfigurationProvider();
044    
045                    return configurationProvider.getConfiguration(clazz, settingsLocator);
046            }
047    
048            public static ConfigurationProvider getConfigurationProvider() {
049                    PortalRuntimePermission.checkGetBeanProperty(
050                            ConfigurationProviderUtil.class);
051    
052                    return _configurationProvider.get(0);
053            }
054    
055            public static <T> T getGroupConfiguration(Class<T> clazz, long groupId)
056                    throws ConfigurationException {
057    
058                    ConfigurationProvider configurationProvider =
059                            getConfigurationProvider();
060    
061                    return configurationProvider.getGroupConfiguration(clazz, groupId);
062            }
063    
064            public static <T> T getPortletInstanceConfiguration(
065                            Class<T> clazz, Layout layout, PortletInstance portletInstance)
066                    throws ConfigurationException {
067    
068                    ConfigurationProvider configurationProvider =
069                            getConfigurationProvider();
070    
071                    return configurationProvider.getPortletInstanceConfiguration(
072                            clazz, layout, portletInstance);
073            }
074    
075            private static final ServiceTrackerList<ConfigurationProvider>
076                    _configurationProvider = ServiceTrackerCollections.openList(
077                            ConfigurationProvider.class);
078    
079    }