Moving to Enterprise JavaBeans 183
WebSphere Application Server Libraries
Sun JSDK Class Libraries
Notice at this point that you have some errors in the tea.business.cb package
because you do not have any of the Component Broker libraries loaded. We
have been unable to find any successful method of having the EJB and
Component Broker libraries coexist in VisualAge for Java. This is sure to
change as they are derived from the same code base. However, in the
versions that we used, they were incompatible.
There are also errors in several other TEA packages because of some
missing WebSphere function. To get around that, we will just import the
missing packages and classes from WebSphere into the IBM EJB Runtime
Support project. Copy the following packages and classes from the
WebSphere implementation into the IBM EJB Runtime Support project:
com.ibm.jbroker package
com.ibm.jbroker.ejb package
com.ibm.CosNaming.TransientNameService class
If you are unsure of how to copy the packages and classes, consult the
VisualAge for Java help, or import Version 1.3 of the IBM EJB Runtime
Support from the repository supplied with the sg245276.zip file.
17.2 Changing the Existing Application
This time, to introduce the use of EJBs, we are going to change the
application by replacing the EmployeeID Component Broker object developed
in Chapter 16, “WebSphere and Component Broker Interoperability” on page
173 with an equivalent EJB. This EJB provides the exact same functionality. It
just covers our purpose of showing how to integrate EJBs in our application.
Among the different possible EJBs, we choose to implement a bean-managed
persistence bean.
17.3 Creating an EJB
Follow these steps to create an EJB:
1. Write a remote interface.
2. Write a home interface.
3. Write a bean.
4. Write a bean key.
184 Using VisualAge for Java Enterprise Version 2 to Develop CORBA and EJB Applications
5. Write a deployment descriptor.
6. Write a manifest file.
7. Package all these files in a jar file.
Fortunately, we can use VisualAge for Java and reduce our effort to develop
the bean class only. All other tasks are handled by the tool, which generates
all additional classes and even provides the final jar file ready for deployment.
And that is not all. Because WebSphere is packaged with VisualAge for Java,
we also have the runtime environment to deploy and test our EJB.
So, let us start from the VisualAge for Java Workbench and select the EJB
tab.
VisualAge for Java gathers EJBs into
groups
. To create a group, select the
EJBs->Add->EJB Group... menu item and fill in the fields as shown in
Figure 80.
Moving to Enterprise JavaBeans 185
Figure 80. Creating a New EJB Group
Select TEAGroup before adding an EJB.
An EJB consists of a number of Java classes and interfaces, such as the
bean class, remote interface, home interface, and a set of deployed classes.
You must manage all these classes as a single entity, so that they can exist in
synchronization. For example, if you need to delete a method from the bean
class, you want to ensure that the corresponding method in the remote
interface is deleted automatically. To manage all Java classes and interfaces
that belong to a bean as a single object, VisualAge for Java allows you to
create EJBs as first-class objects. In the Create Enterprise JavaBean
SmartGuide, you can define a name for the EJB and then define the
individual classes and interfaces that belong to that EJB. You can then
186 Using VisualAge for Java Enterprise Version 2 to Develop CORBA and EJB Applications
version the EJB as a single entity. For example, when you version an EJB, it
will version all of the corresponding Java classes and interfaces and save
their signatures into the EJB object. When a specific version of the EJB is
loaded, the correct version of all the EJB bean classes and remote and home
interfaces are loaded.
Follow these steps to add EJBs:
1. In the EJBs pane, select an EJB group to contain your EJB and click
mouse button 2.
2. From the pop-up menu, select Add - Enterprise JavaBean. The Create
Enterprise JavaBean SmartGuide appears (see Figure 81).
3. Click Finish, and VisualAge for Java will create four classes for you:
EmployeeID interface
EmployeeIDBean class
EmployeeIDHome class
EmployeeIDKey class
Figure 81. Creating an Enterprise Java Bean

Get Using VisualAge for Java Enterprise Version 2 to Develop CORBA and EJB Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.