Conditional Expression
<DefaultValueChecker>
The <DefaultValueChecker> element evaluates the querying element to check if the property stated by the @property attribute equals to its default value. If the result of evaluation matches with the result stated by the attribute @flag, the child elements of <DefaultValueChecker> will be processed. Otherwise, the child elements will be skipped.
The following example shows the use of <DefaultValueChecker> in a template.
<DefaultValueChecker property="root" flag="false">
<Text>The root property has been modified.</Text>
</DefaultValueChecker>
</IterationBlock>
The following table lists the available attributes of <DefaultValueChecker>.
|
|||||||||
Attributes of <DefaultConditionChecker> |
<ValueChecker>
The <ValueChecker> element evaluates the querying element to check if the value of the property stated by the @property attribute equals to the value stated by the @value attribute. If the result of evaluation is true, the child elements of <ValueChecker> will be processed. Otherwise, the child elements will be skipped.
The following example shows the use of <ValueChecker> in a template.
<ValueChecker property="name" value="ShapeCreator">
<Text>ShapeCreator class found!</Text>
</ValueChecker>
<ValueChecker property="description" operator="not equals" value="">
<Text>Description: </Text>
<Property property="description"/>
</ValueChecker>
</IterationBlock>
The following table lists the available attributes of <ValueChecker>.
|
|||||||||||||||||||||||||||
Attributes of <ValueChecker> |
<HasChildElementChecker>
The <HasChildElementChecker> element evaluates the querying element to check if it contains any child element, or type(s) of child elements specified by the @modelType or @modelTypes attributes. If the result of evaluation is true, the child elements of <HasChildElementChecker> will be processed. Otherwise, the child elements will be skipped.
The following example shows the use of <HasChildElementChecker> in a template.
<HasChildElementChecker modelType="Attribute" flag="true">
<IterationBlock modelType="Attribute">
<Property property="name"/>
<ParagraphBreak>
</IterationBlock>
</HasChildElementChecker>
<HasChildElementChecker modelType="Attribute,Operation" flag="true">
<IterationBlock modelTypes="Attribute,Operation">
<Property property="name"/>
<ParagraphBreak>
</IterationBlock>
</HasChildElementChecker>
</IterationBlock>
The following table lists the available attributes of <HasChildElementChecker>.
|
|||||||||||||||||||||||||||
Attributes of <HasChildElementChecker> |
<HasRelationshipChecker>
The <HasRelationshipChecker> element evaluates the querying element to check if it contains any relationship, or type(s) of relationships specified by the @modelType or @modelTypes attributes. If the result of evaluation is true, the child elements of <HasRelationshipChecker> will be processed. Otherwise, the child elements will be skipped.
The following example shows the use of <HasRelationshipChecker> in a template.
<HasRelationshipChecker modelType="Association" flag="true">
<ForEachRelationshipEnd modelType="AssociationEnd" endPointer="self">
<RelationshipEndEndRelationship>
<FromEnd>
<ModelElementProperty property="EndModelElement">
<Property property="name"/>
<Text>, </Text>
</ModelElementProperty>
</FromEnd>
<ToEnd>
<ModelElementProperty property="EndModelElement">
<Property property="name"/>
<Text>, </Text>
</ModelElementProperty>
</ToEnd>
</ForEachRelationshipEnd>
</HasRelationshipChecker>
<HasRelationshipChecker modelType="Generalization" direction="to">
<ForEachSimpleRelationship type="Generalization">
<ModelElementProperty property="from">
<Property property="name"/>
<Text>, </Text>
</ModelElementProperty>
</ForEachSimpleRelationship>
</HasRelationshipChecker>
</IterationBlock>
The following table lists the available attributes of <HasRelationshipChecker>.
|
|||||||||||||||
Attributes of <HasRelationshipChecker> |
<HasDiagramChecker>
The <HasDiagramChecker> element evaluates the querying "thing" (project or model element) to check if it has specified any diagram for a given property specified by the @property attribute. If the result of evaluation is true, the child elements of <HasDiagramChecker> will be processed. Otherwise, the child elements will be skipped.
The following example shows the use of <HasDiagramChecker> in a template.
<HasDiagramChecker diagramType="ClassDiagram" flag="true">
<Text>This project contains at least one class diagram.</Text>
</HasDiagramChecker>
</ProjectBaseInitiationBlock>
The following table lists the available attributes of <HasDiagramChecker>.
|
||||||||||||
Attributes of <HasDiagramChecker> |
<HasValueChecker>
The <HasValueChecker> element evaluates the querying "thing" (project or model element) to check if it has specified a given property, specified by the @property attribute. If the result of evaluation is true, the child elements of <HasDiagramChecker> will be processed. Otherwise, the child elements will be skipped.
The following example shows the use of <HasValueChecker> in a template.
<HasValueChecker property="taggedValues" flag="true">
<Text>This class contains at least one tagged value.</Text>
</HasValueChecker>
</IterationBlock>
The following table lists the available attributes of <HasValueChecker>.
|
||||||||||||||||||
Attributes of <HasValueChecker> |
<HasParentModelChecker>
The <HasParentModelChecker> element evaluates the querying model element to check if it is being contained by a parent model element. If the result of evaluation is true, the child elements of <HasParentModelChecker> will be processed. Otherwise, the child elements will be skipped.
The following example shows the use of <HasParentModelChecker> in a template.
<HasParentModelChecker modelType="Package" flag="true">
<Text>This class contains is contained by package: </Text>
<ParentModel>
<Property property="name"/>
</ParentModel>
</HasParentModelChecker>
</IterationBlock>
The following table lists the available attributes of <HasParentModelChecker>.
|
|||||||||
Attributes of <HasParentModelChecker> |
<HasSubDiagramChecker>
The <HasSubDiagramChecker> element evaluates the querying model element to check if it contains any sub-diagram. If the result of evaluation is true, the child elements of <HasSubDiagramChecker> will be processed. Otherwise, the child elements will be skipped.
The following example shows the use of <HasSubDiagramChecker> in a template.
<HasSubDiagramChecker diagramType="StateMachineDiagram" flag="true">
<ForEachSubDiagram>
<Property property="name"/>
</ForEachSubDiagram>
</HasSubDiagramChecker>
</IterationBlock>
The following table lists the available attributes of <HasSubDiagramChecker>.
|
|||||||||
Attributes of <HasSubDiagramChecker> |
<HasOwnerDiagramsChecker>
The <HasOwnerDiagramsChecker> element evaluates the querying model element to check if it has been visualized in any diagram. If the result of evaluation is true, the child elements of <HasOwnerDiagramsChecker> will be processed. Otherwise, the child elements will be skipped.
The following example shows the use of <HasOwnerDiagramsChecker> in a template.
<HasOwnerDiagramsChecker diagramType="BusinessProcessDiagram" flag="true">
<ForEachOwnerDiagram>
<Property property="name"/>
</ForEachOwnerDiagram>
</HasOwnerDiagramsChecker>
</IterationBlock>
The following table lists the available attributes of <HasOwnerDiagramsChecker>.
|
|||||||||
Attributes of <HasOwnerDiagramsChecker> |
Checking multiple conditions with <Conditions>
The use of <...Checker> enables you to perform checking on single condition. Sometimes, you may want to check for multiple conditions at a time. For example, you may want to output the name of all public and static attributes of a class. In order to check for multiple conditions, use <Conditions>. <...Checker> under <Conditions> will all be evaluated. If the result of evaluation are true for ALL checkers, the subsequent elements will be evaluated. Otherwise, the parent iteration will continue to next round.
Note that <Conditions> supports the type attribute, which enables you to specify the way how the result of checkers are evaluated. The value "and" means that the result of checkers must all be positive in order to continue, while the value "or" means that as long as there is one checker that returns a positive result, the flow can continue.
The following example shows the use of <Conditions> in a template.
<Conditions type="and">
<ValueChecker property="visibility" value="public" />
<ValueChecker property="scope" value="classifier" />
</Conditions>
<Property property="name"/>
<ParagraphBreak/>
</IterationBlock>
Using <...ConditionChecker> (e.g. <IterationBlockConditionChecker>, <ForEachConditionChecker>, etc.)
The following lists out a set of <...ConditionChecker>.
- <IterationBlockConditionChecker>
- <ForEachConditionChecker>
- <ForEachRelationshipConditionChecker>
- <ForEachSimpleRelationshipConditionChecker>
- <ForEachEndRelationshipConditionChecker>
- <ForEachRelationshipEndConditionChecker>
- <ForEachSubDiagramConditionChecker>
- <ForEachOwnerDiagramConditionChecker>
- <ForEachDiagramConditionChecker>
- <ForEachDiagramElementConditionChecker>
- <ModelElementPropertyConditionChecker>
- <FromEndConditionChecker>
- <ToEndConditionChecker>
- <RelationshipEndEndRelationshipConditionChecker>
- <RelationshipEndOppositeEndConditionChecker>
- <DiagramPropertyConditionChecker>
- <DiagramElementPropertyConditionChecker>
- <ParentModelConditionChecker>
- <ParentShapeConditionChecker>
- <OwnerDiagramConditionChecker>
They all share similar usage so let's explain them together. To make it simple, let's explain with <IterationBlockCondictionChecker>, using the example above.
Let's say we want to add a line "Public and static attributes" before we list out the attributes. Here is the problem: If we place a <Text>Public and static attributes</Text> before <IterationBlock>, the line will get output even without any public and static attributes. If we put the <Text> inside the <IterationBlock> and below <Conditions>, the line will get output multiple times if there are multiple public and static attributes.
To solve this problem, use <IterationBlockConditionChecker>. <IterationBlockConditionChecker> enables you to check if there exists an element in an iteration, when certain conditions are applied. The following example is the revised version of the above example. It will output a single line of title above the list of attributes output within the <IterationBlock>.
<Conditions>
<ValueChecker property="visibility" value="public" />
<ValueChecker property="scope" value="classifier" />
</Conditions>
<Text>Public and static attributes</Text>
<ParagraphBreak/>
<IterationBlock modelType="Attribute">
<Conditions>
<ValueChecker property="visibility" value="public" />
<ValueChecker property="scope" value="classifier" />
</Conditions>
<Property property="name"/>
<ParagraphBreak/>
</IterationBlock>
<IterationBlockConditionChecker/>
Using <ConditionsChecker>
The use of <Conditions> allows the filtering of elements in a loop. But there are times that you want to check against a querying model element instead of filtering elements in a looping. In such case, use <ConditionsChecker>
The following example shows the use of <ConditionsChecker> in a template.
<ConditionsChecker>
<Conditions type="and">
<ValueChecker property="visibility" value="public" />
<ValueChecker property="scope" value="classifier" />
</Conditions>
<Property property="name"/>
<ParagraphBreak/>
</ConditionsChecker>
</ElementBaseInitiationBlock>
Using nested checkers in propagated checking
Sometimes, a checking requires the checking of not just the querying element, but certain property of the querying element. Let's say we want to retrieve all public attributes from a class whose attribute type has to be classes with names ended with 'Controller'. In order to handle such a complex checking, we have to create a nested checker structure which involves the nested use of <...Checker> and <Conditions>.
The following example shows the use of various checkers in a nested structure.
<Conditions>
<ValueChecker property="visibility" value="public" />
<ModelElementPropertyConditionChecker property="type">
<Conditions>
<ValueChecker property="name" operator="like" value="Controller" />
<Conditions>
</ModelElementPropertyConditionChecker>
</Conditions>
<Property property="name"/>
<ParagraphBreak/>
</IterationBlock>
Related Resources
The following resources may help you to learn more about the topic discussed in this page.
6. Sorting in Loop | Table of Contents | 8. Working with Table |