Class ApiCompatibilityManager

java.lang.Object
com.broadleafcommerce.common.extension.reflection.ApiCompatibilityManager

public final class ApiCompatibilityManager extends Object
Utility class for managing API compatibility dynamically through reflection. The primary purpose of this class is to expose constructors, methods, and fields defined in various classes and perform dynamic invocation based on configuration. This allows for flexible interaction with APIs while considering version-specific nuances.

Serves as the primary vehicle for bridging between multiple versions of Spring Boot and providing both forward and backward compatibility.
  • Field Details

    • GREATER_THAN_OR_EQUAL_3

      public static final boolean GREATER_THAN_OR_EQUAL_3
    • GREATER_THAN_OR_EQUAL_3_AND_LESS_THAN_3_5

      public static final boolean GREATER_THAN_OR_EQUAL_3_AND_LESS_THAN_3_5
    • GREATER_THAN_OR_EQUAL_3_5

      public static final boolean GREATER_THAN_OR_EQUAL_3_5
  • Method Details

    • builder

      public static ApiCompatibilityManager.Builder builder()
      Creates a new instance of the Builder class for configuring and compiling custom instantiations, methods, and fields to be used within the system.
      Returns:
      a new instance of the Builder class for creating and configuring various entities such as constructors, methods, and fields.
    • construct

      public static <T> T construct(String name, ApiCompatibilityManager.Argument... args)
      Constructs and returns an instance of a type by invoking a pre-configured constructor with the specified arguments. Arguments marked as qualified will be filtered and passed to the constructor.
      Type Parameters:
      T - The type of the object to be constructed.
      Parameters:
      name - The name of the constructor to be invoked. It must match a pre-configured constructor in the system.
      args - The arguments to be passed to the constructor. Only arguments marked as qualified will be included during invocation. Pre-compiled qualifications should be used for performance, such as GREATER_THAN_OR_EQUAL_3.
      Returns:
      The constructed instance of the specified type.
      Throws:
      IllegalStateException - If the specified constructor is not found or if an error occurs during the instantiation process.
    • getConstructor

      public static Constructor<?> getConstructor(String name)
      Retrieves a pre-configured constructor by its name from the system.
      Parameters:
      name - The name of the constructor to retrieve. It must match the name of a pre-configured constructor stored in the system.
      Returns:
      The constructor associated with the specified name, or null if no such constructor exists.
    • invoke

      public static <T> T invoke(String name, Object target, ApiCompatibilityManager.Argument... args)
      Invokes a pre-configured method on the specified target object with the provided arguments. Arguments marked as qualified will be filtered and used during invocation.
      Type Parameters:
      T - The return type of the invoked method.
      Parameters:
      name - The name of the method to be invoked. It must match a pre-configured method in the system.
      target - The target object on which the method will be invoked.
      args - The arguments to be passed to the method. Only arguments marked as qualified will be included. Pre-compiled qualifications should be used for performance, such as GREATER_THAN_OR_EQUAL_3.
      Returns:
      The result of the invoked method, cast to the specified type, or null if the method is not found or the invocation does not yield a result.
      Throws:
      IllegalStateException - If the method with the specified name is not pre-configured in the system.
    • set

      public static void set(String name, Object target, Object value)
      Sets the value of a pre-configured field on the target object. The field to be set must have been registered beforehand in the system.
      Parameters:
      name - The name of the field to set. It must correspond to a pre-configured field.
      target - The target object whose field will be set.
      value - The value to assign to the field.
      Throws:
      IllegalStateException - If the specified field name is not pre-configured in the system.
    • get

      public static <T> T get(String name, Object target)
      Retrieves the value of a pre-configured field from the specified target object. The field to be retrieved must have been registered in the system beforehand.
      Type Parameters:
      T - The expected type of the field value to be retrieved.
      Parameters:
      name - The name of the field to retrieve. It must correspond to a pre-configured field.
      target - The target object from which the field value will be retrieved.
      Returns:
      The value of the field, cast to the specified type.
      Throws:
      IllegalStateException - If the specified field name is not pre-configured in the system.