01: /*
02: * Copyright (c) 2005 Your Corporation. All Rights Reserved.
03: */
04:
05: /*
06: * Created by IntelliJ IDEA.
07: * User: Jacques
08: * Date: Dec 21, 2005
09: * Time: 2:27:19 AM
10: */
11: package com.thoughtworks.proxy.kit;
12:
13: import java.lang.reflect.Method;
14:
15: import com.thoughtworks.proxy.Invoker;
16:
17: /**
18: * A simple {@link com.thoughtworks.proxy.Invoker} implementation, that routes any call to a target object. A <code>null</code> value as
19: * target can be handled, the invocation result will alway be <code>null</code>.
20: *
21: * @author Aslak Hellesøy
22: * @since 0.2, 0.1 in package com.thoughtworks.proxy.toy.decorate
23: */
24: public class SimpleInvoker implements Invoker {
25: private static final long serialVersionUID = 1L;
26:
27: private Object target;
28:
29: /**
30: * Construct a SimpleInvoker.
31: *
32: * @param target the invocation target.
33: * @since 0.2, 0.1 in package com.thoughtworks.proxy.toy.decorate
34: */
35: public SimpleInvoker(final Object target) {
36: this .target = target;
37: }
38:
39: public Object invoke(final Object proxy, final Method method,
40: final Object[] args) throws Throwable {
41: if (method.getName().equals("equals") && proxy == args[0])
42: return Boolean.TRUE;
43: return (target == null ? null : method.invoke(target, args));
44: }
45:
46: /**
47: * Retrieve the target of the invocations.
48: *
49: * @return the target object
50: * @since 0.2
51: */
52: public Object getTarget() {
53: return target;
54: }
55: }
|