01: /**
02: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
03: *
04: * Permission is hereby granted, free of charge, to any person obtaining a copy
05: * of this software and associated documentation files (the "Software"), to deal
06: * in the Software without restriction, including without limitation the rights
07: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
08: * copies of the Software, and to permit persons to whom the Software is
09: * furnished to do so, subject to the following conditions:
10: *
11: * The above copyright notice and this permission notice shall be included in
12: * all copies or substantial portions of the Software.
13: *
14: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20: * SOFTWARE.
21: */package com.liferay.portal.kernel.bean;
22:
23: import com.liferay.portal.kernel.log.Log;
24: import com.liferay.portal.kernel.log.LogFactoryUtil;
25: import com.liferay.portal.kernel.util.PortalClassLoaderUtil;
26:
27: /**
28: * <a href="BeanLocatorUtil.java.html"><b><i>View Source</i></b></a>
29: *
30: * @author Brian Wing Shun Chan
31: *
32: */
33: public class BeanLocatorUtil {
34:
35: public static Object locate(String name)
36: throws BeanLocatorException {
37: if (_beanLocator == null) {
38: _log.error("BeanLocator is null");
39:
40: throw new BeanLocatorException(
41: "BeanLocator has not been set");
42: } else {
43: ClassLoader contextClassLoader = Thread.currentThread()
44: .getContextClassLoader();
45:
46: try {
47: Thread.currentThread().setContextClassLoader(
48: PortalClassLoaderUtil.getClassLoader());
49:
50: return _beanLocator.locate(name);
51: } finally {
52: Thread.currentThread().setContextClassLoader(
53: contextClassLoader);
54: }
55: }
56: }
57:
58: public static Object locate(String name, boolean warn)
59: throws BeanLocatorException {
60:
61: if (_beanLocator == null) {
62: _log.error("BeanLocator is null");
63:
64: throw new BeanLocatorException(
65: "BeanLocator has not been set");
66: } else {
67: ClassLoader contextClassLoader = Thread.currentThread()
68: .getContextClassLoader();
69:
70: try {
71: Thread.currentThread().setContextClassLoader(
72: PortalClassLoaderUtil.getClassLoader());
73:
74: return _beanLocator.locate(name, warn);
75: } finally {
76: Thread.currentThread().setContextClassLoader(
77: contextClassLoader);
78: }
79: }
80: }
81:
82: public static void setBeanLocator(BeanLocator beanLocator) {
83: if (_log.isDebugEnabled()) {
84: _log.debug("Setting BeanLocator " + beanLocator.hashCode());
85: }
86:
87: _beanLocator = beanLocator;
88: }
89:
90: private static Log _log = LogFactoryUtil
91: .getLog(BeanLocatorUtil.class);
92:
93: private static BeanLocator _beanLocator;
94:
95: }
|