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 anInvoker
instance directly
public interface InvokerBuilder<T>
Builder ofInvoker
s. 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 upMyService
from the CDI container, instead of having to obtain a contextual reference manually.Assuming that
builder
is anInvokerBuilder
forMyService.hello()
, such invoker can be built:builder.withInstanceLookup().build();
Later, to invoke thehello()
method, a framework could passnull
as 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 T
build()
Returns the builtInvoker
or 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
- ifposition
is less than 0 or greater than or equal to the number of parameters declared by the target method
-
-