1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package jp.liq.container.vocabulary;
17
18 import java.lang.reflect.Modifier;
19 import java.util.ArrayList;
20 import java.util.List;
21
22 import jp.liq.container.Component;
23 import jp.liq.container.Container;
24 import jp.liq.container.Injector;
25 import jp.liq.container.Module;
26 import jp.liq.container.ContainerVocabulary;
27 import jp.liq.container.component.ConstructorComponent;
28
29 public class SentinelConfig {
30 public SentinelModule configure(Container container) {
31 SentinelModule module = new SentinelModule();
32 container.include(module);
33 return module;
34 }
35
36
37
38
39
40
41 public class SentinelModule extends Module implements ContainerVocabulary {
42 private List<Injector> injectors;
43
44
45
46
47 public SentinelModule() {
48 this.injectors = new ArrayList<Injector>();
49 }
50
51
52
53
54
55
56 public SentinelModule with(Injector injector) {
57 injectors.add(injector);
58 return this;
59 }
60
61
62
63
64 protected <T> Component<T> createComponent(Class<T> type) {
65 if(Modifier.isAbstract(type.getModifiers()) || type.getConstructors().length != 1) {
66 return null;
67 }
68 ConstructorComponent<T> c = component.from(ctor.of(type));
69 for(Injector i : injectors) {
70 c.with(i);
71 }
72 return c;
73 }
74 }
75 }