Interface InvocationContext


  • public interface InvocationContext
    Contextual information about a method invocation, along with methods to alter the invocation process in various ways.
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      java.lang.reflect.Constructor<?> getConstructor()
      Returns the constructor of the target class for which the interceptor was invoked.
      java.util.Map<java.lang.String,​java.lang.Object> getContextData()
      Returns the context data associated with this invocation or lifecycle callback.
      java.lang.reflect.Method getMethod()
      Get the invoked method for this invocation.
      java.lang.Object[] getParameters()
      Get the parameters of the method invocation (for method interceptors).
      java.lang.Object getTarget()
      Get the target instance for this invocation.
      java.lang.Object getTimer()
      Get the timer associated with an @AroundTimeout interceptor method.
      java.lang.Object proceed()
      Proceed with the next stage of invocation processing.
      void setParameters​(java.lang.Object[] params)
      Replace the parameters of the method invocation.
    • Method Detail

      • getTarget

        java.lang.Object getTarget()
        Get the target instance for this invocation.
        Returns:
        the target instance
      • getMethod

        java.lang.reflect.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 as @PostConstruct or @PreDestroy), null is returned.
        Returns:
        the invoked method, or null if none applies to the current invocation context
      • getConstructor

        java.lang.reflect.Constructor<?> getConstructor()
        Returns the constructor of the target class for which the interceptor was invoked. For AroundConstruct 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

        java.lang.Object[] getParameters()
                                  throws java.lang.IllegalStateException
        Get the parameters of the method invocation (for method interceptors).
        Returns:
        the invoked method parameters
        Throws:
        java.lang.IllegalStateException - if the current invocation context refers to a lifecycle callback invocation
      • setParameters

        void setParameters​(java.lang.Object[] params)
                    throws java.lang.IllegalStateException,
                           java.lang.IllegalArgumentException
        Replace the parameters of the method invocation.
        Parameters:
        params - the new parameter values to use for the current invocation
        Throws:
        java.lang.IllegalStateException - if the current invocation context refers to a lifecycle callback invocation
        java.lang.IllegalArgumentException - if the types or quantity of the method parameters does not match the method declaration
      • getContextData

        java.util.Map<java.lang.String,​java.lang.Object> 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-WS MessageContext. If there is no context data, an empty Map 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

        java.lang.Object getTimer()
        Get the timer associated with an @AroundTimeout interceptor method. When intercepting an EJB component timeout, the returned type is javax.ejb.Timer.
        Returns:
        the timer object, or null if the invocation did not apply to a timeout method.
      • proceed

        java.lang.Object proceed()
                          throws java.lang.Exception
        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, then null is returned from this method, and should be returned by the interceptor as well.

        Returns:
        the result of subsequent interceptor method processing
        Throws:
        java.lang.Exception - if an exception is thrown by subsequent processing