use of org.teiid.core.util.LRUCache in project teiid by teiid.
the class TeiidScriptEngine method getMethodMap.
public Map<String, Method> getMethodMap(Class<?> clazz) throws ScriptException {
Map<Class<?>, Map<String, Method>> clazzMaps = null;
Map<String, Method> methodMap = null;
if (properties != null) {
clazzMaps = properties.get();
if (clazzMaps != null) {
methodMap = clazzMaps.get(clazz);
if (methodMap != null) {
return methodMap;
}
}
}
try {
BeanInfo info = Introspector.getBeanInfo(clazz);
PropertyDescriptor[] pds = info.getPropertyDescriptors();
methodMap = new LinkedHashMap<String, Method>();
if (pds != null) {
for (int j = 0; j < pds.length; j++) {
PropertyDescriptor pd = pds[j];
if (pd.getReadMethod() == null || pd instanceof IndexedPropertyDescriptor) {
continue;
}
String name = pd.getName();
Method m = pd.getReadMethod();
methodMap.put(name, m);
}
}
MethodDescriptor[] mds = info.getMethodDescriptors();
if (pds != null) {
for (int j = 0; j < mds.length; j++) {
MethodDescriptor md = mds[j];
if (md.getMethod() == null || md.getMethod().getParameterTypes().length > 0 || md.getMethod().getReturnType() == Void.class || md.getMethod().getReturnType() == void.class) {
continue;
}
String name = md.getName();
Method m = md.getMethod();
methodMap.put(name, m);
}
}
if (clazzMaps == null) {
clazzMaps = Collections.synchronizedMap(new LRUCache<Class<?>, Map<String, Method>>(100));
properties = new SoftReference<Map<Class<?>, Map<String, Method>>>(clazzMaps);
}
clazzMaps.put(clazz, methodMap);
} catch (IntrospectionException e) {
throw new ScriptException(e);
}
return methodMap;
}
Aggregations