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 Problem with EJB 3.0 Specs Intercptors ...... 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 "Problem with EJB 3.0 Specs Intercptors ......" Watch "Problem with EJB 3.0 Specs Intercptors ......" New topic
Author

Problem with EJB 3.0 Specs Intercptors ......

Nitin Takale
Greenhorn

Joined: Nov 30, 2006
Posts: 26
Hi All,

According to EJB 3.0 Specification core contracts and requirements page no..305 if we've to specify lifecycle callback methods which are written inside an interceptor class for a session bean or mdb using Deployment descriptors then ... we've to use post-construct, pre-destroy, post-activate, and pre-passivate elements.

But when I saw the schema file of ejb-jar.xml for ejb3.0 I did not get these elements or any attribute of such type.

So can you please guide me regarding how do I specify the interceptor class which contains lifecycle callback methods using deployment descriptor.

See.. I don't want to write any lifecycle callback methods inside bean class I want to write it inside interceptor class. And I don't want to use Interceptors annotation on my bean class. I want to specify the interceptor using deployment descriptor.

So how to do it ???

thanks

Nitin


Nitin<br /> <br />SCJP 6.0<br />SCBCD 5.0
Sergio Tridente
Ranch Hand

Joined: Mar 22, 2007
Posts: 329

Hi Nitin,

I understand what you say. Well, in fact I was able to find the around-invoke , pre-passivate and post-activate elements of the deployment descriptor: take a look at page 536. It is defined so that they may be specified inside sessionType or interceptorType elements. But the post-construct and pre-destroy are nowhere to be found.

In fact, inside the definition of the interceptorType element there is a documentation element that reads:


The interceptorType element declares information about a single interceptor class. It consists of :
- An optional description.
- The fully-qualified name of the interceptor class.
- An optional list of around invoke methods declared on the interceptor class and/or its super-classes.
- An optional list environment dependencies for the interceptor class and/or its super-classes.
- An optional list of post-activate methods declared on the interceptor class and/or its super-classes.
- An optional list of pre-passivate methods declared on the interceptor class and/or its super-classes.


Again, the post-construct and pre-destroy elements are not mentioned.


This is not what the specification states in section 12.4:

If the deployment descriptor is used to define interceptors, the post-construct, pre-destroy, post-activate, and pre-passivate elements are used.


Furthermore, section 12.8.1 makes the following "mistake":

The interceptor methods are specified by using the around-invoke, pre-construct, post-destroy, pre-passivate, and post-activate elements.


Note it talks about pre-construct (vs. post-construct) and post-destroy (vs. pre-destroy).

This is confusing.
[ September 01, 2008: Message edited by: Sergio Tridente ]

SCJP 1.4 (88%) - SCJP 5.0 Upgrade (93%) - SCWCD 1.4 (97%) - SCBCD 5.0 (98%)
Nitin Takale
Greenhorn

Joined: Nov 30, 2006
Posts: 26
Thanks....Sergio Tridente

But I got the solution for the same... I used Eclipse Ganymede and here goes the ejb-jar.xml of it.....


<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd">
<enterprise-beans>
<session>
<ejb-name>WorkerBean</ejb-name>
<business-remote>com.seed.WorkerBeanRemote</business-remote>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>

</enterprise-beans>

<interceptors>

<interceptor>

<interceptor-class>com.seed.interceptor.LifeCycleInterceptor</interceptor-class>

<post-construct>

<lifecycle-callback-method>oneMoreCreate</lifecycle-callback-method>
</post-construct>
<pre-destroy>

<lifecycle-callback-method>oneMoreDestroy</lifecycle-callback-method>
</pre-destroy>
</interceptor>
</interceptors>
<assembly-descriptor>

<interceptor-binding>

<ejb-name>WorkerBean</ejb-name>

<interceptor-class>com.seed.interceptor.LifeCycleInterceptor</interceptor-class>

</interceptor-binding></assembly-descriptor>

</ejb-jar>


Well that's the way it is ....

bye

nitin
Tomaszz Lewandowski
Ranch Hand

Joined: Sep 07, 2007
Posts: 30
Hello,

<post-construct> and <pre-destroy> elements are in jndiEnvironmentRefsGroup in interceptorType, so the spec is correct, you can use these as subelements of element "interceptor" and "session".


Regards<br />Tomasz Lewandowski<br />SCJP5 (97%) | SCWCD5 (98%)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with EJB 3.0 Specs Intercptors ......