1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.seasar.cubby.plugins.guice.spi;
18
19 import org.seasar.cubby.spi.ContainerProvider;
20 import org.seasar.cubby.spi.container.Container;
21 import org.seasar.cubby.spi.container.LookupException;
22
23 import com.google.inject.ConfigurationException;
24 import com.google.inject.Inject;
25 import com.google.inject.Injector;
26
27
28
29
30
31
32 public class GuiceContainerProvider implements ContainerProvider {
33
34
35 private final Container container;
36
37
38
39
40
41
42
43 @Inject
44 public GuiceContainerProvider(final Injector injector) {
45 this.container = new GuiceContainerImpl(injector);
46 }
47
48
49
50
51 public Container getContainer() {
52 return container;
53 }
54
55
56
57
58
59
60 private static class GuiceContainerImpl implements Container {
61
62
63 private final Injector injector;
64
65
66
67
68
69
70
71 public GuiceContainerImpl(final Injector injector) {
72 this.injector = injector;
73 }
74
75
76
77
78 public <T> T lookup(final Class<T> type) throws LookupException {
79 try {
80 return injector.getInstance(type);
81 } catch (final ConfigurationException e) {
82 throw new LookupException(e);
83 }
84 }
85
86 }
87
88 }