Defining an EJB component

There are three ways to define EJB components in EAServer:

StepsImporting EJB class files

  1. If necessary, create class files for the home, remote, and (optionally) local interfaces, following the EJB standards for these interfaces.

  2. Specify the package to install the component in as follows:

    1. Double-click the Packages folder to expand it.

    2. Highlight the package to which the component will be added.

  3. Choose File | New Component from the menu.

  4. In the Component Wizard, select Import from EJB Class File, and click Next.

  5. Verify that the displayed importer CLASSPATH contains the JAR files and directories required to instantiate the bean’s classes, specifically:

    • Verify that the code base under which the class files are deployed is included.

    • If the classes are in a JAR file, verify that the full path to the JAR file is included.

    • If the class definitions require other JAR files or directories not listed, list them as well.

    If necessary, use the Add, Modify, Delete, Move Up, and Move Down buttons in the Component Wizard to modify the CLASSPATH. The displayed CLASSPATH affects only this importer session, not the EAServer process.

  6. Enter the component name and EJB class and interface names as follows:

  7. EAServer Manager displays the Component Properties dialog box. The Component’s type and Java classes have been filled in by the importer. Specify values for the remaining properties before generating skeletons and running the bean.

  8. Generate stubs and skeletons for the component as follows:

    1. Highlight the component icon.

    2. Choose File | Generate Stub/Skeleton.

    3. Follow the wizard pages to generate skeletons.

    4. Click Generate.

StepsCreating a new EJB component from scratch

Follow this procedure to create a new EJB component and define the home and remote interface.

  1. Select the EAServer Manager package that will contain the component.

  2. Select File | New Component.

  3. In the Component Wizard dialog box, select the Define New Component check box and click Next.

  4. Enter a name for the component and click Finish.

  5. The Component Properties dialog box displays. Make the following changes on the General tab:

    1. Set the Type to correspond to one of the following values:

      Component type

      To indicate

      EJB - Entity Bean

      An entity bean

      EJB - Stateful Session Bean

      A stateful session bean

      EJB - Stateless Session Bean

      A stateless session bean

      EJB - Message Driven Bean

      A message-driven bean

    2. In the EJB Version field, select 2.0. (You can select 1.1. or 1.0, but EJB 2.0 is recommended for new development.)

    3. In the Bean Class field, enter the name of the Java class that will implement your bean, for example, foo.bar.MyBeanImpl.

      NoteThe Home Interface Class, Remote Interface Class, and Primary Key Class fields cannot be edited. These fields are set automatically after the bean’s IDL interfaces and datatypes have been defined. You can change them by changing the component’s IDL interfaces and types in subsequent steps.

    4. Enter a value for the JNDI name field. This field specifies the name by which client applications look up the home interface. The full name consists of the server’s initial naming context followed by a slash (/) and the bean’s JNDI name.

  6. If you are creating an entity bean, specify the primary key as follows:

    1. Define the primary key type as one of the “Defining the primary key type”.

    2. Display the Component Properties dialog box for the component, click on the Persistence tab, and type the name of the IDL primary key type into the Primary Key field. If using mean managed persistence, the Persistence must be set to Component Class (the default). If using container managed persistence (CMP), configure the additional settings described in “Configuring automatic or EJB CMP persistence”.

  7. Click OK to close the Component Properties dialog box.

  8. If methods in your Java remote interface throw exceptions other than java.rmi.RemoteException, define equivalent IDL exceptions now. See Chapter 5, “Defining Component Interfaces,” for more information.

  9. Define home and remote interfaces. EAServer Manager has created default home and remote interfaces named package::componentHome and package::component, respectively, where package is the EAServer Manager package name, and component is the component name.

    1. To change the home or remote interface, follow the steps in “Changing the EJB remote or home interface”.

    2. Edit the home interface methods, following the design patterns described in “Defining home interface methods”.

    3. Edit the remote interface methods. See “Defining remote interface methods”. If portability to other EJB servers is required, use only in parameters in remote interface methods.

    An EJB 2.0 component may have local interfaces, but no remote interfaces. To remove the remote interfaces generated by EAServer Manager, highlight the Interfaces folder under the component icon, then choose File | Remove Remote Interfaces.

  10. Define local interfaces. EAServer Manager has created default local home and local interfaces named package::componentLocalHome and package::componentLocal, respectively, where package is the EAServer Manager package name, and component is the component name.

    1. If you wish to keep the local interfaces, define methods for them as described in “Defining local interfaces”.

    2. If you do not need local interfaces, highlight the Interfaces folder under the component icon, then choose File | Remove Local Interfaces.

  11. Generate stubs and skeletons for the component as follows:

    1. Highlight the component icon.

    2. Choose File | Generate Stub/Skeleton.

    3. Follow the wizard pages to generate skeletons.

    4. Click Generate.

  12. EAServer Manager generates a template for the bean implementation class suffixed with .new, for example MyBeanImpl.java.new. Use this template as the basis for your Java implementation. EAServer Manager also generates Java equivalents for the home and remote interfaces, and for an entity bean, the primary key type.

    If you are creating a stateful session bean with synchronization methods, add implements SessionSynchronization to the class declaration in the implementation template, and add code to implement the methods in the javax.ejb.SessionSynchronization interface.

  13. Compile the component source files, and make sure they are correctly deployed. See “Deploying the component classes”.

  14. If you are testing the component with a Java applet, generate and compile stubs using the html/classes subdirectory as the Java code base.