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