##### Coverage Report - org.seasar.cubby.spi.impl.AbstractRequestParserProvider

Classes in this File | Line Coverage | Branch Coverage | Complexity
AbstractRequestParserProvider |
91% | 11/12
66% | 4/6
| 2.3333333333333335;2.333

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.spi.impl;
17 |  |
18 |  |
     import static org.seasar.cubby.internal.util.LogMessages.format;
19 |  |
20 |  |
     import java.util.Collection;
21 |  |
     import java.util.Map;
22 |  |
23 |  |
     import javax.servlet.http.HttpServletRequest;
24 |  |
25 |  |
     import org.seasar.cubby.controller.RequestParser;
26 |  |
     import org.seasar.cubby.controller.impl.DefaultRequestParser;
27 |  |
     import org.seasar.cubby.spi.RequestParserProvider;
28 |  |
     import org.slf4j.Logger;
29 |  |
     import org.slf4j.LoggerFactory;
30 |  |
31 |  |
     /**
32 |  |
      * {@link RequestParser} のプロバイダの抽象的な実装です。
33 |  |
      * <p>
34 |  |
      * このクラスのサブクラスは {{@link #getRequestParsers()} をオーバーライドして使用可能な要求解析機の一覧を返してください。
35 |  |
      * </p>
36 |  |
      *
37 |  |
      * @author baba
38 |  |
      */
39 | 5 |
     public abstract class AbstractRequestParserProvider implements
40 |  |
                     RequestParserProvider {
41 |  |
42 |  |
             /** ロガー。 */
43 | 1 |
             private static final Logger logger = LoggerFactory
44 |  |
                             .getLogger(AbstractRequestParserProvider.class);
45 |  |
46 |  |
             /** デフォルトの {@link RequestParser} */
47 | 5 |
             private final RequestParser defaultRequestParser = new DefaultRequestParser();
48 |  |
49 |  |
             /**
50 |  |
              * {@inheritDoc}
51 |  |
              */
52 |  |
             public Map<String, Object[]> getParameterMap(
53 |  |
                             final HttpServletRequest request) {
54 | 5 |
                     final RequestParser requestParser = findRequestParser(request);
55 | 5 |
                     if (logger.isDebugEnabled()) {
56 | 5 |
                             logger.debug(format("DCUB0016", requestParser));
57 |  |
                     }
58 | 5 |
                     final Map<String, Object[]> parameterMap = requestParser
59 |  |
                                     .getParameterMap(request);
60 | 5 |
                     return parameterMap;
61 |  |
             }
62 |  |
63 |  |
             /**
64 |  |
              * 要求を解析できる {@link RequestParser} を検索します。
65 |  |
              *
66 |  |
              * @param request
67 |  |
              *            要求
68 |  |
              * @return 要求を解析できる {@link RequestParser}
69 |  |
              */
70 |  |
             protected RequestParser findRequestParser(final HttpServletRequest request) {
71 | 5 |
                     for (final RequestParser requestParser : getRequestParsers()) {
72 | 8 |
                             if (requestParser.isParsable(request)) {
73 | 5 |
                                     return requestParser;
74 |  |
                             }
75 |  |
                     }
76 | 0 |
                     return defaultRequestParser;
77 |  |
             }
78 |  |
79 |  |
             /**
80 |  |
              * 要求解析機の一覧を取得します。
81 |  |
              *
82 |  |
              * @return 要求解析機の一覧
83 |  |
              */
84 |  |
             protected abstract Collection<RequestParser> getRequestParsers();
85 |  |
86 |  |
     }