Module hw06

Class ObjectLoader<ReturnT>

java.lang.Object
provided.utils.loader.impl.AObjectLoader<ReturnT>
provided.utils.loader.impl.ObjectLoader<ReturnT>
Type Parameters:
ReturnT - The type of object to be created.
All Implemented Interfaces:
IObjectLoader<ReturnT>

public class ObjectLoader<ReturnT> extends AObjectLoader<ReturnT>
Factory that dynamically class loads and instantiates an object of type ReturnT This is a non-recursive object loader that should be used when the fully qualified name of the desired class can be determined BEFORE the object loader is invoked.
Author:
Stephen Wong
  • Field Details

    • errorFac

      private Function<Object[],​ReturnT> errorFac
      Lambda function to return an error object of type ReturnT
  • Constructor Details

    • ObjectLoader

      public ObjectLoader(Function<Object[],​ReturnT> errorFac)
      Constructor for the class. The given errorFac is used to generate instances when the loadInstance() method is otherwise unable to do so because of a processing error.
      Parameters:
      errorFac - A factory method that takes the same array of input parameters that loadInstance() takes and returns an instance of ReturnT.
  • Method Details

    • errorHandler

      protected ReturnT errorHandler(Exception ex, String className, Object... args)
      Prints the given Exception to stderr and then invokes the stored errorFac to generate an error object.
      Specified by:
      errorHandler in class AObjectLoader<ReturnT>
      Parameters:
      ex - The Exception that was generated
      className - The fully qualified name of the class that was attempted to be loaded
      args - The constructor parameters for the given class name.
      Returns:
      An "error" object