Class JKFactory

java.lang.Object
com.jk.core.factory.JKFactory

public class JKFactory extends Object
This class provides methods for creating instances, associating implementations, and checking for the existence of beans in a Spring context.
Version:
1.0
Author:
Dr. Jalal H. Kiswani
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    This method outputs the names of all beans registered in the Spring context.
    static boolean
    exists(Class<?> clas)
    This method checks whether a bean of the specified class exists in the Spring context.
    static <T> T
    instance(Class<T> superClass)
    This method retrieves an instance of the provided superclass, either from a predefined map, the Spring context, or by directly instantiating the class.
    static <T> T
    instance(Class<T> superClass, Class<? extends T> defaultHandler)
    This method retrieves an instance of the provided superclass and falls back to a default handler if no bean definition is found in the Spring context.
    static void
    main(String[] args)
    This main method makes an instance of the JKFactory with the Test class.
    static void
    register(Class<?> implementation)
    This method registers an instance of the provided class in the Spring context.
    static void
    setImplementation(Class<?> clas, Class<?> impl)
    This method associates an interface or superclass with its corresponding implementation class.
    static <T> Class<? extends T>
    type(Class<T> class1)
    This method gets the runtime class of an instance created from the provided class.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • JKFactory

      public JKFactory()
  • Method Details

    • register

      public static void register(Class<?> implementation)
      This method registers an instance of the provided class in the Spring context.
      Parameters:
      implementation - Represents the class to be registered as a bean in the Spring context.
    • instance

      public static <T> T instance(Class<T> superClass)
      This method retrieves an instance of the provided superclass, either from a predefined map, the Spring context, or by directly instantiating the class.
      Type Parameters:
      T - Specifies the type of the class to be instantiated.
      Parameters:
      superClass - Specifies the superclass or interface class to obtain an instance of.
      Returns:
      an instance of the provided superclass or interface.
    • dumpBeansNames

      public static void dumpBeansNames()
      This method outputs the names of all beans registered in the Spring context.
    • main

      public static void main(String[] args)
      This main method makes an instance of the JKFactory with the Test class.
      Parameters:
      args - The command-line arguments.
    • type

      public static <T> Class<? extends T> type(Class<T> class1)
      This method gets the runtime class of an instance created from the provided class.
      Type Parameters:
      T - Specifies the type of the class and instance
      Parameters:
      class1 - Specifies the class for which the runtime class of an instance is to be obtained
      Returns:
      the runtime class of an instance created from the provided class.
    • exists

      public static boolean exists(Class<?> clas)
      This method checks whether a bean of the specified class exists in the Spring context.
      Parameters:
      clas - Specifies the class to check for bean existence.
      Returns:
      true, if a bean of the specified class exists, false otherwise.
    • setImplementation

      public static void setImplementation(Class<?> clas, Class<?> impl)
      This method associates an interface or superclass with its corresponding implementation class.
      Parameters:
      clas - Specifies the interface or superclass class to be associated.
      impl - Specifies the implementation class to be associated with the interface or superclass.
    • instance

      public static <T> T instance(Class<T> superClass, Class<? extends T> defaultHandler)
      This method retrieves an instance of the provided superclass and falls back to a default handler if no bean definition is found in the Spring context.
      Type Parameters:
      T - Specifies the type of the class to be instantiated.
      Parameters:
      superClass - Specifies the superclass class for which an instance is to be obtained.
      defaultHandler - Specifies the default handler class to use if no bean definition is found.
      Returns:
      an instance of the provided superclass or the default handler.