The attributes in input and output
objects can be collections of other objects. When you specify a submap
mapping rule in a mapping declaration, you can create input and output
filters that are applied to the elements in the collection of the
attribute. When you run the transformation, the filter is applied
to each element in the collection. If the filter returns
true for
the element, the element is transformed.
Before you begin
You
must have a mapping model open. A mapping
model has .mapping as a file name extension. The mapping model must contain at least one
mapping declaration,
and a submap mapping rule must be defined in the mapping declaration.
About this task
To create an input or output object filter in a submap
mapping rule:
Procedure
- In the editor area, right-click the submap mapping rule;
then click Show in Properties.
- In the Properties view, click the Input
Filter or Output Filter tab.
- Select the Filter Input Elements or Filter
Output Elements check box.
Note: If you are
creating an input object filter, when the check box is clear, the
submap mapping rule is applied to all elements in the list when you
run the transformation. If you are creating an output object filter,
when the check box is clear, the first object in the collection of
candidate output objects is referenced in the output attribute.
- To specify the code for the filter, complete one of the
following steps:
- Click Inline, then type Java code in the text area below the Code option;
then click Apply. The code that you specify
must return a Boolean value. You can specify only the method body;
the transformation authoring framework defines the method signature.
Tip: To
see a list of valid variable names, in the text area below the Inline button,
press Ctrl+Space.
Note: For
input filters, you might specify a variable called <name>_src,
which provides the current value from the collection in the attribute.
For output filters, <name>_tgt, provides the current value from
the collection in the attribute.
- Click External to specify the Java class that contains the code to apply as
a filter for the submap mapping rule. The Java class
that you specify must extend the org.eclipse.emf.query.conditions.Condition class.
You must also implement the isSatisfied(Object object) method,
where object is set to the current element in the
collection; this method returns a Boolean value. When you click Browse,
a dialog box enforces the selection of a valid class.
Tip: To
create a class that implements a filter, click New;
then complete the fields in the New Java Class window.
- Click .
Example
For example, if the input attribute of a submap mapping
rule is a list of EClassifiers, you can create an input object filter
that evaluates the isAbstract function for each element. The parameter
to the isAbstract function is an instance of an element in the list.
Each EClassifier that is abstract is added to a result set. When you
run the transformation, the submap mapping rule is applied to each
EClassifier in the result set.