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.portal.spring.aop;
16  
17  import org.aopalliance.intercept.MethodInterceptor;
18  import org.aopalliance.intercept.MethodInvocation;
19  
20  /**
21   * <a href="BeanInterceptor.java.html"><b><i>View Source</i></b></a>
22   *
23   * @author     Brian Wing Shun Chan
24   * @deprecated
25   */
26  public class BeanInterceptor implements MethodInterceptor {
27  
28      public Object invoke(MethodInvocation invocation) throws Throwable {
29          Thread currentThread = Thread.currentThread();
30  
31          ClassLoader contextClassLoader = currentThread.getContextClassLoader();
32  
33          try {
34              if ((_classLoader != null) &&
35                  (contextClassLoader != _classLoader)) {
36  
37                  currentThread.setContextClassLoader(_classLoader);
38              }
39  
40              return invocation.proceed();
41          }
42          catch (Throwable t) {
43              if (_exceptionSafe) {
44                  return null;
45              }
46              else {
47                  throw t;
48              }
49          }
50          finally {
51              if ((_classLoader != null) &&
52                  (contextClassLoader != _classLoader)) {
53  
54                  currentThread.setContextClassLoader(contextClassLoader);
55              }
56          }
57      }
58  
59      public void setClassLoader(ClassLoader classLoader) {
60          _classLoader = classLoader;
61      }
62  
63      public void setExceptionSafe(boolean exceptionSafe) {
64          _exceptionSafe = exceptionSafe;
65      }
66  
67      private ClassLoader _classLoader;
68      private boolean _exceptionSafe;
69  
70  }