Class EntityParameterResolver
java.lang.Object
io.fluxzero.sdk.modeling.EntityParameterResolver
- All Implemented Interfaces:
ParameterResolver<Object>, PreparedParameterResolver<Object>
Resolves handler method parameters that reference an
Entity or the entity's value.
This resolver supports parameters of either Entity<T> or the entity's actual type T.
It will traverse the hierarchy of parent-child relationships between entities (if any) to find the closest match.
Resolution logic supports both HasEntity and HasMessage sources:
- If the input implements
HasEntity, the existing entity is used. - If the input implements
HasMessage, the resolver attempts to extract the aggregate type and ID. Aggregate metadata is resolved directly usingFluxzero#loadAggregate; routing keys still useFluxzero#loadEntitybecause they may point at nested entities.
The entity is only resolved if:
- The parameter type is assignable from the resolved entity type (or the
Entity<T>type). - Or, the entity has a parent matching the required parameter type.
This resolver determines handler method specificity and can thus be used in disambiguation when multiple handler methods are present in the same target class.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceMarker for handler-selection contexts where anEntityparameter should only be matched from message metadata. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanIndicates that this resolver contributes to disambiguating handler methods when multiple handlers are present in the same target class.protected Entity<?> getMatchingEntity(Object input, Parameter parameter) Attempts to retrieve anEntityinstance matching the given method parameter.protected booleanReturnstrueif the entity or any of its parents match the expected parameter type, respecting nullable flags on parameters.booleanmatches(Parameter parameter, Annotation methodAnnotation, Object input) Determines whether the parameter can be resolved from the given input.booleanmayApply(Executable method, Class<?> targetClass) Returnstrueif this resolver might apply to the given method.protected Supplier<?> Returns aSupplierthat returns the entity if the entity or any of its parents match the expected parameter type.resolve(Parameter parameter, Annotation methodAnnotation) Provides aSupplierthat returns the matching entity or its value for the given parameter.resolveIfPossible(Parameter parameter, Annotation methodAnnotation, Object input) Returns a prepared resolver for the given message, ornullwhen this resolver cannot handle the parameter.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ParameterResolver
prepare, specificityPriority, test
-
Constructor Details
-
EntityParameterResolver
public EntityParameterResolver()
-
-
Method Details
-
mayApply
Description copied from interface:ParameterResolverReturnstrueif this resolver might apply to the given method. Implementations should perform only inexpensive checks and never throw.- Specified by:
mayApplyin interfaceParameterResolver<Object>- Parameters:
method- the handler method or constructortargetClass- the declaring or target class- Returns:
trueif this resolver could apply,falseotherwise
-
resolve
Provides aSupplierthat returns the matching entity or its value for the given parameter. Will recursively traverse parent entities if needed.- Specified by:
resolvein interfaceParameterResolver<Object>- Parameters:
parameter- the parameter for which a value must be injectedmethodAnnotation- the annotation on the handler method- Returns:
- a function that supplies the resolved value
-
matches
Determines whether the parameter can be resolved from the given input. The match succeeds if a suitable entity or value can be found in the message or entity context.- Specified by:
matchesin interfaceParameterResolver<Object>- Parameters:
parameter- the method parametermethodAnnotation- the annotation on the handler methodinput- the handler input (e.g.,DeserializingMessageorHasEntity)- Returns:
- true if the parameter can be resolved from the input, false otherwise
-
resolveIfPossible
public Function<Object,Object> resolveIfPossible(Parameter parameter, Annotation methodAnnotation, Object input) Description copied from interface:PreparedParameterResolverReturns a prepared resolver for the given message, ornullwhen this resolver cannot handle the parameter.- Specified by:
resolveIfPossiblein interfacePreparedParameterResolver<Object>
-
getMatchingEntity
Attempts to retrieve anEntityinstance matching the given method parameter.The search is performed on:
HasEntityinput types (directly returning the contained entity)HasMessageinput types (by extracting aggregate metadata and loading the entity)
- Parameters:
input- the message or entity contextparameter- the method parameter being resolved- Returns:
- the matching
Entityornullif not resolvable
-
matches
-
resolve
-
determinesSpecificity
public boolean determinesSpecificity()Indicates that this resolver contributes to disambiguating handler methods when multiple handlers are present in the same target class.This is useful when more than one method matches a message, and the framework must decide which method is more specific. If this returns
true, the resolver's presence and compatibility with the parameter may influence which handler is selected.- Specified by:
determinesSpecificityin interfaceParameterResolver<Object>- Returns:
- true, signaling that this resolver helps determine method specificity
-