1
22
23 package com.liferay.portal.kernel.util;
24
25 import java.lang.reflect.InvocationTargetException;
26
27
32 public class PortalClassInvoker {
33
34 public static Object invoke(String className, String methodName)
35 throws Exception {
36
37 return invoke(className, methodName, new Object[] {});
38 }
39
40 public static Object invoke(String className, String methodName, Object arg)
41 throws Exception {
42
43 return invoke(className, methodName, new Object[] {arg});
44 }
45
46 public static Object invoke(
47 String className, String methodName, Object arg1, Object arg2)
48 throws Exception {
49
50 return invoke(className, methodName, new Object[] {arg1, arg2});
51 }
52
53 public static Object invoke(
54 String className, String methodName, Object arg1, Object arg2,
55 Object arg3)
56 throws Exception {
57
58 return invoke(className, methodName, new Object[] {arg1, arg2, arg3});
59 }
60
61 public static Object invoke(
62 String className, String methodName, Object[] args)
63 throws Exception {
64
65 return invoke(className, methodName, args, true);
66 }
67
68 public static Object invoke(
69 String className, String methodName, boolean newInstance)
70 throws Exception {
71
72 return invoke(className, methodName, new Object[] {}, newInstance);
73 }
74
75 public static Object invoke(
76 String className, String methodName, Object arg,
77 boolean newInstance)
78 throws Exception {
79
80 return invoke(className, methodName, new Object[] {arg}, newInstance);
81 }
82
83 public static Object invoke(
84 String className, String methodName, Object arg1, Object arg2,
85 boolean newInstance)
86 throws Exception {
87
88 return invoke(
89 className, methodName, new Object[] {arg1, arg2}, newInstance);
90 }
91
92 public static Object invoke(
93 String className, String methodName, Object arg1, Object arg2,
94 Object arg3, boolean newInstance)
95 throws Exception {
96
97 return invoke(
98 className, methodName, new Object[] {arg1, arg2, arg3},
99 newInstance);
100 }
101
102 public static Object invoke(
103 String className, String methodName, Object[] args,
104 boolean newInstance)
105 throws Exception {
106
107 Thread currentThread = Thread.currentThread();
108
109 ClassLoader contextClassLoader = currentThread.getContextClassLoader();
110
111 try {
112 currentThread.setContextClassLoader(
113 PortalClassLoaderUtil.getClassLoader());
114
115 MethodWrapper methodWrapper = new MethodWrapper(
116 className, methodName, args);
117
118 return MethodInvoker.invoke(methodWrapper, newInstance);
119 }
120 catch (InvocationTargetException ite) {
121 throw (Exception)ite.getCause();
122 }
123 finally {
124 currentThread.setContextClassLoader(contextClassLoader);
125 }
126 }
127
128 }