001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.googleapps;
016    
017    import com.liferay.portal.kernel.googleapps.GEmailSettingsManager;
018    import com.liferay.portal.kernel.googleapps.GGroupManager;
019    import com.liferay.portal.kernel.googleapps.GNicknameManager;
020    import com.liferay.portal.kernel.googleapps.GUserManager;
021    import com.liferay.portal.kernel.googleapps.GoogleAppsFactory;
022    import com.liferay.portal.kernel.security.pacl.DoPrivileged;
023    
024    import java.util.Map;
025    import java.util.concurrent.ConcurrentHashMap;
026    
027    /**
028     * @author Brian Wing Shun Chan
029     */
030    @DoPrivileged
031    public class GoogleAppsFactoryImpl implements GoogleAppsFactory {
032    
033            @Override
034            public GEmailSettingsManager getGEmailSettingsManager(long companyId) {
035                    return getGoogleApps(companyId).getGEmailSettingsManager();
036            }
037    
038            @Override
039            public GGroupManager getGGroupManager(long companyId) {
040                    return getGoogleApps(companyId).getGGroupManager();
041            }
042    
043            @Override
044            public GNicknameManager getGNicknameManager(long companyId) {
045                    return getGoogleApps(companyId).getGNicknameManager();
046            }
047    
048            @Override
049            public GUserManager getGUserManager(long companyId) {
050                    return getGoogleApps(companyId).getGUserManager();
051            }
052    
053            protected GoogleApps getGoogleApps(long companyId) {
054                    GoogleApps googleApps = _googleAppsMap.get(companyId);
055    
056                    if (googleApps == null) {
057                            googleApps = new GoogleApps(companyId);
058    
059                            _googleAppsMap.put(companyId, googleApps);
060                    }
061    
062                    return googleApps;
063            }
064    
065            private static Map<Long, GoogleApps> _googleAppsMap =
066                    new ConcurrentHashMap<Long, GoogleApps>();
067    
068    }