1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
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  }