1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.openehealth.ipf.platform.camel.core.closures;
17
18 import groovy.lang.Closure;
19
20 import org.codehaus.groovy.runtime.InvokerInvocationException;
21
22
23
24
25
26
27 public abstract class ClosureAdapter {
28
29 private final Closure closure;
30
31 public ClosureAdapter(Closure closure) {
32 this.closure = closure;
33 }
34
35 public Closure getClosure() {
36 return closure;
37 }
38
39 public Object call(Object... args) {
40 return callClosure(closure, args);
41 }
42
43 public static Object callClosure(Closure closure, Object... args) {
44 try {
45 return closure.call(args);
46 } catch (InvokerInvocationException e) {
47 if (e.getCause() instanceof RuntimeException) {
48 throw (RuntimeException)e.getCause();
49 } else {
50 throw e;
51 }
52 }
53 }
54
55 }