1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.cubby.plugins.s2.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 import org.seasar.framework.container.ComponentNotFoundRuntimeException;
22 import org.seasar.framework.container.CyclicReferenceRuntimeException;
23 import org.seasar.framework.container.S2Container;
24 import org.seasar.framework.container.TooManyRegistrationRuntimeException;
25
26
27
28
29
30
31
32 public class S2ContainerProvider implements ContainerProvider {
33
34 public static final String s2Container_BINDING = "bindingType=must";
35
36
37 private final Container container = new S2ContainerImpl();
38
39
40 private S2Container s2Container;
41
42
43
44
45
46
47
48 public void setS2Container(final S2Container s2Container) {
49 this.s2Container = s2Container;
50 }
51
52
53
54
55 public Container getContainer() {
56 return container;
57 }
58
59
60
61
62
63
64
65 private class S2ContainerImpl implements Container {
66
67
68
69
70
71
72 public <T> T lookup(final Class<T> type) throws LookupException {
73 try {
74 final T component = type.cast(s2Container.getRoot()
75 .getComponent(type));
76 if (component == null) {
77 throw new LookupException();
78 }
79 return component;
80 } catch (final ComponentNotFoundRuntimeException e) {
81 throw new LookupException(e);
82 } catch (final TooManyRegistrationRuntimeException e) {
83 throw new LookupException(e);
84 } catch (final CyclicReferenceRuntimeException e) {
85 throw new LookupException(e);
86 }
87 }
88
89 }
90
91 }