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
40
41
42 @Inject
43 public GuiceContainerProvider(final Injector injector) {
44 this.container = new GuiceContainerImpl(injector);
45 }
46
47
48
49
50 public Container getContainer() {
51 return container;
52 }
53
54
55
56
57
58
59 private static class GuiceContainerImpl implements Container {
60
61
62 private final Injector injector;
63
64
65
66
67
68
69
70 public GuiceContainerImpl(final Injector injector) {
71 this.injector = injector;
72 }
73
74
75
76
77 public <T> T lookup(final Class<T> type) throws LookupException {
78 try {
79 return injector.getInstance(type);
80 } catch (final ConfigurationException e) {
81 throw new LookupException(e);
82 }
83 }
84
85 }
86
87 }