Home

 

Adding and deriving attributes

In JET transformations, variable information is stored into attributes. The exemplar authoring tool identifies two different types of attributes:

Attribute: Input attribute that has to be provided by the input model

Derived attribute: Attribute derived from an input attribute, usually used to satisfy a naming convention (such as artifacts, Java variables)

Let us now add the necessary attributes and derived attributes:

Right-click the client type, and select New Æ Attribute. Call this new attribute name.

Repeat the previous operation to add the package attribute.

Select the Create Project: RAD75PatternsClient action and view its properties in the Properties view. The name action parameter is used by the transformation to name the test client project when it is first created. As we said before, this name must be variable and related to the name attribute we just created. This is what we do in the next steps.

Figure 9-6 Create Project Properties

Select the entire text of the action parameters name, right-click, and select Replace with Model Reference.

In the Replace with Model References dialog, select the client type and click New, because we want to add the Client string to the name attribute.

In the Create New Derived Attribute dialog, enter projectName as Attribute Name. Point the cursor to the start of the Calculation field and click Insert Model Reference.

Figure 9-7 Insert Model Reference

In the Select Model Reference dialog, select the name attribute of the client type and click OK.

Note that a query expression for the name attribute as been inserted as {$client/@name}RAD75PatternsClient. Change the expression to {$client/@name}Client to define the calculation correctly.
Click OK to get back to Replace with Model References dialog.

Figure 9-8 Final definition of the projectName derived attribute

Note: The syntax used for the calculation is related to the fact that access to the variable content is done by navigating an XML Document Object Model (DOM) using XPath.

In the Replace with Model References dialog, select the projectName attribute and click OK.

Figure 9-9 Final project name variable

Using the same approach to replace the path parameter of the .classpath and .project elements. Select RAD75PatternsClient and replace the text with a model reference to the projectName attribute:

{$client/$projectName}/.classpath

{$client/$projectName}/.project

Figure 9-10 Adding a reference to the .project path variable

Select the Create File: BankClient.java action, and in the Properties view replace RAD75PatternsClient in the value of the path action parameter with a model reference to the projectName attribute:

{$client/$projectName}/src/itso/rad75/bank/client/BankClient.java

We defined package as a variable, therefore we want to replace itso/rad75/bank/client by a new derived attribute. Right-click client and select New Æ Derived Attribute. Name the derived attribute clientDirectory.

Figure 9-11 Attribute deriving the directory path from the package attribute

Note: Consider the expression on the Calculation box:

{translate($client/@package,'.','/')}

This translates the package attribute (in the form itso.rad75.bank.client) into a directory path (in the form itso/rad75/bank/client).

The translate function is a standard XPath function. To learn more about the standard XPath function, go to http://www.w3.org/TR/xpath. To learn more about the Rational Application Developer additional XPath functions, look into the help at Developing Æ Developing XML applications Æ Creating XPath expressions.

Select the Create File: BankClient.java action and in the Properties view replace the package directory with a reference to the clientDirectory attribute:
old: {$client/@projectName}/src/itso/rad75/bank/client/BankClient.java
new: {$client/$projectName}/src/{$client/$clientDirectory}/BankClient.java

Figure 9-12 Final version of the BankClient.java path parameter

Save the transformation. The completed model is shown in Figure | -13.

Figure 9-13 Final model for the JET transformation

ibm.com/redbooks