001    /**
002     * Copyright (c) 2000-2013 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.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            public GEmailSettingsManager getGEmailSettingsManager(long companyId) {
034                    return getGoogleApps(companyId).getGEmailSettingsManager();
035            }
036    
037            public GGroupManager getGGroupManager(long companyId) {
038                    return getGoogleApps(companyId).getGGroupManager();
039            }
040    
041            public GNicknameManager getGNicknameManager(long companyId) {
042                    return getGoogleApps(companyId).getGNicknameManager();
043            }
044    
045            public GUserManager getGUserManager(long companyId) {
046                    return getGoogleApps(companyId).getGUserManager();
047            }
048    
049            protected GoogleApps getGoogleApps(long companyId) {
050                    GoogleApps googleApps = _googleAppsMap.get(companyId);
051    
052                    if (googleApps == null) {
053                            googleApps = new GoogleApps(companyId);
054    
055                            _googleAppsMap.put(companyId, googleApps);
056                    }
057    
058                    return googleApps;
059            }
060    
061            private static Map<Long, GoogleApps> _googleAppsMap =
062                    new ConcurrentHashMap<Long, GoogleApps>();
063    
064    }