View Javadoc

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  	private static final Logger logger = Logger
35  			.getLogger(CubbyConfiguration.class);
36  
37  	/** デフォルトのリクエスト解析器。 */
38  	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  		return requestParser;
51  	}
52  
53  	/**
54  	 * {@inheritDoc}
55  	 */
56  	public FormatPattern getFormatPattern() {
57  		return formatPattern;
58  	}
59  
60  	/**
61  	 * インスタンス化します。
62  	 * <p>
63  	 * 指定されたコンテナのルートから設定情報のインスタンスを取得します。
64  	 * </p>
65  	 * 
66  	 * @param container
67  	 *            コンテナ
68  	 */
69  	public CubbyConfigurationImpl(final S2Container container) {
70  		final S2Container root = container.getRoot();
71  
72  		if (root.hasComponentDef(RequestParser.class)) {
73  			final ComponentDef componentDef = root
74  					.getComponentDef(RequestParser.class);
75  			this.requestParser = (RequestParser) componentDef.getComponent();
76  			if (logger.isDebugEnabled()) {
77  				logger.log("DCUB0009", new Object[] { RequestParser.class,
78  						this.requestParser });
79  			}
80  		} else {
81  			this.requestParser = DEFAULT_REQUEST_PARSER;
82  			if (logger.isDebugEnabled()) {
83  				logger.log("DCUB0008", new Object[] { RequestParser.class,
84  						this.requestParser });
85  			}
86  		}
87  
88  		if (root.hasComponentDef(FormatPattern.class)) {
89  			final ComponentDef componentDef = root
90  					.getComponentDef(FormatPattern.class);
91  			this.formatPattern = (FormatPattern) componentDef.getComponent();
92  			if (logger.isDebugEnabled()) {
93  				logger.log("DCUB0009", new Object[] { FormatPattern.class,
94  						this.formatPattern });
95  			}
96  		} else {
97  			this.formatPattern = new FormatPatternImpl();
98  			if (logger.isDebugEnabled()) {
99  				logger.log("DCUB0008", new Object[] { FormatPattern.class,
100 						this.formatPattern });
101 			}
102 		}
103 
104 	}
105 
106 }