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   * 
28   * @author baba
29   * 
30   */
31  public class CubbyConfigurationImpl implements CubbyConfiguration {
32  
33  	private static final Logger logger = Logger
34  			.getLogger(CubbyConfiguration.class);
35  
36  	private static final RequestParser DEFAULT_REQUEST_PARSER = new DefaultRequestParserImpl();
37  
38  	private final RequestParser requestParser;
39  
40  	private final FormatPattern formatPattern;
41  
42  	public RequestParser getRequestParser() {
43  		return requestParser;
44  	}
45  
46  	public FormatPattern getFormatPattern() {
47  		return formatPattern;
48  	}
49  
50  	public CubbyConfigurationImpl(final S2Container container) {
51  		final S2Container root = container.getRoot();
52  
53  		if (root.hasComponentDef(RequestParser.class)) {
54  			final ComponentDef componentDef = root
55  					.getComponentDef(RequestParser.class);
56  			this.requestParser = (RequestParser) componentDef.getComponent();
57  			if (logger.isDebugEnabled()) {
58  				logger.log("DCUB0009", new Object[] { RequestParser.class,
59  						this.requestParser });
60  			}
61  		} else {
62  			this.requestParser = DEFAULT_REQUEST_PARSER;
63  			if (logger.isDebugEnabled()) {
64  				logger.log("DCUB0008", new Object[] { RequestParser.class,
65  						this.requestParser });
66  			}
67  		}
68  
69  		if (root.hasComponentDef(FormatPattern.class)) {
70  			final ComponentDef componentDef = root
71  					.getComponentDef(FormatPattern.class);
72  			this.formatPattern = (FormatPattern) componentDef.getComponent();
73  			if (logger.isDebugEnabled()) {
74  				logger.log("DCUB0009", new Object[] { FormatPattern.class,
75  						this.formatPattern });
76  			}
77  		} else {
78  			this.formatPattern = new FormatPatternImpl();
79  			if (logger.isDebugEnabled()) {
80  				logger.log("DCUB0008", new Object[] { FormatPattern.class,
81  						this.formatPattern });
82  			}
83  		}
84  
85  	}
86  
87  }