A binding file contains location information necessary to resolve external references for an application or module. For example, binding information is needed to map an external resource from its logical name (in the deployment descriptor) to its actual JNDI name, or map security roles to users and groups. EJB bindings are stored in the META-INF\ibm-ejb-jar-bnd.xmi file contained in the JAR file for the module.
Binding files are automatically generated by the Application Assembly Tool. However, it can be useful to understand their structure and content in the event that you want to or need to manually edit them.
The BeenThere enterprise bean in the sample application named sampleapp contains the following simple binding:
<ejbbnd:EJBJarBinding xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:ejbbnd="ejbbnd.xmi" xmlns:commonbnd="commonbnd.xmi" xmlns:ejb="ejb.xmi" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmi:id="ejb-jar_ID_Bnd"> <ejbJar href="META-INF/ejb-jar.xml#ejb-jar_ID"/> <ejbBindings xmi:id="Session_1_Bnd" jndiName="jndi/BeenThere"> <enterpriseBean xsi:type="ejb:Session" href="META-INF/ejb-jar.xml#Session_1"/> </ejbBindings> . . . </ejbbnd:EJBJarBinding>
In the example, the bean named BeenThere (as linked to in the EJB 1.1 deployment descriptor META-INF/ejb-jar.xml#Session_1) is to be bound under the global JNDI name jndi/BeenThere via the JNDI name entry.
CMP beans have more complicated bindings because they also have a binding to a data source. The following example is from the Increment bean in the same application:
<ejbbnd:EJBJarBinding xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:ejbbnd="ejbbnd.xmi" xmlns:commonbnd="commonbnd.xmi" xmlns:ejb="ejb.xmi" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmi:id="EJBJarBinding_1"> <ejbJar href="META-INF/ejb-jar.xml#Increment_jar"/> <ejbBindings xmi:id="EnterpriseBeanBinding_1" jndiName="IncBean"> <datasource xmi:id="ResourceRefBinding_1" jndiName="jdbc/SampleDataSource"> <defaultAuth xsi:type="commonbnd:BasicAuthData" xmi:id="BasicAuthData_1" userId="" password="{XOR}"/> </datasource> <enterpriseBean xsi:type="ejb:ContainerManagedEntity" href="META-INF/ejb-jar.xml#ContainerManagedEntity_1"/> </ejbBindings> <defaultDatasource xmi:id="ResourceRefBinding_2" jndiName="jdbc/SampleDataSource"> <defaultAuth xsi:type="commonbnd:BasicAuthData" xmi:id="BasicAuthData_2"> <userId xsi:null="true"/> <password xsi:null="true"/> </defaultAuth> </defaultDatasource> </ejbbnd:EJBJarBinding>
Notice that the above configuration declares both the global JNDI name of the bean (IncBean) as well as the JNDI name of the data source of the CMP bean. It declares the latter by using the ResourceRefBinding entry (jdbc/SampleDataSource). The latter JNDI name maps to a configured resource in the application server:
<applicationserver:Domain.resourceProviders> <resources:JDBCDriver xmi.id="JDBCDriver_1"name="Db2JdbcDriver" ... > <resources:J2EEResourceProvider.factories> <resources:DataSource xmi.id="DataSource_3" name="MyDS" jndiName="jdbc/SampleDataSource"... /> </resources:J2EEResourceProvider.factories> </resources:JDBCDriver>