| HookFactory.java |
1 /**
2 * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3 *
4 * This library is free software; you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License as published by the Free
6 * Software Foundation; either version 2.1 of the License, or (at your option)
7 * any later version.
8 *
9 * This library is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12 * details.
13 */
14
15 package com.liferay.mail.util;
16
17 import com.liferay.portal.kernel.log.Log;
18 import com.liferay.portal.kernel.log.LogFactoryUtil;
19 import com.liferay.portal.kernel.util.PortalClassLoaderUtil;
20 import com.liferay.portal.util.PropsValues;
21
22 /**
23 * <a href="HookFactory.java.html"><b><i>View Source</i></b></a>
24 *
25 * @author Brian Wing Shun Chan
26 */
27 public class HookFactory {
28
29 public static Hook getInstance() {
30 if (_hook == null) {
31 if (_log.isDebugEnabled()) {
32 _log.debug("Instantiate " + PropsValues.MAIL_HOOK_IMPL);
33 }
34
35 ClassLoader classLoader = PortalClassLoaderUtil.getClassLoader();
36
37 try {
38 _hook = (Hook)classLoader.loadClass(
39 PropsValues.MAIL_HOOK_IMPL).newInstance();
40 }
41 catch (Exception e) {
42 _log.error(e, e);
43 }
44 }
45
46 if (_log.isDebugEnabled()) {
47 _log.debug("Return " + _hook.getClass().getName());
48 }
49
50 return _hook;
51 }
52
53 public static void setInstance(Hook hook) {
54 if (_log.isDebugEnabled()) {
55 _log.debug("Set " + hook.getClass().getName());
56 }
57
58 _hook = hook;
59 }
60
61 private static Log _log = LogFactoryUtil.getLog(HookFactory.class);
62
63 private static Hook _hook = null;
64
65 }