Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
xml
xml
borderStylesolid
title<sys:environment> Example
<openejb-jar xmlns="http://openejb.apache.org/xml/ns/openejb-jar-2.2"
             xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.2">

    <sys:environment>
        <sys:moduleId>
            <sys:groupId>default</sys:groupId>
            <sys:artifactId>openejb-jar-1</sys:artifactId>
            <sys:version>2.0</sys:version>
            <sys:type>ear</sys:type>
        </sys:moduleId>

        <sys:dependencies>
            <sys:dependency>
                <sys:groupId>org.apache.geronimo.testsuite</sys:groupId>
                <sys:artifactId>agent-ds</sys:artifactId>
                <sys:version>2.2-SNAPSHOT</sys:version>
                <sys:type>car</sys:type>
            </sys:dependency>

            <sys:dependency>
                <sys:groupId>org.apache.geronimo.configs</sys:groupId>
                <sys:artifactId>tomcat6</sys:artifactId>
                <sys:version>2.2-SNAPSHOT</sys:version>
                <sys:type>car</sys:type>
            </sys:dependency>
        </sys:dependencies>
    </sys:environment>

</openejb-jar>

CMP Entity Beans

Container Managed Persistence (CMP) is still fully supported in OpenEJB/Geronimo, although the Java Persistence API is generally considered a better approach in Java EE. Apache Geronimo uses OpenJPA for providing Java Persistence API to Java EE applications deployed in the server. More information and details about the JPA deployment descriptor can be found here: Java Persistence API deployment plans.

<naming:cmp-connection-factory>



<sec:security>

The <sec:security> The <naming:cmp-connection-factory> XML element uses the Geronimo Naming Security namespace, which is used to identify the common elements for resolving EJB references, resource references, and Web services references, which is documented here:and is documented here:

The <naming:cmp-connection-factory> element is used to specify a JDBC connection pool that should be used by Container Managed Persistence (CMP) entity beans to connect to a database. Since the <naming:cmp-connection-factory> element points to a database pool using the same syntax a resource reference uses, there are multiple methods available to refer to the connection pool. It can be specified by a simple name using the <resource-link> element, by pattern using the <pattern> element, or finally by URL using the <url> element. The resource-link handles most common resource situations where the JDBC pools are deployed as J2EE connectors in the same application, or deployed standalone in the same server. But pattern or URL can be use for any. An example openejb-jar.xml using all three techniques is shown:

...

<sec:security> element groups the security role mapping settings for the EJB application. This is an optional element, but if it is present all the EJB modules must make the appropriate access checks as outlined in the JACC specification. This element includes the <role-mapping> section that references the role(s) defined in the <security-role> element in the application.xml file.

<sys:gbean>

The <sys:gbean> XML element uses the Geronimo System namespace described at http://geronimo.apache.org/schemas-2.1/docs/geronimo-module-1.2.xsd.htmlImage Added.

The <sys:gbean> element is used to define GBean(s) that are configured and deployed with the EJB. These additional Geronimo services will be deployed when the application is deployed (and stopped when the application is stopped). Normally, the implementation classes for these services are included at the server level and referenced using a dependency element.

CMP Entity Beans

Container Managed Persistence (CMP) is still fully supported in OpenEJB/Geronimo, although the Java Persistence API is generally considered a better approach in Java EE. Apache Geronimo uses OpenJPA for providing Java Persistence API to Java EE applications deployed in the server. More information and details about the JPA deployment descriptor can be found here: Java Persistence API deployment plans.

...

<naming:cmp-connection-factory>

...

The <naming:cmp-connection-factory> XML element uses the Geronimo Naming namespace, which is used to identify the common elements for resolving EJB references, resource references, and Web services references, which is documented here:

...

...

The <naming:cmp-connection-factory> element is used to specify a JDBC connection pool that should be used by Container Managed Persistence (CMP) entity beans to connect to a database. Since the <naming:cmp-connection-factory> element points to a database pool using the same syntax a resource reference uses, there are multiple methods available to refer to the connection pool. It can be specified by a simple name using the <resource-link> element, by pattern using the <pattern> element, or finally by URL using the <url> element. The resource-link handles most common resource situations where the JDBC pools are deployed as J2EE connectors in the same application, or deployed standalone in the same server. But pattern or URL can be use for any. An example openejb-jar.xml using all three techniques is shown:

Code Block
xml
xml
borderStylesolid
title<naming:cmp-connection-factory> Example

<openejb-jar xmlns="http://openejb.apache.org/xml/ns/openejb-jar-2.2"
   2"
             xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.2"
             xmlns:naming="http://geronimo.apache.org/xml/ns/naming-1.2">

    <sys:environment>
        <sys:moduleId>
            <sys:groupId>default</sys:groupId>
            <sys:artifactId>openejb-jar-1</sys:artifactId>
            <sys:version>2.0</sys:version>xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.2"
            <sys:type>ear</sys:type>
        </sys:moduleId> xmlns:naming="http://geronimo.apache.org/xml/ns/naming-1.2">

        <sys:dependencies>environment>
            <sys:dependency>moduleId>
                <sys:groupId>org.apache.geronimo.testsuite<groupId>default</sys:groupId>
                <sys:artifactId>agentartifactId>openejb-jar-ds<1</sys:artifactId>
                <sys:version>2.2-SNAPSHOT<0</sys:version>
                <sys:type>car<type>ear</sys:type>
        </sys:moduleId>

       </sys:dependency>

 <sys:dependencies>
            <sys:dependency>
                <sys:groupId>org.apache.geronimo.configs<testsuite</sys:groupId>
                <sys:artifactId>tomcat6<artifactId>agent-ds</sys:artifactId>
                <sys:version>2.2-SNAPSHOT</sys:version>
                <sys:type>car</sys:type>
            </sys:dependency>

        </sys:dependencies>
    </sys:environment>
<sys:dependency>
    <!-- Begin configuration for Container Managed Persistence (CMP) -->

    <naming:cmp-connection-factory>

<sys:groupId>org.apache.geronimo.configs</sys:groupId>
         <naming:pattern>
       <sys:artifactId>tomcat6</sys:artifactId>
     <naming:groupId>resourcelocator-pattern-groupid</naming:groupId>
            <naming:artifactId>resourcelocator-pattern-artifactid</naming:artifactId>
<sys:version>2.2-SNAPSHOT</sys:version>
              <naming:version>resourcelocator-pattern-version</naming:version>  <sys:type>car</sys:type>
            <naming:module>resourcelocator-pattern-module</naming:module></sys:dependency>
        </sys:dependencies>
    <naming:name>resourcelocator-pattern-name</naming:name></sys:environment>

    <!-- Begin configuration  </naming:pattern>

    for Container Managed Persistence (CMP) -->

    <naming:resource-link>resourcelocator-resourcelink</naming:resource-link>

cmp-connection-factory>

        <naming:pattern>
            <naming:groupId>resourcelocator-pattern-groupid</naming:groupId>
            <naming:url>resourcelocatorartifactId>resourcelocator-pattern-url<artifactid</naming:url>

artifactId>
            <<naming:version>resourcelocator-pattern-version</naming:cmp-connection-factory>version>

    <!-- End configuration for Container Managed Persistence (CMP) <naming:module>resourcelocator-pattern->

</openejb-jar>

<ejb-ql-compiler-factory>

module</naming:module>
            <naming:name>resourcelocator-pattern-name</naming:name>
        </naming:pattern>

        <naming:resource-link>resourcelocator-resourcelink</naming:resource-link>

        <naming:url>resourcelocator-url</naming:url>

    </naming:cmp-connection-factory>

    <!-- End configuration for Container Managed Persistence (CMP) -->

</openejb-jar>


<ejb-ql-compiler-factory>

The <ejb-ql-compiler-factory> XML element The <ejb-ql-compiler-factory> XML element uses the OpenEJB default namespace for a openejb-jar.xml file, which is documented here:

...

Code Block
xml
xml
borderStylesolid
title<enforce-foreign-key-constraints> Example
<openejb-jar xmlns="http://openejb.apache.org/xml/ns/openejb-jar-2.2"
             xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.2"
             xmlns:naming="http://geronimo.apache.org/xml/ns/naming-1.2">

    <sys:environment>
        <sys:moduleId>
            <sys:groupId>default</sys:groupId>
            <sys:artifactId>openejb-jar-1</sys:artifactId>
            <sys:version>2.0</sys:version>
            <sys:type>ear</sys:type>
        </sys:moduleId>

        <sys:dependencies>
            <sys:dependency>
                <sys:groupId>org.apache.geronimo.testsuite</sys:groupId>
                <sys:artifactId>agent-ds</sys:artifactId>
                <sys:version>2.2-SNAPSHOT</sys:version>
                <sys:type>car</sys:type>
            </sys:dependency>

            <sys:dependency>
                <sys:groupId>org.apache.geronimo.configs</sys:groupId>
                <sys:artifactId>tomcat6</sys:artifactId>
                <sys:version>2.2-SNAPSHOT</sys:version>
                <sys:type>car</sys:type>
            </sys:dependency>
        </sys:dependencies>
    </sys:environment>

    <!-- Begin configuration for Container Managed Persistence (CMP) -->

    <naming:cmp-connection-factory>
        <naming:pattern>
            <naming:groupId>resourcelocator-pattern-groupid</naming:groupId>
            <naming:artifactId>resourcelocator-pattern-artifactid</naming:artifactId>
            <naming:version>resourcelocator-pattern-version</naming:version>
            <naming:module>resourcelocator-pattern-module</naming:module>
            <naming:name>resourcelocator-pattern-name</naming:name>
        </naming:pattern>

        <naming:resource-link>resourcelocator-resourcelink</naming:resource-link>

        <naming:url>resourcelocator-url</naming:url>
    </naming:cmp-connection-factory>

    <ejb-ql-compiler-factory>ejbQlCompilerFactory</ejb-ql-compiler-factory>

    <db-syntax-factory>dbSyntaxFactory</db-syntax-factory>

    <enforce-foreign-key-constraints/>

    <!-- End configuration for Container Managed Persistence (CMP) -->

</openejb-jar>

EJB Entity Beans

<relationships>

The <relationships> EJB Entity Beans settings can include JNDI names used by remote clients, CMP settings, and COBRA configurations and resolving references. Unless otherwise noted, all the EJB Entity Beans XML element uses the OpenEJB default namespace for a openejb-jar.xml file, which is documented described here:

<enterprise-beans>

Container-managed relationships are initially defined in the ejb-jar.xml deployment descriptor, but the mappings to specific database elements are defined in the openejb-jar.xml file using the <relationship> element.



Common Elements for EJB Entity, Session, and Message-driven Beans

Unless otherwise noted, all the Common, EJB Entity, EJB Session, and EJB Message-driven elements use the OpenEJB default namespace for a The <enterprise-beans> element used to specify references by <entity> EJB's. For example, a EJB Entity Bean would be specified similarly as below in an openejb-jar.xml file: , which is documented here:

<enterprise-beans>

The <enterprise-beans> element used to specify references by <entity>, <session>, or <message-driven> EJB's. For example, a EJB Entity Bean would be specified similarly as below in an openejb-jar.xml file:

Code Block
Code Block
xml
xml
borderStylesolid
title<enterprise-beans> <entity> Example
    <enterprise-beans>

        <entity>
            <ejb-name>ExchangeRate</ejb-name>
            <local-jndi-name>ExchangeRate</local-jndi-name>
            <resource-ref>
                <ref-name>jdbc/BankDataSource</ref-name>
                <resource-<resource-link>BankPool</resource-link>
            </resource-ref>
        </entity>

    </enterprise-beans>

<ejb-name>

The <ejb-name> element identifies the EJB that these settings apply to and must match the <ejb-name> for the EJB in ejbA EJB Session Bean would be specified similarly as below in an openejb-jar.xml file.

<jndi-name>

The Home interface for the EJB is registered in JNDI at the address specified here. This global JNDI name is used by application clients to connect to this EJB. It is only meaningful if the EJB has a (remote) Home interface.

<local-jndi-name>

The LocalHome interface for the EJB is registered in JNDI at the address specified here. It is only meaningful if the EJB has a LocalHome interface.

<tssGroup>

The <tssGroup> set of elements is used to contains CORBA security settings (i.e., for EJBs exposed as CORBA objects). It is not necessary if the EJB will not be accessed via CORBA.

JNDI Environment References

All the JNDI reference elements in this section use the Geronimo Naming namespace, which is used to identify the common elements for resolving EJB references, resource references, and Web services references, and is documented here:

Additionally, more information and details about JNDI references can be found here: JNDI.

<naming:abstract-naming-entry>

The <abstract-naming-entry> element is not technically a JNDI reference element. It is included in this section because it is an abstract element used for containing these JNDI reference types:

...

:

Code Block
xml
xml
borderStylesolid
title<session> Example

<enterprise-beans>

    <session>
        <ejb-name>RetrieveEmployeeInfoBean</ejb-name>
        <business-remote>examples.session.stateless_dd.RetrieveEmployeeInfo</business-remote>
        <ejb-class>examples.session.stateless_dd.RetrieveEmployeeInfoBean</ejb-class>
        <session-type>Stateless</session-type>
        <transaction-type>Container</transaction-type>

        <resource-ref>
            <res-ref-name>jdbc/DataSource</res-ref-name>
            <res-type>javax.sql.DataSource</res-type>
            <res-auth>Container</res-auth>
            <res-sharing-scope>Shareable</res-sharing-scope>
        </resource-ref>
    </session>

</enterprise-beans>

And an EJB Message-driven Bean would be specified similarly as below in an openejb-jar.xml file:

Code Block
xml
xml
borderStylesolid
title<message-driven> Example

<enterprise-beans>

    <message-driven>
        <ejb-name>OrderRecvMDB</ejb-name>
        <resource-adapter>
            <resource-link>CommonConnectionFactory</resource-link>
        </resource-adapter>
        <activation-config>
            <activation-config-property>
                <activation-config-property-name>destination</activation-config-property-name>
                <activation-config-property-value>OrderQueue</activation-config-property-value>
            </activation-config-property>
            <activation-config-property>
                <activation-config-property-name>destinationType</activation-config-property-name>
                <activation-config-property-value>javax.jms.Queue</activation-config-property-value>

...

<naming:ejb-ref>

The <naming:ejb-ref> element is used to map EJB references to EJB's in other applications using remote home and remote interface. The application which contains the EJB being referenced should either be in same EAR or should be included in dependency list of this application. Also note as the EJB's referenced are in a different JVM all the client interfaces should also be included in the current application.

<naming:ejb-local-ref>

The <naming:ejb-local-ref> element is used to map EJB references to EJB's in other applications using local home and local interface. The application which contains the EJB being referenced should either be in same EAR or should be included in dependency list of this application. Also note as the EJB's referenced are in a different JVM all the client interfaces should also be included in the current application.

<naming:service-ref>

The <naming:service-ref> is used to map service references to service's in other applications. The application which contains the EJB being referenced should either be in same EAR or should be included in dependency list of this application.

<naming:resource-ref>

The <naming:resource-ref> element is used to map resource references to resources like JDBC resources, JMS resources, etc. configured outside the current application.

<naming:resource-env-ref>

The <naming:resource-env-ref> element is used to map resource references to administrative objects deployed as a part of connectors.

<naming:message-destination>

The <naming:message-destination> element is used to map resource references to a message-destination which is used within the deployed web application. These are typically a JMS queue or topic which acts like a destination for the messages delivered. Like all the JNDI references in this section, this element will not cause the creation of a message-destination, references an existing message-destination used within the deployed EJB application.

EJB Session Entity Beans

<enterprise-beans>

The <enterprise-beans> element used to specify references by <entity> EJB's. For example, a EJB Entity Bean would be specified similarly as below in an openejb-jar.xml file:

Code Block
xmlxml
borderStylesolid
title<enterprise-beans> Example

    <enterprise-beans>

        <session>
            <ejb-name>RetrieveEmployeeInfoBean</ejb-name>
            <business-remote>examples.session.stateless_dd.RetrieveEmployeeInfo</business-remote></activation-config-property>
            <ejb-class>examples.session.stateless_dd.RetrieveEmployeeInfoBean</ejb-class></activation-config>
            <session-type>Stateless</session-type>
            <transaction-type>Container</transaction-type>

            <resource-ref>
                <res-ref-name>jdbc/DataSource</res-ref-name>
                <res-type>javax.sql.DataSource</res-type>
                <res-auth>Container</res-auth>
                <res-sharing-scope>Shareable</res-sharing-scope>
            </resource-ref>
        </session>

    </enterprise-beans>

<ejb-name>

The <ejb-name> element identifies the EJB that these settings apply to and must match the <ejb-name> for the EJB in ejb-jar.xml file.

<jndi-name>

The Home interface for the EJB is registered in JNDI at the address specified here. This global JNDI name is used by application clients to connect to this EJB. It is only meaningful if the EJB has a (remote) Home interface.

<local-jndi-name>

</message-driven>

</enterprise-beans>

<ejb-name>

The <ejb-name> element identifies the EJB that these settings apply to and must match the <ejb-name> for the EJB in ejb-jar.xml file.

<jndi-name>

The Home interface for the EJB is registered in JNDI at the address specified here. This global JNDI name is used by application clients to connect to this EJB. It is only meaningful if the EJB has a (remote) Home interface.

<local-jndi-name>

The LocalHome interface for the EJB is The LocalHome interface for the EJB is registered in JNDI at the address specified here. It is only meaningful if the EJB has a LocalHome interface.

<tssGroup>

The <tssGroup> set of elements is used to contains CORBA security settings (i.e., for EJBs exposed as CORBA objects). It is not necessary if the EJB will not be accessed via CORBA.

JNDI Environment References

All the JNDI reference elements in this section use the Geronimo Naming namespace, which is used to identify the common elements for resolving EJB references, resource references, and Web services references, and is documented here:

...

Additionally, more information and details about JNDI references can be found here: JNDI.

<naming:abstract-naming-entry>

The <abstract-naming-entry> element is not technically a JNDI reference element. It is included in this section because it is an abstract element used for containing these JNDI reference types:

  • <gbean-ref>

    The <gbean-ref> element is used to map GBean references to GBeans configured outside the current module

  • <persistenceunit-ref>

    The <persistenceunit-ref> element is used to map persistence unit references to persistence units configured outside the current module

  • <persistencecontext-ref>

    The <persistencecontext-ref> element is used to map persistence context references to persistence contexts configured outside the current module
<naming:ejb-ref>

The <naming:ejb-ref> element is used to map EJB references to EJB's in other applications using remote home and remote interface. The application which contains the EJB being referenced should either be in same EAR or should be included in dependency list of this application. Also note as the EJB's referenced are in a different JVM all the client interfaces should also be included in the current application.

<naming

...

The <naming:ejb-local-ref> element is used to map EJB references to EJB's in other applications using local home and local interface. The application which contains the EJB being referenced should either be in same EAR or should be included in dependency list of this application. Also note as the EJB's referenced are in a different JVM all the client interfaces should also be included in the current application.

<naming:service-ref>

The <naming:service-ref> is used to map service references to service's in other applications. The application which contains the EJB being referenced should either be in same EAR or should be included in dependency list of this application.

<naming:resource-ref>

The <naming:resource-ref> element is used to map resource references to resources like JDBC resources, JMS resources, etc. configured outside the current application.

<naming:resource-env-ref>

The <naming:resource-env-ref> element is used to map resource references to administrative objects deployed as a part of connectors.

<naming:message-destination>

The <naming:message-destination> element is used to map resource references to a message-destination which is used within the deployed web application. These are typically a JMS queue or topic which acts like a destination for the messages delivered. Like all the JNDI references in this section, this element will not cause the creation of a message-destination, references an existing message-destination used within the deployed EJB application.

EJB Message-driven Beans

Entity, Session, Message-driven EJB XML Elements:

...

<sec:security>

The <sec:security> XML element uses the Geronimo Security namespace, and is documented here:

The <sec:security> element groups the security role mapping settings for the EJB application. This is an optional element, but if it is present all the EJB modules must make the appropriate access checks as outlined in the JACC specification. This element includes the <role-mapping> section that references the role(s) defined in the <security-role> element in the application.xml file.

<sys:gbean>

The <sys:gbean> XML element uses the Geronimo System namespace described at http://geronimo.apache.org/schemas-2.1/docs/geronimo-module-1.2.xsd.htmlImage Removed.

The <sys:gbean> element is used to define GBean(s) that are configured and deployed with the EJB. These additional Geronimo services will be deployed when the application is deployed (and stopped when the application is stopped). Normally, the implementation classes for these services are included at the server level and referenced using a dependency element.

Samples

For example, the below XML content is the deployment descriptor (ejb-jar.xml) of a stateless session bean that connects to a back end DB2 database.

...


<?xml version="1.0" encoding="UTF-8" ?>
<ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" version="3.0"
         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">

    <description>Stateless Session Bean Example</description>
    <display-name>Stateless Session Bean Example</display-name>

    <enterprise-beans>
        <session>
            <ejb-name>RetrieveEmployeeInfoBean</ejb-name>
            <business-remote>examples.session.stateless_dd.RetrieveEmployeeInfo</business-remote>
            <ejb-class>examples.session.stateless_dd.RetrieveEmployeeInfoBean</ejb-class>
            <session-type>Stateless</session-type>
            <transaction-type>Container</transaction-type>

            <resource-ref>
                <res-ref-name>jdbc/DataSource</res-ref-name>
                <res-type>javax.sql.DataSource</res-type>
                <res-auth>Container</res-auth>
                <res-sharing-scope>Shareable</res-sharing-scope>
            </resource-ref>
        </session>
    </enterprise-beans>

    <interceptors>
        <interceptor>

            <interceptor-class>
                examples.session.stateless_dd.RetrieveEmployeeInfoCallbacks
            </interceptor-class>

            <post-construct>
                <lifecycle-callback-method>construct</lifecycle-callback-method>
            </post-construct>

            <post-activate>
                <lifecycle-callback-method>activate</lifecycle-callback-method>
            </post-activate>

            <pre-passivate>
                <lifecycle-callback-method>passivate</lifecycle-callback-method>
            </pre-passivate>
        </interceptor>
    </interceptors>

    <assembly-descriptor>
        <interceptor-binding>

            <ejb-name>RetrieveEmployeeInfoBean</ejb-name>

            <interceptor-class>
                examples.session.stateless_dd.RetrieveEmployeeInfoCallbacks
            </interceptor-class>

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

</ejb-jar>
:ejb-local-ref>

The <naming:ejb-local-ref> element is used to map EJB references to EJB's in other applications using local home and local interface. The application which contains the EJB being referenced should either be in same EAR or should be included in dependency list of this application. Also note as the EJB's referenced are in a different JVM all the client interfaces should also be included in the current application.

<naming:service-ref>

The <naming:service-ref> is used to map service references to service's in other applications. The application which contains the EJB being referenced should either be in same EAR or should be included in dependency list of this application.

<naming:resource-ref>

The <naming:resource-ref> element is used to map resource references to resources like JDBC resources, JMS resources, etc. configured outside the current application.

<naming:resource-env-ref>

The <naming:resource-env-ref> element is used to map resource references to administrative objects deployed as a part of connectors.

<naming:message-destination>

The <naming:message-destination> element is used to map resource references to a message-destination which is used within the deployed web application. These are typically a JMS queue or topic which acts like a destination for the messages delivered. Like all the JNDI references in this section, this element will not cause the creation of a message-destination, references an existing message-destination used within the deployed EJB application.

EJB Entity Beans

EJB Entity Beans settings can include JNDI names used by remote clients, CMP settings, and COBRA configurations and resolving references.

EJB Session Beans

An EJB session bean represents an interactive session between a single client and an application deployed on the server, and can also include JNDI names used by remote clients, CMP settings, and COBRA configurations and resolving references.

EJB Message-driven Beans

Message-driven bean settings include mapping the MDB to a specific message destination (usually a JMS Topic or Queue), as well as resolving references to other EJBs, resources, or Web services.

<naming:resource-adapter>

The <naming:resource-adapter> XML element uese the Geronimo Naming namespace, which is used to identify the common elements for resolving EJB references, resource references, and Web services references, and is documented here:

The <naming:resource-adapter> element identifies the resource adapter that this message-driven bean connects to. This is typically a JMS server, which is ActiveMQ for the default Geronimo JMS provider. It identifies the resource adapter instance that this MDB should use to connect to its destination. For example, a specific ActiveMQ broker may have several resource adapter instances set up, with different authentication settings, and this identifies the specific instance to use. Like the <naming:cmp-connection-factory>, there are multiple methods available to refer to the ActiveMQ broker. It can be specified by a simple name using the <resource-link> element, by pattern using the <pattern> element, or finally by URL using the <url> element. The resource-link handles most common resource situations (e.g., a JMS resource adapter deployed as part of the same EAR or in the top level of the server), but pattern or URL can be use for any. This might be important if, for example, two resource adapter deployments use the same name, so that the <resource-link> does not uniquely identify one and it must be fully-qualified. This can be used to identify any resource adapter in the same EAR or at the top level in the server. The value specified here should match the <resourceadapter-name> specified for the resource adapter instance in its Geronimo deployment plan.

<activation-config>

The <activation-config> XML element is used to specify any configuration data (in the form of name/value pairs) required by the resource adapter in order to supply messages to the MDB. For example:

Code Block
xml
xml
borderStylesolid
title<activation-config> Example

<activation-config>

    <activation-config-property>
        <activation-config-property-name>destination</activation-config-property-name>
        <activation-config-property-value>OrderQueue</activation-config-property-value>
    </activation-config-property>

    <activation-config-property>
        <activation-config-property-name>destinationType</activation-config-property-name>
        <activation-config-property-value>javax.jms.Queue</activation-config-property-value>
    </activation-config-property>

</activation-config>
Note

The default namespace of the above XML document is http://java.sun.com/xml/ns/javaee. The XML elements that do not have a namespace prefix belong to the default namespace.

In EJB3.0, most of the deployment descriptor declarations can be done through the corresponding annotations in the bean class. However, if a deployment descriptor is supplied (ejb-jar.xml), the declarations in the deployment descriptor will override the annotations.

The ejb module connects to back end datasource using its JNDI name jdbc/DataSource as declared in the ejb-jar.xml. It also declares that the ejb is a stateless session bean and provides an interceptor class for the bean. The interceptor class will have callback methods which container calls when the corresponding events occur in the bean's life cycle.

For the above deployment descriptor, we will have to provide a corresponding deployment plan file (openejb-jar.xml) that maps the declared datasource to actual datasource deployed in the server. The following is the deployment plan.

...


<openejb-jar xmlns="http://openejb.apache.org/xml/ns/openejb-jar-2.2"
         xmlns:naming="http://geronimo.apache.org/xml/ns/naming-1.2"
         xmlns:sec="http://geronimo.apache.org/xml/ns/security-2.0"
         xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.2">

    <sys:environment>
        <sys:moduleId>
            <sys:groupId>samples</sys:groupId>
            <sys:artifactId>EmployeeDemo-ejb-dd</sys:artifactId>
            <sys:version>3.0</sys:version>
            <sys:type>jar</sys:type>
        </sys:moduleId>

        <sys:dependencies>
            <sys:dependency>
                <sys:groupId>console.dbpool</sys:groupId>
                <sys:artifactId>jdbc/FEmployeeDatasource</sys:artifactId>
                <sys:version>1.0</sys:version>
                <sys:type>rar</sys:type>
           </sys:dependency>
        </sys:dependencies>
    </sys:environment>

    <enterprise-beans>
        <session>
            <ejb-name>RetrieveEmployeeInfoBean</ejb-name>
            <naming:resource-ref>
                <naming:ref-name>jdbc/DataSource</naming:ref-name>
                <naming:resource-link>jdbc/EmployeeDatasource</naming:resource-link>
            </naming:resource-ref>
        </session>
    </enterprise-beans>
</openejb-jar>
Note

The default namespace of the above XML document is http://openejb.apache.org/xml/ns/openejb-jar-2.2. The XML elements that do not have a namespace prefix belong to the default namespace.

Observe the various XML tags and corresponding namespaces used in the deployment plan for various purposes.

<sys:environment> .. </sys:environment> : These elements provide the moduleId configuration and the dependencies. The moduleId elements provide the configuration name for the ejb module. So, when the ejb module is deployed, it is given the configuration name samples/EmployeeDemo-ejb-dd/3.0/jar. The dependencies elements provide the configurations and third party libraries on which the ejb module is dependent on. These configurations and libraries will be available to the ejb module via a classloader hierarchy. In this case, the ejb module is dependent on console.dbpool/jdbc/FEmployeeDatasource/1.0/jar which is the configuration of the deployed Datasource that connects to a back end DB2 database. The Datasource deploys a database connection pool (javax.sql.Datasource) with name jdbc/EmployeeDatasource.

<enterprise-beans> .. </enterprise-beans> : These elements help us to configure the enterprise beans. In this case, the datasource reference jdbc/DataSource is mapped to jdbc/EmployeeDatasource.

In the ejb bean class, the following java code is used to obtain a connection from the datasource.

...


....
....
Context initContext = new InitialContext();
Context envContext  = (Context)initContext.lookup("java:comp/env");
DataSource ds = (DataSource)envContext.lookup("jdbc/DataSource");
Connection con = ds.getConnection();
....
....

...