Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

How to Utilize EJB 2.0 Local References-2 : Page 2


advertisement

Two Kinds of References
To access enterprise beans from other enterprise beans, a special mechanism is provided by the container. This mechanism allows a bean provider to refer to the homes of other enterprise beans using "logical" names called EJB references. These references are special entries declared in the application's deployment descriptor that is then used by the container to construct the enterprise bean's environment. In the deployment descriptor, the Deployer binds the EJB references used in the enterprise bean code to the homes of other enterprise beans that the bean needs to access.

Before the EJB 2.0 Specification, there was only one way to reference one enterprise bean from another. That was to use the bean's remote interface, which requires a remote procedure call across the network, just like a normal EJB client. If several beans are collaborating to fill a particular transaction, then the expense of marshalling and unmarshalling the necessary objects across the network can become quite substantial.

With the 2.0 Specification, a new kind of bean interface was defined that would allow beans in the same container to refer to each other directly, without the network overhead of the remote interface. This new mechanism is called a local interface. A local interface is a standard Java interface that does not inherit from RMI. An enterprise bean can be defined as having a local interface, a remote interface, or both.



Specifying a Local Reference for a Bean
A local reference is specified in the same manner that a traditional remote reference is specified - the deployment descriptor. In fact, the deployment descriptor elements for a local reference mirror exactly the elements for a remote reference.

The code snippet below is a look at a typical remote reference:


<ejb-ref>
	<description>This is a Product entity</description>
	<ejb-ref-name>ejb/Product</ejb-ref-name>
	<ejb-ref-type>Entity</ejb-ref-type>
	<home>com.xyz.widgets.ProductHome</home>
	<remote>com.xyz.widgets.Product</remote>
	<ejb-link>../products/product.jar#Product</ejb-link>
</ejb-ref> 

The code snippet below is a look at a local reference for the same bean:


<ejb-local-ref>
	<description>This is a Product entity</description>
	<ejb-ref-name>ejb/Product</ejb-ref-name>
	<ejb-ref-type>Entity</ejb-ref-type>
	<local-home>com.xyz.widgets.ProductHome</local-home>
	<local>com.xyz.widgets.Product</local>
	<ejb-link>../products/product.jar#Product</ejb-link>
</ejb-local-ref> 

Here's a quick look at what each of these elements is used for:

 

<ejb-local-ref>

The top-level, containing element

<description>

An optional element used to provide a comments

<ejb-ref-name>

The logical name used with the referencing beans code to refer to this reference

<ejb-ref-type>

The Java type expected by the enterprise bean

<local-home>

The fully qualified class name for the referenced beans local home interface

<local>

The fully qualified class name for the referenced beans local interface

<ejb-link>

An optional element that can be used to create a greater degree of decoupling between the two enterprise beans

 



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date