This section provides instructions for creating sequence and collaboration diagrams from source code using the Generate Sequence Diagram wizard.
|
To generate a sequence diagram from an operation, follow these steps: 1. Open the class diagram containing the class with the operation that you want to model. 2. In the Diagram view, locate the desired class, and select the operation.
3. Select the Generate Sequence Diagram command from the operation context menu to display the Generate Sequence Diagram wizard. |
![]() |
|
4. The first page of the wizard allows you to specify options for the generated diagrams, such as:
See Specifying Options for Sequence Diagram Generation for descriptions of the options listed above. Check the desired options, and click Next. |
![]() |
|
5. On the next page, select the packages and classes that you want to display in the generated diagram. All packages and classes are selected by default. However, some Java packages/classes may not be relevant, for example, java.lang.integer. You can increase the meaningfulness of the generated diagram by removing anything that does not help explain the sequence of operations. 6. In the Package/Class list, for those elements that you decide to show in the diagram, check whether or not to show implementation detail in the generated diagram. 7. Click Finish to generate the diagram. The sequence diagram opens in the Diagram view.
|
![]() |
Together allows you to quickly convert between sequence and collaboration diagrams. However, whenever you generate a sequence diagram from source code, it is specified as a sequence diagram, and Together tracks it as such. The diagram displays in the UML Explorer and UML Navigator views as a sequence diagram, and it opens in that view. For example, once you generate a sequence diagram from source code, it will always display in the UML Explorer and UML Navigator views, and open in the Diagram view as a sequence diagram. However, you can choose to view it as a collaboration diagram.
To convert between sequence and collaboration diagrams:
Right click on the diagram background.
If the diagram is a sequence diagram, select Show as Collaboration from the diagram context menu. If viewing a collaboration diagram, the menu command is Show as Sequence.
Repeat this process to toggle between the two diagrams.
NB: You can also switch between diagrams using the context menu for the diagram in the UML Explorer or UML Navigator.
Use the following options to control how sequence diagrams are generated. These
options are accessible on the first page of the Generate Sequence Diagram wizard
when you choose to generate a sequence diagram from code.
Depth of call nesting: During source code parsing, this value limits how deep the parser traverses the source code calling sequence. In other words, you may request a sequence diagram from the main() method of a complex application. This value can keep the generated sequence diagram from becoming so large that it is unusable.
In general, the higher the number, the greater the risk of producing a very complex sequence diagram. Also, in such cases, the length of time required to parse the source code increases.
Tip: You may even want to use this feature as a means for quickly generating a high-level sequence diagram for a complex operation by using a low call nesting value (1-3). Then, based on the results in that diagram, you can choose to look deeper and/or create additional sequence diagrams for each of the major methods uncovered.
Exclude messages to self: This option specifies whether to show messages to self on the generated sequence diagram.
Create multiple diagrams: This option specifies how many sequence diagrams
will be created if you select multiple operations before you invoke
the Generate Sequence Diagram command. If this option is checked, multiple sequence
diagrams are generated (one diagram for each operation). If this option is not
checked, one diagram is generated with multiple initial messages.
Show multiple diagrams: If you generated multiple sequence diagrams (see Create multiple diagrams above), this option specifies whether to show all generated diagrams immediately.
Tip: If this option is not checked, you can still open any generated diagram from the UML Explorer or UML Navigator views. If you choose to create a hyperlink (see Create hyperlinks below), you can also use the Hyperlinks command on the context menu of the operation to open the diagram.
Create hyperlinks: Check this option to create a Hyperlink from the selected operation to the generated sequence diagram. The operation displays in blue font to indicate that a hyperlink exists. For more information on hyperlinks, see Working with Hyperlinks.