Understanding Deployment Descriptors


As discussed in Chapter 3, bean providers must declare all middleware requirements in a deployment descriptor file; for example, the life cycle for a specified bean, including transactions, persistence, and security services. Entity bean authors indicate how the container should manage the bean. The container should specify whether a bean is a session bean, the type of session bean (stateful or stateless), or one of the two types of entity beans—container-managed persistent bean or bean-managed persistent bean. The deployment descriptor should indicate whether the bean is a message-driven bean. If so, it must indicate that the MDB has no interface.

In EJB 2.0, a deployment descriptor file is an XML file. An EJB container should usually provide a tool to generate the deployment descriptor.

The descriptor file for the bean factory application introduced in Chapter 3 is shown here, and we’ll take a close look at the elements in the next section. Here is the file:

//An ejb deployment descriptor file for the bean factory application:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.
//DTD Enterprise JavaBeans 2.0//EN"
"http://java.sun.com/dtd/ejb-jar_2_0.dtd">
<ejb-jar>
<enterprise-beans>
<session>
<display-name>beanFactory</display-name>
<ejb-name>beanFactory</ejb-name>
<home>com.dps.bean.session.beanFactory</home>
<remote>com.dps.bean.session.beanFactory</remote>
<ejb-class>com.dps.bean.session.beanFactoryBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
</enterprise-beans>
<assembly-descriptor>
<container-transaction>
<method>
<ejb-name>beanFactory</ejb-name>
<method-name>*</method-name>
</method>
<trans-attribute>Required</trans-attribute>
</container-transaction>
</assembly-descriptor>
</ejb-jar>

The bean factory deployment descriptor file begins with the xml declaration, which indicates that the XML file conforms with the XML specification 1.0 and the encoding is UTF-8. The Document Type Definition indicates that the file is an ejb deployment descriptor, and it provides the default namespace declaration as well as the URL for Sun Microsystems, the official body for defining the EJB specification 2.0.

The <ejb-jar> header is the root for the descriptor. Next, the file indicates that the bean type is a session bean. The <display-name> is beanFactory, the <ejb-name> is also beanFactory. The descriptor indicates that the <home> is com.dps.bean.session .beanFactoryHome. The <remote> interface is com.dps.bean.session.beanFactory.

The <ejb-class> is com.dps.bean.session.beanFactoryBean. The descriptor details the <session-type> as stateless. The <transaction-type> is container managed, while the <assembly-descriptor> is a container transaction.

The <method> specified is beanFactory. Finally, the <trans-attribute> indicates that the method is required.

Examining the Deployment Descriptor

The root of every deployment descriptor as displayed here is the <ejb-jar> element. This element contains several subelements, some required, some not. The <enterprise-beans> subelement contains its own set of subelements. They include the following:

  • <session>

  • <entity>

  • <message-driven>

Table 4-1 lists the <ejb-jar> subelements.

Table 4-1: <ejb-jar> Subelements

Subelement

Required/Optional

Description

<description>

Optional

The subelement.

<display-name>

Optional

The JAR file and other EJB components.

<small-icon>

Optional

A small icon used to represent the JAR file.

<large-icon>

Optional

A large icon used to represent the JAR file.

<enterprise-beans>

Required

Beans residing with the JAR file. Only one such element is permitted within the deployment descriptor.

<ejb-client-jar>

Optional

The path of the client JAR, used by the client to access EJBs listed in the deployment descriptor.

<assembly-descriptor>

Optional

How EJBs are used by the J2EE application.

Table 4-2 contains a list of <session> and <entity> elements.

Table 4-2: <session> and <entity> Elements

Subelement

Required/Optional

Description

<description>

Optional

The session or entity bean.

<display-name>

Optional

The JAR file and EJB components.

<small-icon>

Optional

A small icon used to represent either the session or entity bean.

<large-icon>

Optional

A large icon used to represent either the session or entity bean.

<ejb-name>

Requires one

The name of the session or entity bean.

<home>

EJB 1.1, one required EJB 2.0, optional

The full-qualified class name of the session or entity EJB remote home interface.

<remote>

EJB 1.1, one required EJB 2.0, optional

The full-qualified class name of the session or entity EJB remote interface.

<local-home>

EJB 2.0, optional

The full-qualified class name of the session or entity EJB local home interface.

<local>

EJB 2.0, optional

The full-qualified class name of the session or entity EJB local interface.

<ejb-class>

Requires one

The full-qualified class name of the session or entity EJB class.

<primkey-field>

Entity bean, optional

The entity bean primary key field when the entity bean uses container-managed persistence.

<prim-key-class>

Entity bean, requires one

The primary key class for the entity bean.

<persistence-type>

Entity bean, requires one

Either CMP or BMP beans.

<reentrant>

Entity bean, requires one Values are true or false

Reentrant invocations are either allowed or not allowed.

<cmp-version>

EJB 2.0, optional EJB containers must support both EJB 2.0 and EJB 1.1

The CMP version.

<abstract-schema-name>

EJB 2.0, optional

Identifies entity beans in a JAR file.

<cmp-field>

Entity bean only, zero or more must exist for each cmp field in the entity EJB class. Must contain a <field-name> element

This element is meant for CMP entity beans.

<env-entry>

Optional, zero or more

An environment entry available through JNDI ENC.

<ejb-ref>

Optional, zero or more

A remote EJB reference entry available through JNDI ENC.

<ejb-local-ref>

EJB 2.0, optional, zero or more

A local EJB reference entry available through JNDI ENC.

<resource-ref>

Optional, zero or more

A reference to a connection factory available through JNDI ENC.

<resource-env-ref>

EJB 2.0, optional, zero or more

Required administered objects.

<security-role-ref>

Optional, zero or more

Identifies security roles.

<security-identity>

EJB 2.0, optional

The principal for a method.

<session-type>

Requires one session bean Value: stateless or stateful

Specifies whether a session bean is stateless or stateful.

<transaction-type>

Requires one session bean Value: bean or container

Specifies that a session bean manages transactions or the container manages the transactions.

<query>

EJB 2.0, optional, zero or more

Contains an EJB QL statement bound to a find or select method.

Table 4-3 presents a list of <message-driven> elements.

Table 4-3: <message-driven> Elements

Subelement

Required/Optional

Description

<description>

Optional

The session or entity bean.

<display-name>

Optional

The JAR file and EJB components.

<small-icon>

Optional

A small icon used to represent the message-driven bean.

<large-icon>

Optional

A large icon used to represent the message-driven bean.

<ejb-name>

Requires one

The message-driven bean's name.

<ejb-class>

Requires one

The fully qualified class name of the MDB EJB class.

<transaction-type>

Requires one session bean Value: bean or container

Specifies whether an MDB manages the transaction or the container manages the transaction.

<security-identity>

EJB 2.0, optional

The principal for a method.

<env-entry>

Optional, zero or more

An environment entry available through JNDI ENC.

<ejb-ref>

Optional, zero or more

A remote EJB reference available through JNDI ENC.

<ejb-local-ref>

EJB 2.0, optional, zero or more

A local EJB reference available through JNDI ENC.

<resource-ref>

Optional, zero or more

A reference to a connection factory available through JNDI ENC.

<resource-env-ref>

EJB 2.0, optional, zero or more

Required administered objects.

<message-selector>

Optional

A conditional expression using Boolean logic to select messages received from a topic or queue and subsequently delivered to a client.

<acknowledge-mode>

Required only if EJB manages transactions.

The type of acknowledgment used when a message is received.

<message-driven-destination>

Required Values: javax.jms.Queue or javax.jms.Topic

The type of destination subscribed or listened to by the MDB.

Note that there is one other important piece of information about the <message-selector> subelement. XML files use a special syntax for processing unparsed characters such as the less-than symbol and greater-than symbol.

Here is a method for eliminating this problem:

<message-selector>
<![CDATA[ a > 90 and b < 70);]];

Understand that the XML parser views the less-than symbol as the beginning of a markup tag. It sees the greater-than symbol as the end of a markup tag. CDATA solves this problem by ignoring both of them. The parser will not try to process them.

Now that you have a complete list of the bean types and their characteristics, the only way to become totally familiar with JNDI is to practice using it. The pursuit is informative and worthwhile.




.NET & J2EE Interoperability
Microsoft .NET and J2EE Interoperability Toolkit (Pro-Developer)
ISBN: 0735619220
EAN: 2147483647
Year: 2004
Pages: 101
Authors: Simon Guest

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net