This section describes the programming and deployment descriptor interfaces that allow the application component provider to refer to the homes of enterprise beans using "logical" names called EJB references. The EJB references are special entries in the application component's naming environment. The deployer binds the EJB references to the enterprise bean's homes in the target operational environment. The deployment descriptor also allows the application assembler to link an EJB reference declared in one application component to an enterprise bean contained in an EJB JAR file in the same J2EE application. The link is an instruction to the tools used by the deployer describing the binding of the EJB reference to the home of the specified target enterprise bean. J2EE.5.3.1 Application Component Provider's ResponsibilitiesThis subsection describes the application component provider's view and responsibilities with respect to EJB references. It does so in two sections, the first describing the API for accessing EJB references, and the second describing the syntax for declaring the EJB references. J2EE.5.3.1.1 Programming Interfaces for EJB ReferencesThe application component provider must use EJB references to locate the home interfaces of enterprise bean as follows .
The following example illustrates how an application component uses an EJB reference to locate the home interface of an enterprise bean. public void changePhoneNumber(...) { ... // Obtain the default initial JNDI context. Context initCtx = new InitialContext(); // Look up the home interface of the EmployeeRecord // enterprise bean in the environment. Object result = initCtx.lookup( "java:comp/env/ejb/EmplRecord"); // Convert the result to the proper type. EmployeeRecordHome emplRecordHome = (EmployeeRecordHome) javax.rmi.PortableRemoteObject.narrow(result, EmployeeRecordHome.class); ... } In the example, the application component provider assigned the environment entry ejb/EmplRecord as the EJB reference name to refer to the home of an enterprise bean. J2EE.5.3.1.2 Declaration of EJB ReferencesAlthough the EJB reference is an entry in the application component's environment, the application component provider must not use a env-entry element to declare it. Instead, the application component provider must declare all the EJB references using the ejb-ref elements of the deployment descriptor. This allows the consumer of the application component's JAR file (i.e., the application assembler or deployer) to discover all the EJB references used by the application component. Each ejb-ref element describes the interface requirements that the referencing application component has for the referenced enterprise bean. The ejb-ref element contains an optional description element and the mandatory ejb-ref-name, ejb-ref-type , home, and remote elements. The ejb-ref-name element specifies the EJB reference name; its value is the environment entry name used in the application component code. The ejb-ref-type element specifies the expected type of the enterprise bean; its value must be either Entity or Session . The home and remote elements specify the expected Java types of the referenced enterprise bean's home and remote interfaces. The following example illustrates the declaration of EJB references in the deployment descriptor. ... <ejb-ref> <description> This is a reference to the entity bean that encapsulates access to employee records. </description> <ejb-ref-name>ejb/EmplRecord</ejb-ref-name> <ejb-ref-type>Entity</ejb-ref-type> <home>com.wombat.empl.EmployeeRecordHome</home> <remote>com.wombat.empl.EmployeeRecord</remote> </ejb-ref> <ejb-ref> <ejb-ref-name>ejb/Payroll</ejb-ref-name> <ejb-ref-type>Entity</ejb-ref-type> <home>com.aardvark.payroll.PayrollHome</home> <remote>com.aardvark.payroll.Payroll</remote> </ejb-ref> <ejb-ref> <ejb-ref-name>ejb/PensionPlan</ejb-ref-name> <ejb-ref-type>Session</ejb-ref-type> <home>com.wombat.empl.PensionPlanHome</home> <remote>com.wombat.empl.PensionPlan</remote> </ejb-ref> ... J2EE.5.3.2 Application Assembler's ResponsibilitiesThe application assembler can use the ejb-link element in the deployment descriptor to link an EJB reference to a target enterprise bean. The link will be observed by the deployment tools. The application assembler specifies the link to an enterprise bean as follows:
The following example illustrates the use of the ejb-link element in the deployment descriptor. The enterprise bean reference should be satisfied by the bean named EmployeeRecord . The EmployeeRecord enterprise bean may be packaged in the same module as the component making this reference, or it may be packaged in another module within the same J2EE application as the component making this reference. ... <ejb-ref> <description> This is a reference to the entity bean that encapsulates access to employee records. It has been linked to the entity bean named EmployeeRecord in this application. </description> <ejb-ref-name>ejb/EmplRecord</ejb-ref-name> <ejb-ref-type>Entity</ejb-ref-type> <home>com.wombat.empl.EmployeeRecordHome</home> <remote>com.wombat.empl.EmployeeRecord</remote> <ejb-link>EmployeeRecord</ejb-link> </ejb-ref> ... J2EE.5.3.3 Deployer's ResponsibilitiesThe deployer is responsible for the following:
J2EE.5.3.4 J2EE Product Provider's ResponsibilitiesThe J2EE product provider must provide the deployment tools that allow the deployer to perform the tasks described in the previous subsection. The deployment tools provided by the J2EE product provider must be able to process the information supplied in the ejb-ref elements in the deployment descriptor. At the minimum, the tools must be able to:
|