1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   * 
13   */
14  
15  package com.liferay.portal.kernel.util;
16  
17  import java.io.Serializable;
18  
19  import java.lang.reflect.Method;
20  
21  /**
22   * <a href="MethodWrapper.java.html"><b><i>View Source</i></b></a>
23   *
24   * @author Brian Wing Shun Chan
25   */
26  public class MethodWrapper implements Serializable {
27  
28      public MethodWrapper(String className, String methodName) {
29          this(className, methodName, new Object[0]);
30      }
31  
32      public MethodWrapper(String className, String methodName, Object argument) {
33          this(className, methodName, new Object[] {argument});
34      }
35  
36      public MethodWrapper(
37          String className, String methodName, Object[] arguments) {
38  
39          _className = className;
40          _methodName = methodName;
41          _arguments = arguments;
42      }
43  
44      public MethodWrapper(Method method, Object[] arguments) {
45          this(method.getDeclaringClass().getName(), method.getName(), arguments);
46  
47          _argumentClassNames = new String[arguments.length];
48  
49          Class<?>[] parameterTypes = method.getParameterTypes();
50  
51          for (int i = 0; i < parameterTypes.length; i++) {
52              _argumentClassNames[i] = parameterTypes[i].getName();
53          }
54      }
55  
56      public String getClassName() {
57          return _className;
58      }
59  
60      public String getMethodName() {
61          return _methodName;
62      }
63  
64      /**
65       * @deprecated Use <code>getArguments</code>.
66       */
67      public Object[] getArgs() {
68          return getArguments();
69      }
70  
71      public String[] getArgumentClassNames() {
72          return _argumentClassNames;
73      }
74  
75      public Object[] getArguments() {
76          Object[] arguments = new Object[_arguments.length];
77  
78          System.arraycopy(_arguments, 0, arguments, 0, _arguments.length);
79  
80          return arguments;
81      }
82  
83      private String _className;
84      private String _methodName;
85      private String[] _argumentClassNames;
86      private Object[] _arguments;
87  
88  }