001
014
015 package com.liferay.portal.kernel.util;
016
017 import java.lang.reflect.Method;
018
019 import java.util.Map;
020 import java.util.concurrent.ConcurrentHashMap;
021
022
026 public class MethodCache {
027
028 public static void reset() {
029 _methods.clear();
030 }
031
032
035 protected static Method get(MethodKey methodKey)
036 throws NoSuchMethodException {
037
038 Method method = _methods.get(methodKey);
039
040 if (method == null) {
041 Class<?> declaringClass = methodKey.getDeclaringClass();
042
043 method = declaringClass.getDeclaredMethod(
044 methodKey.getMethodName(), methodKey.getParameterTypes());
045
046 if (!method.isAccessible()) {
047 method.setAccessible(true);
048 }
049
050 _methods.put(methodKey, method);
051 }
052
053 return method;
054 }
055
056 private static Map<MethodKey, Method> _methods =
057 new ConcurrentHashMap<MethodKey, Method>();
058
059 }