1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.apache.commons.inject.impl; |
18 | |
|
19 | |
import java.lang.reflect.Method; |
20 | |
|
21 | |
import org.apache.commons.inject.api.IBinding; |
22 | |
import org.apache.commons.inject.api.IInjector; |
23 | |
import org.apache.commons.inject.api.IPoint; |
24 | |
import org.apache.commons.inject.util.Exceptions; |
25 | |
|
26 | |
public class MethodPoint<T> implements IPoint<T>, IInjectorAware { |
27 | |
private final IBinding<Object>[] bindings; |
28 | |
private final Method method; |
29 | |
|
30 | 108 | public MethodPoint(IBinding<Object>[] pBindings, Method pMethod) { |
31 | 108 | bindings = pBindings; |
32 | 108 | method = pMethod; |
33 | 108 | } |
34 | |
|
35 | |
@Override |
36 | |
public void injectTo(T pInstance, IInjector pInjector) { |
37 | |
try { |
38 | 320 | final Object[] args = new Object[bindings.length]; |
39 | 350 | for (int i = 0; i < args.length; i++) { |
40 | 30 | args[i] = bindings[i].getProvider().get(); |
41 | |
} |
42 | 320 | if (!method.isAccessible()) { |
43 | 56 | method.setAccessible(true); |
44 | |
} |
45 | 320 | method.invoke(pInstance, args); |
46 | 0 | } catch (Throwable t) { |
47 | 0 | throw Exceptions.show(t); |
48 | 320 | } |
49 | 320 | } |
50 | |
|
51 | |
@Override |
52 | |
public void init(IInjector pInjector) { |
53 | 270 | for (IBinding<Object> binding : bindings) { |
54 | 42 | if (binding instanceof IInjectorAware) { |
55 | 42 | ((IInjectorAware) binding).init(pInjector); |
56 | |
} |
57 | |
} |
58 | 228 | } |
59 | |
} |