Show TOC Start of Content Area

Procedure documentation Developing the EJB 3.0 Module  Locate the document in its SAP Library structure

Prerequisites

The Windows  Open Perspective   Other   Java EE perspective is opened.  

Procedure

Creating the EJB Module Project

You develop the EJB 3.0 classes in an EJB 3.0 project in the Java EE perspective.

...

       1.      Choose File  New   Project… from the main menu.

       2.      Choosing EJB  EJB Project on the New Project screen. Choose Next.

This graphic is explained in the accompanying text

       3.      Enter ConverterEJB in the Project Name field.

       4.      Leave the Default Configuration for SAP Libraries in the Configurations field. The default configurations include EJB 3.0 and Java 5.0 project facets.

       5.      To assign the EJB project to an Enterprise Application project, choose Add project to an EAR and enter ConverterEAR in EAR Project Name field.

Note

The ConverterEAR project is created automatically when you complete the wizard.

This graphic is explained in the accompanying text

       6.      Choose Finish to create your EJB 3.0 project.

Creating the Stateless Session Bean

...

       1.      From the context menu of the ejbModule node of the ConverterEJB project choose New  Other.

This graphic is explained in the accompanying text

       2.      Choose EJB EJB 3.0 EJB Session Bean 3.0 on the New screen. Choose Next.

       3.      Enter ConverterBean in the EJB Class Name field and com.sap.tutorial.javaee in the Default EJBPackage field.

       4.      Select Stateless in the Session Type field.

       5.      Select Container in the Transaction Type field.

       6.      Deselect the Remote checkbox for Create Business Interface.

This graphic is explained in the accompanying text

       7.      Choose Finish.

       8.      Implement the business logic of ConverterBean by entering the following code in its body:

private BigDecimal dollarRate = new BigDecimal("1.2");

private BigDecimal euroRate = new BigDecimal("0.83");

 

public BigDecimal dollarToEuro(BigDecimal dollars) {

  BigDecimal result = dollars.multiply(euroRate);

  return result.setScale(2, BigDecimal.ROUND_UP);

  }

         

public BigDecimal euroToDollar(BigDecimal euros) {

  BigDecimal result = euros.multiply(dollarRate);

  return result.setScale(2, BigDecimal.ROUND_UP);

  }

       9.      To import the additional classes that you refer in your code, choose Source  Organize Imports from the main menu.

   10.      To add the dollarToEuro business method to the bean’s local interface, locate the Outline view and from the context menu of the method choose EJB Methods  Add to Local Interfaces.

Repeat the same step to add the euroToDollar method to the local interface as well.

This graphic is explained in the accompanying text

   11.      Choose File Save from the main menu to save the bean.

 

End of Content Area