This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes <method> in ejb-jar deployment descriptor. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "&lt;method&gt; in ejb-jar deployment descriptor." Watch "&lt;method&gt; in ejb-jar deployment descriptor." New topic
Author

&lt;method&gt; in ejb-jar deployment descriptor.

Mellon Sun
Ranch Hand

Joined: Feb 20, 2003
Posts: 126
In the O'REILLY's book Enterprise JavaBeans 3.0, the descriptor samples do not use method element.

<ejb-jar>
...
<assembly-descriptor>
<interceptor-binding>
<ejb-name>TravelAgentBean</ejb-name>
<interceptor-class>...</interceptor-class>
<method-name>bookPassage</method-name>
<method-params>
<method-param>...</method-param>
<method-param>...</method-param>
</method-params>
</interceptor-binding>
</assembly-descriptor>
</ejb-jar>

I tried my own descriptor like the above but encountered an error. Affter I looked up http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd, I got that there is an method element enclosing the method-name and method-params needed.

I thought it is a miss before I read same snippet in Mikalai Zaikin's study guide:

<interceptor-binding>
<ejb-name>...
<interceptor-class>...
<method-name>...
<method-params>...
</interceptor-binding>

After all, there is little chance two different writers make one same mistake. Anyboy know this exactly?


SCJP,SCWCD1.3,SCWCD1.4,SCJD,SCBCD5,SCEA5
Ralph Jaus
Ranch Hand

Joined: Apr 27, 2008
Posts: 342
In your samples the "method" element is needed. See core spec page 519, 520 for the schema and four very nice examples.


SCJP 5 (98%) - SCBCD 5 (98%)
Tomaszz Lewandowski
Ranch Hand

Joined: Sep 07, 2007
Posts: 30
I think that specification is self-contradicting in this case, because in the deployment descriptor schema there is a "method" element, but in chapter 12, the specification gives bad example:

<interceptor-binding>
<ejb-name>EmployeeService</ejb-name>
<interceptor-class>org.acme.MyIC</interceptor-class>
<method-name>myMethod</method-name>
<method-params>
<method-param>java.lang.String</method-param>
<method-param>java.lang.String</method-param>
</method-params>
</interceptor-binding>


Regards<br />Tomasz Lewandowski<br />SCJP5 (97%) | SCWCD5 (98%)
Mellon Sun
Ranch Hand

Joined: Feb 20, 2003
Posts: 126
Yes, in "JSR 220: Enterprise JavaBeansTM,Version 3.0 EJB Core Contracts and Requirements", there are conflicts about this topic.

Page 312-313:

There are four possible styles of the interceptor element syntax:
Style 1:
<interceptor-binding>
<ejb-name>*</ejb-name>
<interceptor-class>INTERCEPTOR</interceptor-class>
</interceptor-binding>
Specifying the ejb-name element as the wildcard value "*" designates default interceptors (interceptors
that apply to all enterprise beans contained in the ejb-jar).
Style 2:
<interceptor-binding>
<ejb-name>EJBNAME</ejb-name>
<interceptor-class>INTERCEPTOR</interceptor-class>
</interceptor-binding>
This style is used to refer to interceptors associated with the specified enterprise bean class (class-level
interceptors).
Style 3:
<interceptor-binding>
<ejb-name>EJBNAME</ejb-name>
<interceptor-class>INTERCEPTOR</interceptor-class>
<method-name>METHOD</method-name>
</interceptor-binding>
This style is used to associate a method-level interceptor with the specified method of the specified
enterprise bean. If there are multiple methods with the same overloaded name, the element of this style
refers to all the methods with the overloaded name. Method-level interceptors can only be associated
with business methods of the bean class. Note that the wildcard value "*" cannot be used to specify
method-level interceptors.
Specification of Interceptors in the Deployment DescriptorEnterprise JavaBeans 3.0, Final Release Interceptors

Style 4:
<interceptor-binding>
<ejb-name>EJBNAME</ejb-name>
<interceptor-class>INTERCEPTOR</interceptor-class>
<method-name>METHOD</method-name>
<method-params>
<method-param>PARAM-1</method-param>
<method-param>PARAM-2</method-param>
...
<method-param>PARAM-n</method-param>
</method-params>
<interceptor-binding>

And in page 519-520:

There are four possible styles of the interceptor element syntax :
1.
<interceptor-binding>
<ejb-name>*</ejb-name>
<interceptor-class>INTERCEPTOR</interceptor-class>
</interceptor-binding>
Specifying the ejb-name as the wildcard value "*" designates
default interceptors (interceptors that apply to all session and
message-driven beans contained in the ejb-jar).
2.
<interceptor-binding>
<ejb-name>EJBNAME</ejb-name>
<interceptor-class>INTERCEPTOR</interceptor-class>
</interceptor-binding>
This style is used to refer to interceptors associated with the
specified enterprise bean(class-level interceptors).
3.
<interceptor-binding>
<ejb-name>EJBNAME</ejb-name>
<interceptor-class>INTERCEPTOR</interceptor-class>
<method>
<method-name>METHOD</method-name>
</method>
</interceptor-binding>
This style is used to associate a method-level interceptor with
the specified enterprise bean. If there are multiple methods
with the same overloaded name, the element of this style refers
to all the methods with the overloaded name. Method-level
interceptors can only be associated with business methods of the
bean class. Note that the wildcard value "*" cannot be used
to specify method-level interceptors.
4.
<interceptor-binding>
<ejb-name>EJBNAME</ejb-name>
<interceptor-class>INTERCEPTOR</interceptor-class>
<method>
<method-name>METHOD</method-name>
<method-params>
<method-param>PARAM-1</method-param>
<method-param>PARAM-2</method-param>
...
<method-param>PARAM-N</method-param>
</method-params>
</method>
</interceptor-binding>
Mellon Sun
Ranch Hand

Joined: Feb 20, 2003
Posts: 126
In GlassFish V2 and NetBean6.5, the prior one with no <method> element doesn't work. So, it is clear now. Thanks.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: &lt;method&gt; in ejb-jar deployment descriptor.
 
Similar Threads
deployment descriptor (ejb-jar.xml) problem
ejb-jar.xml for EJB3.0
interceptors in the EJB 3.0 ejb-jar.xml
Problem with EJB 3.0 Specs Intercptors ......
EJB 3.1 - interceptors ordering and binding definition