Class ApiCompatibilityManager.Builder

java.lang.Object
com.broadleafcommerce.common.extension.reflection.ApiCompatibilityManager.Builder
Enclosing class:
ApiCompatibilityManager

public static class ApiCompatibilityManager.Builder extends Object
The Builder class is used to configure and compile constructors, methods, and fields that can later be invoked or manipulated in a dynamic and reflective way. The Builder supports registering entities such as instantiations, methods, and fields with specific qualifications, which can then be fetched, invoked, or accessed during runtime. The Builder supports fluent API to allow chaining configurations for instantiations, method invocations, and field accesses. It verifies that names for these entities are unique and ensures that they meet specific qualification criteria before being compiled into the system.
  • Constructor Details

    • Builder

      public Builder()
  • Method Details

    • withInstantiation

      public ApiCompatibilityManager.Builder withInstantiation(String name, String qualifyExpression, String classname, String... paramTypes)
      Adds an instantiation entry to the builder with the specified parameters.
      Parameters:
      name - the name of the instantiation entry - usually a class simple name
      qualifyExpression - the qualifying expression for the instantiation
      classname - the fully qualified name of the class to instantiate
      paramTypes - the parameter types for the instantiation
      Returns:
      the builder instance for method chaining
    • withInstantiation

      public ApiCompatibilityManager.Builder withInstantiation(String name, String qualifyExpression, Supplier<Constructor<?>> supplier)
      Adds an instantiation entry to the builder with the specified parameters, using a supplier to acquire the constructor to be instantiated.
      Parameters:
      name - the name of the instantiation entry - usually the simple name of the class
      qualifyExpression - the qualifying expression for the instantiation
      supplier - a supplier providing the constructor to use for instantiation
      Returns:
      the builder instance for method chaining
    • withMethod

      public ApiCompatibilityManager.Builder withMethod(String name, String qualifyExpression, String classname, String methodname, String... paramTypes)
      Adds a method entry to the builder with the specified parameters. This entry represents a method reference to be used within the building process.
      Parameters:
      name - the name of the method entry
      qualifyExpression - the qualifying expression for the method
      classname - the fully qualified name of the class containing the method
      methodname - the name of the method to reference
      paramTypes - the parameter types of the method
      Returns:
      the builder instance for method chaining
    • withField

      public ApiCompatibilityManager.Builder withField(String name, String qualifyExpression, String classname, String fieldName)
      Adds a field entry to the builder with the specified parameters.
      Parameters:
      name - the name of the field entry
      qualifyExpression - the qualifying expression for the field
      classname - the fully qualified name of the class containing the field
      fieldName - the name of the field to reference
      Returns:
      the builder instance for method chaining
    • compile

      public void compile()
      Compiles the configuration and populates the mapping of invokable constructors, methods, and fields based on the entries defined in the builder. This method filters entries using a qualifying expression and verifies uniqueness for each added element. Constructs or retrieves reflective elements such as constructors, methods, and fields, making them accessible for invocation. This method processes the following: - Instantiations: Validates qualifying conditions and ensures no duplicate constructors exist for each instantiation entry. Reflective constructors are resolved and stored. - Instantiation Factories: Similar to regular instantiations but relies on a supplier to provide constructors dynamically. Ensures no duplicates are defined for the same name. - Methods: Validates qualifiers and resolves reflective method references. Ensures unique methods are mapped for invocation. - Fields: Resolves and validates field references via reflection. Ensures fields are both unique and accessible. Throws an IllegalStateException if: - A duplicate entry exists for a constructor, method, or field with the same name. - A referenced class, method, or field does not exist or is otherwise inaccessible. Exceptions encountered during the class or reflection processing are wrapped within an IllegalStateException for uniform error handling during compilation.