View Javadoc
1   /*******************************************************************************
2    * Portions created by Sebastian Thomschke are copyright (c) 2005-2013 Sebastian
3    * Thomschke.
4    *
5    * All Rights Reserved. This program and the accompanying materials
6    * are made available under the terms of the Eclipse Public License v1.0
7    * which accompanies this distribution, and is available at
8    * http://www.eclipse.org/legal/epl-v10.html
9    *
10   * Contributors:
11   *     Sebastian Thomschke - initial implementation.
12   *******************************************************************************/
13  package net.sf.oval.localization.locale;
14  
15  import java.util.Locale;
16  
17  /**
18   * @author Sebastian Thomschke
19   */
20  public class ThreadLocalLocaleProvider implements LocaleProvider
21  {
22  	private final ThreadLocal<Locale> locale = new ThreadLocal<Locale>();
23  
24  	/**
25  	 * Gets the locale of the current thread
26  	 */
27  	public Locale getLocale()
28  	{
29  		final Locale l = locale.get();
30  		return l == null ? Locale.getDefault() : l;
31  	}
32  
33  	/**
34  	 * Sets the locale for the current thread
35  	 */
36  	public void setLocale(Locale locale)
37  	{
38  		this.locale.set(locale);
39  	}
40  }