001    /**
002     * Copyright (c) 2000-2012 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.auth;
016    
017    import com.liferay.portal.kernel.log.Log;
018    import com.liferay.portal.kernel.log.LogFactoryUtil;
019    import com.liferay.portal.kernel.util.InstanceFactory;
020    import com.liferay.portal.security.pacl.PACLClassLoaderUtil;
021    import com.liferay.portal.util.PropsValues;
022    
023    /**
024     * @author Amos Fong
025     */
026    public class FullNameValidatorFactory {
027    
028            public static FullNameValidator getInstance() {
029                    if (_fullNameValidator == null) {
030                            if (_log.isDebugEnabled()) {
031                                    _log.debug(
032                                            "Instantiate " + PropsValues.USERS_FULL_NAME_VALIDATOR);
033                            }
034    
035                            ClassLoader classLoader =
036                                    PACLClassLoaderUtil.getPortalClassLoader();
037    
038                            try {
039                                    _fullNameValidator =
040                                            (FullNameValidator)InstanceFactory.newInstance(
041                                                    classLoader, PropsValues.USERS_FULL_NAME_VALIDATOR);
042                            }
043                            catch (Exception e) {
044                                    _log.error(e, e);
045                            }
046                    }
047    
048                    if (_log.isDebugEnabled()) {
049                            _log.debug("Return " + _fullNameValidator.getClass().getName());
050                    }
051    
052                    return _fullNameValidator;
053            }
054    
055            public static void setInstance(FullNameValidator fullNameValidator) {
056                    if (_log.isDebugEnabled()) {
057                            _log.debug("Set " + fullNameValidator.getClass().getName());
058                    }
059    
060                    _fullNameValidator = fullNameValidator;
061            }
062    
063            private static Log _log = LogFactoryUtil.getLog(
064                    FullNameValidatorFactory.class);
065    
066            private static FullNameValidator _fullNameValidator;
067    
068    }