001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portal.kernel.util;
022:
023: /**
024: * <a href="PortalClassInvoker.java.html"><b><i>View Source</i></b></a>
025: *
026: * @author Brian Wing Shun Chan
027: *
028: */
029: public class PortalClassInvoker {
030:
031: public static Object invoke(String className, String methodName)
032: throws Exception {
033:
034: return invoke(className, methodName, new Object[] {});
035: }
036:
037: public static Object invoke(String className, String methodName,
038: Object arg) throws Exception {
039:
040: return invoke(className, methodName, new Object[] { arg });
041: }
042:
043: public static Object invoke(String className, String methodName,
044: Object arg1, Object arg2) throws Exception {
045:
046: return invoke(className, methodName,
047: new Object[] { arg1, arg2 });
048: }
049:
050: public static Object invoke(String className, String methodName,
051: Object arg1, Object arg2, Object arg3) throws Exception {
052:
053: return invoke(className, methodName, new Object[] { arg1, arg2,
054: arg3 });
055: }
056:
057: public static Object invoke(String className, String methodName,
058: Object[] args) throws Exception {
059:
060: return invoke(className, methodName, args, true);
061: }
062:
063: public static Object invoke(String className, String methodName,
064: boolean newInstance) throws Exception {
065:
066: return invoke(className, methodName, new Object[] {},
067: newInstance);
068: }
069:
070: public static Object invoke(String className, String methodName,
071: Object arg, boolean newInstance) throws Exception {
072:
073: return invoke(className, methodName, new Object[] { arg },
074: newInstance);
075: }
076:
077: public static Object invoke(String className, String methodName,
078: Object arg1, Object arg2, boolean newInstance)
079: throws Exception {
080:
081: return invoke(className, methodName,
082: new Object[] { arg1, arg2 }, newInstance);
083: }
084:
085: public static Object invoke(String className, String methodName,
086: Object arg1, Object arg2, Object arg3, boolean newInstance)
087: throws Exception {
088:
089: return invoke(className, methodName, new Object[] { arg1, arg2,
090: arg3 }, newInstance);
091: }
092:
093: public static Object invoke(String className, String methodName,
094: Object[] args, boolean newInstance) throws Exception {
095:
096: ClassLoader contextClassLoader = Thread.currentThread()
097: .getContextClassLoader();
098:
099: try {
100: Thread.currentThread().setContextClassLoader(
101: PortalClassLoaderUtil.getClassLoader());
102:
103: MethodWrapper methodWrapper = new MethodWrapper(className,
104: methodName, args);
105:
106: return MethodInvoker.invoke(methodWrapper, newInstance);
107: } finally {
108: Thread.currentThread().setContextClassLoader(
109: contextClassLoader);
110: }
111: }
112:
113: }
|