Creating JET transformations to import UML model information from spreadsheets
Before you begin
You must have the Structured Data Importer features installed.
You must convert the spreadsheet to import into a comma-separated value (.csv) file.
Procedure
- Create a JET transformation project: Click File > New > Other > JET Transformation Project; then complete the steps in the wizard.
- In the new project, double-click the plugin.xml file.
- On the Extensions page, in the All Extensions section, expand org.eclipse.jet.transform, and click transform.
- In the Extension Element Details section, complete the
following steps:
- In the startTemplate field, specify the project-relative path to the JET template that is the entry point for the transformation. Typically, this template is located in the templates folder of the JET transformation project; for example, templates/main.jet. Depending on the complexity of your project, this template might also be the template that contains the code to parse the spreadsheet information.
- In the modelLoader field, specify com.ibm.xtools.jet.loaders.csv.
- Add the corresponding plug-in dependencies.
- On the Dependencies page, in the Required Plug-ins section, click Add.
- In the Plug-in Selection window, in the Select a Plug-in field, specify com.ibm.xtools.jet.loaders.
- From the Matching items list, select the matching plug-in, and click OK.
- Optional: Add the JET tag
library to import as an extension of the JET transformation.
- On the Extensions page, in the All Extensions section, click (transform), and expand (tagLibraries).
- Right-click (tagLibraries), and click New > importLibrary.
- Optional: On the Extensions
page, in the Extension Element Details section, set the properties
of the tag library to import.
- In the id field, specify the name of the tag library to import. The JET templates in the transformation project use this identifier to determine which tag library to load, as in this example. Specify an identifier that follows Java™ naming conventions, as in this example: my.jet.tag.library.
- In the usePrefix field, specify
a prefix that uniquely identifies the tags in this library. Specify
a prefix that contains only alphanumeric characters.
By specifying a prefix, in subsequent references to the tag library, you can use the prefix name instead of the name of the tag library. For example, if you specify a prefix of uml, in the JET template you can specify <uml:element name> instead of <my.jet.tag.library:element name>.
- In the autoImport field, specify true.
By specifying true, when the compiled JET template is invoked by the transformation, this entire tag library is loaded. You do not have to use the taglib directive to load the JET library from the JET template.
If you specify false, in the JET template, the taglib directive must precede the first invocation of a JET tag, as in the following example:When the transformation invokes this JET template, and when the JET template interprets the taglib directive that specifies this tag library, the entire contents of the tag library are loaded.... <%@taglib prefix="uml" id="my.taglib.jet.uml.umlTags" %> <uml:package name="{$curRow/cell[2]}" description="{$curRow/cell[3]}" owner="$ownerVar" /> ...
- Click File > Save.
- In the JET template that you specify in step 4.a, add code to read
the custom CSV format and generate the correct domain element by using
the corresponding JET tag. Consider the following excerpt
from a .csv file, where the first row corresponds to the column headings
in a spreadsheet, and the next rows create a package called testPackage1
and an actor called testActor in testPackage1.
ElementType,ElementName,Description,RelatedTo,RelatedType,Owner,Properties Package,testPackage1,Test the creation of a Package.,,,, Actor,testActor,Test the creation of an Actor.,,,testPackage1,
The JET template that parses the preceding excerpt and creates the corresponding UML elements might look like the following code fragment:<%@taglib prefix="uml" id="com.ibm.xtools.taglib.jet.uml.umlTags" %> <c:setVariable select="/csv/row[1]" var="header"/> <c:setVariable select="0" var="i"/> <c:iterate select="/csv/row" var="curRow"> <c:setVariable select="$i + 1" var="i"/> <%-- Skip header --%> <c:if test="$i!=1"> <%-- resolve the owner column Note: TargetObject variable refers to the object that is selected as the target model.--%> <c:if test="$curRow/cell[6]!=''"> <uml:find name="{$curRow/cell[6]}" owner="$TargetObject" findRecursive="true" var="ownerVar"/> </c:if> <%-- create package --%> <c:if test="$curRow/cell[1]='Package'"> <c:if test="isVariableDefined('ownerVar')=false"> <c:setVariable select="$TargetObject" var="ownerVar"/> </c:if> <uml:package name="{$curRow/cell[2]}" description="{$curRow/cell[3]}" owner="$ownerVar" /> </c:if> <%-- create actor --%> <c:if test="$curRow/cell[1]='Actor'"> <c:if test="isVariableDefined('ownerVar')=false"> <c:setVariable select="$TargetObject" var="ownerVar"/> </c:if> <uml:actor name="{$curRow/cell[2]}" description="{$curRow/cell[3]}" owner="$ownerVar" /> </c:if> </c:iterate>
To view a sample JET template, see the related sample at the end of this topic. In the sample project, in the main.jet file, see the first rows of code that import a row from the file, and observe how the code in the template parses the information to create the corresponding model element. The spreadsheet data in the file to import are parameters that correspond to the cell numbers in the JET template.
- Save the changes to the JET template or templates that you updated. If you enabled the Project > Build Automatically option, the project builds automatically. Otherwise, you must build the project manually.
What to do next
Feedback