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 public static Object invoke(
028 boolean newInstance, MethodKey methodKey, Object... arguments)
029 throws Exception {
030
031 Thread currentThread = Thread.currentThread();
032
033 ClassLoader contextClassLoader = currentThread.getContextClassLoader();
034
035 try {
036 currentThread.setContextClassLoader(
037 PortalClassLoaderUtil.getClassLoader());
038
039 MethodHandler methodHandler = new MethodHandler(
040 methodKey, arguments);
041
042 return methodHandler.invoke(newInstance);
043 }
044 catch (InvocationTargetException ite) {
045 Throwable cause = ite.getCause();
046
047 if (cause instanceof Error) {
048 throw new SystemException(ite);
049 }
050 else {
051 throw (Exception)cause;
052 }
053 }
054 finally {
055 currentThread.setContextClassLoader(contextClassLoader);
056 }
057 }
058
059 }