| HookFactory.java |
1 /**
2 * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3 *
4 * The contents of this file are subject to the terms of the Liferay Enterprise
5 * Subscription License ("License"). You may not use this file except in
6 * compliance with the License. You can obtain a copy of the License by
7 * contacting Liferay, Inc. See the License for the specific language governing
8 * permissions and limitations under the License, including but not limited to
9 * distribution rights of the Software.
10 *
11 *
12 *
13 */
14
15 package com.liferay.documentlibrary.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.DL_HOOK_IMPL);
33 }
34
35 ClassLoader classLoader = PortalClassLoaderUtil.getClassLoader();
36
37 try {
38 _hook = (Hook)classLoader.loadClass(
39 PropsValues.DL_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;
64
65 }