1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.ibatis.reflection;
17
18 import java.util.concurrent.ConcurrentHashMap;
19 import java.util.concurrent.ConcurrentMap;
20
21 public class DefaultReflectorFactory implements ReflectorFactory {
22 private boolean classCacheEnabled = true;
23 private final ConcurrentMap<Class<?>, Reflector> reflectorMap = new ConcurrentHashMap<Class<?>, Reflector>();
24
25 public DefaultReflectorFactory() {
26 }
27
28 @Override
29 public boolean isClassCacheEnabled() {
30 return classCacheEnabled;
31 }
32
33 @Override
34 public void setClassCacheEnabled(boolean classCacheEnabled) {
35 this.classCacheEnabled = classCacheEnabled;
36 }
37
38 @Override
39 public Reflector findForClass(Class<?> type) {
40 if (classCacheEnabled) {
41
42 Reflector cached = reflectorMap.get(type);
43 if (cached == null) {
44 cached = new Reflector(type);
45 reflectorMap.put(type, cached);
46 }
47 return cached;
48 } else {
49 return new Reflector(type);
50 }
51 }
52
53 }