001
014
015 package com.liferay.portal.kernel.util;
016
017 import com.liferay.portal.kernel.exception.SystemException;
018
019 import java.lang.reflect.InvocationTargetException;
020
021
025 public class PortalClassInvoker {
026
027
031 @Deprecated
032 public static Object invoke(
033 boolean newInstance, MethodKey methodKey, Object... arguments)
034 throws Exception {
035
036 return invoke(methodKey, arguments);
037 }
038
039 public static Object invoke(MethodKey methodKey, Object... arguments)
040 throws Exception {
041
042 Thread currentThread = Thread.currentThread();
043
044 ClassLoader contextClassLoader = currentThread.getContextClassLoader();
045
046 try {
047 currentThread.setContextClassLoader(
048 PortalClassLoaderUtil.getClassLoader());
049
050 MethodHandler methodHandler = new MethodHandler(
051 methodKey, arguments);
052
053 return methodHandler.invoke();
054 }
055 catch (InvocationTargetException ite) {
056 Throwable cause = ite.getCause();
057
058 if (cause instanceof Error) {
059 throw new SystemException(ite);
060 }
061 else {
062 throw (Exception)cause;
063 }
064 }
065 finally {
066 currentThread.setContextClassLoader(contextClassLoader);
067 }
068 }
069
070 }