1 package org.apache.onami.autobind.annotations.features;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 import static java.lang.String.format;
21 import static java.util.logging.Level.FINE;
22 import static org.apache.onami.autobind.annotations.To.Type.IMPLEMENTATION;
23 import static org.apache.onami.autobind.install.BindingStage.BINDING;
24 import static org.apache.onami.autobind.install.BindingStage.IGNORE;
25
26 import java.lang.annotation.Annotation;
27 import java.util.Map;
28
29 import javax.inject.Singleton;
30
31 import org.apache.onami.autobind.annotations.Bind;
32 import org.apache.onami.autobind.install.BindingStage;
33
34 @Singleton
35 public class ImplementationBindingFeature
36 extends AutoBindingFeature
37 {
38
39 @Override
40 public BindingStage accept( Class<Object> annotatedClass, Map<String, Annotation> annotations )
41 {
42 if ( annotations.containsKey( Bind.class.getName() ) )
43 {
44 Bind annotation = (Bind) annotations.get( Bind.class.getName() );
45 if ( !annotation.multiple() && ( IMPLEMENTATION == annotation.to().value() ) )
46 {
47 return BINDING;
48 }
49 }
50 return IGNORE;
51 }
52
53 @Override
54 public void process( final Class<Object> annotatedClass, final Map<String, Annotation> annotations )
55 {
56 final boolean asSingleton =
57 ( annotations.containsKey( com.google.inject.Singleton.class.getName() ) || annotations.containsKey( javax.inject.Singleton.class.getName() ) );
58
59 if ( _logger.isLoggable( FINE ) )
60 {
61 _logger.fine( format( "Binding Class %s. Singleton? %s ", annotatedClass, asSingleton ) );
62 }
63
64 bind( annotatedClass, null, ( asSingleton ? Singleton.class : null ) );
65 }
66
67 }