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            @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    }