Annotation Interface Message


@Retention(RUNTIME) public @interface Message
Annotation for message classes to control
  • contribution uri to point to resource bundles in a different location
  • caching behavior

ResourceBundle location

Via the contributionURI parameter it is possible to specify the location of the resource bundle files. It supports the following location patterns:

  • platform:/[plugin|fragment]/[Bundle-SymbolicName]
    Load the OSGi resource bundle out of the bundle/fragment named [Bundle-SymbolicName].
    For example:
    @Message(contributionURI="platform:/plugin/com.example.e4.translation.extension")
    will load the OSGi resource bundle that is configured in the MANIFEST.MF of the com.example.e4.translation.extension plug-in.
  • platform:/[plugin|fragment]/[Bundle-SymbolicName]/[Path]/[Basename]
    Load the resource bundle specified by [Path] and [Basename] out of the bundle/fragment named [Bundle-SymbolicName].
    For example:
    @Message(contributionURI="platform:/plugin/com.example.e4.translation/resources/another")
    will load the resource bundle that is located in the folder resources/another in the com.example.e4.translation plug-in.
  • bundleclass://[plugin|fragment]/[Bundle-SymbolicName]/[Fully-Qualified-Classname]
    Instantiate the class-based resource bundle specified by [Fully-Qualified-Classname] out of the bundle/fragment named [Bundle-SymbolicName]. Note that the class needs to be a subtype of ResourceBundle.
    For example:
    @Message(contributionURI="bundleclass://com.example.e4.translation/com.example.e4.translation.resources.MockBundle")
    will load the class-based resource bundle MockBundle in package com.example.e4.translation.resources in the com.example.e4.translation plug-in.

Note:
If the resource bundle files are located in the same package as the messages class having the same base name, or the OSGI resource bundle should be used (by default located in OSGI-INF/l10n with base name bundle) it is not necessary to specify the contributionURI parameter.

Caching behavior

Via the referenceType parameter it is possible to specify the caching behavior of message class instances.

  • ReferenceType.NONE
    The message instance is not cached. Each requestor gets its own instance.
  • ReferenceType.WEAK
    The message instance is cached as a weak reference. If every requestor was garbage collected, the message instance is also discarded at the next garbage collection cycle.
  • ReferenceType.SOFT
    The message instance is cached as a soft reference. If every requestor was garbage collected, the message instance is not immediately discarded with the next garbage collection cycle, but will be retained for a while in memory. This is the default configuration!

Examples:

Loading through a dedicated class

 @Message(contributionURI = "bundleclass://mybundle/my.ResourceBundleClass")
 public class ResourceBundleClassMessages {
        public String message_1;
 }
 

No caching

 @Message(referenceType = ReferenceType.NONE)
 public class ResourceBundleClassMessages {
        public String message_1;
 }
 

Loading through a dedicated class with weak reference type

 @Message(contributionURI = "bundleclass://mybundle/my.ResourceBundleClass", referenceType = ReferenceType.WEAK)
 public class ResourceBundleClassMessages {
        public String message_1;
 }
 
Since:
1.2
  • Element Details

    • referenceType

      Message.ReferenceType referenceType
      Returns:
      optional caching behavior
      See Also:
      Default:
      SOFT
    • contributorURI

      @Deprecated(forRemoval=true, since="4.26") String contributorURI
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use contributionURI instead
      Default:
      ""
    • contributionURI

      String contributionURI
      Returns:
      optional parameter to point to resource bundles in a different location
      Since:
      2.0
      See Also:
      Default:
      ""