2
* Spin - transparent threading solution for non-freezing Swing applications.
3
* Copyright (C) 2002 Sven Meier
5
* This library is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU Lesser General Public
7
* License as published by the Free Software Foundation; either
8
* version 2.1 of the License, or (at your option) any later version.
10
* This library is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* Lesser General Public License for more details.
15
* You should have received a copy of the GNU Lesser General Public
16
* License along with this library; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
import java.lang.reflect.Method;
23
import net.sf.cglib.proxy.Enhancer;
24
import net.sf.cglib.proxy.Factory;
25
import net.sf.cglib.proxy.MethodInterceptor;
26
import net.sf.cglib.proxy.MethodProxy;
29
* A factory of proxies utilizing CGLib.
31
public class CGLibProxyFactory extends ProxyFactory {
33
public Object createProxy(Object object, Evaluator evaluator) {
34
return Enhancer.create(object.getClass(), new SpinMethodInterceptor(object, evaluator));
37
public boolean isProxy(Object object) {
43
if (!(object instanceof Factory)) {
47
Factory factory = (Factory)object;
48
return (factory.getCallback(0) instanceof SpinMethodInterceptor);
51
protected boolean areProxyEqual(Object proxy1, Object proxy2) {
52
SpinMethodInterceptor methodInterceptor1 = (SpinMethodInterceptor)((Factory)proxy1).getCallback(0);
53
SpinMethodInterceptor methodInterceptor2 = (SpinMethodInterceptor)((Factory)proxy2).getCallback(0);
55
return methodInterceptor1.object == methodInterceptor2.object;
59
* Method interceptor for the <em>Spin</em> proxy.
61
private class SpinMethodInterceptor implements MethodInterceptor {
63
private Object object;
64
private Evaluator evaluator;
66
public SpinMethodInterceptor(Object object, Evaluator evaluator) {
68
this.evaluator = evaluator;
72
* Handle the invocation of a method on the <em>Spin</em> proxy.
74
* @param proxy the proxy instance
75
* @param method the method to invoke
76
* @param args the arguments for the method
77
* @param methodProxy non-intercepted proxy for the method
78
* @return the result of the invocation on the wrapped object
79
* @throws Throwable if the wrapped method throws a <code>Throwable</code>
81
public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
82
return evaluteInvocation(evaluator, proxy, new Invocation(this.object, method, args));
b'\\ No newline at end of file'