Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Enterprise JavaBeans™ Specification, v1.1 - Sun Microsystems.pdf
Скачиваний:
11
Добавлен:
24.05.2014
Размер:
1.62 Mб
Скачать

Sun Microsystems Inc.

Enterprise bean environment

Enterprise JavaBeans v1.1, Final Release

EJB references

14.3.1 Bean Provider’s responsibilities

This subsection describes the Bean Provider’s view and responsibilities with respect to EJB references.

14.3.1.1 EJB reference programming interfaces

The Bean Provider must use EJB references to locate the home interfaces of other enterprise beans as follows.

Assign an entry in the enterprise bean’s environment to the reference. (See subsection 14.3.1.2 for information on how EJB references are declared in the deployment descriptor.)

The EJB specification recommends, but does not require, that all references to other enterprise beans be organized in the ejb subcontext of the bean’s environment (i.e. in the java:comp/env/ejb JNDI context).

Look up the home interface of the referenced enterprise bean in the enterprise bean’s environment using JNDI.

The following example illustrates how an enterprise bean uses an EJB reference to locate the home interface of another enterprise bean.

public class EmployeeServiceBean implements SessionBean {

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 Bean Provider of the EmployeeServiceBean enterprise bean assigned the environment entry ejb/EmplRecord as the EJB reference name to refer to the home of another enterprise bean.

14.3.1.2 Declaration of EJB references in deployment descriptor

Although the EJB reference is an entry in the enterprise bean’s environment, the Bean Provider must not use a env-entry element to declare it. Instead, the Bean Provider must declare all the EJB references using the ejb-ref elements of the deployment descriptor. This allows the ejb-jar consumer (i.e. Application Assembler or Deployer) to discover all the EJB references used by the enterprise bean.

11/24/99

208

Sun Microsystem Inc

EJB references

Enterprise JavaBeans v1.1, Final Release

Enterprise bean environment

Each ejb-ref element describes the interface requirements that the referencing enterprise bean 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 enterprise bean 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.

An EJB reference is scoped to the session or entity bean whose declaration contains the ejb-ref element. This means that the EJB reference is not accessible to other enterprise beans at runtime, and that other enterprise beans may define ejb-ref elements with the same ejb-ref-name without causing a name conflict.

The following example illustrates the declaration of EJB references in the deployment descriptor.

...

<enterprise-beans> <session>

...

<ejb-name>EmployeeService</ejb-name> <ejb-class>

com.wombat.empl.EmployeeServiceBean </ejb-class>

...

<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>

...

</session>

...

</enterprise-beans>

...

209

11/24/99