1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.doxia.sink.impl;
20
21 import java.lang.reflect.InvocationHandler;
22 import java.lang.reflect.InvocationTargetException;
23 import java.lang.reflect.Method;
24 import java.util.List;
25
26 import org.apache.maven.doxia.sink.Sink;
27
28
29
30
31 public class EventCapturingSinkProxy implements InvocationHandler {
32
33 private final Sink sink;
34 private final List<String> capturedEventNames;
35
36
37
38
39
40
41
42 public static Sink newInstance(Sink sink, List<String> capturedEventNames) {
43 return (Sink) java.lang.reflect.Proxy.newProxyInstance(
44 sink.getClass().getClassLoader(),
45 new Class<?>[] {Sink.class},
46 new EventCapturingSinkProxy(sink, capturedEventNames));
47 }
48
49 private EventCapturingSinkProxy(Sink sink, List<String> capturedEventNames) {
50 this.sink = sink;
51 this.capturedEventNames = capturedEventNames;
52 }
53
54 @Override
55 public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
56 Object result;
57 try {
58 capturedEventNames.add(method.getName());
59 result = method.invoke(sink, args);
60 } catch (InvocationTargetException e) {
61 throw e.getTargetException();
62 }
63 return result;
64 }
65 }