There are three ways to define EJB components in EAServer:
Importing an EJB-JAR file An EJB-JAR file contains the implementation classes, interface classes, and deployment descriptor for one or more beans archived in a standard format. Chapter 9, “Importing and Exporting Application Components,” in the EAServer System Administration Guide describes how to import EJB-JAR files.
Importing class files EAServer Manager can import the method information for the home, remote, and local interfaces from Java class files. Use this method if:
You have created a bean’s interfaces and implementation class, but have not created the deployment descriptor that is required to create an EJB-JAR file. You will need to manually configure properties that would otherwise be read from the deployment descriptor.
You have created nothing, but prefer editing Java in your code editor to editing IDL in EAServer Manager.
Defining the component from scratch You can define the component and it’s interfaces in EAServer Manager, using the IDL editing facilities in EAServer Manager to define the home, remote, and (optional) remote interfaces.
Importing EJB class files
If necessary, create class files for the home, remote, and (optionally) local interfaces, following the EJB standards for these interfaces.
Specify the package to install the component in as follows:
Double-click the Packages folder to expand it.
Highlight the package to which the component will be added.
Choose File | New Component from the menu.
In the Component Wizard, select Import from EJB Class File, and click Next.
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.
Enter the component name and EJB class and interface names as follows:
Component name The name of the component to be created in EAServer Manager, for example, FinanceBean.
Component type Choose one of the following to match your implementation:
Type |
Description |
---|---|
JaguarEJB::StatelessSessionBean |
A stateless session bean |
JaguarEJB::StatefulSessionBean |
A stateful session bean |
JaguarEJB::EntityBean |
An entity bean with bean-managed persistence. |
Bean class name The full path to the Java class file that contains the bean’s implementation class.
Primary key class If defining an entity bean, enter the full path to the Java class file that contains the bean’s remote interface. If defining a session bean, leave blank.
Specify remote interface If the Bean has remote interfaces, select this option and configure the following:
Home interface class – The full path to the Java class file that contains the Bean’s home interface.
Remote interface class – The full path to the Java class file that contains the Bean’s remote interface.
Specify local interface If the Bean has local interfaces, select this option and configure the following:
Local home interface class – The full path to the Java class file that contains the Bean’s local home interface.
Local interface class – The full path to the Java class file that contains the Bean’s local interface.
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.
Generate stubs and skeletons for the component as follows:
Highlight the component icon.
Choose File | Generate Stub/Skeleton.
Follow the wizard pages to generate skeletons.
Click Generate.
Creating a new EJB component from scratch
Follow this procedure to create a new EJB component and define the home and remote interface.
Select the EAServer Manager package that will contain the component.
Select File | New Component.
In the Component Wizard dialog box, select the Define New Component check box and click Next.
Enter a name for the component and click Finish.
The Component Properties dialog box displays. Make the following changes on the General tab:
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 |
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.)
In the Bean Class field, enter the name of the Java class that will implement your bean, for example, foo.bar.MyBeanImpl.
The 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.
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.
If you are creating an entity bean, specify the primary key as follows:
Define the primary key type as one of the “Defining the primary key type”.
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”.
Click OK to close the Component Properties dialog box.
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.
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.
To change the home or remote interface, follow the steps in “Changing the EJB remote or home interface”.
Edit the home interface methods, following the design patterns described in “Defining home interface methods”.
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.
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.
If you wish to keep the local interfaces, define methods for them as described in “Defining local interfaces”.
If you do not need local interfaces, highlight the Interfaces folder under the component icon, then choose File | Remove Local Interfaces.
Generate stubs and skeletons for the component as follows:
Highlight the component icon.
Choose File | Generate Stub/Skeleton.
Follow the wizard pages to generate skeletons.
Click Generate.
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.
Compile the component source files, and make sure they are correctly deployed. See “Deploying the component classes”.
If you are testing the component with a Java applet, generate and compile stubs using the html/classes subdirectory as the Java code base.
Copyright © 2005. Sybase Inc. All rights reserved. |