Class Resources
- java.lang.Object
-
- org.apache.calcite.runtime.Resources
-
public class Resources extends java.lang.Object
Defining wrapper classes around resources that allow the compiler to check whether the resources exist and have the argument types that your code expects.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
Resources.BaseMessage
The message in the default locale.static class
Resources.BooleanProp
Boolean property instance.(package private) static class
Resources.BuiltinMethod
static interface
Resources.Default
Default value of a property.static class
Resources.DoubleProp
Double property instance.static class
Resources.Element
Element in a resource (either a resource or a property).(package private) static class
Resources.EmptyPropertyAccessor
static class
Resources.ExInst<T extends java.lang.Exception>
Sub-class ofResources.Inst
that can throw an exception without caused by.static class
Resources.ExInstWithCause<T extends java.lang.Exception>
Sub-class ofResources.Inst
that can throw an exception.static class
Resources.Inst
Resource instance.static class
Resources.IntProp
Integer property instance.(package private) static class
Resources.MyPropertyResourceBundle
Resource bundle based on properties.static class
Resources.NoDefaultValueException
Thrown when a default value is needed but a property does not have one.static class
Resources.Prop
Property instance.private static class
Resources.PropertiesAccessor
Implementation ofResources.PropertyAccessor
that reads from aProperties
.static interface
Resources.Property
Property of a resource.static interface
Resources.PropertyAccessor
Means by which a resource can get values of properties, given their name.static interface
Resources.Resource
The name of the property in the resource file.static class
Resources.ShadowResourceBundle
ShadowResourceBundle
is an abstract base class forResourceBundle
classes which are backed by a properties file.static class
Resources.StringProp
String property instance.static class
Resources.Validation
Types of validation that can be performed on a resource.
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.ThreadLocal<java.util.Locale>
MAP_THREAD_TO_LOCALE
-
Constructor Summary
Constructors Modifier Constructor Description private
Resources()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> T
create(java.lang.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(java.lang.String base, java.lang.Class<T> clazz)
Creates an instance of the resource object.private static <T> T
create(java.lang.String base, Resources.PropertyAccessor accessor, java.lang.Class<T> clazz)
static <T> T
create(java.util.Properties properties, java.lang.Class<T> clazz)
Creates an instance of the resource object that can access properties but not resources.static <T> T
create(Resources.PropertyAccessor accessor, java.lang.Class<T> clazz)
Creates an instance of the resource object that can access properties but not resources.private static boolean
equal(java.lang.Object o0, java.lang.Object o1)
Returns whether two objects are equal or are both null.static java.util.Locale
getThreadLocale()
Returns the preferred locale of the current thread, or null if the thread has not calledsetThreadLocale(java.util.Locale)
.protected static java.util.Locale
getThreadOrDefaultLocale()
Returns the preferred locale of the current thread, or the default locale if the current thread has not calledsetThreadLocale(java.util.Locale)
.static void
setThreadLocale(java.util.Locale locale)
Sets the locale for the current thread.static void
validate(java.lang.Object o)
Applies all validations to all resource methods in the given resource object.static void
validate(java.lang.Object o, java.util.EnumSet<Resources.Validation> validations)
Applies the given validations to all resource methods in the given resource object.private static java.lang.Object
zero(java.lang.Class<?> clazz)
-
-
-
Method Detail
-
getThreadOrDefaultLocale
protected static java.util.Locale getThreadOrDefaultLocale()
Returns the preferred locale of the current thread, or the default locale if the current thread has not calledsetThreadLocale(java.util.Locale)
.- Returns:
- Locale
-
setThreadLocale
public static void setThreadLocale(java.util.Locale locale)
Sets the locale for the current thread.- Parameters:
locale
- Locale
-
getThreadLocale
public static java.util.Locale getThreadLocale()
Returns the preferred locale of the current thread, or null if the thread has not calledsetThreadLocale(java.util.Locale)
.- Returns:
- Locale
-
create
public static <T> T create(java.lang.Class<T> clazz)
Creates an instance of the resource object, using the class's name as the name of the resource file.- Type Parameters:
T
- Resource type- Parameters:
clazz
- Interface that contains a method for each resource- Returns:
- Instance of the interface that can be used to instantiate resources
- See Also:
create(String, Class)
-
create
public static <T> T create(java.lang.String base, java.lang.Class<T> clazz)
Creates an instance of the resource object.The resource interface has methods that return
Resources.Inst
andResources.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 valuea0
.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.
- Type Parameters:
T
- Resource type- Parameters:
base
- Base name of the resource.properties fileclazz
- Interface that contains a method for each resource- Returns:
- Instance of the interface that can be used to instantiate resources
-
create
public static <T> T create(Resources.PropertyAccessor accessor, java.lang.Class<T> clazz)
Creates an instance of the resource object that can access properties but not resources.
-
create
public static <T> T create(java.util.Properties properties, java.lang.Class<T> clazz)
Creates an instance of the resource object that can access properties but not resources.
-
create
private static <T> T create(java.lang.String base, Resources.PropertyAccessor accessor, java.lang.Class<T> clazz)
-
validate
public static void validate(java.lang.Object o)
Applies all validations to all resource methods in the given resource object.- Parameters:
o
- Resource object to validate
-
validate
public static void validate(java.lang.Object o, java.util.EnumSet<Resources.Validation> validations)
Applies the given validations to all resource methods in the given resource object.- Parameters:
o
- Resource object to validatevalidations
- Validations to perform
-
zero
private static java.lang.Object zero(java.lang.Class<?> clazz)
-
equal
private static boolean equal(java.lang.Object o0, java.lang.Object o1)
Returns whether two objects are equal or are both null.
-
-