com.softicar.platform.common.core.locale.LocaleScope Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of platform-common Show documentation
Show all versions of platform-common Show documentation
The SoftiCAR Platform is a lightweight, Java-based library to create interactive business web applications.
package com.softicar.platform.common.core.locale;
/**
* An {@link AutoCloseable} that controls {@link CurrentLocale}.
*
* @author Oliver Richers
*/
public class LocaleScope implements AutoCloseable {
private final ILocale originalLocale;
/**
* Sets {@link CurrentLocale} to the given {@link ILocale}.
*
* @param locale
* the {@link ILocale} to set (never null)
*/
public LocaleScope(ILocale locale) {
this.originalLocale = CurrentLocale.get();
CurrentLocale.set(locale);
}
/**
* Reverts {@link CurrentLocale} to the original value.
*/
@Override
public void close() {
CurrentLocale.set(originalLocale);
}
}