1 package org.apache.onami.autobind.scanner;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 import static java.lang.System.getProperty;
21 import static java.util.logging.Level.FINE;
22 import static java.util.logging.Level.INFO;
23 import static java.util.logging.Level.SEVERE;
24 import static java.util.logging.Logger.getLogger;
25
26 import java.io.IOException;
27 import java.util.Set;
28 import java.util.logging.Logger;
29
30 import javax.inject.Inject;
31
32 import org.apache.onami.autobind.annotations.Bind;
33 import org.apache.onami.autobind.annotations.GuiceModule;
34 import org.apache.onami.autobind.install.InstallationContext;
35 import org.apache.onami.autobind.scanner.features.BindingScannerFeature;
36 import org.apache.onami.autobind.scanner.features.ScannerFeature;
37
38 import com.google.inject.Binder;
39 import com.google.inject.Module;
40
41
42
43
44
45
46
47 public class ScannerModule
48 implements Module
49 {
50
51 private static String LINE_SEPARATOR = getProperty( "line.separator" );
52
53 private final Logger _logger = getLogger( getClass().getName() );
54
55 @Inject
56 private ClasspathScanner _scanner;
57
58 @Inject
59 private Set<ScannerFeature> _listeners;
60
61 @Inject
62 private InstallationContext _context;
63
64 @Override
65 public void configure( Binder binder )
66 {
67 if ( _logger.isLoggable( INFO ) )
68 {
69 StringBuilder builder = new StringBuilder( _scanner.getClass().getName() )
70 .append( " is using following Scanner Features: " )
71 .append( LINE_SEPARATOR );
72 for ( ScannerFeature listener : _listeners )
73 {
74 builder.append( listener.getClass().getName() ).append( LINE_SEPARATOR );
75 }
76 _logger.log( INFO, builder.toString() );
77 }
78 for ( ScannerFeature listener : _listeners )
79 {
80 if ( listener instanceof BindingScannerFeature )
81 {
82 ( (BindingScannerFeature) listener ).setBinder( binder );
83 if ( _logger.isLoggable( FINE ) )
84 {
85 _logger.fine( "Binding AnnotationListeners " + listener.getClass().getName() );
86 }
87 }
88 }
89 try
90 {
91 _scanner.scan();
92 }
93 catch ( IOException e )
94 {
95 _logger.log( SEVERE, "Failure while Scanning the Classpath for Classes with Annotations.", e );
96 }
97 try
98 {
99 _context.process();
100 }
101 catch ( Exception e )
102 {
103 _logger.log( SEVERE, "Failure while executing the collected Tasks.", e );
104 }
105 }
106
107 }