Class ApiCompatibilityManager.Builder
java.lang.Object
com.broadleafcommerce.common.extension.reflection.ApiCompatibilityManager.Builder
- Enclosing class:
- ApiCompatibilityManager
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcompile()Compiles the configuration and populates the mapping of invokable constructors, methods, and fields based on the entries defined in the builder.Adds a field entry to the builder with the specified parameters.withInstantiation(String name, String qualifyExpression, String classname, String... paramTypes) Adds an instantiation entry to the builder with the specified parameters.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.withMethod(String name, String qualifyExpression, String classname, String methodname, String... paramTypes) Adds a method entry to the builder with the specified parameters.
-
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 namequalifyExpression- the qualifying expression for the instantiationclassname- the fully qualified name of the class to instantiateparamTypes- 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 classqualifyExpression- the qualifying expression for the instantiationsupplier- 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 entryqualifyExpression- the qualifying expression for the methodclassname- the fully qualified name of the class containing the methodmethodname- the name of the method to referenceparamTypes- 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 entryqualifyExpression- the qualifying expression for the fieldclassname- the fully qualified name of the class containing the fieldfieldName- 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 anIllegalStateExceptionif: - 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 anIllegalStateExceptionfor uniform error handling during compilation.
-