Package javax.interceptor
Interface InvocationContext
public interface InvocationContext
Contextual information about a method invocation, along with methods to alter the invocation process
in various ways.
-
Method Summary
Modifier and TypeMethodDescriptionConstructor
<?> Returns the constructor of the target class for which the interceptor was invoked.Returns the context data associated with this invocation or lifecycle callback.Get the invoked method for this invocation.Object[]
Get the parameters of the method invocation (for method interceptors).Get the target instance for this invocation.getTimer()
Get the timer associated with an@AroundTimeout
interceptor method.proceed()
Proceed with the next stage of invocation processing.void
setParameters
(Object[] params) Replace the parameters of the method invocation.
-
Method Details
-
getTarget
Object getTarget()Get the target instance for this invocation.- Returns:
- the target instance
-
getMethod
Method getMethod()Get the invoked method for this invocation. If the invoked method is an@AroundInvoke
or@AroundTimeout
interceptor method, the method of the target class is returned. For lifecycle callback interceptors (such asinvalid reference
@PostConstruct
invalid reference
@PreDestroy
null
is returned.- Returns:
- the invoked method, or
null
if none applies to the current invocation context
-
getConstructor
Constructor<?> getConstructor()Returns the constructor of the target class for which the interceptor was invoked. ForAroundConstruct
interceptor, the constructor of the target class is returned. For all other interceptors, a null value is returned.- Returns:
- the constructor, or a null value
-
getParameters
Get the parameters of the method invocation (for method interceptors).- Returns:
- the invoked method parameters
- Throws:
IllegalStateException
- if the current invocation context refers to a lifecycle callback invocation
-
setParameters
Replace the parameters of the method invocation.- Parameters:
params
- the new parameter values to use for the current invocation- Throws:
IllegalStateException
- if the current invocation context refers to a lifecycle callback invocationIllegalArgumentException
- if the types or quantity of the method parameters does not match the method declaration
-
getContextData
Returns the context data associated with this invocation or lifecycle callback. If the current context is an invocation on a web service endpoint, the map returned will be the JAX-WSMessageContext
. If there is no context data, an emptyMap
object will be returned. Normally, information stored in this map is available to subsequent interceptors in an interceptor chain, so this mechanism may be used to pass information from one interceptor to the next.- Returns:
- the context map
-
getTimer
Object getTimer()Get the timer associated with an@AroundTimeout
interceptor method. When intercepting an EJB component timeout, the returned type isinvalid reference
javax.ejb.Timer
- Returns:
- the timer object, or
null
if the invocation did not apply to a timeout method.
-
proceed
Proceed with the next stage of invocation processing. Calling this method may cause another interceptor to be invoked, or it may cause the final target object to be invoked. The return value of this method is the result of the subsequent invocation processing, or of the invocation itself. Normally an interceptor will return this value to its caller; however, it is also possible to return a different value.If the intercepted method's return type is
void
, or if this is a lifecycle method interceptor, thennull
is returned from this method, and should be returned by the interceptor as well.- Returns:
- the result of subsequent interceptor method processing
- Throws:
Exception
- if an exception is thrown by subsequent processing
-