001    /**
002     * Copyright (c) 2000-2012 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 As of 6.0.5, replaced by {@link
026     *             com.liferay.kernel.util.MethodHandler}
027     */
028    public class MethodWrapper implements Serializable {
029    
030            public MethodWrapper(Method method, Object[] arguments) {
031                    this(method.getDeclaringClass().getName(), method.getName(), arguments);
032    
033                    _argumentClassNames = new String[arguments.length];
034    
035                    Class<?>[] parameterTypes = method.getParameterTypes();
036    
037                    for (int i = 0; i < parameterTypes.length; i++) {
038                            _argumentClassNames[i] = parameterTypes[i].getName();
039                    }
040            }
041    
042            public MethodWrapper(String className, String methodName) {
043                    this(className, methodName, new Object[0]);
044            }
045    
046            public MethodWrapper(String className, String methodName, Object argument) {
047                    this(className, methodName, new Object[] {argument});
048            }
049    
050            public MethodWrapper(
051                    String className, String methodName, Object[] arguments) {
052    
053                    _className = className;
054                    _methodName = methodName;
055                    _arguments = arguments;
056            }
057    
058            /**
059             * @deprecated Replaced by {@link #getArguments()}.
060             */
061            public Object[] getArgs() {
062                    return getArguments();
063            }
064    
065            public String[] getArgumentClassNames() {
066                    return _argumentClassNames;
067            }
068    
069            public Object[] getArguments() {
070                    Object[] arguments = new Object[_arguments.length];
071    
072                    System.arraycopy(_arguments, 0, arguments, 0, _arguments.length);
073    
074                    return arguments;
075            }
076    
077            public String getClassName() {
078                    return _className;
079            }
080    
081            public String getMethodName() {
082                    return _methodName;
083            }
084    
085            @Override
086            public String toString() {
087                    StringBundler sb = new StringBundler(9);
088    
089                    sb.append("{className=");
090                    sb.append(_className);
091                    sb.append(", methodName=");
092                    sb.append(_methodName);
093    
094                    if (_argumentClassNames != null) {
095                            sb.append(", argumentClassNames=");
096                            sb.append(Arrays.toString(_argumentClassNames));
097                    }
098    
099                    sb.append(", arguments=");
100                    sb.append(Arrays.toString(_arguments));
101                    sb.append("}");
102    
103                    return sb.toString();
104            }
105    
106            private String[] _argumentClassNames;
107            private Object[] _arguments;
108            private String _className;
109            private String _methodName;
110    
111    }