Type casting refines the results of a query
and allows Rational® Publishing Engine to
treat .xsd schema types as being from a different
type, similar to cast operations in programming languages. A type
is not assigned to schema elements that can have more than one valid
type. You define the types for these elements with the cast
to type feature in the Data source schema view.
Before you begin
In
Rational Publishing Engine 1.2
and earlier, the cast can be applied only to the last segment of the
query. Query examples:
- Correct: Packages/Packages/NestedElements/ModelElement(Class)
- Incorrect: Packages/Packages/NestedElements/ModelElement(Class)/Attributes
To make the second query example valid in
Rational Publishing Engine 1.2,
you must split it in two queries:
- $1 - Packages/Packages/NestedElements/ModelElement(Class)
- $2 - $1/Attributes
In Rational Publishing Engine 1.2.0.1,
the cast can be applied to any segment of the query.
About this task
Type casting works as an alternate filter for
data source elements. A cast query filters the results of the regular
query to return only the elements that can be cast to the selected
type. After the type is selected, it becomes available in the Data
Source Schema view under the anyType element.
Queries built using cast allow access to all the child elements and
attributes of the type cast. The result set returned by a cast query
is identical to the result set returned by a query that is filtered
with an equivalent IsKindOf predicate. The difference
between the cast query and filtered query is that a cast query gives
access to the cast type attributes and child elements while the filtered
query does not.
Note: IBM® Rational Tau and IBM Rational Rhapsody® data
sources support type casting.
Procedure
- Drag a
Container element into the
template content editor.
- From the Data Source Schema view,
drag the ownedMember class into template.
- Name the container Class Container for
quick reference.
- Click the
icon and select the Class type
cast for the ownedMember.
- Drag a
Paragraph element and place
it below the container element, and add the name of the package inside
the Class Container by dragging the Name(string) attribute.
- Drag a
Text element to the template
content editor.
- From the Data Source Schema view,
drag the static text (Active) to the text element.
- Right-click the text element, and then click .
- In the Set Condition for Current Element window,
expand Attributes, and select the check box
for IsActive attribute.
- For the Left operand , select IsActive.
- For the Operator, select Equals.
- For the Right operand, enter true.
- Click Add. The
condition displays as: IsActive == "true"
- Click OK.
Results
Adding a Class cast to the ownedMember element
of a package allows you to define the following query, which returns
only the definitions that are classes from the same context: