1 | |
package org.apache.onami.autobind.scanner.features; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
import static com.google.inject.multibindings.Multibinder.newSetBinder; |
21 | |
|
22 | |
import java.lang.annotation.Annotation; |
23 | |
|
24 | |
import org.apache.onami.autobind.scanner.ScannerModule; |
25 | |
|
26 | |
import com.google.inject.binder.ScopedBindingBuilder; |
27 | |
import com.google.inject.multibindings.Multibinder; |
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | 0 | public abstract class MultiBindingScannerFeature |
35 | |
extends BindingScannerFeature |
36 | |
{ |
37 | |
|
38 | |
protected <T, V extends T> void bindInstance( V impl, Class<T> interf, Annotation annotation, |
39 | |
Class<? extends Annotation> scope ) |
40 | |
{ |
41 | |
Multibinder<T> builder; |
42 | 0 | synchronized ( _binder ) |
43 | |
{ |
44 | 0 | if ( annotation != null ) |
45 | |
{ |
46 | 0 | builder = newSetBinder( _binder, interf, annotation ); |
47 | |
} |
48 | |
else |
49 | |
{ |
50 | 0 | builder = newSetBinder( _binder, interf ); |
51 | |
} |
52 | |
|
53 | 0 | builder.addBinding().toInstance( impl ); |
54 | 0 | } |
55 | 0 | } |
56 | |
|
57 | |
protected void bindConstant( String value, Annotation annotation ) |
58 | |
{ |
59 | |
Multibinder<String> builder; |
60 | 0 | synchronized ( _binder ) |
61 | |
{ |
62 | 0 | builder = newSetBinder( _binder, String.class, annotation ); |
63 | 0 | builder.addBinding().toInstance( value ); |
64 | 0 | } |
65 | 0 | } |
66 | |
|
67 | |
protected <T, V extends T> void bind( Class<V> impl, Class<T> interf, Annotation annotation, |
68 | |
Class<? extends Annotation> scope ) |
69 | |
{ |
70 | |
Multibinder<T> builder; |
71 | 0 | synchronized ( _binder ) |
72 | |
{ |
73 | 0 | if ( annotation != null ) |
74 | |
{ |
75 | 0 | builder = newSetBinder( _binder, interf, annotation ); |
76 | |
} |
77 | |
else |
78 | |
{ |
79 | 0 | builder = newSetBinder( _binder, interf ); |
80 | |
} |
81 | |
|
82 | 0 | ScopedBindingBuilder scopedBindingBuilder = builder.addBinding().to( impl ); |
83 | 0 | if ( scope != null ) |
84 | |
{ |
85 | 0 | scopedBindingBuilder.in( scope ); |
86 | |
} |
87 | 0 | } |
88 | 0 | } |
89 | |
|
90 | |
} |