Package jakarta.enterprise.invoke
Interface InvokerBuilder<T>
-
- Type Parameters:
T- type of outcome of this builder; always represents anInvoker, but does not necessarily have to be anInvokerinstance directly
public interface InvokerBuilder<T>Builder ofInvokers. Allows configuring additional behaviors on top of a plain method invocation.Lookups
For the target bean instance (withInstanceLookup()) and for each target method parameter (withArgumentLookup(int)), it is possible to specify that the corresponding value passed toInvoker.invoke()shall be ignored and a value shall be looked up from the CDI container instead.For example, assume the following managed bean exists:
@Dependent public class MyService { public String hello(String name) { return "Hello " + name + "!"; } }A CDI-based framework may want to build an invoker for thehello()method that automatically looks upMyServicefrom the CDI container, instead of having to obtain a contextual reference manually.Assuming that
builderis anInvokerBuilderforMyService.hello(), such invoker can be built:builder.withInstanceLookup().build();
Later, to invoke thehello()method, a framework could passnullas the instance:invoker.invoke(null, new Object[] { "world" })The invoker would look up the instance of the target bean automatically, so the method would be invoked correctly and the return value would be"Hello world!".- Since:
- 4.1
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description Tbuild()Returns the builtInvokeror some representation of it.InvokerBuilder<T>withArgumentLookup(int position)Enables lookup of the argument on givenposition.InvokerBuilder<T>withInstanceLookup()Enables lookup of the target bean instance.
-
-
-
Method Detail
-
withInstanceLookup
InvokerBuilder<T> withInstanceLookup()
Enables lookup of the target bean instance.- Returns:
- this builder
-
withArgumentLookup
InvokerBuilder<T> withArgumentLookup(int position)
Enables lookup of the argument on givenposition.- Parameters:
position- zero-based position of the target method parameter for which lookup should be enabled- Returns:
- this builder
- Throws:
java.lang.IllegalArgumentException- ifpositionis less than 0 or greater than or equal to the number of parameters declared by the target method
-
-