001    /**
002     * Copyright (c) 2000-2010 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.portlet.journal.lar;
016    
017    import com.liferay.portal.kernel.log.Log;
018    import com.liferay.portal.kernel.log.LogFactoryUtil;
019    import com.liferay.portal.kernel.util.PortalClassLoaderUtil;
020    import com.liferay.portal.util.PropsValues;
021    
022    /**
023     * @author Joel Kozikowski
024     */
025    public class JournalCreationStrategyFactory {
026    
027            public static JournalCreationStrategy getInstance() {
028                    if (_journalCreationStrategy == null) {
029                            if (_log.isDebugEnabled()) {
030                                    _log.debug(
031                                            "Instantiate " + PropsValues.JOURNAL_LAR_CREATION_STRATEGY);
032                            }
033    
034                            ClassLoader classLoader = PortalClassLoaderUtil.getClassLoader();
035    
036                            try {
037                                    _journalCreationStrategy =
038                                            (JournalCreationStrategy)classLoader.loadClass(
039                                                    PropsValues.JOURNAL_LAR_CREATION_STRATEGY).
040                                                            newInstance();
041                            }
042                            catch (Exception e) {
043                                    _log.error(e, e);
044                            }
045                    }
046    
047                    if (_log.isDebugEnabled()) {
048                            _log.debug(
049                                    "Return " + _journalCreationStrategy.getClass().getName());
050                    }
051    
052                    return _journalCreationStrategy;
053            }
054    
055            public static void setInstance(
056                    JournalCreationStrategy journalCreationStrategy) {
057    
058                    if (_log.isDebugEnabled()) {
059                            _log.debug("Set " + journalCreationStrategy.getClass().getName());
060                    }
061    
062                    _journalCreationStrategy = journalCreationStrategy;
063            }
064    
065            private static Log _log = LogFactoryUtil.getLog(
066                    JournalCreationStrategyFactory.class);
067    
068            private static JournalCreationStrategy _journalCreationStrategy;
069    
070    }