Class ApiCompatibilityManager
java.lang.Object
com.broadleafcommerce.common.extension.reflection.ApiCompatibilityManager
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordRepresents an argument that can be passed to methods or constructors, with an optional qualifier to determine if it should undergo qualification checks or processing.static classThe 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. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final booleanstatic final booleanstatic final boolean -
Method Summary
Modifier and TypeMethodDescriptionbuilder()Creates a new instance of the Builder class for configuring and compiling custom instantiations, methods, and fields to be used within the system.static <T> Tconstruct(String name, ApiCompatibilityManager.Argument... args) Constructs and returns an instance of a type by invoking a pre-configured constructor with the specified arguments.static <T> TRetrieves the value of a pre-configured field from the specified target object.static Constructor<?>getConstructor(String name) Retrieves a pre-configured constructor by its name from the system.static <T> Tinvoke(String name, Object target, ApiCompatibilityManager.Argument... args) Invokes a pre-configured method on the specified target object with the provided arguments.static voidSets the value of a pre-configured field on the target object.
-
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
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
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 asGREATER_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
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
nullif no such constructor exists.
-
invoke
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 asGREATER_THAN_OR_EQUAL_3.- Returns:
- The result of the invoked method, cast to the specified type, or
nullif 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
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
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.
-