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 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 synchronized ( _binder )
43 {
44 if ( annotation != null )
45 {
46 builder = newSetBinder( _binder, interf, annotation );
47 }
48 else
49 {
50 builder = newSetBinder( _binder, interf );
51 }
52
53 builder.addBinding().toInstance( impl );
54 }
55 }
56
57 protected void bindConstant( String value, Annotation annotation )
58 {
59 Multibinder<String> builder;
60 synchronized ( _binder )
61 {
62 builder = newSetBinder( _binder, String.class, annotation );
63 builder.addBinding().toInstance( value );
64 }
65 }
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 synchronized ( _binder )
72 {
73 if ( annotation != null )
74 {
75 builder = newSetBinder( _binder, interf, annotation );
76 }
77 else
78 {
79 builder = newSetBinder( _binder, interf );
80 }
81
82 ScopedBindingBuilder scopedBindingBuilder = builder.addBinding().to( impl );
83 if ( scope != null )
84 {
85 scopedBindingBuilder.in( scope );
86 }
87 }
88 }
89
90 }