- java.lang.Object
-
- eu.ess.xaos.tools.annotation.Bundles
-
public class Bundles extends Object
Utility method to be used withBundle
,BundleItem
, andBundleItems
annotations.Here and example of ho to use the annotations and this utility class:
@Bundle( name = "Messages" ) public class SomeClass { @BundleItem( key = "exception.message", comment = "Message used in the thrown illegal state exception.\n" + " {0} Message from the original exception.", message = "Operation not permitted [original message: {0}]." ) public void doSomething() { try { ... } catch ( Exception ex ) { throw new IllegalStateException( Bundles.get(getClass(), "exception.message", ex.getMessage()), ex ); } } }
Note: when using
Bundles
the passedClass
's package must must be opened to thexaos.tools
module, i.e. it must be included into an opens statement in themodule-info
class.- Author:
- claudio.rosati@esss.se
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
get(Class<?> clazz, String key, Object... parameters)
Used to retrieve a message from a resource bundle populated through theBundle
,BundleItem
, andBundleItems
annotations.
-
-
-
Method Detail
-
get
public static String get(Class<?> clazz, String key, Object... parameters) throws MissinBundleException, MissingResourceException
Used to retrieve a message from a resource bundle populated through theBundle
,BundleItem
, andBundleItems
annotations.- Parameters:
clazz
- The class containing theBundle
,BundleItem
, andBundleItems
annotations. TheBundle
annotation is searched for the name of the resource bundle to be used.key
- The key string in the resource bundle to retrieve the message. It mus be specified in the same was as done in the correspondingBundleItem.key()
annotation.parameters
- If the message string contains{0}, {1}, ... {n}
parameters, they will be orderly substituted with the ones provided here.MessageFormat.format(java.lang.String, java.lang.Object...)
will be used to format the message.- Returns:
- The found message string formatted with the given
parameters
. - Throws:
MissinBundleException
- If a proper resource bundle cannot be loaded.MissingResourceException
- If a message cannot be found for the givenkey
.
-
-