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.util;
016    
017    import com.liferay.portal.kernel.log.Log;
018    import com.liferay.portal.kernel.log.LogFactoryUtil;
019    import com.liferay.portal.kernel.util.MethodParameter;
020    import com.liferay.portal.kernel.util.MethodParametersResolver;
021    
022    import java.lang.reflect.AccessibleObject;
023    import java.lang.reflect.Method;
024    
025    import java.util.HashMap;
026    import java.util.Map;
027    
028    import jodd.paramo.Paramo;
029    
030    /**
031     * @author Igor Spasic
032     */
033    public class MethodParametersResolverImpl implements MethodParametersResolver {
034    
035            public MethodParameter[] resolveMethodParameters(Method method) {
036                    MethodParameter[] methodParameters = _methodParameters.get(method);
037    
038                    if (methodParameters != null) {
039                            return methodParameters;
040                    }
041    
042                    try {
043                            Class<?>[] methodParameterTypes = method.getParameterTypes();
044    
045                            jodd.paramo.MethodParameter[] joddMethodParameters =
046                                    Paramo.resolveParameters(method);
047    
048                            methodParameters = new MethodParameter[joddMethodParameters.length];
049    
050                            for (int i = 0; i < joddMethodParameters.length; i++) {
051                                    methodParameters[i] = new MethodParameter(
052                                            joddMethodParameters[i].getName(),
053                                            joddMethodParameters[i].getSignature(),
054                                            methodParameterTypes[i]);
055                            }
056                    }
057                    catch (Exception e) {
058                            _log.error(e, e);
059    
060                            return null;
061                    }
062    
063                    _methodParameters.put(method, methodParameters);
064    
065                    return methodParameters;
066            }
067    
068            private static Log _log = LogFactoryUtil.getLog(
069                    MethodParametersResolverImpl.class);
070    
071            private Map<AccessibleObject, MethodParameter[]> _methodParameters =
072                    new HashMap<AccessibleObject, MethodParameter[]>();
073    
074    }