Customization Options for Applications

This documentation shows how to customize the I18N services.

The customization options are for application development only. Libraries must not provide exception context information in their artifacts.

Additional information on customizing the core services can be found in the smart-exceptions-core documentation.

Default Configuration

The default configuration, that usually is serving most needs well, is provided by

de.smartics.exceptions.i18n.context.SystemDefaultI18nExceptionContext

This default enables I18N support and generates UUIDs as unique identifiers for your exceptions.

Custom Configuration

You may want to replace some services provided by the de.smartics.exceptions.ExceptionContext. This is done by adding the file:

META-INF/services/de.smartics.exceptions.core.ExceptionContext

to your project.

The file contains the name of an implementation of ExceptionContext, e.g.:

de.smartics.exceptions.i18n.context.SystemDefaultI18nExceptionContext

The I18N library requires a special kind of exception context which is defined in de.smartics.exceptions.i18n.I18nExceptionContext .

public interface I18nExceptionContext extends ExceptionContext {
  /**
   * Returns the bundle provider that helps to access resource bundles.
   *
   * @return the bundle provider that helps to access resource bundles.
   */
  BundleProvider getBundleProvider();

  /**
   * Returns the implementation to use for the message composer.
   *
   * @return the implementation to use for the message composer.
   */
  MessageComposer getMessageComposer();

  /**
   * Returns the identifier of a template to be used for rendering the exception
   * information.
   *
   * @return the template identifier.
   */
  MessageTemplate getMessageTemplateId();

  /**
   * Returns the formatter for code messages. Override to control the
   * representation of exception and message bean instances.
   *
   * @return the formatter for code messages.
   */
  I18nCodeMessageFormatter getCodeMessageFormatter();
}

Loading Bundles from alternative Locations

Basically you have to supply a de.smartics.exceptions.i18n.BundleProvider (which defaults to de.smartics.messages.core.ClassPathBundleProvider) to access message bundles for localized message templates. You may replace the default provider to fetch bundles from a different location, e.g. a content management system. Please note that you have to provide bundles for all codes that used within the application. This includes codes for all libraries the application depends upon.

Composing Messages

If you are not satisfied with the default message composer, you may replace it with your own implementation of the de.smartics.exceptions.i18n.MessageComposer interface. The composer is responsible to fill the place holders in the message templates with values. The default implementation de.smartics.exceptions.i18n.message.DefaultMessageComposer serves most needs well.

de.smartics.exceptions.i18n.message.MessageTemplate are an experimental form to select from different rendering styles. This may be discarded in the final version. If you want to alter the representation of the messages, use the CodeMessageFormatter (covered in the next section).

Controlling the Rendering of Messages

The rendering of message and exception representation is realized by the default implementation of de.smartics.exceptions.core.CodeMessageFormatter that is replaced by de.smartics.exceptions.i18n.I18nCodeMessageFormatter in the context of I18N. A default implementation is provided by de.smartics.exceptions.i18n.DefaultI18nCodeMessageFormatter.

You may want to change this if, e.g. you always want to print out the stack trace or if you want to remove the exception throw time.