aspose 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
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Interceptor state - specification question