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