1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.jboss.netty.handler.codec.serialization;
17
18 import java.util.Map;
19
20 class CachingClassResolver implements ClassResolver {
21
22 private final Map<String, Class<?>> classCache;
23 private final ClassResolver delegate;
24
25 CachingClassResolver(ClassResolver delegate, Map<String, Class<?>> classCache) {
26 this.delegate = delegate;
27 this.classCache = classCache;
28 }
29
30 public Class<?> resolve(String className) throws ClassNotFoundException {
31
32 Class<?> clazz;
33 clazz = classCache.get(className);
34 if (clazz != null) {
35 return clazz;
36 }
37
38
39 clazz = delegate.resolve(className);
40
41 classCache.put(className, clazz);
42 return clazz;
43 }
44
45 }