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.security.permission;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.security.pacl.permission.PortalRuntimePermission;
019    import com.liferay.registry.Registry;
020    import com.liferay.registry.RegistryUtil;
021    import com.liferay.registry.ServiceTracker;
022    
023    /**
024     * @author Preston Crary
025     */
026    public class UserBagFactoryUtil {
027    
028            public static UserBag create(long userId) throws PortalException {
029                    return getUserBagFactory().create(userId);
030            }
031    
032            public static UserBagFactory getUserBagFactory() {
033                    PortalRuntimePermission.checkGetBeanProperty(UserBagFactoryUtil.class);
034    
035                    return _instance._serviceTracker.getService();
036            }
037    
038            private UserBagFactoryUtil() {
039                    Registry registry = RegistryUtil.getRegistry();
040    
041                    _serviceTracker = registry.trackServices(UserBagFactory.class);
042    
043                    _serviceTracker.open();
044            }
045    
046            private static final UserBagFactoryUtil _instance =
047                    new UserBagFactoryUtil();
048    
049            private final ServiceTracker<?, UserBagFactory> _serviceTracker;
050    
051    }