##### Coverage Report - org.seasar.cubby.plugins.s2.S2ContainerPlugin

Classes in this File | Line Coverage | Branch Coverage | Complexity
S2ContainerPlugin |
0% | 0/30
0% | 0/6
| 2.0;2

1 |  |
     /*
2 |  |
      * Copyright 2004-2009 the Seasar Foundation and the Others.
3 |  |
      *
4 |  |
      * Licensed under the Apache License, Version 2.0 (the "License");
5 |  |
      * you may not use this file except in compliance with the License.
6 |  |
      * You may obtain a copy of the License at
7 |  |
      *
8 |  |
      *     http://www.apache.org/licenses/LICENSE-2.0
9 |  |
      *
10 |  |
      * Unless required by applicable law or agreed to in writing, software
11 |  |
      * distributed under the License is distributed on an "AS IS" BASIS,
12 |  |
      * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13 |  |
      * either express or implied. See the License for the specific language
14 |  |
      * governing permissions and limitations under the License.
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 |  |
      * Cubby を <a href="http://s2container.seasar.org/2.4/ja/">S2Container</a>
37 |  |
      * に統合するためのプラグインです。
38 |  |
      * <p>
39 |  |
      * このプラグインが提供するプロバイダは以下の通りです。
40 |  |
      * <ul>
41 |  |
      * <li>{@link BeanDescProvider}</li>
42 |  |
      * <li>{@link ContainerProvider}</li>
43 |  |
      * <li>{@link RequestParserProvider}</li>
44 |  |
      * <li>{@link PathResolverProvider}</li>
45 |  |
      * <li>{@link ConverterProvider}</li>
46 |  |
      * </ul>
47 |  |
      * </p>
48 |  |
      *
49 |  |
      * @see <a href="http://s2container.seasar.org/2.4/ja/">S2Container</a>
50 |  |
      * @author baba
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 |  |
                     // HACK
60 |  |
                     // In "mvn tomcat:run", JspFactory.getDefaultFactory() returns null.
61 |  |
                     // because static initializer of "JspRuntimeContext" has not been
62 |  |
                     // executed yet.
63 |  |
                     // Like "JasperListener" in "server.xml"
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 |  |
              * {@inheritDoc}
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 |  |
              * {@inheritDoc}
99 |  |
              * <p>
100 |  |
              * {@link S2BeanELResolver} を {@link JspApplicationContext} に登録します。
101 |  |
              * </p>
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 |  |
              * {@inheritDoc}
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 |  |
     }