javax.interceptor
Interface InvocationContext


public interface InvocationContext

Exposes context information about the intercepted invocation and operations that enable interceptor methods to control the behavior of the invocation chain.


    @AroundInvoke
    public Object logInvocation(InvocationContext ctx) throws Exception {
       String class = ctx.getMethod().getDeclaringClass().getName();
       String method = ctx.getMethod().getName();
       Logger.global.entering(class, method, ctx.getParameters());
       try {
          Object result = ctx.proceed();
          Logger.global.exiting(class, method, result);
          return result;
       }
       catch (Exception e) {
          Logger.global.throwing(class, method, e);
          throw e;
       }

    }
 
 

Since:
Interceptors 1.0

Method Summary
 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()
          Returns the method of the target class for which the interceptor was invoked.
 java.lang.Object[] getParameters()
          Returns the parameter values that will be passed to the method of the target class.
 java.lang.Object getTarget()
          Returns the target instance.
 java.lang.Object getTimer()
          Returns the timer object associated with a timeout method invocation on the target class, or a null value for method and lifecycle callback interceptor methods.
 java.lang.Object proceed()
          Proceed to the next interceptor in the interceptor chain.
 void setParameters(java.lang.Object[] params)
          Sets the parameter values that will be passed to the method of the target class.
 

Method Detail

getTarget

java.lang.Object getTarget()
Returns the target instance.

Returns:
the target instance

getTimer

java.lang.Object getTimer()
Returns the timer object associated with a timeout method invocation on the target class, or a null value for method and lifecycle callback interceptor methods. For example, when associated with an EJB component timeout, this method returns Timer

Returns:
the timer object or a null value
Since:
Interceptors 1.1

getMethod

java.lang.reflect.Method getMethod()
Returns the method of the target class for which the interceptor was invoked. For method interceptors, the method of the target class is returned. For lifecycle callback interceptors, a null value is returned.

Returns:
the method, or a null value

getParameters

java.lang.Object[] getParameters()
Returns the parameter values that will be passed to the method of the target class. If setParameters() has been called, getParameters() returns the values to which the parameters have been set.

Returns:
the parameter values, as an array
Throws:
java.lang.IllegalStateException - if invoked within a lifecycle callback method.

setParameters

void setParameters(java.lang.Object[] params)
Sets the parameter values that will be passed to the method of the target class.

Parameters:
params - the parameter values, as an array
Throws:
java.lang.IllegalStateException - if invoked within a lifecycle callback method.
java.lang.IllegalArgumentException - if the types of the given parameter values do not match the types of the method parameters, or if the number of parameters supplied does not equal the number of method parameters.

getContextData

java.util.Map<java.lang.String,java.lang.Object> getContextData()
Returns the context data associated with this invocation or lifecycle callback. If there is no context data, an empty Map<String,Object> object will be returned.

Returns:
the context data, as a map

proceed

java.lang.Object proceed()
                         throws java.lang.Exception
Proceed to the next interceptor in the interceptor chain. Return the result of the next method invoked, or a null value if the method has return type void.

Returns:
the return value of the next method in the chain
Throws:
java.lang.Exception


Submit a bug or feature

Copyright © 2009-2011, Oracle Corporation and/or its affiliates. All Rights Reserved. Use is subject to license terms.

Generated on 10-February-2011 12:41


Spec-Zone.ru - all specs in one place



free hit counter