Show TOC Start of Content Area

Procedure documentation Developing the Project  Locate the document in its SAP Library structure

Use

In this step, you create the required Java development objects for the development activity – that is, you create the package, the interface, and the classes required by this tutorial.

Prerequisites

You work in the Java perspective in the Package Explorer view.

Procedure

Add a Package to Your DC

...

       1.      Open the project node of your component and select the src/packages folder.

       2.      From the context menu, choose New Package.

       3.      Enter org.example.tax as the name of the new Java package and choose Finish.

Add an Interface to Your DC

...

       1.      Select the package org.example.tax and choose New Interface from the context menu.

       2.      Enter ITaxCalculator as the name and choose Finish.

The dialog window Add files to DTR appears.

       3.      When asked to add the new file to the Design Time Repository, confirm this by choosing OK.

       4.      Select your activity New Java Component and again choose OK.

Note

For certain development steps, you can specify an activity as the default activity. All your changes are automatically added to this activity. To do this, in the Open Activities view, choose Use as Default from the context menu of an activity. To deactivate this option, in the same view in the context menu of the workspace, choose Always Explicitly Select Activity. If, for example, you want to create a new DC, you should choose this option or select a new default activity because activities are – among others – used to group related file versions.

The Java editor appears for ITaxCalculator automatically.

       5.      Insert the following code:

package org.example.tax;

 

public interface ITaxCalculator {

   double calculateTax(double income);

}

       6.      Save your entries.

Add Classes to Your DC

You are in the Jave perspective in the Package Explorer view.

Add Class TaxCalculator

...

       1.      Select the package org.example.tax and choose New Class from the context menu.

       2.      Enter TaxCalculator as the name and choose Finish.

A dialog box is displayed.

       3.      When asked to add the new file to the DTR repository, confirm this by choosing OK.

       4.      Select activity New Java Component, if necessary, and again choose OK.

Note

If you specified this activity as the default activity, the query does not appear.

The Java editor appears for TaxCalculator automatically.

       5.      Insert the following code:

package org.example.tax;

 

public class TaxCalculator implements ITaxCalculator {

 

   private double rate = 0.5;

 

   public double calculateTax(double income) {

      return income * rate;

   }

}

       6.      Save your entries.

Add Class TaxFactory

...

       1.      Select the package org.example.tax and choose New Class from the context menu.

       2.      Enter TaxFactory as the name and choose Finish.

A dialog box is displayed.

       3.      When asked to add the new file to the DTR repository, confirm this by choosing OK.

       4.      Select activity New Java Component, if necessary, and again choose OK.

The Java editor appears for TaxFactory automatically.

       5.      Insert the following code:

package org.example.tax;

 

public class TaxFactory {

   

   public static  ITaxCalculator createInstance(){

      return new TaxCalculator();

   }

}

       6.      Save your entries.

Result

You have now created and added the required Java package, interface, and classes for this tutorial. They are now part of the development activity.

Next Step

Building the Development Component Locally

End of Content Area