001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.kernel.util;
016    
017    import java.io.Serializable;
018    
019    import java.lang.reflect.Method;
020    
021    import java.util.Arrays;
022    
023    /**
024     * @author         Brian Wing Shun Chan
025     * @deprecated
026     */
027    public class MethodWrapper implements Serializable {
028    
029            public MethodWrapper(String className, String methodName) {
030                    this(className, methodName, new Object[0]);
031            }
032    
033            public MethodWrapper(String className, String methodName, Object argument) {
034                    this(className, methodName, new Object[] {argument});
035            }
036    
037            public MethodWrapper(
038                    String className, String methodName, Object[] arguments) {
039    
040                    _className = className;
041                    _methodName = methodName;
042                    _arguments = arguments;
043            }
044    
045            public MethodWrapper(Method method, Object[] arguments) {
046                    this(method.getDeclaringClass().getName(), method.getName(), arguments);
047    
048                    _argumentClassNames = new String[arguments.length];
049    
050                    Class<?>[] parameterTypes = method.getParameterTypes();
051    
052                    for (int i = 0; i < parameterTypes.length; i++) {
053                            _argumentClassNames[i] = parameterTypes[i].getName();
054                    }
055            }
056    
057            public String getClassName() {
058                    return _className;
059            }
060    
061            public String getMethodName() {
062                    return _methodName;
063            }
064    
065            /**
066             * @deprecated Use <code>getArguments</code>.
067             */
068            public Object[] getArgs() {
069                    return getArguments();
070            }
071    
072            public String[] getArgumentClassNames() {
073                    return _argumentClassNames;
074            }
075    
076            public Object[] getArguments() {
077                    Object[] arguments = new Object[_arguments.length];
078    
079                    System.arraycopy(_arguments, 0, arguments, 0, _arguments.length);
080    
081                    return arguments;
082            }
083    
084            public String toString() {
085                    StringBundler sb = new StringBundler(9);
086    
087                    sb.append("{className=");
088                    sb.append(_className);
089                    sb.append(", methodName=");
090                    sb.append(_methodName);
091    
092                    if (_argumentClassNames != null) {
093                            sb.append(", argumentClassNames=");
094                            sb.append(Arrays.toString(_argumentClassNames));
095                    }
096    
097                    sb.append(", arguments=");
098                    sb.append(Arrays.toString(_arguments));
099                    sb.append("}");
100    
101                    return sb.toString();
102            }
103    
104            private String _className;
105            private String _methodName;
106            private String[] _argumentClassNames;
107            private Object[] _arguments;
108    
109    }