1 package com.github.mygreen.supercsv.builder;
2
3 import java.lang.reflect.InvocationTargetException;
4 import java.lang.reflect.Method;
5 import java.util.Objects;
6
7 import org.supercsv.exception.SuperCsvReflectionException;
8
9
10
11
12
13
14
15
16 public class ListenerCallbackMethod extends CallbackMethod {
17
18 private final Object listener;
19
20 public ListenerCallbackMethod(final Object listener, final Method method) {
21 super(method);
22 Objects.requireNonNull(listener);
23 this.listener = listener;
24 }
25
26 @Override
27 protected void execute(final Object record, final Object[] paramValues) {
28 try {
29 method.invoke(listener, paramValues);
30
31 } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
32 Throwable t = e.getCause() == null ? e : e.getCause();
33 throw new SuperCsvReflectionException(
34 String.format("Fail execute method '%s#%s'.", listener.getClass().getName(), method.getName()),
35 t);
36 }
37
38
39 }
40
41 }