Output all class associations into document

Doc. Composer allow user retrieve and output model details by creating custom templates. In this article we will create customize template to output the associations for classes under specific scope.

To output all class associations into document:

  1. Go to Tools > Doc. Composer > Manage Template XML.

    Manage Template XML

  2. Select Class under Model Type.

    Select Class Model

  3. Right click on any template and select Duplicate… from popup menu.

    Duplicate any template

  4. Name the template as ClassAssociations, and choose Description as it icon.

    Name the tempalte as ClassAssociations

  5. Replace the content of the template as follow.
    <?xml version="1.0" encoding="UTF-8"?>
    <ElementBaseInitiationBlock>    
        <!-- Basic -->
        <Inline template="Basic (with anchor mark)"/>                
        <!-- Relationships -->
        <Text style="@heading+">Relationships</Text>
        <ParagraphBreak/>    
        <HasRelationshipChecker>        
            <TableBlock colWidths="40, 30, 30" tableStyle="Summaries">
                <TableRow>
                    <TableCell>
                        <Text>Relationship</Text>
                    </TableCell>
                    <TableCell>
                        <Text>From</Text>
                    </TableCell>
                    <TableCell>
                        <Text>To</Text>
                    </TableCell>
                </TableRow>            
                <ForEachEndRelationship>
                    <TableRow>
                        <TableCell>
                            <Icon/>
                            <Property property="name"/>
                        </TableCell>
                        <TableCell>
                            <FromEnd>
                                <Property property="name"/>
                                <Property property="multiplicity"/>
                            </FromEnd>
                        </TableCell>
                        <TableCell>
                            <ToEnd>
                                <Property property="name"/>
                                <Property property="multiplicity"/>
                            </ToEnd>
                        </TableCell>
                    </TableRow>
                </ForEachEndRelationship>            
            </TableBlock>
            <ParagraphBreak/>        
        </HasRelationshipChecker>        
    </ElementBaseInitiationBlock>
  6. Press Save button and close the Manage Template XML.
  7. Now go to Tools > Doc. Composer.

    Open Doc. Composer

  8. Select Build Doc from Scratch.

    Select Build Doc from Scratch

    Select Build Doc from Scratch

  9. Select the container containing your classes in Model Explorer.

    Select the container containing the classes

  10. Drag the Loop template into document.

    Create loop

  11. The Loop dialog will list out the classes being included in the loop.

    Classes included by the loop

    Classes included by the loop

  12. Switch to Element Types tab, and select ClassAssociations as the template.

    Select ClassAssociations as the template

  13. Press OK.

Now the associations for all classes covered in the loop is outputted to the document.

Associations for all classes covered by the loop are being outputted

Associations for all classes covered by the loop are being outputted

Explanation of the template

The template first check do the classes having any relationships.

<?xml version="1.0" encoding="UTF-8"?>
<ElementBaseInitiationBlock>    
    <!-- Basic -->
    <Inline template="Basic (with anchor mark)"/>                    
    <!-- Relationships -->
    <Text style="@heading+">Relationships</Text>
    <ParagraphBreak/>    
    <HasRelationshipChecker>        
        <TableBlock colWidths="40, 30, 30" tableStyle="Summaries">

If the class it working on having relationships then it try to loop through all the End Relationship (where association is one of it).

<ForEachEndRelationship>
    <TableRow>
        <TableCell>
            <Icon/>
            <Property property="name"/>
        </TableCell>

Then it retrieve both From and To end element and output its properties.

<TableCell>
    <FromEnd>
        <Property property="name"/>
        <Property property="multiplicity"/>
    </FromEnd>
</TableCell>
<TableCell>
    <ToEnd>
        <Property property="name"/>
        <Property property="multiplicity"/>
    </ToEnd>
</TableCell>

 

Related Know-how

Related Link

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply