Managing the EJB home

Why and when to perform this task

To access an enterprise bean, a CORBA C++ client needs to locate the EJB home. The client obtains the root naming context from the naming service and uses it to locate the EJB home. Obtaining the naming context can be done explicitly by the client or implicitly by the Object Request Broker's (ORB's) string_to_object method.

Steps for this task

  1. Identify the EJB home JNDI name for the enterprise bean's full path.

    In WebSphere, the JNDI name for a bean is mapped to the home class for that bean. The JNDI name is specified in the ibm-ejb-jar-bnd.xmi file generated for the deployed bean's JAR file. If you run the command WAS_HOME/bin/dumpNameSpace, you can see the mapping of the JNDI name to the corresponding Java class. For an enterprise bean, the JNDI name (top)/ejbhome is mapped to the home class. The enterprise bean is located in (top), which is the WebSphere Application Server equivalent to the server's root.

    If the EJB home is located on a known server, such as server1, the three components of (top) are "cell", "server", and "server1". In this case, (top) can be specified as cell/servers/server1.

    For example, if the EJB home for the valuetype sample class com.ibm.websphere.vtlib.sample.Person is on server1, the full EJB home JNDI name is cell/servers/server1/com/ibm/websphere/vtlib/sample/Person.

    What happens when you perform this step.
  2. Map the JNDI name to an object using one of two methods
    Map the EJB home JNDI name using a URL and string_to_object
    For the URL method of mapping the name, form a URL representing the EJB home JNDI name and pass it on a call to the ORB's string_to_object method. The URL should be a corbaname that contains the string-modified name of the EJB home. For the valuetype sample, the person bean might be located as follows when the person home is deployed on server1:
    char * home_url = "corbaname::localhost/NameService#cell/servers/server1/com/ibm/websphere/vtlib/sample/Person";
    ::CORBA::Object_var homeObj = NULL;
    homeObj = orb->string_to_object( home_url );
    if (CORBA::is_nil(homeObj))
         { // handle error }
    
    Map the EJB home JNDI name by invoking resolve on the naming context
    For the resolve method of mapping the name, create a CosNaming::Name object and initialize it to identify the person home. Obtain the naming context and call its resolve method. The following code creates a CosNaming Name for the bean's full path:
    // Obtain the naming context.  (where op is a valid ORB pointer)
    //
    CORBA::Object * objPtr = op->resolve_initial_references( "NameService" );
    rootNameContext = ::CosNaming::NamingContext::_narrow(objPtr);
    if (CORBA::is_nil( rootNameContext ))
      { // handle error }
    
    // Create a CosNaming Name for the bean's full path
    //
    ::CosNaming::Name *ejbName = new ::CosNaming::Name; 
    ejbName->length( 9 ); 
    (*ejbName)[0].id = ::CORBA::string_dup( "cell" ); 
    (*ejbName)[0].kind = ::CORBA::string_dup( "" ); 
    (*ejbName)[1].id = ::CORBA::string_dup( "servers" ); 
    (*ejbName)[1].kind = ::CORBA::string_dup( "" ); 
    (*ejbName)[2].id = ::CORBA::string_dup( "server1" ); 
    (*ejbName)[2].kind = ::CORBA::string_dup( "" ); 
    (*ejbName)[3].id = ::CORBA::string_dup( "com" ); 
    (*ejbName)[3].kind = ::CORBA::string_dup( "" ); 
    (*ejbName)[4].id = ::CORBA::string_dup( "ibm" ); 
    (*ejbName)[4].kind = ::CORBA::string_dup( "" ); 
    (*ejbName)[5].id = ::CORBA::string_dup( "websphere" ); 
    (*ejbName)[5].kind = ::CORBA::string_dup( "" ); 
    (*ejbName)[6].id = ::CORBA::string_dup( "vtlib" ); 
    (*ejbName)[6].kind = ::CORBA::string_dup( "" ); 
    (*ejbName)[7].id = ::CORBA::string_dup( "sample" ); 
    (*ejbName)[7].kind = ::CORBA::string_dup( "" ); 
    (*ejbName)[8].id = ::CORBA::string_dup( "Person" ); 
    (*ejbName)[8].kind = ::CORBA::string_dup( "" ); 
    
    // Invoke resolve
    //
    ::CORBA::Object_var homeObj = NULL;
    homeObj = rootNameContext->resolve( ejbName );
    if (CORBA::is_nil( homeObj ))
      { // handle error }
    
  3. Narrow to a specific EJB Home
    Finally, narrow the object returned from either resolve or string_to_object. Use the PersonHome's _narrow method:
    ::com::ibm::websphere::vtlib::sample::PersonHome_ptr personHome = NULL;
    personHome = ::com::ibm::websphere::vtlib::sample::PersonHome::_narrow(homeObj);
    if (CORBA::is_nil(personHome))
       { // handle error }
    

Example

What to do next

The object pointer to the EJB home can be used to create an enterprise bean object. For example:

ejbPtr = ejbHomePtr->create();

When the EJB object is created successfully, any of its methods can be called. For example:

msg = ejbPtr->message();


Related tasks
Developing a CORBA C++ client



Searchable topic ID:   tcor_ipgmc5
Last updated: Jun 21, 2007 8:07:48 PM CDT    WebSphere Business Integration Server Foundation, Version 5.0.2
http://publib.boulder.ibm.com/infocenter/wasinfo/index.jsp?topic=/com.ibm.wasee.doc/info/ee/corba/tasks/tcor_ipgmc5.html

Library | Support | Terms of Use | Feedback