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 org.apache.commons.inject.api.IBinding; |
20 | |
import org.apache.commons.inject.api.IInjector; |
21 | |
import org.apache.commons.inject.api.IPoint; |
22 | |
import org.apache.commons.inject.api.IProvider; |
23 | |
|
24 | |
public class BindingProxy<T> implements IBinding<T>, IInjectorAware { |
25 | |
private IBinding<T> binding; |
26 | |
private boolean initialized; |
27 | |
private boolean isResolvedLater; |
28 | |
private final String cause; |
29 | 23 | private final RuntimeException rte = new RuntimeException(); |
30 | |
|
31 | 23 | public BindingProxy(String pCause) { |
32 | 23 | cause = pCause; |
33 | 23 | } |
34 | |
|
35 | |
public boolean isResolvedLater() { |
36 | 23 | return isResolvedLater; |
37 | |
} |
38 | |
|
39 | |
public void setResolvedLater(boolean pResolvedLater) { |
40 | 9 | isResolvedLater = pResolvedLater; |
41 | 9 | } |
42 | |
|
43 | |
@Override |
44 | |
public synchronized IProvider<T> getProvider() { |
45 | 199 | if (!initialized) { |
46 | 0 | throw new IllegalStateException("This Binding hasn't been initialized.", rte); |
47 | |
} |
48 | 199 | return binding.getProvider(); |
49 | |
} |
50 | |
|
51 | |
@Override |
52 | |
public IPoint<T> getPoint() { |
53 | 0 | if (!initialized) { |
54 | 0 | throw new IllegalStateException("This Binding hasn't been initialized."); |
55 | |
} |
56 | 0 | return binding.getPoint(); |
57 | |
} |
58 | |
|
59 | |
public synchronized void setBinding(IBinding<T> pBinding) { |
60 | 23 | if (pBinding == null) { |
61 | 0 | throw new NullPointerException("The proxied binding must not be null."); |
62 | |
} |
63 | 23 | binding = pBinding; |
64 | 23 | initialized = true; |
65 | 23 | } |
66 | |
|
67 | |
public String getCause() { |
68 | 0 | return cause; |
69 | |
} |
70 | |
|
71 | |
@Override |
72 | |
public void init(IInjector pInjector) { |
73 | 169 | if (binding != null && binding instanceof IInjectorAware) { |
74 | 169 | ((IInjectorAware) binding).init(pInjector); |
75 | |
} |
76 | 169 | } |
77 | |
} |