Coverage Report - org.seasar.cubby.controller.impl.CubbyConfigurationImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
CubbyConfigurationImpl
100%
25/25
67%
8/12
3
 
 1  
 /*
 2  
  * Copyright 2004-2008 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.controller.impl;
 17  
 
 18  
 import org.seasar.cubby.action.FormatPattern;
 19  
 import org.seasar.cubby.action.impl.FormatPatternImpl;
 20  
 import org.seasar.cubby.controller.CubbyConfiguration;
 21  
 import org.seasar.cubby.controller.RequestParser;
 22  
 import org.seasar.framework.container.ComponentDef;
 23  
 import org.seasar.framework.container.S2Container;
 24  
 import org.seasar.framework.log.Logger;
 25  
 
 26  
 /**
 27  
  * Cubby の全体的な設定情報の実装です。
 28  
  * 
 29  
  * @author baba
 30  
  * @since 1.0.0
 31  
  */
 32  
 public class CubbyConfigurationImpl implements CubbyConfiguration {
 33  
 
 34  1
         private static final Logger logger = Logger
 35  
                         .getLogger(CubbyConfiguration.class);
 36  
 
 37  
         /** デフォルトのリクエスト解析器。 */
 38  1
         private static final RequestParser DEFAULT_REQUEST_PARSER = new DefaultRequestParserImpl();
 39  
 
 40  
         /** リクエスト解析器。 */
 41  
         private final RequestParser requestParser;
 42  
 
 43  
         /** フォーマットパターン。 */
 44  
         private final FormatPattern formatPattern;
 45  
 
 46  
         /**
 47  
          * {@inheritDoc}
 48  
          */
 49  
         public RequestParser getRequestParser() {
 50  8
                 return requestParser;
 51  
         }
 52  
 
 53  
         /**
 54  
          * {@inheritDoc}
 55  
          */
 56  
         public FormatPattern getFormatPattern() {
 57  38
                 return formatPattern;
 58  
         }
 59  
 
 60  
         /**
 61  
          * インスタンス化します。
 62  
          * <p>
 63  
          * 指定されたコンテナのルートから設定情報のインスタンスを取得します。
 64  
          * </p>
 65  
          * 
 66  
          * @param container
 67  
          *            コンテナ
 68  
          */
 69  40
         public CubbyConfigurationImpl(final S2Container container) {
 70  40
                 final S2Container root = container.getRoot();
 71  
 
 72  39
                 if (root.hasComponentDef(RequestParser.class)) {
 73  11
                         final ComponentDef componentDef = root
 74  
                                         .getComponentDef(RequestParser.class);
 75  11
                         this.requestParser = (RequestParser) componentDef.getComponent();
 76  11
                         if (logger.isDebugEnabled()) {
 77  11
                                 logger.log("DCUB0009", new Object[] { RequestParser.class,
 78  
                                                 this.requestParser });
 79  
                         }
 80  11
                 } else {
 81  28
                         this.requestParser = DEFAULT_REQUEST_PARSER;
 82  28
                         if (logger.isDebugEnabled()) {
 83  28
                                 logger.log("DCUB0008", new Object[] { RequestParser.class,
 84  
                                                 this.requestParser });
 85  
                         }
 86  
                 }
 87  
 
 88  39
                 if (root.hasComponentDef(FormatPattern.class)) {
 89  11
                         final ComponentDef componentDef = root
 90  
                                         .getComponentDef(FormatPattern.class);
 91  11
                         this.formatPattern = (FormatPattern) componentDef.getComponent();
 92  11
                         if (logger.isDebugEnabled()) {
 93  11
                                 logger.log("DCUB0009", new Object[] { FormatPattern.class,
 94  
                                                 this.formatPattern });
 95  
                         }
 96  11
                 } else {
 97  28
                         this.formatPattern = new FormatPatternImpl();
 98  28
                         if (logger.isDebugEnabled()) {
 99  28
                                 logger.log("DCUB0008", new Object[] { FormatPattern.class,
 100  
                                                 this.formatPattern });
 101  
                         }
 102  
                 }
 103  
 
 104  39
         }
 105  
 
 106  
 }