public class Resources extends Object
If this class belongs to a package other than
net.hydromatic.resource
, it was probably generated by the Maven
plugin (groupId: "net.hydromatic", artifactId:
"hydromatic-resource-maven-plugin"). Code generation allows projects to use
this resource library without adding a runtime dependency on another JAR.
Modifier and Type | Class and Description |
---|---|
static interface |
Resources.BaseMessage
The message in the default locale.
|
(package private) static class |
Resources.BuiltinMethod |
static class |
Resources.ExInst<T extends Exception>
Sub-class of
Resources.Inst that can throw an exception without caused
by. |
static class |
Resources.ExInstWithCause<T extends Exception>
Sub-class of
Resources.Inst that can throw an exception. |
static class |
Resources.Inst
Resource instance.
|
(package private) static class |
Resources.MyPropertyResourceBundle
Resource bundle based on properties.
|
static interface |
Resources.Property
Property of a resource.
|
static interface |
Resources.Resource
The name of the property in the resource file.
|
static class |
Resources.ShadowResourceBundle
ShadowResourceBundle is an abstract base class for
ResourceBundle classes which are backed by a properties file. |
static class |
Resources.Validation
Types of validation that can be performed on a resource.
|
Modifier and Type | Field and Description |
---|---|
private static ThreadLocal<Locale> |
MAP_THREAD_TO_LOCALE |
Modifier | Constructor and Description |
---|---|
private |
Resources() |
Modifier and Type | Method and Description |
---|---|
static <T> T |
create(Class<T> clazz)
Creates an instance of the resource object, using the class's name as
the name of the resource file.
|
static <T> T |
create(String base,
Class<T> clazz)
Creates an instance of the resource object.
|
private static boolean |
equal(Object o0,
Object o1)
Returns whether two objects are equal or are both null.
|
static Locale |
getThreadLocale()
Returns the preferred locale of the current thread, or null if the
thread has not called
setThreadLocale(java.util.Locale) . |
protected static Locale |
getThreadOrDefaultLocale()
Returns the preferred locale of the current thread, or
the default locale if the current thread has not called
setThreadLocale(java.util.Locale) . |
static void |
setThreadLocale(Locale locale)
Sets the locale for the current thread.
|
static void |
validate(Object o)
Applies all validations to all resource methods in the given
resource object.
|
static void |
validate(Object o,
EnumSet<Resources.Validation> validations)
Applies the given validations to all resource methods in the given
resource object.
|
private static Object |
zero(Class<?> clazz) |
private static final ThreadLocal<Locale> MAP_THREAD_TO_LOCALE
protected static Locale getThreadOrDefaultLocale()
setThreadLocale(java.util.Locale)
.public static void setThreadLocale(Locale locale)
locale
- Localepublic static Locale getThreadLocale()
setThreadLocale(java.util.Locale)
.public static <T> T create(Class<T> clazz)
T
- Resource typeclazz
- Interface that contains a method for each resourcecreate(String, Class)
public static <T> T create(String base, Class<T> clazz)
The resource interface has methods that return Resources.Inst
and
Resources.ExInst
values. Each of those methods is basically a factory method.
This method creates an instance of that interface backed by a resource
bundle, using a dynamic proxy (Proxy
).
Suppose that base = "com.example.MyResource" and the current locale is "en_US". A method
@BaseMessage("Illegal binary string {0}") ExInst<IllegalArgumentException> illegalBinaryString(String a0);will look up a resource "IllegalBinaryString" from the resource file "com/example/MyResource_en_US.properties", and substitute in the parameter value
a0
.
The resource in the properties file may or may not be equal to the base message "Illegal binary string {0}". But in the base locale, it probably should be.
T
- Resource typebase
- Base name of the resource.properties fileclazz
- Interface that contains a method for each resourcepublic static void validate(Object o)
o
- Resource object to validatepublic static void validate(Object o, EnumSet<Resources.Validation> validations)
o
- Resource object to validatevalidations
- Validations to performCopyright © 2012–2016 The Apache Software Foundation. All rights reserved.