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 java.util.logging.Level.INFO; |
23 | |
import static java.util.logging.Logger.getLogger; |
24 | |
import static org.apache.onami.autobind.install.BindingStage.IGNORE; |
25 | |
|
26 | |
import java.lang.annotation.Annotation; |
27 | |
import java.util.Map; |
28 | |
import java.util.logging.Logger; |
29 | |
|
30 | |
import javax.inject.Singleton; |
31 | |
|
32 | |
import org.apache.onami.autobind.annotations.GuiceModule; |
33 | |
import org.apache.onami.autobind.install.BindingStage; |
34 | |
import org.apache.onami.autobind.install.bindjob.BindingJob; |
35 | |
import org.apache.onami.autobind.install.bindjob.ModuleBindingJob; |
36 | |
import org.apache.onami.autobind.scanner.features.BindingScannerFeature; |
37 | |
|
38 | |
import com.google.inject.Module; |
39 | |
|
40 | |
@Singleton |
41 | 0 | public class ModuleBindingFeature |
42 | |
extends BindingScannerFeature |
43 | |
{ |
44 | |
|
45 | 0 | private final Logger _logger = getLogger( getClass().getName() ); |
46 | |
|
47 | |
@Override |
48 | |
public BindingStage accept( Class<Object> annotatedClass, Map<String, Annotation> annotations ) |
49 | |
{ |
50 | 0 | if ( annotations.containsKey( GuiceModule.class.getName() ) ) |
51 | |
{ |
52 | 0 | GuiceModule module = (GuiceModule) annotations.get( GuiceModule.class.getName() ); |
53 | 0 | return module.stage(); |
54 | |
} |
55 | 0 | return IGNORE; |
56 | |
} |
57 | |
|
58 | |
@Override |
59 | |
public void process( final Class<Object> annotatedClass, Map<String, Annotation> annotations ) |
60 | |
{ |
61 | 0 | BindingJob job = new ModuleBindingJob( annotatedClass.getName() ); |
62 | 0 | if ( !tracer.contains( job ) ) |
63 | |
{ |
64 | 0 | if ( _logger.isLoggable( INFO ) ) |
65 | |
{ |
66 | 0 | _logger.info( "Installing Module: " + annotatedClass.getName() ); |
67 | |
} |
68 | 0 | synchronized ( _binder ) |
69 | |
{ |
70 | 0 | _binder.install( (Module) injector.getInstance( annotatedClass ) ); |
71 | 0 | } |
72 | |
} |
73 | |
else |
74 | |
{ |
75 | 0 | String message = format( "Ignoring BindingJob \"%s\", because it was already bound.", job ); |
76 | |
|
77 | 0 | if ( _logger.isLoggable( FINE ) ) |
78 | |
{ |
79 | 0 | _logger.log( FINE, message, new Exception( message ) ); |
80 | |
} |
81 | 0 | else if ( _logger.isLoggable( INFO ) ) |
82 | |
{ |
83 | 0 | _logger.log( INFO, message ); |
84 | |
} |
85 | |
} |
86 | 0 | } |
87 | |
|
88 | |
} |