001    /**
002     * Copyright (c) 2000-present 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.concurrent.ConcurrentReferenceKeyHashMap;
018    import com.liferay.portal.kernel.memory.FinalizeManager;
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.concurrent.ConcurrentMap;
026    
027    import jodd.paramo.Paramo;
028    
029    /**
030     * @author Igor Spasic
031     */
032    public class MethodParametersResolverImpl implements MethodParametersResolver {
033    
034            @Override
035            public MethodParameter[] resolveMethodParameters(Method method) {
036                    MethodParameter[] methodParameters = _methodParameters.get(method);
037    
038                    if (methodParameters != null) {
039                            return methodParameters;
040                    }
041    
042                    Class<?>[] methodParameterTypes = method.getParameterTypes();
043    
044                    jodd.paramo.MethodParameter[] joddMethodParameters =
045                            Paramo.resolveParameters(method);
046    
047                    methodParameters = new MethodParameter[joddMethodParameters.length];
048    
049                    for (int i = 0; i < joddMethodParameters.length; i++) {
050                            methodParameters[i] = new MethodParameter(
051                                    joddMethodParameters[i].getName(),
052                                    joddMethodParameters[i].getSignature(), methodParameterTypes[i],
053                                    true);
054                    }
055    
056                    _methodParameters.put(method, methodParameters);
057    
058                    return methodParameters;
059            }
060    
061            private static final ConcurrentMap
062                    <AccessibleObject, MethodParameter[]> _methodParameters =
063                            new ConcurrentReferenceKeyHashMap<>(
064                                    FinalizeManager.WEAK_REFERENCE_FACTORY);
065    
066    }