Skip Headers
Oracle® Containers for J2EE Enterprise JavaBeans Developer's Guide
10g Release 3 (10.1.3)
B14428-01
  Go To Documentation Library
Home
Go To Product List
Solution Area
Go To Table Of Contents
Contents
Go To Index
Index

Previous
Previous
Next
Next
 

Looking Up an EJB 2.1 EJB

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.

Using Initial Context

This section describes:

For more information, see "Configuring the Initial Context Factory".

Looking Up the Remote Interface of an EJB 2.1 EJB Using ejb-ref

To look up the remote interface of an EJB using an ejb-ref:

  1. 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").

  2. Determine whether or not a prefix is required (see "Selecting an EJB Reference").

  3. 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".

Looking Up the Remote Interface of an EJB 2.1 EJB Using location

To look up the remote interface of an EJB using its location:

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

  2. Determine whether or not a prefix is required (see "Selecting an EJB Reference").

  3. 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".

Looking up the Local Interface of an EJB 2.1 EJB Using local-ref

To look up the remote interface of an EJB using an ejb-local-ref:

  1. 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").

  2. Determine whether or not a prefix is required (see "Selecting an EJB Reference").

  3. 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".

Looking up the Local Interface of an EJB 2.1 EJB Using local-location

To look up the local interface of an EJB using its local-location:

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

  2. Determine whether or not a prefix is required (see "Selecting an EJB Reference").

  3. 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".