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            public OrganizationMembershipPolicy getOrganizationMembershipPolicy() {
047                    return _organizationMembershipPolicy;
048            }
049    
050            public void setOrganizationMembershipPolicy(
051                    OrganizationMembershipPolicy organizationMembershipPolicy) {
052    
053                    if (_log.isDebugEnabled()) {
054                            _log.debug(
055                                    "Set " + ClassUtil.getClassName(organizationMembershipPolicy));
056                    }
057    
058                    if (organizationMembershipPolicy == null) {
059                            _organizationMembershipPolicy =
060                                    _originalOrganizationMembershipPolicy;
061                    }
062                    else {
063                            _organizationMembershipPolicy = organizationMembershipPolicy;
064                    }
065            }
066    
067            private static Log _log = LogFactoryUtil.getLog(
068                    OrganizationMembershipPolicyFactory.class);
069    
070            private static volatile OrganizationMembershipPolicy
071                    _organizationMembershipPolicy;
072            private static OrganizationMembershipPolicy
073                    _originalOrganizationMembershipPolicy;
074    
075    }