File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Interceptor state - specification question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Interceptor state - specification question" Watch "Interceptor state - specification question" New topic
Author

Interceptor state - specification question

Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 916

Hi,


In the specification in the section 12.1.Overview (page 301 in my version) I found this text :

It is possible to carry state across multiple interceptor method invocations for a single business method invocation or lifecycle callback event for a bean in the context data of the InvocationContext
object.


What I understand is : if I invoke more interceptor methods with the same call (business method) I can preserve the state. The same logic for the life cycle methods.
Or more simple the state is preserved as long as I am in the same InvocationContext.

Am I right ?


Regards,
Mihai


SCJP, SCJD, SCWCD, OCPJBCD
Remko Strating
Ranch Hand

Joined: Dec 28, 2006
Posts: 893
You can use the method invocationContext.getContextData() for getting a Map in which you can store different objects by a name.

These objects can be shared between the different interceptors.

If you use

invocationContext.getContextData().put("objectname","object") in one interceptor.

You will retrieve the value with

invocationContext.getContextData().get("objectname") in the next interceptors in the invocation chain.


Remko (My website)
SCJP 1.5, SCWCD 1.4, SCDJWS 1.4, SCBCD 1.5, ITIL(Manager), Prince2(Practitioner), Reading/ gaining experience for SCEA,
Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 916

Thanks, then I have an other related question.

An Interceptor can have state or not. By state I mean fields (can base its logic on the fields values).
IMHO no, with only one exception, the interceptors for the statefull bean.
I base this assumption on the next extract from "12.2 Interceptor Life Cycle"

The lifecycle of an interceptor instance is the same as that of the bean instance with which it is associated. When the bean instance is created, interceptor instances are created for each interceptor class defined for the bean. These interceptor instances are destroyed when the bean instance is removed.


Am I right ?

Regards,
Mihai
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Interceptor state - specification question
 
Similar Threads
Method signatures for container callbacks
Multiple life-cycle Callback methods per class
Doubts regarding javabeat questions
multiple AroundInvoke
Lifecycle callback interceptor