Class EntityParameterResolver

java.lang.Object
io.fluxcapacitor.javaclient.modeling.EntityParameterResolver
All Implemented Interfaces:
ParameterResolver<Object>

public class EntityParameterResolver extends Object implements ParameterResolver<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, then loads the entity from the platform using FluxCapacitor#loadEntity.

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.

  • Constructor Details

    • EntityParameterResolver

      public EntityParameterResolver()
  • Method Details

    • resolve

      public Function<Object,Object> resolve(Parameter parameter, Annotation methodAnnotation)
      Provides a Supplier that returns the matching entity or its value for the given parameter. Will recursively traverse parent entities if needed.
      Specified by:
      resolve in interface ParameterResolver<Object>
      Parameters:
      parameter - the parameter for which a value must be injected
      methodAnnotation - the annotation on the handler method (unused here)
      Returns:
      a function that supplies the resolved value
    • matches

      public boolean matches(Parameter parameter, Annotation methodAnnotation, Object input)
      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:
      matches in interface ParameterResolver<Object>
      Parameters:
      parameter - the method parameter
      methodAnnotation - the annotation on the handler method (unused here)
      input - the handler input (e.g., DeserializingMessage or HasEntity)
      Returns:
      true if the parameter can be resolved from the input, false otherwise
    • getMatchingEntity

      protected Entity<?> getMatchingEntity(Object input, Parameter parameter)
      Attempts to retrieve an Entity instance matching the given method parameter.

      The search is performed on:

      • HasEntity input types (directly returning the contained entity)
      • HasMessage input types (by extracting aggregate metadata and loading the entity)
      Parameters:
      input - the message or entity context
      parameter - the method parameter being resolved
      Returns:
      the matching Entity or null if not resolvable
    • matches

      protected boolean matches(Parameter parameter, Entity<?> entity)
      Returns true if the entity or any of its parents match the expected parameter type.
    • resolve

      protected Supplier<?> resolve(Parameter parameter, Entity<?> entity)
      Returns a Supplier that returns the entity if the entity or any of its parents match the expected parameter type.
    • isAssignable

      protected boolean isAssignable(Parameter parameter, Entity<?> entity)
      Returns true if the entity or any of its parents match the expected parameter type.
    • 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:
      determinesSpecificity in interface ParameterResolver<Object>
      Returns:
      true, signaling that this resolver helps determine method specificity