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