Skip Headers
Oracle® Containers for J2EE Enterprise JavaBeans Developer's Guide
10g (10.1.3.5.0)

Part Number E13981-01
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Feedback page
Contact Us

Go to previous page
Previous
Go to next page
Next
View PDF

Configuring a Life Cycle Callback Interceptor Method on an Interceptor Class of an EJB 3.0 Session Bean

You can designate an interceptor method on an interceptor class of an EJB 3.0 session bean as a life cycle callback interceptor method.

To configure a life cycle callback interceptor method on an interceptor class, you must do the following:

  1. Create an interceptor class.

    This can be any POJO class.

  2. Implement the life cycle callback interceptor method.

    Callback methods defined on a bean's interceptor class have the following signature:

    Object <METHOD>(InvocationContext)
    
  3. Associate a life cycle event with the callback interceptor method (see "Using Annotations").

    A life cycle event can only be associated with one callback interceptor method, but a life cycle callback interceptor method may be used to interpose on multiple callback events. For example, @PostConstruct and @PreDestroy may appear only once in an interceptor class, but you may associate both @PostConstruct and @PreDestroy with the same callback interceptor method.

  4. Associate the interceptor class with your EJB 3.0 session bean (see "Configuring an Interceptor Class for an EJB 3.0 Session Bean").

For more information, see the following:

Using Annotations

You can specify an interceptor class method as an EJB 3.0 session bean life cycle callback method using any of the following annotations:

  • @PostConstruct

  • @PreDestroy

  • @PrePassivate (stateful session beans only)

  • @PostActivate (stateful session beans only)

Example 5-4 shows an interceptor class for a stateful session bean. It designates method myPrePassivateInterceptorMethod as the life cycle callback interceptor method for the pre-passivate life cycle event using the @PrePassivate annotation. It also designates method myPostConstructInterceptorMethod as the life cycle callback interceptor method for both the post-construct and post-activate life cycle events using the @PostConstruct and @PostActivate annotations. OC4J invokes the appropriate life cycle method only when the appropriate life cycle event occurs. OC4J invokes all other non-life cycle interceptor methods (such as myInterceptorMethod) each time you invoke a session bean business method (see "Configuring an Interceptor Class for an EJB 3.0 Session Bean").

Example 5-4 Interceptor Class

public class MyStatefulSessionBeanInterceptor {
    ...
    protected void myInterceptorMethod (InvocationContext ctx) {
        ...
        ctx.proceed();
        ...
    }

    @PostConstruct
    @PostActivate
    protected void myPostConstructInterceptorMethod (InvocationContext ctx) {
        ...
        ctx.proceed();
        ...
    }
    @PrePassivate
    protected void myPrePassivateInterceptorMethod (InvocationContext ctx) {
        ...
        ctx.proceed();
        ...
    }
}