Show TOC

Procedure documentationDeveloping the EJB 3.0 Module Locate this document in the navigation 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. 1.Choose  File   New   Project..   from the main menu.

  2. 2. Choose   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 Configuration field. The default configurations include EJB 3.0 and Java 6.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 Note

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

    End of the note.

    This graphic is explained in the accompanying text.

  6. Choose Finish to create your EJB 3.0 project.

Creating the Stateless Session Bean
  1. In the context menu of the ejbModule node of the ConverterEJB project, choose  File   Other  

    This graphic is explained in the accompanying text.

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

  3. Enter ConverterBean in the Class Name field and com.sap.tutorial.javaee in the Java Package field.

  4. Select Stateless in the State 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:

    Syntax Syntax

    1. 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);
        }
      
    End of the code.
  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 in 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.