Class 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.

    • Field Detail

      • MAP_THREAD_TO_LOCALE

        private static final java.lang.ThreadLocal<java.util.Locale> MAP_THREAD_TO_LOCALE
    • Constructor Detail

      • Resources

        private Resources()
    • 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 called setThreadLocale(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 called setThreadLocale(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 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.

        Type Parameters:
        T - Resource type
        Parameters:
        base - Base name of the resource.properties file
        clazz - 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 validate
        validations - 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.