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.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.security.pacl.PACLClassLoaderUtil;
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 =
035                                    PACLClassLoaderUtil.getPortalClassLoader();
036    
037                            try {
038                                    _journalCreationStrategy =
039                                            (JournalCreationStrategy)classLoader.loadClass(
040                                                    PropsValues.JOURNAL_LAR_CREATION_STRATEGY).
041                                                            newInstance();
042                            }
043                            catch (Exception e) {
044                                    _log.error(e, e);
045                            }
046                    }
047    
048                    if (_log.isDebugEnabled()) {
049                            _log.debug(
050                                    "Return " + _journalCreationStrategy.getClass().getName());
051                    }
052    
053                    return _journalCreationStrategy;
054            }
055    
056            public static void setInstance(
057                    JournalCreationStrategy journalCreationStrategy) {
058    
059                    if (_log.isDebugEnabled()) {
060                            _log.debug("Set " + journalCreationStrategy.getClass().getName());
061                    }
062    
063                    _journalCreationStrategy = journalCreationStrategy;
064            }
065    
066            private static Log _log = LogFactoryUtil.getLog(
067                    JournalCreationStrategyFactory.class);
068    
069            private static JournalCreationStrategy _journalCreationStrategy;
070    
071    }