| Oracle® Containers for J2EE Enterprise JavaBeans Developer's Guide 10g (10.1.3.5.0) Part Number E13981-01 |
|
|
View PDF |
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:
Create an interceptor class.
This can be any POJO class.
Implement the life cycle callback interceptor method.
Callback methods defined on a bean's interceptor class have the following signature:
Object <METHOD>(InvocationContext)
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.
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:
You can specify an interceptor class method as an EJB 3.0 session bean life cycle callback method using any of the following annotations:
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();
...
}
}