|
Oracle® Containers for J2EE Enterprise JavaBeans Developer's Guide
10g Release 3 (10.1.3) B14428-01 |
|
![]() Previous |
![]() Next |
Using EJB 2.1, you can look up an EJB using the InitialContext (see "Using Initial Context").
To look up an EJB 3.0 EJB using the InitalContext, use the same approach.
This section describes:
Looking Up the Remote Interface of an EJB 2.1 EJB Using ejb-ref
Looking Up the Remote Interface of an EJB 2.1 EJB Using location
Looking up the Local Interface of an EJB 2.1 EJB Using local-ref
Looking up the Local Interface of an EJB 2.1 EJB Using local-location
For more information, see "Configuring the Initial Context Factory".
To look up the remote interface of an EJB using an ejb-ref:
Define an ejb-ref for the EJB in the ejb-jar.xml file.
Example 19-35 ejb-jar.xml For an ejb-ref
<ejb-ref> <ejb-ref-name>ejb/Test</ejb-ref-name> <ejb-ref-type>Session</ejb-ref-type> <local>Test</local> </ejb-ref>
For more information, see "Configuring an Environment Reference to a Remote EJB").
Determine whether or not a prefix is required (see "Selecting an EJB Reference").
Look up the EJB using the ejb-ref-name and the appropriate prefix (if required).
Example 19-36 Looking Up Using ejb-ref
InitialContext ic = new InitialContext();
Object homeObject = context.lookup("java:comp/env/ejb/Test");
CartHome home = (CartHome)PortableRemoteObject.narrow(homeObject,CartHome.class);
For more information, see "Configuring the Initial Context Factory".
To look up the remote interface of an EJB using its location:
Define the entity-deployment attribute location in the orion-ejb-jar.xml file.
Example 19-37 orion-ejb-jar.xml For location
<entity-deployment name=EmployeeBean" location="app/EmployeeBean" ... > ... </entity-deployment>
The default value for location is the value of entity-deployment attribute name.
Determine whether or not a prefix is required (see "Selecting an EJB Reference").
Look up the EJB using the location.
Example 19-38 Looking Up Using location
InitialContext ic = new InitialContext();
Object homeObject = context.lookup("java:comp/env/app/EmployeeBean");
CartHome home = (CartHome)PortableRemoteObject.narrow(homeObject,CartHome.class);
For more information, see "Configuring the Initial Context Factory".
To look up the remote interface of an EJB using an ejb-local-ref:
Define an ejb-local-ref for the EJB in the ejb-jar.xml file.
Example 19-39 ejb-jar.xml For an ejb-local-ref
<ejb-local-ref> <ejb-ref-name>ejb/Test</ejb-ref-name> <ejb-ref-type>Session</ejb-ref-type> <local>Test</local> </ejb-local-ref>
For more information, see "Configuring an Environment Reference to a Local EJB").
Determine whether or not a prefix is required (see "Selecting an EJB Reference").
Look up the EJB using the ejb-ref-name and the appropriate prefix (if required).
Example 19-40 Looking Up
InitialContext ic = new InitialContext();
Object homeObject = context.lookup("java:comp/env/ejb/Test");
CartHome home = (CartHome)PortableRemoteObject.narrow(homeObject,CartHome.class);
For more information, see "Configuring the Initial Context Factory".
To look up the local interface of an EJB using its local-location:
Define the entity-deployment attribute local-location in the orion-ejb-jar.xml file.
Example 19-41 orion-ejb-jar.xml For local-location
<entity-deployment name=EmployeeBean" local-location="app/EmployeeBean" ... > ... </entity-deployment>
The default value for location is the value of entity-deployment attribute name.
Determine whether or not a prefix is required (see "Selecting an EJB Reference").
Look up the EJB using the local-location.
Example 19-42 Looking Up Using local-location
InitialContext ic = new InitialContext();
Object homeObject = context.lookup("java:comp/env/app/EmployeeBean");
CartHome home = (CartHome)PortableRemoteObject.narrow(homeObject,CartHome.class);
For more information, see "Configuring the Initial Context Factory".