[Enterprise Extensions only]

C++ CORBA client, locating the EJB home

If a C++ CORBA client is to access an Enterprise JavaBean, it needs to locate the EJB home. After locating the root naming context, the client can use the Naming Service to locate the EJB home. In WebSphere Application Server 3.5, Enterprise JavaBeans were bound into the root naming context that was shared by all hosts using the same administrative database. In WebSphere Application Server 4.0, each host has its own root context. To maintain the semantic compatability between WebSphere Application Server 3.5 and 4.0, all the Enterprise JavaBeans in 4.0 are bound into the domain's legacy root. This is equivalent to the root naming context to which all Enterprise JavaBeans were bound in WebSphere Application Server 3.5.

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_root/bin/dumpNameSpace, you can see the mapping of the JNDI name to the corresponding Java class. For an Enterprise JavaBean, the JNDI name (top)/ejbhome is mapped to the home class. The Enterprise JavaBean is located in (top), the WebSphere Application Server 4.0 equivalent to the domain's legacy root. The three components of (top) are "domain", "legacyRoot", and ejbcontext. The following code creates a COSNaming Name for the bean's full path:

 ::CosNaming::Name *ejbName = new ::CosNaming::Name; 
ejbName->length( 4 ); 
(*ejbName)[0].id = ::CORBA::string_dup( "domain" ); 
(*ejbName)[0].kind = ""; 
(*ejbName)[1].id = ::CORBA::string_dup( "legacyRoot" ); 
(*ejbName)[1].kind = ::CORBA::string_dup( "" ); 
(*ejbName)[2].id = ::CORBA::string_dup( "ejbcontext" ); 
(*ejbName)[2].kind = ::CORBA::string_dup( "" ); 
(*ejbName)[3].id = ::CORBA::string_dup( "ejbhome" ); 
(*ejbName)[3].kind = ::CORBA::string_dup( "" ); 

The steps to locate an EJB home are:

  1. Creating a COSNaming Name for the Enterprise JavaBean's full path:
  2. Calling resolve (with Name) on the root naming context
  3. Narrowing the object returned by resolve() to the appropriate type, an object pointer to the EJB home.

For an example of locating an EJB home, see the samples article "Tutorial: Creating a user-defined C++ client that uses an EJB" at WAS_HOME/Enterprise/samples/sampcppsdk/ejbsamp/hellosamp/wsBuildEJBClient.htm (if you have installed the samples option).

The object pointer to the EJB home can be used to create a Enterprise JavaBean object, as described in Using an Enterprise JavaBean.