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.security.membershippolicy;
016    
017    import com.liferay.portal.kernel.log.Log;
018    import com.liferay.portal.kernel.log.LogFactoryUtil;
019    import com.liferay.portal.kernel.util.ClassUtil;
020    import com.liferay.portal.kernel.util.InstanceFactory;
021    import com.liferay.portal.util.ClassLoaderUtil;
022    import com.liferay.portal.util.PropsValues;
023    
024    /**
025     * @author Sergio Gonz??lez
026     * @author Shuyang Zhou
027     */
028    public class OrganizationMembershipPolicyFactoryImpl
029            implements OrganizationMembershipPolicyFactory {
030    
031            public void afterPropertiesSet() throws Exception {
032                    if (_log.isDebugEnabled()) {
033                            _log.debug(
034                                    "Instantiate " + PropsValues.MEMBERSHIP_POLICY_ORGANIZATIONS);
035                    }
036    
037                    ClassLoader classLoader = ClassLoaderUtil.getPortalClassLoader();
038    
039                    _originalOrganizationMembershipPolicy =
040                            (OrganizationMembershipPolicy)InstanceFactory.newInstance(
041                                    classLoader, PropsValues.MEMBERSHIP_POLICY_ORGANIZATIONS);
042    
043                    _organizationMembershipPolicy = _originalOrganizationMembershipPolicy;
044            }
045    
046            @Override
047            public OrganizationMembershipPolicy getOrganizationMembershipPolicy() {
048                    return _organizationMembershipPolicy;
049            }
050    
051            public void setOrganizationMembershipPolicy(
052                    OrganizationMembershipPolicy organizationMembershipPolicy) {
053    
054                    if (_log.isDebugEnabled()) {
055                            _log.debug(
056                                    "Set " + ClassUtil.getClassName(organizationMembershipPolicy));
057                    }
058    
059                    if (organizationMembershipPolicy == null) {
060                            _organizationMembershipPolicy =
061                                    _originalOrganizationMembershipPolicy;
062                    }
063                    else {
064                            _organizationMembershipPolicy = organizationMembershipPolicy;
065                    }
066            }
067    
068            private static Log _log = LogFactoryUtil.getLog(
069                    OrganizationMembershipPolicyFactoryImpl.class);
070    
071            private static volatile OrganizationMembershipPolicy
072                    _organizationMembershipPolicy;
073            private static OrganizationMembershipPolicy
074                    _originalOrganizationMembershipPolicy;
075    
076    }