01: // Copyright (c) 2003-2007, Jodd Team (jodd.sf.net). All Rights Reserved.
02:
03: package jodd.proxetta;
04:
05: import org.objectweb.asm.ClassReader;
06:
07: import java.util.Map;
08: import java.util.HashMap;
09: import java.io.IOException;
10:
11: /**
12: * Definition of a single proxy tells which {@link Proxy} implementation is
13: * applied on some target methods set.
14: */
15: public abstract class ProxyDefinition {
16:
17: protected Class<? extends Proxy> proxy;
18: protected ClassReader proxyClassReader;
19:
20: protected ProxyDefinition(Class<? extends Proxy> proxy) {
21: this .proxy = proxy;
22: proxyClassReader = proxyClassReaderCache.get(proxy);
23: if (proxyClassReader == null) {
24: try {
25: proxyClassReader = new ClassReader(proxy.getName());
26: } catch (IOException ioex) {
27: throw new ProxettaException(ioex);
28: }
29: proxyClassReaderCache.put(proxy, proxyClassReader);
30: }
31: }
32:
33: /**
34: * Returns class with proxy implementation.
35: */
36: public Class<? extends Proxy> getProxy() {
37: return proxy;
38: }
39:
40: /**
41: * Returns the proxy name. It is a simple class name of a proxy class.
42: */
43: public String getProxyName() {
44: return proxy.getSimpleName();
45: }
46:
47: /**
48: * Returns proxy class reader. They are cachned due to performances.
49: */
50: public ClassReader getProxyClassReader() {
51: return proxyClassReader;
52: }
53:
54: /**
55: * Returns <code>true</code> if provided package, class name and method signature
56: * should be wrapped with the proxy.
57: */
58: public abstract boolean apply(MethodSignature msign);
59:
60: // ---------------------------------------------------------------- cache
61:
62: protected static Map<Class, ClassReader> proxyClassReaderCache = new HashMap<Class, ClassReader>();
63:
64: }
|