Class JKExceptionHandlerFactory

java.lang.Object
com.jk.core.exceptions.handler.JKExceptionHandlerFactory

public class JKExceptionHandlerFactory extends Object
This class is a factory used to create JKExceptionHandler objects.

This class provides the necessary methods needed to create the objects and specify their types and attributes.

Version:
1.0
Author:
Dr. Jalal H. Kiswani
  • Constructor Details

    • JKExceptionHandlerFactory

      public JKExceptionHandlerFactory()
  • Method Details

    • getInstance

      public static JKExceptionHandlerFactory getInstance()
      This method gets the single instance of JKExceptionHandlerFactory.

      if no instance been initiated yet, it initiate a new one then returns it.

      Returns:
      single instance of JKExceptionHandlerFactory
    • getDefaultHandler

      public JKExceptionHandler getDefaultHandler()
      This method gets the default exception handler.

      if no instance been initiated yet, it initiate a new one then returns it.

      Returns:
      the default exception handler.
    • getHandler

      public JKExceptionHandlerInfo getHandler(Class<? extends Throwable> clas)
      This method gets a suitable exception handler depending on the specified throwable.
      Parameters:
      clas - Specifies the throwable that the created handler should handle.
      Returns:
      a suitable exception handler.
    • getHandler

      public <T extends Throwable> JKExceptionHandlerInfo getHandler(T t)
      This method gets a suitable exception handler depending on a custom throwable class object of type T.
      Type Parameters:
      T - Specifies the generic type of the custom throwable object.
      Parameters:
      t - Specifies the custom throwable object.
      Returns:
      a suitable exception handler.
    • setDefaultExceptionHandler

      public void setDefaultExceptionHandler(JKExceptionHandler defaultExceptionHandler)
      This method replaces the current default exception handler.
      Parameters:
      defaultExceptionHandler - Represents the new default exception handler.
    • setHandler

      public void setHandler(Class<? extends Throwable> clas, JKExceptionHandler handler)
      This method adds the specified handler and its associated throwable to the list of handlers of this factory.
      Parameters:
      clas - Specifies the throwable that the specified handler deals with.
      handler - Specifies the exception handler responsible for the specified throwable type.
    • registerHandlers

      public void registerHandlers(String packageString)
      This method registers the handlers within the specifies package.
      Parameters:
      packageString - Specifies the name of the package to search in.
    • main

      public static void main(String[] args)
      This main method registers the handlers in the annotation package and gives handle an IOException with a custom message for testing purposes.
      Parameters:
      args - Specifies the command line arguments.