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