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.plugins.oval.validation;
18  
19  /**
20   * スレッドに関連付けられる入力検証の状態です。
21   * 
22   * @author baba
23   */
24  public class OValValidationContext {
25  
26  	/** {@link OValValidationContext} を保持する {@link ThreadLocal} */
27  	private static final ThreadLocal<OValValidationContext> context = new ThreadLocal<OValValidationContext>() {
28  
29  		@Override
30  		protected OValValidationContext initialValue() {
31  			return new OValValidationContext();
32  		}
33  
34  	};
35  
36  	/** メッセージキーのプリフィックス。 */
37  	private String resourceKeyPrefix;
38  
39  	/**
40  	 * インスタンス化禁止。
41  	 */
42  	private OValValidationContext() {
43  	}
44  
45  	/**
46  	 * スレッドに関連付けられた {@link OValValidationContext} を取得します。
47  	 * 
48  	 * @return スレッドに関連付けられた {@link OValValidationContext}
49  	 */
50  	public static OValValidationContext get() {
51  		return context.get();
52  	}
53  
54  	/**
55  	 * スレッドに関連付けられた {@link OValValidationContext} を削除します。
56  	 */
57  	public static void remove() {
58  		context.remove();
59  	}
60  
61  	/**
62  	 * メッセージキーのプリフィックスを取得します。
63  	 * 
64  	 * @return メッセージキーのプリフィックス
65  	 */
66  	public String getResourceKeyPrefix() {
67  		return resourceKeyPrefix;
68  	}
69  
70  	/**
71  	 * メッセージキーのプリフィックスを設定します。
72  	 * 
73  	 * @param resourceKeyPrefix
74  	 *            メッセージキーのプリフィックス
75  	 */
76  	public void setResourceKeyPrefix(String resourceKeyPrefix) {
77  		this.resourceKeyPrefix = resourceKeyPrefix;
78  	}
79  
80  }