For each mapping declaration in the mapping model, the transformation authoring framework generates a Java source file with the name nTransform.java, where n represents the name of the mapping declaration. Collectively, these Java files compose the transformation code. In addition to generating the implementation code for the transformation, the transformation authoring framework also generates code to register the transformation with the transformation service. After you create a mapping declaration, you can incrementally add mapping rules and generate the source code, or implementations, for the mapping rules. You do not have to define all mapping rules before generating the source code.
Mapping declarations typically follow a naming convention of x2y, where x represents the input object type and y represents the output object type. For example, a mapping declaration named Package2EPackage specifies a mapping declaration that has Package as an input object, and EPackage as an output object.
A map between elements establishes the correspondence between their attributes, which permits the exchange of data between them. Most maps provide the ability to further manipulate the data between the source and target. For example, you might choose to specify calculations or make other modifications to the data by creating custom code, which enables you to assign values to the target.
To create a class-to-class mapping declaration in the mapping model:
To add an input object and an output object to the class-to-class mapping declaration:


After you add the input and output objects to the mapping declaration, you can define the mapping rules between the attributes. Mapping rules, also called mappings, specify how to assign a value to an attribute of an output object, according to the values of the attributes of an input object.
You create a mapping rule between the name attribute of the input and output objects. The target class has the same name as the class in the input model; you could also think of this as creating a copy of the class. In a later lesson, you add the mapping operations to the mapping rule.
You create a submap mapping rule between the ownedOperation attribute of the input and output objects. For each operation in the ownedOperation collection, the generated operation in the target model has the same name and visibility as the operation in the input model.
A submap is an invocation of one map from within another map. The submap being invoked can, but need not, be defined in the same mapping file as the map that invokes it. A submap enables you to map a complex type in the input model to a complex type in the output model. The submap that you create can invoke a map that exists in any mapping file. Defining submaps in separate mapping files encourages the reuse of maps; however, creating multiple mapping files might increase project maintenance. Submaps can also include other submaps, which results in a hierarchical structure.
You can also create submap mapping rules between the input objects and output objects in a mapping declaration.
For each submap in a mapping declaration, an extractor named getInputFeatureToOutputFeature_UsingMap_Extractor is generated in the containing transform, where InputFeature represents the name of the input attribute, OutputFeature represents the name of the output attribute, and Map represents the name of the mapping declaration.
You can specify semantic refinements by using the Object Constraint Language (OCL) API that Eclipse provides.
An inherited mapping rule, and the rule or extractor generated from that mapping, maintains the same relative position in the processing order as the overridden mapping rule and its generated rule or extractor.
For each move or custom mapping rule in a mapping declaration, a rule is added to the generated transformation source code. For each submap mapping rule, a content extractor is generated in the transformation source code. When you create a mapping rule, its type is determined by the input and output attributes that you select. For example, if the input and output attributes are compatible primitive types, such as strings or integers, a move mapping rule is specified. If the input and output attributes are complex types, a submap rule is specified. If neither move nor submap are appropriate mapping rule types, a custom mapping rule is specified.
To define the mapping rules in the Class2Class mapping declaration:
At this point in the lesson, in the editor area, the submap has an adornment with a red circled X, which indicates an error. Put the mouse pointer over this adornment to view the error message. The error message states that you must select a mapping declaration for the submap mapping rule to invoke. To resolve this error, create an operation-to-operation mapping declaration.
To create an operation-to-operation mapping declaration: