Design patterns describe a standard solution to a recurring software development problem, and provide solutions that you can apply in many situations. If you reuse designs by using design patterns, you can increase the quality and reliability of the solution.
A pattern specification describes the problem that a pattern solves, the context in which the proposed solution is appropriate, and provides an abstract description of the solution. The process of applying this abstraction to a particular problem is called pattern application. A tool that assists with pattern application is called a pattern implementation. A pattern implementation enables you to describe a pattern application in terms of the abstractions in the pattern specification. You can use the pattern implementation to generate the artifacts such as the files, folders, and projects that make up your solution. Depending on the design pattern, you might specify additional logic in the generated artifacts.
JET and the JET transformation authoring functionality support pattern implementations where the input is described in a structured model and the generated pattern solution consists of text files. These pattern implementations are also called model-to-text transformations.
JET model-to-text transformations accept Extensible Markup Language (XML) documents and Eclipse Modeling Framework (EMF) models as input, and produce Eclipse files, folders, and projects as output. The input and output types that the JET transformation produces are extensible by using the JET Software Development Kit (SDK).
To create JET transformations, you must install the Transformation authoring component.
To create a model-to-text transformation by using the JET transformation authoring functionality, you complete the following high-level steps:
The transformation input schema and JET actions are collectively called the transformation model and are displayed in the editor area. Most JET transformations are created by repeating steps 2, 3, and 4 as necessary.
A transformation input schema describes the structure of the input for the transformation. The input schema is displayed as a hierarchy of element types and attributes.
Although JET can read models that have very complex input schemas, to facilitate the authoring process, the functionality for authoring JET transformations is restricted to defining basic schemas.
You cannot specify cardinalities with JET transformation authoring functionality. All element containment is zero-to-many. For example, an input schema can specify that books contain chapters, but the input schema cannot specify the number of chapters that books contain.
For example, you can create a UML-to-JET transformation input mapping that invokes the JET transformation. This mapping enables you to develop a JET transformation with a basic input schema, but enables transformation users to describe the input by using Unified Modeling Language (UML).
Note: You cannot specify the UML metamodel as the source model in a mapping.
When the design pattern abstractions are captured in the input schema, you must determine how the artifacts in the reference solution, also called the exemplar, derive from this schema. Transformation actions, also called JET actions, create projects, folders, and files. When the JET transformation runs, a JET action is invoked each time that an element of that type is encountered in the transformation input.
Each JET action has action parameters that control how the action behaves. These parameters are set to values that re-create the exemplar artifact that creates the JET action. Typically, you customize these parameter values to include the values that are extracted from the transformation input.
JET file actions create file contents by evaluating a JET template. When you update the project, these templates are created if they do not exist. The initial content of the templates is the same as the content in the exemplar file that you specified when you created the corresponding file action. You can modify the generated template to generate the content that is customized for the transformation input.
When you account for exemplar artifacts in the transformation model, you can delete an artifact from the editor area if the transformation does not generate a specific type of artifact. The physical file, folder, or project that you delete is not affected. You can also ignore an artifact, which enables the artifact to remain in the editor area, and enables you to undo the ignore action and associate the artifact with the transformation input schema.
The JET actions and templates that are created when you author a transformation are copies of the exemplar artifacts. Typically, you modify the action parameters and template contents to specify the values in the transformation input.
You can replace selected text with references to the transformation input when you edit the parameter values of the JET actions.
Transformation input references are in the form of XML Path (XPath) expressions. XPath, which is a standard of the World Wide Web Consortium, is designed for XML documents; however, JET adapts this standard to support multiple input model types.
XPath expressions that are embedded in action parameter values are enclosed in braces ({ }), and when you replace variables with model references, these expressions are displayed in a {$variable/@attribute} format, where variable is the name of an input model element, and attribute is the name of an attribute in the element. Each input model element has an associated XPath variable name. By default, the authoring environment keeps the variable name synchronized with the element name.
Although the authoring functionality creates basic XPath expressions, JET provides a comprehensive implementation of the XPath 1.0 specification, and includes a suite of XPath functions that can manipulate values from the transformation input. For example, the XPath expression {lower-case($person/@name)} converts the input reference $person/@name to lowercase.
You can use XPath functions anywhere that an XPath expression is allowed.
Check the Problems view for detailed information about the JET markers.
You can create derived attributes to eliminate repetitive calculations. A derived attribute is an attribute of an input schema element that is generated by a calculation instead of provided as transformation input. The calculation can reference other elements and attributes in the input schema. You can create derived attributes directly when you edit a transformation mapping model, or whenever you insert transformation model references.
During the traversal of the transformation input, the derived attribute calculations and calculations for JET action parameters that are associated with an input schema element can reference the XPath variables that refer to the current element, and each of the variables that belong to ancestor elements.
To assist you to identify text in the templates that should be replaced by references to the transformation input, the text replacements that you specify are monitored. Each time that you replace a text string with a specific reference to the transformation input, this text is stored as exemplar text in the transformation input model, which you can view, add, or remove. This text is also used to create JET Replace markers, which highlight text that is similar to the text in the JET templates that the transformation generates. You can resolve JET Replace markers by using the Eclipse Quick Fix mechanism. This functionality enables you to replace the text with the appropriate JET tag, or to ignore the marker because no change to the text is necessary.
You can create a UML interface and project infrastructure that transforms a UML model into a JET input model that you can use as input for a JET transformation. You can use this functionality to graphically represent non-graphical models that serve as the input to JET transformations. For example, you might create this infrastructure to create a UML interface for a non-graphical model, such as a JET-based Java bean pattern.
The model-to-model mapping transformation transforms a UML model into a JET input model.
The UML profile in this project defines the stereotypes and extensions for the UML model that serves as input to the model-to-model transformation. The generated UML profile project is compatible with the UML profile tooling functionality.
This project contains the Java application programming interface (API) for the generated JET input model.
This feature project references the model-to-text JET transformation that transforms the generated JET input model, and the EMF project that contains the Java API for the generated JET input model. You can export this project by using the Eclipse Deployable Feature export functionality.