Class ErrorCode

  • All Implemented Interfaces:
    java.io.Serializable

    public abstract class ErrorCode
    extends java.lang.Object
    implements java.io.Serializable

    Base class of all error codes for BaseExceptions.

    The error code consists of an obligatory "product" an optional "module" and an obligatory "number". Product and module should be short or abbreviations and should follow a pattern standardized by conventions.

    In its written form (see getString()) the parts will be converted to upper case, combined and separated by an "-"-character, f.e. "JCR-4711" or "ECM-TPS-42".

    toString() creates a string for debugging and protocol purpose and should not be used for business semantics.

    It is recommended for all products to create their own product-specific extension of ErrorCode encapsulating the product-name-part of the error code, f.e.:

     public class MyProductErrorCode extends ErrorCode
     {
         private static final String PRODUCT = "JCS";
     
         public MyProductErrorCode(String module, int number)
         {
             super(PRODUCT, module, number);
         }
     
         public MyProductErrorCode(int number)
         {
             super(PRODUCT, number);
         }
     }
     
    A product can also enforce the use (or no use) of the module part by omitting one of the constructors in its own error code extension.

    Author:
    agz
    See Also:
    BaseException, Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected static java.lang.String SERARATOR
      The separator to use when formatting the written form.
    • Constructor Summary

      Constructors 
      Constructor Description
      ErrorCode​(java.lang.String product, int number)
      Creates a new ErrorCode with the specified product, module and number.
      ErrorCode​(java.lang.String product, java.lang.String module, int number)
      Creates a new ErrorCode with the specified product, module and number.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String getModule()
      Returns the module (upper case) or null if no module was specified.
      int getNumber()
      Returns the number.
      java.lang.String getProduct()
      Returns the product (upper case).
      java.lang.String getString()
      Returns the written form of this error code.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • SERARATOR

        protected static final java.lang.String SERARATOR
        The separator to use when formatting the written form.
        See Also:
        Constant Field Values
    • Constructor Detail

      • ErrorCode

        public ErrorCode​(java.lang.String product,
                         java.lang.String module,
                         int number)
        Creates a new ErrorCode with the specified product, module and number.

        The specified product must not be null or empty.

        The specified module is optional (may be null).

        The specified number must be greater than 0.

        Parameters:
        product - product of the new error code
        module - module of the new error code
        number - number of the new error code
      • ErrorCode

        public ErrorCode​(java.lang.String product,
                         int number)
        Creates a new ErrorCode with the specified product, module and number.

        The specified product must not be null or empty.

        The specified number must be greater than 0.

        Parameters:
        product - product of the new error code
        number - number of the new error code
    • Method Detail

      • getProduct

        public final java.lang.String getProduct()
        Returns the product (upper case).
        Returns:
        the product
      • getModule

        public final java.lang.String getModule()
        Returns the module (upper case) or null if no module was specified.
        Returns:
        the module
      • getNumber

        public final int getNumber()
        Returns the number.
        Returns:
        the number
      • getString

        public final java.lang.String getString()
        Returns the written form of this error code.

        It is a combination of the product, module and number part, separated by a "-"-character, f.e. "JCR-4711" or "ECM-TPS-42"

        If used in a BaseException, this written form is the resource key used for localization.

        Returns:
        the written form of this error code.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object