Entering content frame

Procedure documentation Scenario 2: Step 1 – Create and Locally Build a Java DC Locate the document in its SAP Library structure

In this step, developer 1 creates a simple Structure linkdevelopment component (DC) of Structure linktype Java and exposes some classes in a Structure linkpublic part (which you could call a DC interface).

...

Prerequisites

You have started the SAP NetWeaver Developer Studio.

Work in the Context of a Development Configuration

       1.      Open the Development Configurationperspective.

       2.      To log on to the DTR, choose This graphic is explained in the accompanying text in the toolbar or log on in the context menu of the Active DCs view. Enter USER1 and the corresponding password.

       3.      In the Development Configuration perspective, switch to the Active DCs view.

       4.      Open the CONFIG1 folder.

Note

Besides the software components (SCs) example.org_technology and example.org_application, which you are meant to develop, you see these three entries:

·         sap.com_SAP_BUILDT

·         sap.com_SAP_JTECHS

·         sap.com_SAP-JEE

You can use them but not change them.

Create a New Development Component (DC) and an Activity

You are in the Development Configuration perspective.

...

       1.      Select the entry example.org_technology. In the context menu, choose Create new DC.

A wizard Development Component Project appears.

       2.      In the wizard, enter the following:

                            a.      Vendor: example.org

                            b.      Name: technology/tax/calculator

                            c.      Caption: Tax Calculator

                            d.      Type: Java.

       3.      Choose Next.

A dialog window DTR Activity appears.

       4.      To create a new activity, choose New Activity.

Note

This activity is used to record the creation of the component in the DTR.

       5.      Enter New Java Component as display name of the new activity and choose OK.

The dialog window DTR Activity appears. Your new activity is selected.

       6.      Choose Next.

The dialog window New Java Project appears.

       7.      Accept the proposed settings by choosing Finish.

The wizard now creates the DC. The Java perspective is opened automatically and you see a new project for your component in the Package Explorer view.

Add a Package to Your DC

You are in the Java perspective.

...

       1.      Choose the view Package Explorer.

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

       3.      From the context menu, choose New ® Package.

       4.      Enter org.example.tax as 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 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 for ITaxCalculator appears 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 name and choose Finish.

A dialog window appears.

       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 for TaxCalculator appears 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 name and choose Finish.

A dialog window appears.

       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 for TaxFactory appears automatically.

       5.      Insert the following code:

package org.example.tax;

public class TaxFactory {
    

    
public static  ITaxCalculator createInstance(){
        
return new TaxCalculator();
    }
}

 

       6.      Save your entries.

Build Your DC Locally

You are in the Java perspective.

...

       1.      Switch to the Java DC Explorer view.

       2.      In the context menu of your  DC, choose Development Component ® Build...

The dialog window Build Development Components appears.

       3.      Select your project node and confirm with OK.

Note

The component is compiled, but no archives are created since the component up to now has no public parts.

Add Public Parts to Your DC

Public Part api

Add a public part to the component to publish ITaxCalculator and TaxFactory. You are in the Java perspective.

...

       1.      Go to the Java DC Explorer view.

       2.      To add a public part, open the node DC MetaData.

       3.      Select the node Public Parts.

       4.      From the context menu, choose New Public Part...

The dialog window Add Public Part appears.

       5.      In the dialog, enter api as name of the new public part.

       6.      Select the radio button Provides an API for developing/compiling other DCs.

Note

This creates a public part other components can compile against. For more information on the purposes of public parts, see Structure linkPurposes of Public Parts.

       7.      Enter API of the Tax Calculator as caption.

       8.      To confirm your changes, choose Finish.

A dialog window appears.

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

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

Add Public Part Entities to Public Part api

...

       1.      Open the Public Parts node in the Java DC Explorerview.

You see a new entry named api.

       2.      Select api ® Entities and choose Edit Entities… from the context menu.

A dialog window Input Help: Entities appears.

       3.      Select Java Class in the Select Entity Type tree and mark the checkboxes of the following entries in the hierarchical display:

                            a.      ITaxCalculator  

                            b.      TaxFactory.

       4.      In the section Add Entity to Public Part, select the entry as Classand confirm with Finish.

This adds ITaxCalculator and TaxFactory to the public part.

Build Your DC Locally

You are in the Java perspective in the Java DC Explorer view.

...

       1.      In the context menu of your  DC, choose Development Component ® Build...

The dialog window Build Development Components appears.

       2.      Select your project node (if necessary) and confirm with OK.

An archive for the selected DC is created.

Note

Check this: In the Package Explorer view, follow the path: gen ® default ® public ® api ® lib ® java: The archive is named example.org~technology~tax~calculator~api.jar.

Public Part tax

You are in the Java perspective in the Java DC Explorer view.

...

       1.      To add a public part, open the node DC MetaData and select Public Parts.

From the context menu, choose New Public Part.A dialog window appears.

       2.      In the New Public Part dialog, enter tax as the name of the new public part.

       3.      Select the radio button Can be packaged into other build results (e.g.SDAs).

Note

This public part is used to assemble a runtime archive containing the full set of classes. Furthermore, this public part later will be used to wrap this library with a deployable J2EE library.

To display and change the Structure linkpurpose of the public part, use the Properties view.

       4.      Enter Tax Calculator Library as caption.

       5.      To confirm your changes, choose Finish.

A dialog window appears.

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

       7.      If you do not use a default activity, select the New Java Component activity and again choose OK.

Note

Open the Public Parts node in the Java DC Explorerview. You now see two public parts, api and tax.

Add Public Part Entities to Public Part tax

...

       1.      Select the Entities node of tax and in the context menu, choose Edit Entities.

A wizard appears.

       2.      In the Select Entity Type list, select the entry Java Package Tree.

       3.      In the Select Entities tree, select the entry org.

       4.      In the section Add Entity to Public Part, select the entry as Class.

       5.      To confirm your entries, choose Finish.

Note

This will add the Package Tree to the public part. You can now see the entries under the Entities node.

Build Your DC Locally

You are in the Java perspective.

...

       1.      Choose the Java DC Explorer view.

       2.      In the context menu, choose Development Component ® Build...

The dialog window Build Development Components appears.

       3.      Select your project node (if necessary) and confirm with OK.

Now the component build creates two archives:

¡        example.org~technology~tax~calculator~api.jar contains the classes against which other components can compile.

¡        example.org~technology~tax~calculator~tax.jar contains all classes, but is not usable for component builds. Therefore, the class TaxCalculator is private to the component.

Note

You can find them in the Java perspective in the Package Explorer view under the path: Project node ® gen ® default ® public ®

·         api ® lib ® java ® api.jar

·         tax ®lib ® java ® tax.jar

Checking In the Activity

...

       1.      Switch to the Development Configuration perspective.

       2.      In the Open Activities view, select your activity New Java Component.

Note

You can add the Open Activities view to other perspectives in order to avoid switching the perspective.

       3.      Choose Checkin from the context menu.

A dialog window appears.

       4.      Enter a description of your changes if you like and choose OK.

All changes are stored on the DTR server.

 

 

 

 

Leaving content frame