View Javadoc

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.controller.impl;
18  
19  import java.util.Locale;
20  import java.util.Map;
21  import java.util.ResourceBundle;
22  
23  import org.seasar.cubby.controller.MessagesBehaviour;
24  import org.seasar.cubby.internal.util.ResourceBundleMap;
25  
26  /**
27   * メッセージの振る舞いのデフォルト実装です。
28   * 
29   * @author baba
30   */
31  public class DefaultMessagesBehaviour implements MessagesBehaviour {
32  
33  	/** デフォルトのメッセージリソース名。 */
34  	public static final String DEFAULT_RESOURCE_NAME = "messages";
35  
36  	/** リソースバンドル、完全指定されたクラス名の基底名。 */
37  	private String baseName = DEFAULT_RESOURCE_NAME;
38  
39  	/**
40  	 * リソースバンドル、完全指定されたクラス名の基底名を取得します。
41  	 * 
42  	 * @return リソースバンドル、完全指定されたクラス名の基底名
43  	 */
44  	public String getBaseName() {
45  		return baseName;
46  	}
47  
48  	/**
49  	 * リソースバンドル、完全指定されたクラス名の基底名を設定します。
50  	 * 
51  	 * @param baseName
52  	 *            リソースバンドル、完全指定されたクラス名の基底名
53  	 */
54  	public void setBaseName(final String baseName) {
55  		this.baseName = baseName;
56  	}
57  
58  	/**
59  	 * {@inheritDoc}
60  	 */
61  	public ResourceBundle getBundle(final Locale locale) {
62  		final ClassLoader classLoader = Thread.currentThread()
63  				.getContextClassLoader();
64  		final ResourceBundle bundle = ResourceBundle.getBundle(baseName,
65  				(locale == null ? Locale.getDefault() : locale), classLoader);
66  		return bundle;
67  	}
68  
69  	/**
70  	 * {@inheritDoc}
71  	 */
72  	public Map<String, Object> toMap(final ResourceBundle bundle) {
73  		return new ResourceBundleMap(bundle);
74  	}
75  
76  }