Class Invokers

java.lang.Object
pro.verron.officestamper.core.Invokers
All Implemented Interfaces:
org.springframework.expression.MethodResolver

public class Invokers extends Object implements org.springframework.expression.MethodResolver

The Invokers class serves as an implementation of the MethodResolver interface.

It is designed to provide an efficient mechanism for resolving method executors based on method names and argument types.

The class organizes and stores registered invokers in a structured map, enabling streamlined method resolution at runtime.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final record 
    Represents argument types associated with method invocation.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Invokers(Stream<Invoker> invokerStream)
    Constructs an Invokers instance, grouping and mapping invokers by their names and argument types to their corresponding executors.
  • Method Summary

    Modifier and Type
    Method
    Description
    static Invoker
    Creates an Invoker for a custom function.
    @Nullable org.springframework.expression.MethodExecutor
    resolve(org.springframework.expression.EvaluationContext context, Object targetObject, String name, List<org.springframework.core.convert.TypeDescriptor> argumentTypes)
    Resolves a method executor for a given method name and argument types within the specified context and target object.
    static Stream<Invoker>
    streamInvokersFromClass(Map<Class<?>,?> interfaces2implementations)
    Transforms a map containing interface-to-implementation mappings into a stream of Invoker objects.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Invokers

      public Invokers(Stream<Invoker> invokerStream)
      Constructs an Invokers instance, grouping and mapping invokers by their names and argument types to their corresponding executors.
      Parameters:
      invokerStream - a stream of Invoker objects, where each invoker encapsulates the method name, its parameter types, and the associated method executor.
  • Method Details

    • streamInvokersFromClass

      public static Stream<Invoker> streamInvokersFromClass(Map<Class<?>,?> interfaces2implementations)
      Transforms a map containing interface-to-implementation mappings into a stream of Invoker objects. Each entry in the map is processed to generate a flat stream of relevant Invoker instances.
      Parameters:
      interfaces2implementations - a map where keys represent interface classes and values represent their corresponding implementations, used to derive invoker instances.
      Returns:
      a stream of Invoker objects derived from the provided map entries.
    • ofCustomFunction

      public static Invoker ofCustomFunction(CustomFunction cf)
      Creates an Invoker for a custom function.
      Parameters:
      cf - the custom function.
      Returns:
      the invoker.
    • resolve

      public @Nullable org.springframework.expression.MethodExecutor resolve(org.springframework.expression.EvaluationContext context, Object targetObject, String name, List<org.springframework.core.convert.TypeDescriptor> argumentTypes)
      Resolves a method executor for a given method name and argument types within the specified context and target object. This method attempts to find a matching executor for methods registered with a specific name and compatible argument types.
      Specified by:
      resolve in interface org.springframework.expression.MethodResolver
      Parameters:
      context - the evaluation context in which the method is being resolved, providing necessary state and configuration.
      targetObject - the object on which the resolved method will be invoked.
      name - the name of the method to resolve.
      argumentTypes - a list of type descriptors representing the argument types of the method to resolve.
      Returns:
      the resolved MethodExecutor if a compatible method is found; otherwise, returns null.