1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.seasar.cubby.plugins.s2; |
17 | |
|
18 | |
import javax.el.ELResolver; |
19 | |
import javax.servlet.ServletContext; |
20 | |
import javax.servlet.jsp.JspApplicationContext; |
21 | |
import javax.servlet.jsp.JspFactory; |
22 | |
|
23 | |
import org.seasar.cubby.plugin.AbstractPlugin; |
24 | |
import org.seasar.cubby.plugins.s2.el.S2BeanELResolver; |
25 | |
import org.seasar.cubby.spi.BeanDescProvider; |
26 | |
import org.seasar.cubby.spi.ContainerProvider; |
27 | |
import org.seasar.cubby.spi.ConverterProvider; |
28 | |
import org.seasar.cubby.spi.PathResolverProvider; |
29 | |
import org.seasar.cubby.spi.Provider; |
30 | |
import org.seasar.cubby.spi.RequestParserProvider; |
31 | |
import org.seasar.framework.container.S2Container; |
32 | |
import org.seasar.framework.container.factory.SingletonS2ContainerFactory; |
33 | |
import org.seasar.framework.log.Logger; |
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
public class S2ContainerPlugin extends AbstractPlugin { |
53 | |
|
54 | |
|
55 | 0 | private static final Logger logger = Logger |
56 | |
.getLogger(S2ContainerPlugin.class); |
57 | |
|
58 | |
static { |
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
try { |
65 | 0 | Class.forName("org.apache.jasper.compiler.JspRuntimeContext"); |
66 | 0 | } catch (final Exception e) { |
67 | 0 | if (logger.isDebugEnabled()) { |
68 | 0 | logger.debug(e.getMessage()); |
69 | |
} |
70 | 0 | } |
71 | 0 | } |
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | 0 | public S2ContainerPlugin() { |
77 | 0 | support(BeanDescProvider.class); |
78 | 0 | support(ContainerProvider.class); |
79 | 0 | support(RequestParserProvider.class); |
80 | 0 | support(PathResolverProvider.class); |
81 | 0 | support(ConverterProvider.class); |
82 | 0 | } |
83 | |
|
84 | |
|
85 | |
private ServletContext servletContext; |
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
@Override |
91 | |
public void initialize(final ServletContext servletContext) |
92 | |
throws Exception { |
93 | 0 | super.initialize(servletContext); |
94 | 0 | this.servletContext = servletContext; |
95 | 0 | } |
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
@Override |
104 | |
public void ready() { |
105 | 0 | final JspFactory jspFactory = JspFactory.getDefaultFactory(); |
106 | 0 | if (jspFactory != null) { |
107 | 0 | final JspApplicationContext jspApplicationContext = jspFactory |
108 | |
.getJspApplicationContext(servletContext); |
109 | 0 | final S2Container container = SingletonS2ContainerFactory |
110 | |
.getContainer(); |
111 | 0 | final ELResolver[] elResolvers = (ELResolver[]) container |
112 | |
.findAllComponents(ELResolver.class); |
113 | 0 | for (final ELResolver elResolver : elResolvers) { |
114 | 0 | jspApplicationContext.addELResolver(elResolver); |
115 | 0 | logger.log("ICUB0001", new Object[] { elResolver }); |
116 | |
} |
117 | |
} |
118 | 0 | } |
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | |
@Override |
124 | |
public <S extends Provider> S getProvider(final Class<S> service) { |
125 | 0 | if (this.isSupport(service)) { |
126 | 0 | final S2Container container = SingletonS2ContainerFactory |
127 | |
.getContainer(); |
128 | 0 | return service.cast(container.getComponent(service)); |
129 | |
} else { |
130 | 0 | return null; |
131 | |
} |
132 | |
} |
133 | |
|
134 | |
} |