Tutorial 2: Step 1 – Create, Locally Build, Check In a Java DC

In this step, developer 1 creates a simple development component (DC) of type Java and exposes some classes in a public part (which you could call a DC interface).

...

Prerequisites

·        You have started the SAP NetWeaver Developer Studio.

·        You have imported a development configuration.

Create a New Development Component (DC) and create an Activity

...

You are in the perspective Development Configuration in the Inactive DCs view.

       1.      Open the node of your SC Appl_dev.

       2.      Select the entry example.org_application and in the context menu, choose Create New DC.

A wizard Development Component Project appears.

       3.      In the wizard enter the following:

                            a.      Vendor: example.org (if required)

                            b.      Name:

                            c.      (prefix from selection list): appl

                            d.      (text input): tax/calc

                            e.      Caption: Tax Calculator

                              f.      Domain: Financial Services, if available

                            g.      Type: Java.

       4.      Choose Next.

A dialog window DTR Activity appears.

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

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

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

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

       7.      Choose Next.

The dialog window New Java Project appears.

       8.      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.

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 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.

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 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.

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.

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, publishing ITaxCalculator and TaxFactory. You are in the Java perspective.

...

       1.      Go to the Java DC Explorer view.

       2.      To add a public part, open your DC node.

       3.      Open the DC MetaData node.

       4.      Select the node Public Parts.

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

The dialog window Add Public Part appears.

       6.      In the New Public Part dialog enter api as name of the new public part.

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

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

       8.      Enter API of the Tax Calculator as caption.

       9.      To confirm your changes, choose Finish.

A dialog box is displayed.

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

   11.      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 Java DC Explorer view.

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 Class and 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.

Check this: In the Package Explorer view, follow the path: gen ® default ® public ® api ® lib ® java: The archive is named example.org~appl~tax~calc~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.

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

A dialog box appears.

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

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

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 purpose of the public part, use the Properties view.

       5.      Enter Tax Calculator Library as caption.

       6.      To confirm your changes, choose Finish.

A dialog box is displayed.

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

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

Open the Public Parts node in Java DC Explorer view. 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.

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~appl~tax~calc~api.jar contains the classes against which other components can be compiled.

Ў        example.org~appl~tax~calc~tax.jar contains all classes, but cannot be used for component builds. Therefore the class TaxCalculator is private to the component.

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

Check in the Activity

...

...

       1.      Switch to the Development Configuration perspective.

This perspective by default contains the Open Activities view. You see the node of your development configuration.

       2.      Open the node and the node of the workspace underneath.

You see your open activities.

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

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

       4.      Choose Checkin from the context menu.

A dialog box appears.

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

A dialog window Activation appears, which allows an immediate build in the CBS.

       6.      To build your DC at a later time, choose Cancel.

All changes are stored on the DTR server.