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