5 Developing Applications Using Modeling

This chapter describes how to use the modeling tools and technologies to create Unified Modeling Language (UML) class, profile, activity, sequence, and use case diagrams, as well as database, EJB, and business component diagrams to model your various business services and database structures.

This chapter includes the following sections:

About Modeling with Diagrams

JDeveloper supports six standard UML diagrams types, and four business services diagram types to model the software and systems development for your applications.

All of the diagram types can be created using the New Gallery wizards and are supported with the JDeveloper diagram editor, Components window, and the Properties window.

UML Diagrams

JDeveloper offers six standard UML diagram types:

  • Activity Diagram. Model system behavior as coordinated actions. You can use activity objects to model business processes, such as tasks for business goals, like shipping, or order processing.

  • Activity Diagram with Partitions. Model a single activity, showing its partitions as vertical divisions (lanes).

  • Class Diagram. Model the structure of your system. Use to inspect the architecture of existing classes, attributes, operations, associations, generalizations and interface realizations.

  • Sequence Diagram. Model the traces of system behavior as a sequence of events. Sequence diagrams primarily show this as messages between objects ordered chronologically.

  • Use Case Diagram. Model what a system is supposed to do. A use case diagram is a collection of actors, use cases, and their communications.

  • Profile Diagram. Define extensions to UML using profiles and stereotypes.

Business Services Diagrams

There are four diagrams that support business services:

  • Business Components Diagram. Model entity objects, view objects, application modules and the relationships between them.

  • Database Diagram. Model your online and offline database tables and their relationships as well as views, materialized views, sequences, public and private synonyms.

  • EJB Diagram. Model the entity beans, session and message-driven beans inside a system, and the relationships between them.

  • Java Class Diagram. Model the relationships and the dependencies between Java classes, enums, fields, methods, references, inheritance relationships, and implementation relationships.

Transformations

Transformation is the process of creating Java objects from UML classes, or creating UML classes from Java classes. The transformation types are as follows:

Creating, Using, and Managing Diagrams

Oracle JDeveloper provides you with a wide range of tools and diagram choices to model your application systems. There are wizards to walk you through creating your diagrams and elements, as well as a Components window and Properties window to make it easy to drag and drop, and to edit a variety of elements without leaving your editing window.

Figure 5-1 shows the diagram editor window, with a class diagram, as well as the Applications window and Components window. Open diagrams by double-clicking them in the Applications window, and once open, drag-and-drop components onto the diagram editor from the Components window.

Once you have created your diagram, add components to your diagram from the Components window. Zoom in and out of your diagrams with keystroke commands or view them at original size, or a percentage of the original size. When you are finished, you can publish your diagram as an image or print it using the right-click context menu or the main menu commands.

Figure 5-1 Create Class Diagram Example

This image is described in the surrounding text

Figure 5-2 Class Diagram Example Showing Component Window

This image is described in the surrounding text

Creating a New Diagram

The New Gallery wizard creates a diagram that is ready to contain your components. The wizard lets you choose the diagram type, specify the package, and select the components you want access in the Component window. Figure 5-3 shows an example create dialog for a class diagram.

To create a new diagram:

  1. In the Applications window, select your project, then choose File > New From Gallery > General > Diagrams.
  2. Select a diagram type, click OK.
  3. The default package for a diagram is the default package specified in the project settings. An empty diagram is created in the specified package in the current project, and opened in the content area. Click OK.

Working with Diagram Elements

Diagram elements are available in the Components window from which they can be dragged into the diagram. There are a variety of tools to help you manage your elements visually, as well as managing the properties of your elements.

How to Locate an Element on a Diagram

Click on the element name in the Structure window. The element is selected in the diagram. You can also use the thumbnail window of the diagram to find an element. To display a thumbnail view of a diagram, select the diagram either in the applications window or by clicking on the background of the diagram, then choose Window > Thumbnail. You can grab the view area box and move it over elements on the thumbnail view of the diagram. The corresponding elements are brought into view on the main diagram.

How to Select Specific Elements on a Diagram

Press and hold down the Ctrl key, then click the element on the diagram.

How to Select All Elements on a Diagram

Select all elements on a diagram to perform actions on all elements at the same time, such as align, copy, delete, or move. Click on the diagram surface, and then select any element, and choose Edit > Select All. You can also drag out an area on the diagram surface to select all or multiple elements.

How to Select All Elements of the Same Type

If you want to edit or manage many elements of the same type, at the same time, use the select all option.

To select all elements of the same type:

  1. Select an object of the type you want.
  2. From the context menu, choose Select All This Type.

How to Deselect an Element in a Group of Selected Elements

If you select a group of elements, and you want to exclude particular elements, use the deselect option. This might be quicker than selecting the entire group one element at a time.

To deselect a selected element in a group of selected elements:

  1. Press and hold down the Ctrl key.
  2. Click the element(s) on the diagram to deselect.

How to Group Elements on a Diagram

Grouping elements locks two or more elements into a purely visual container.

To form a group of elements:

  1. Expand the diagram annotations accordion, if necessary. In the Components window, click Group.
  2. Position the pointer at the corner of the area on the diagram to group the elements, then press and hold down the mouse button.
  3. Drag the mouse pointer over the area.
  4. Release the mouse button when the objects are entirely enclosed.

How to Manage Grouped Elements

Use the Manage Group feature to move elements in and out of groups, move elements to other groups, or move groups in and out of other groups.

To manage grouped elements on a diagram:

  1. Select the group to manage.
  2. Right-click and select Manage Group.

    To move elements in and out of groups by Shift+drag the element to the desired position.

How to Change Semantic Properties

Open the Properties dialog in one of the following ways:

  • Double-click an element on the diagram.

  • Right-click an element on the diagram, and from its context menu, choose Properties.

How to Change Element Properties Using the Properties window

  1. Select Window > Properties. The Properties window displays both visual and semantic properties.
  2. Select the diagram element.
  3. Select the property to change.
  4. On the right of the Properties window, select the control and change the value. (The control may be an edit box, a drop-down list, a checkbox, etcetera). If a single element is selected all valid properties are available; it multiple elements are selected, only the properties valid for all elements are selected.

How to Change the Element Color or Font

  1. Select the element or elements on the diagram.
  2. Then in the Properties window (Window >Properties), on the Graphical Options tab, select the current color (or the box for font type), make the required change(s), then press Enter.

    Alternatively, on the tool bar, select the font type, font size, or color box, then make the required change.

    Another option is to choose Visual Properties from the context menu, then make the required change.

How to Change the Visual Properties of New Diagram Elements

Use the Preferences dialog to define the default visual properties of any elements you add to your diagrams.

To change the default setting of diagram elements to be added to a diagram:

  1. Choose Tools > Preferences, select Diagrams, select the diagram type, and then (from the Edit Preferences for drop-down box), select the element type to change, as shown in Figure 5-3.The preferences might be displayed on a single panel or multiple tabs.
  2. Change the default values as you require, and click OK.

Figure 5-3 Class Diagram Preferences Dialog

This image is described in the surrounding text

How to Copy Visual Properties

Use the Preferences dialog to copy preferences between elements.

To copy and paste visual properties to elements:

  1. Select a diagram element.
  2. Right-click and select Copy Graphical options from the context menu.
  3. Select the target element(s).
  4. Right-click and select Paste Graphical Options from the context menu.

How to Resize Elements on a Diagram

Resize an element by dragging the grab bars until the item is the size you want. Some diagram elements cannot be resized, such as initial and final nodes.

Certain element types also have internal grab bars, that are displayed when an element is selected. These internal grab bars are for resizing the compartments of those diagram elements.

Whenever a diagram element is resized towards the visible edge of the diagram, the diagram is automatically scrolled. New diagram pages are added where an element is resized off the diagram surface.

To resize a diagram element:

  1. Select the element to resize.
  2. Position the pointer on any grab bar on the element and hold down the mouse button. The pointer is displayed as a double-headed arrow when it is over a grab bar.
  3. Drag the grab bar until the element is resized, then release the mouse button.

How to Display Related Classes on a Diagram

Classes and interfaces related to those currently displayed on the diagram can be brought onto the diagram. This includes classes or interfaces that are extended, implemented, or referenced by the selected class or interface.

Choose from the following options to display related classes on a diagram:

  • Select the class or interface, on the diagram, then choose Diagram > Show > Related Elements.

  • Right-click the class or interface, on the diagram, then choose Diagram > Show > Related Elements.

How to Move Diagram Elements

Dragging elements on the diagram surface is the easiest way of moving elements. To move elements over a larger areas, cut and paste. Whenever a diagram element is moved towards the visible edge of the diagram, the diagram is automatically scrolled. New diagram pages are added where an element is moved off the diagram surface.

To move diagram elements:

  1. Select the element, or elements to move.
  2. Position the pointer on the elements, then press and hold down the mouse button.
  3. Drag the selected elements to their new position.
  4. Release the mouse button. If an element overlaps another element they are displayed on top of one another. Right-clicking the element and choose Bring to Front to view.

How to Undo the Last Action on a Diagram

You can undo and redo your most recent graphical actions by choosing Edit >Undo [...] or clicking the undo icon. Graphical actions change the appearance of elements on the diagram surface and include the following:

  • Cutting and pasting elements on diagrams.

  • Altering the position and size of diagram elements.

  • Changing the font, color, and line width of diagram elements.

Changes to an element's semantic properties can only be undone if the technology (Java, for example) permits it. Changing an element's semantic properties might prevent previous graphical changes from being undone.

To redo an action, choose Edit > Redo [...] or click the redo icon

How to Copy Elements to Another Diagram

Use the context menu or keystrokes to copy elements across different diagrams.

To copy elements from a diagram and paste them into another diagram:

  1. Select the diagram elements, then choose Copy on the context menu, or choose the Copy icon on the toolbar, or press Ctrl-C.
  2. Open the destination diagram.
  3. Place the pointer where you want the diagram elements to be added, then choose Paste from the context menu (or choose the Paste icon on the toolbar, or press Ctrl-V.

How to Rename a Diagram

Renaming changes the diagram name without leaving a copy of the original.

To rename a diagram:

  1. In the Applications window, select the diagram to rename.
  2. Choose File > Rename.

How to Publish a Diagram as an Image

Use the right-click context option to publish your diagram as a graphic image. You can preview and print your diagram once it is published as an image.

To publish a diagram as an image:

  1. Right-click your diagram, then choose Publish Diagram.

    Alternatively, click on the surface of the diagram, then choose Diagram > Publish Diagram.

  2. Select the destination folder from the table for the image file.
  3. From the File type drop-down list, select the file type for the image file (SVG, SVGZ, JPEG, or PNG).
  4. In the File name box, enter a name for the image file, including the appropriate file extension (svg, svgz, jpg, or png).
  5. Click Save.

How to Setup a Page for Printing

Change from portrait to landscape or your margins for printing using page setup.

To setup the page before printing:

  1. Click on the surface of the diagram you want to print, then choose File > Page Setup.
  2. Make changes to the settings on the tabs of the Page Setup dialog.

How to Set the Area of a Diagram to Print

Set a specific area of your diagram to print using set print area off the File menu option.

To set the area of the diagram to print:

  1. Choose File > Print Area > Set Print Area.
  2. On the diagram, drag the mouse pointer to enclose the objects on the diagram to print. The area to print is shown with a dashed outline. If you do not set an area, then the whole diagram is printed.

How to See a Preview of Your Page Before Printing

To see a preview of your page go to File > Print Preview. You can also set print options from this page by choosing Print Options. On the Print Option page you can add header and footer content as well as text formatting.

How to Clear a Diagram Print Area

To clear a diagram print area choose File > Print Area > Clear Print Area.

How to Zoom in and Out of a Diagram

Use Ctrl+scroll to zoom in and out of diagrams. When you are using the thumbnail view, use scroll to zoom. There are also zoom options on the diagram toolbar.

How to Display an Entire Diagram

In the zoom drop-down list, located on diagram toolbar, choose Fit to Window, or click the diagram, then choose Diagram > Zoom > Fit to Window.

How to Display the Selected Elements at the Maximum Size

In the zoom drop-down list, located on the diagram toolbar, choose Zoom to Selected, or click the diagram, then choose Diagram > Zoom > Zoom to Selected.

How to Display a Diagram in its Original Size

In the zoom drop-down list, located on the diagram toolbar, choose 100%, or click the diagram, then choose Diagram > Zoom > 100%.

How to Delete a Diagram

Delete the diagram and related diagram elements using the menu bar.

To delete a diagram:

  1. In the Applications window, select the diagram to remove.
  2. Choose Edit > Delete. These commands remove the diagram file from the system and close the editing window for that diagram. The elements for the deleted diagram remain in the applications window and on the file system.

    You can also delete a diagram from the Applications window. In the Applications window, right-click on the diagram name and choose Delete.

Working with Diagram Layout

Diagrams can be laid out in hierarchical, symmetrical, grid, and row styles. Elements within your diagrams can also have customized layout styles. There are many preferences available to customize the way you diagram looks. Most preferences can be set using the various diagram preferences dialogs at Tools > Preferences > Diagrams (diagram type), as shown in Figure 5-4. From the general preferences dialog you can choose Edit Preferences for to set specific preferences for new diagrams.

Figure 5-4 Class Diagram Visual Properties

This image is described in the surrounding text

How to Use a Hierarchical Diagram Layout

Hierarchical layout puts diagram elements in hierarchies based on generalization structures and other edges with a defined direction, as show in Figure 5-5. edges between the nodes are laid out using the most direct route. Nodes on a diagram that are not connected to any other nodes are laid out in a grid layout. Hierarchical layout is available in four orientations: top to bottom, bottom to top, left to right and right to left.

Figure 5-5 Hierarchical Diagram Layout Example

This image is described in the surrounding text

How to Use Layout Edges on a Diagram

Diagram edges can be laid out in either oblique or rectilinear line styles. Oblique lines can be repositioned at any angle. Rectilinear lines are always shown as a series of right angles.

You can set the default line style for each diagram edge using the "Line Style" preference under Tools > Preferences > Diagrams > Class and from the Edit Preferences dropdown, select Association, as shown in Figure 5-6.

Figure 5-6 Diagram Preferences, Edit Preferences for Line Style

This image is described in the surrounding text

You can also set the line style for all instances of that diagram type. Keep in mind that when the line style of an individual edge is changed to oblique, and you change the line style from rectilinear to oblique, no change will be apparent on the diagram, but you will then be able to move any of the lines on the diagram into a new position at any angle.

You can select individual diagram edges and change their line style. If you change an individual line from oblique to rectilinear, the line will be redrawn using right angles. If you change an individual line from rectilinear to oblique, no change will be made to the line, but you can reposition it (or portions of it) at any angle.

You can also choose the crossing styles for your lines to be bridge or tunnel style. Selecting bridge creates two parallel lines where the lines intersect. Selecting tunnel creates a semi-circle shape on the intersection. The default style is a regular crossing over of the two lines where the lines intersect.

How to Use a Symmetrical Diagram Layout

Symmetrical layout aligns diagram elements symmetrically based on the edges between the nodes as shown in Figure 5-7. Under certain circumstances, a symmetrical layout will position nodes in a radial layout around a central node. Nodes on a diagram that are not connected to any other nodes are laid out in a grid layout.

Figure 5-7 Symmetrical Diagram Example

This image is described in the surrounding text

How to Use an Orthogonal Diagram Layout

Orthogonal diagrams show hierarchical and non-hierarchical elements where the aligned edges of a component all follow the same direction, as shown in Figure 5-8. For class diagrams, the generalization hierarchy is simply aligned, indicating the independence of each element.

Figure 5-8 Orthogonal Diagram Layout Example

This image is described in the surrounding text

How to Use a Grid Diagram Layout

Grid layout puts the diagram elements in a grid pattern with nodes laid out in straight lines either in rows from left to right, or in columns from top to bottom, as shown in Figure 5-9. Nodes are laid out starting with the top left node.

Figure 5-9 Grid Diagram Layout Example

This image is described in the surrounding text

How to Lay Out Diagram Elements

Layout styles are available by opening the context menu for a diagram and choosing Lay Out Shapes, or by selecting the Diagram > Layout Shapes as shown in Figure 5-10.

Figure 5-10 Diagram Layout Options Dropdown

This image is described in the surrounding text

To layout elements on a diagram:

  1. Choose one of the following:
    • Select the individual elements on the diagram.

    • Click the surface of the diagram to layout all the elements on a diagram.

    • Select the container element to layout all the elements within a container element.

  2. On the diagram tool bar, choose the required layout style from the dropdown list, shown in Figure 5-10.

After the selected elements have been laid out they remain selected to be moved together to any position on the diagram.

To set the layout for new elements on a diagram, click on the diagram background and select Visual Properties from the context menu.

To set the default layout for new elements on a diagram go to Tools > Preferences > Diagrams.

How to Lay Out Diagrams Using the Grid

Diagram elements can be automatically snapped to the nearest grid lines, even if the grid is not displayed on the diagram. Grid cells on the diagram are square and only one value is required to change both the height and width of the grid cells. By default, elements are not snapped to the grid on activity diagrams. To set the default diagram grid display and behavior go to Tools > Preferences, select Diagrams. From there you can select the Show Grid checkbox to display the grid or Snap to Grid checkbox to snap elements to the grid. The grid does not have to be displayed for elements to be snapped to it.

To define diagram grid display and behavior for the current diagram:

  1. Click the surface of the diagram.
  2. In the View > Properties window, select to Show Grid, or Snap to Grid.

How to Distribute Diagram Elements

Distributing diagram elements spatially arranges elements to specific point, such as top, bottom, etc. When you are distributing elements, the outermost selected elements on the vertical and horizontal axes are used as the boundaries. To fine tune the distribution, move the outermost elements in the selection, then redistribute the element.

To distribute diagram elements:

  1. Select three or more diagram elements and choose Diagram > Distribute.
  2. Select the distribution for the elements.
    • Select the horizontal distribution: None, Left, Center, Spacing, or Right.

    • Select the vertical distribution: None, Top, Center, Spacing, or Bottom.

  3. Click OK.

How to Align Diagram Elements

Elements can be aligned vertically and horizontally. You can also change the location of elements to have equal vertical and horizontal spacing.

To align and size elements:

  1. Select two or more elements. Choose Diagram > Align.
  2. Choose from the following:
    • Select the horizontal alignment.

    • Select the vertical alignment.

  3. Use the Size Adjustments checkboxes to set the size of the selected elements:
    • Select the Same Width for all the selected elements to have the same width. The new element width is the average width of the selected element.

    • Select the Same Height for all the selected elements to have the same height. The new element height is the average height of the selected elements.

  4. Click OK.

Working with Diagram Nodes

In a UML diagram a node can represent a physical device or an execution environment. A physical device can be a single device or a configuration of multiple devices. An execution environment is a software container (such as an operating system or an EJB). You can create nodes inside or outside elements.

How to Create a Node on a Diagram

Create a node using the Components window.

To create a node on a diagram:

  1. Select the node type you want to create from those listed in the Components window for your diagram.
  2. Click the diagram where you want to create the node, or drag it from the component palette. This adds the node at its default size.

    Alternatively, click and hold down the mouse button where you want to place one of the corners of the node and drag the node outline to the opposite node corner and release the mouse button.

  3. Enter the name for the node when the default element name is highlighted on the new node.

How to Create Internal Nodes on a Diagram Element

Elements can be represented on a diagram as internal nodes on other diagram elements.

Internal nodes can be used to create the following:

  • Inner classes and inner interfaces.

  • Relation usages.

Figure 5-11 Symbolic Diagram Class View

This image is described in the surrounding text

Figure 5-12 Expanded Diagram Class View Showing Internal Nodes

This image is described in the surrounding text

To create an internal node on a diagram element:

  1. Select the node on the diagram to create an internal node.

  2. Choose Diagram > View As Expanded to display an expanded view of the node.

  3. Create the node for the internal node inside the expanded box, or drag the appropriate node from the Applications window, or diagram, and drop it in the expanded node to create an inner node.

To change the way nodes are presented on a diagram:

Select the diagram element(s) and choose one of the following:

  • Diagram > View As > Compact.

  • Diagram > View As > Symbolic.

  • Diagram > View As > Expanded.

To optimize the size of nodes on a diagram:

Use the optimize feature of the right-click context menu to optimize your nodes. Optimizing will adjust the size of the nodes so that all attributes show.

  1. Select the nodes to resize.
  2. Right-click the selected nodes then choose Optimize Shape Size > Height and Width, as one option, or separately.

Working with Diagram Edges

You can hide a single edge or any number of edges on your diagrams. Edges that are hidden on a diagram continue to show in the Structure window, with "hidden" appended. If there are any hidden edges, you can bring them back into view individually or all at once.

How to Hide Edges on a Diagram

To hide one or more edges:

  1. Select the diagram edge to hide. (To select all edges of a particular type, right-click an edge, then choose Select All This Type.)
  2. Right-click and choose Hide Selected Shapes.

    You can also go to the Structure window, select the edge or edges to hide, right-click and choose Hide Shapes.

How to Show Hidden Edges on a Diagram

In the Structure window, select the edge to show, right-click and choose Show Hidden Shapes.

How to Show all Hidden Edges on a Diagram

In the Structure window, select the edges to show, right-click and choose Show Hidden Shapes.

How To List All Hidden Edges Together in the Structure Window

Right-click an object listed in the Structure window and choose Order By Visibility.

How to Change Crossing Styles on a Diagram

You can choose the crossing styles for your lines to be bridge or tunnel style. Selecting bridge creates two parallel lines where the lines intersect. Selecting tunnel creates a semi-circle shape on the intersection. The default style is a regular crossing over of the two lines where the lines intersect. You can also choose no crossing style, which is the default setting.

Annotating Your Diagrams

Notes are used for adding explanatory text to a diagram or the elements on a diagram. A note can be attached to one or more elements. A note is stored as part of the current diagram, not as a separate file system element. Note options are available in the Components window, as shown in Figure 5-13.

Figure 5-13 Annotations in the Components window

This image is described in the surrounding text

How to Add a Note to a Diagram

Use the Diagram Annotations feature in the Components window to add a note to your diagram.

To add a note to a diagram:

  1. Click the Note icon in the Diagram Annotations section of the Components window.
  2. To create the note at the default size, click the diagram to create the note.

    To create the note at a different size, click the diagram, drag the note box to the desired size, and release the mouse button.

  3. Enter the text for the note, then click the diagram surface.

How to Attach a Note to an Element on a Diagram

The Components window Diagram Annotations feature provides an Attachment component to attach notes to your diagram elements.

To attach a note to an element on a diagram:

  1. Click the Attachment icon in the Diagram Annotations section of the Components window.
  2. Click the note.
  3. Click the element that you want to attach the note to.

How to Change the Font on a Note

Change the font using the standard editing options available on the note element.

To change the font size, color, bold, or italics on a note:

  1. Click the note element. The text editing box appears.
  2. Select the text to edit.
  3. Select your text format.

Storing Diagrams

Diagrams are stored on disk as diagram files. Diagram files reference the elements that are displayed on the diagram and contain display information for those elements (size, color, font, display of various properties etc.). Diagram files are stored in the folder for the package in which the diagram resides, which is stored in the model path specified in the project settings. Notes, diagram links and dependencies are also stored in the diagram file.

To set the model path:

  • Choose Application > Default Project Properties > Project Source Paths > Modelers.

Diagram elements such as Java classes are referenced in the diagram file, but their definition and implementation details are only stored in the implementation files for those elements. Although the diagrammatic details for these elements (position, color, size, etc.) are stored in the diagram file, no separate model definitions of these elements are stored.

Using UML

The UML elements that are created independently in the New Gallery are listed in the application window and can be dropped onto your diagrams. You can also create a UML application, which allows you to quickly create diagrams and related components.

UML element properties allow you to customize both display appearance (graphical options such as color or font) or semantic properties which describe the behavior of the element when it is deployed (attributes, display options, class relationships, and so forth).

The general preferences dialog sets preferences for all diagrams of that type Right-click and choose Visual Properties to edit preferences for the diagram currently in your editing window.

Creating UML Elements Off a Diagram

Use the New Gallery to create UML elements without a pre-existing diagram.

To create UML elements off a diagram:

  1. Select the project in the Applications window.
  2. Select File > New. The New Gallery opens.
  3. In the Categories panel, open the General node and select the UML node. The UML elements are listed in the Items panel.
  4. In the Items panel, select the UML element to create, then click OK. The properties dialog opens for the selected UML element.
  5. Complete the properties dialog, then click OK. The UML element is added to the applications window.

Storing UML Elements Locally

UML elements are stored in individual files. Their location is dependent on the package property of the element. These element files hold the properties defined against the various elements, but the diagram file still defines which elements are displayed on the diagram and the visual properties of those elements.

Element files for modeled UML elements are stored in the appropriate package folder under the folder specified in the project model path. To set the model path, choose Application > Default Project Properties > Project Source Paths > Modelers.

Using UML Profiles

A UML Profile can be applied to a UML model to specify additional semantics. JDeveloper includes the two UML 2.4.1 standard profiles and a profile for transforming UML objects to Offline Database objects. It also allows other profiles to be registered. These may be third party or user defined.

How to Create a Profile

Follow these steps to create a profile.

  1. Create a new project.

  2. Right-click the project and select Project Properties from the context menu. Select the Libraries and Classpath node. Click the Add Library button on the right.

  3. In the Add Library dialog, select UML 2.4.1 Metamodel and click OK.

  4. Right-click the project and select New > From Gallery.

  5. In the General category, select the UML node. In the Items pane, select Profile, and click OK. The Properties editor opens.

    1. Give the profile a name. The name is used to identify the profile when it is applied.

    2. Give the profile a URI. This is the namespace URI that will be used for the XML namespace when persisting an applied profile.

    3. Make sure that the profile has no owning package.

    You can create both Stereotypes and Extensions as Package Elements within the Profile, however it is easier to do this using a Profile diagram.

  6. Click OK to close the Project Properties dialog.

How to Export a Profile

  1. Select the project containing the profile and select File > Export.
  2. Choose Export UML as XMI.
  3. In the Export dialog, choose a location and select MOF 2.4.1 XMI 2.4.1 from the version dropdown.

How to Add a Profile

To add a profile, go to Tools > Preferences > UML > Profiles. The profiles page shows all of the current profiles (authored by you or a third party) available in the application, as shown on Figure 5-14. Under Tool Metamodels, click Add (+). Once you have added a profile, select it and click Edit. Specify the document URI for the profile. The document URI is used when persisting references to elements in the profile, in particular a profile application's reference to the profile.

Figure 5-14 UML Preferences Profiles Dialog

This image is described in the surrounding text

How to Apply a Profile to a UML Package

Follow these steps to apply a profile to a UML package.

  1. In the Applications window right-click on the UML package and choose Properties.
  2. In the Package Properties dialog, Structure list select Profile Application. Click Add (+) and choose a UML profile. Edit any property values and click OK.
  3. In the Structure list, select Packaged Element.
    profile applied
  4. Expand a metaclass instance, choose Applied Stereotype and click Add (+) and select a property. The properties available depend on the UML profile you are using.

    For example, expand the Class node, select Applied Stereotype, and click Add (+). Figure 5-15 shows the Name after Transform property from the UML profile DatabaseProfile.

    Figure 5-15 Package Properties Dialog Showing Resulting Class Name for UML Transformation

    This image is described in the surrounding text

Importing and Exporting UML

UML models created using other modeling software can be imported into JDeveloper using XML Metadata Interchange (XMI) if the models are UML 2.1.1 to 2.4.1 compliant.

The XMI specification describes how to use the metamodel to transform UML models as XML documents.

How to Import and Export UML Models Using XMI

The following are restrictions that apply to importing:

  • Diagrams cannot be imported.

  • You can use XMI to import one or more files. Any profiles referenced by XMI must first be registered with JDeveloper using Tools > Preferences > UML > Profiles.

  • Each profile must be in a separate file. For more information see, Using UML Profiles.

To import UML model from XMI:

  1. With an empty project selected in the Applications window, choose File > Import.
  2. Select UML from XMI, then click OK.

    Figure 5-16 Choose UML from XMI Dialog

    This image is described in the surrounding text
  3. Complete the Import UML from XMI dialog. Diagrams can be automatically created from the imported model. he dialog will offer you this option during the process, as shown in Figure 5-17.

    Figure 5-17 Import UML from XMI Dialog

    This image is described in the surrounding text

How to Export UML Models as XMI

Follow these steps to export a UML model as XMI.

  1. Select your project.
  2. Choose File > Export.

    Figure 5-18 Choose UML as XMI Dialog

    This image is described in the surrounding text

    Figure 5-19 Export UML as XMI Dialog

    This image is described in the surrounding text

Typical Error Messages When Importing

There are some typical errors and warnings that you can encounter in your XMI Import Log during import. Many of these can be easily resolved with a few simple steps, as detailed in Table 5-1. Double clicking on the items in the log navigates to the problem element. Often issues arise because of incorrect namespaces and standard object references.

As with other XML, the structure of a valid file is specified by XML schemas, which are referenced by xmlns namespaces. The XML consists of elements that represent objects or the values of their parent element object and attributes that are values. Sometimes the values are references to other objects that may be represented as an href as for HTML.


Table 5-1 Typical Error Messages When Importing

Error Type Error Detail Resolution

Missing Profile

  • Error(16,80): The appliedProfile property has multiplicity [1..1]

  • Error(17,70): Attempt to deference missing element http://example.oracle.com/MyProfile#_0

  • Warning(2,356): http://example.oracle.com/MyProfile is not a recognized namespace

  • Warning(22,142): Element urn:uuid:2b45f92d-31c8-4f67-8898-00a2f5bbfd22 ignored

In UML there is an extension mechanism that allows further XML schemas to be specified in a 'profile'. The messages above indicate that a relevant profile has not been registered. To register a profile see, Using UML Profiles.

Invalid XMI Version

Error(2,360): 2.0 is incorrect version for http://schema.omg.org/spec/XMI/2.1

This message occurs because there is a mismatch between the xmi:version attribute and the xmlns:xmi namespace. The xmi:version should be 2.1

Invalid UML Namespace

Warning(2,356): http://schema.omg.org/spec/UML/2.1.1/Unknown is not a recognized namespace.

This message occurs because the xmlns:uml namespace should be http://schema.omg.org/spec/UML/2.1.1/uml.xml

Invalid L2 Standard Profile Namespace

  • Error(13,80): The appliedProfile property has multiplicity [1..1].

  • Error(14,81): Attempt to deference missing element http://schema.omg.org/spec/UML/2.1.1/L2Unknown#_0

  • Warning(2,344): http://schema.omg.org/spec/UML/2.1.1/L2Unknown is not a recognized namespace

This case is when a standard profile is already registered with the tool. Change the XMI so that the xmlns namespace is http://schema.omg.org/spec/UML/2.1.1/StandardProfileL2.xmi and the reference is http://schema.omg.org/spec/UML/2.1.1/StandardProfileL2.xmi#_0.

Invalid L3 Standard Profile Namespace

  • Error(13,80): The appliedProfile property has multiplicity [1..1].

  • Error(14,81): Attempt to deference missing element http://schema.omg.org/spec/UML/2.1.1/L2Unknown#_0

  • Warning(2,344): http://schema.omg.org/spec/UML/2.1.1/L2Unknown is not a recognized namespace

There is a second standard profile already registered. If the profile is incorrectly referenced the messages will be similar to the L2 Profile Namespace. The correct namespace is http://schema.omg.org/spec/UML/2.1.1/StandardProfileL3.xmi and the correct reference is http://schema.omg.org/spec/UML/2.1.1/StandardProfileL3.xmi#_0.

Invalid Standard Data Type Reference

Error(7,75): Attempt to deference missing element http://schema.omg.org/spec/UML/2.1.1/Unknown#String

  • http://schema.omg.org/spec/UML/2.1.1/uml.xml#Boolean

  • http://schema.omg.org/spec/UML/2.1.1/uml.xml#Integer

  • http://schema.omg.org/spec/UML/2.1.1/uml.xml#String

  • http://schema.omg.org/spec/UML/2.1.1/uml.xml#UnlimitedNatural


Using MOF Model Libraries

MOF (Meta-Object Facility) Model Library.jar files enable UML objects from one project to be reused by another.

UML objects can be included in a library in one of two ways:

  • Using JDeveloper's own format

  • Using an .xmi file supplied by a third party, where each object must have an ID that is unique within the file.

In the latter case you could import the XMI file to convert it into JDeveloper's format. However, this does not preserve object identifiers, which might be necessary if you want to be able to export your own models with standardized references to the library objects.

You might find it useful to reference the model libraries found in the JDeveloper installation:

  • .../oracle/jdeveloper/jdev/extensions/oracle.uml.v2

    The two ZIP files in this directory use catalogs.

  • .../oracle/jdeveloper/jdev/extensions/oracle.jdeveloper.db.modeler.transform

    The transform ZIP uses the JDeveloper format.

How to Create an XMI Catalog File

When library objects only have IDs, references to them include the URL of their containing file. By default this is the physical location on disk, which might be machine specific. Instead an alias should be specified for the file in the form of an .xml Catalog file.

Use text editor to create a.xmi file with the following information:

<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE catalog PUBLIC "-//OASIS//DTD XML Catalogs V1.1//EN"  "http://www.oasis-open.org/committees/entity/release/1.1/catalog.dtd"><catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">  <uri name="http://example.oracle.com/MyLibrary.xmi" uri="MyLibrary.xmi"/>  <uri name="http://example.oracle.com/MyLibraryAlias.xmi" uri="http://example.oracle.com/MyLibrary.xmi"/></catalog>

The first URI element maps a standard name to the library file, which is specified relative to the location of the catalog in the library. There should be one of these entries for each .xmi file. Optionally, further URI elements such as the second element above, can be used to specify additional aliases for the standard name. This can be useful if there are multiple versions of the library.

Note that only the above URI element from the OASIS XML Catalog specification is supported.

Create a MOF Model JAR File

To create a MOF model JAR file:

  1. Right-click the project that contains the model and choose Properties. In the Project Properties dialog, choose Libraries and Classpath.

    Click Add Library or Add JAR/Directory to add any .xmi and catalog .xml files to your project's model path. Click OK.

  2. Choose File > New > From Gallery. From the General category, select Deployment Profiles. Choose the MOF Model Library item and click OK.

    1. Specify the name of your deployment profile and click OK. The MOF Model Library dialog opens with JAR Options selected on the left.

    2. In the JAR options area, browse to the location of your JAR file and complete the dialog. Click OK. You return to the Project Properties Deployment page.

  3. In the Deployment Profiles area, double-click the name of your MOF Model Library. Select Library Options in the panel on the left.

    • Enter a name in the Library Name field. It does not have to be the same as the deployment profile name.

    • If you have a catalog file, fill in the MOF Catalog Entry field to specify the catalog location within the JAR file. You can check the file groups to see what will be included in the JAR file.

    • Click OK.

  4. To deploy your changes to the JAR you have just created, right-click the project and choose Deploy > MyMOFLibrary.

Add a MOF Model Library

To add a MOF model library

If you want to add a library to your project add the source path for your MOF Model Library as detailed here. If you redeploy, you can update the JAR with any new changes you make.

  1. Select your project and choose Tools >Manage Libraries. Select the Libraries tab and click the New... button.
  2. In the Library Name field supply your MOF model library name.
  3. Add the root model folders of the JAR to the source path. Right-click the project and choose Properties. Select the Project Source Paths node and in the Java Source Paths area on the right, click the Add button and browse to the library path, and click OK.
Use a MOF Model Library

To use a MOF model library

  1. Create a new project or select an existing project.
  2. View the project properties and choose the Libraries and Classpath node.
  3. Click Add Library and browse to the location of your MOF model library.
  4. Click OK.

Using Transformations

JDeveloper supports UML transformations on your database tables, Java classes, and interfaces.

You can perform transformations multiple times using the same source and target models. There are also some reverse transformations to UML from Java classes.

To perform a transformation:

  • Select UML objects or elements, database tables, or a Java class.

  • From the main menu select Diagram > Transform (the Diagram menu is only visible when a suitable element is selected).

  • Select a transformation type. See Transformation Types.

Transformation Types

Once you start the transformation you must choose one of three transformation types:

    • Model Only. Creates the definitions of the transformed elements, but does not add them to a diagram. The model is created, then displayed in the Applications window in the current project.

    • Same Diagram. Creates transformed elements in the current diagram. The created model can be viewed in:

      • The Applications window.

      • The UML Class diagram. If the conversion is from a database, it will be visible as modeled tables and constraints.

    • New Diagram. Creates a new diagram for the transformed elements. If this is a database, the new class diagram will have classes for each transformed database table.

UML-Java Transformation

You can use the UML modeling tools to create a UML Class model, and then transform it to Java, or vice-versa.

Transform UML to Java

  1. Select the UML elements to transform.
  2. Select the transformation type, as described in Transformation Types.
  3. Click OK, as shown in Figure 5-20.

Figure 5-20 Transform Dialog Showing UML Options

This image is described in the surrounding text

Transform Java to UML

  1. Select the Java Element to transform and select Transform from the context menu.
  2. Select the transformation type, as described in Transformation Types.
  3. Click OK, as show in Figure 5-21.

Figure 5-21 Transform Dialog Showing Java to UML Options

This image is described in the surrounding text

UML-Offline Database Transformation

You can use the UML modeling tools to create a UML Class model, and then transform it to Java, or an offline database.

Transform an Offline Database Diagram to UML

  1. Select the offline database object or objects you want to transform.
  2. Right-click and choose Transform.
  3. Select the transformation type, as described in Transformation Types.
  4. The Transform dialog appears as shown in Figure 5-22. Select Offline Database Objects to UML.
  5. Click OK.

    Figure 5-22 Transformation Dialog Showing Offline Database to UML Dialog Option

    This image is described in the surrounding text

Transform UML to Offline Database Objects

  1. In the Applications window, select the project containing the UML classes to transform.
  2. Choose File > New > From Gallery.
  3. Expand the Database Tier and choose Offline Database Objects.
  4. From the items list, choose Offline Database Objects from UML Class Model and click OK.

    The Offline Database Objects from UML Class Model wizard opens.

    When you invoke the wizard from the New Gallery, the offline database objects created during the transformation process are only available in the Applications window.

  5. Specify settings.
    • Default. Resets the settings in Table 5-2 to default values.

    • Previous Transformation. When you have previously run the wizard in this session of JDeveloper you can select this option to use the last set of transform settings.

    • Previously saved file. Select to use transform settings saved to a file. See Transformation Settings, and Table 5-2.

  6. Specify source. Expand the folders on the left, select the elements to be transformed for the database model and use the > arrow to move them to the Selected list. See Figure 5-23.

    Figure 5-23 Create Offline Database from UML Class Model Example

    This image is described in the surrounding text.
  7. Specify Target. Specify the target database and its schema. Click Help for an explanation of each option.
  8. Set Naming Options. Select the UML name conversion formats.
  9. Set Hierarchy Options. Specify the transformation rule and enable/disable creation of an intersection table. Click Help for an explanation of each option, and see Set Hierarchy Options, for a detailed discussion.
  10. Set Logging Options. Select the messages to be logged.
  11. Inspect a preview. The final page of the wizard gives you the opportunity to view the database model, and to save the transformation settings to a file. See Table 5-2.
  12. Click Finish. The offline database objects are created and displayed in the Applications window. The transformation settings are saved (if you have enabled that option).

Transform UML Classes on a Diagram to an Offline Database

  1. Open the diagram to transform.
  2. Select the elements to transform. Right-click and choose Transform.
  3. Select the transformation type, as described in Transformation Types.

    Figure 5-24 Transform Dialog Showing

    UML to DB transform options
  4. Choose UML to Offline Database.
  5. The transform wizard opens and you can select the options for the transformation, similar to Transform UML to Offline Database Objects, steps 5 through 12.

Set Hierarchy Options

There are four types of generalization to specify on the Set Hierarchy Options page on the Create Offline Database Objects from UML Class Model wizard.

The options are:

  • Transform root classes

  • Transform leaf classes

  • Transform all classes, with generalization

  • Transform all classes, creating foreign keys

Consider the case of two root classes and three leaf classes, as shown in Figure 5-25.

Figure 5-25 Diagram Showing Two Root and Three Leaf Classes

This image is described in the surrounding text

If you select the option Transform Root Classes, root classes are transformed into offline tables, and all the attributes and foreign keys from their descendant classes in the hierarchy are also transformed as shown in Figure 5-26. You also have an option of creating a discriminator column. The discriminator column contains marker values for the persistence layer to decipher what subclass to instantiate for a particular row.

Figure 5-26 Transformed Root Classes

This image is described in the surrounding text

If you select the option Transform leaf classes, leaf classes are transformed into offline tables, and they inherit their columns and foreign keys from their ancestor classes, as shown in Figure 5-27.

Figure 5-27 Leaf Classes Transformed Inheriting From Generalized Classes

This image is described in the surrounding text

If you select the option Transform all classes, with inheritance, an offline table is created for every class in the transform set. Each table inherits columns and foreign keys from its ancestor tables but is otherwise independent, as shown in example Figure 5-28.

Figure 5-28 All Classes Transformed, Inheriting from Generalized Classes

This image is described in the surrounding text

If you select the Transform all classes, creating foreign keys option to generalized classes, an offline table is created for every class in the transform set. No columns or foreign keys are inherited; a foreign key is created to the parent table or tables, as shown in Figure 5-29.

Figure 5-29 All Classes Transformed with Foreign Keys

This image is described in the surrounding text

Transformation Settings

Table 5-2 shows the information that can be saved when you choose the Save Transform Settings to File option on the final page of the Create Offline Database Objects from UML Class Model wizard. See Step 12 in Transform UML to Offline Database Objects.


Table 5-2 Transform Settings That Can Be Saved

Transform Settings Page in Wizard and Notes

Target project and offline database

Specify Target. Specify where to transform the UML objects to.

Offline schema

Specify Target. The schema to transform the objects into.

Note that if you select Choose Schema and specify a schema which does not exist it will be created. If you transform once to a new schema, rename the schema then transform again reusing the same settings the old schema is recreated and the transformed objects will be created there.

UML name conversions

Set Naming Options. Specify the rule for capitalizing and pluralizing UML names.

Invert role names

Set Naming Options. Specify whether to use the role names at the adjacent or opposite ends of a UML association when creating foreign key columns.

Add comment option

Set Naming Options. Specifies whether the new offline database objects should have comments explaining how they were created.

Hierarchy options

Set Hierarchy Options. Determines how classes in a hierarchy should inherit attributes and associations when they are transformed into tables.

Many-to-many associations

Set Hierarchy Options. Specifies whether to create intersection tables for many-to-many associations.

Log messages

Set Logging Options. Specifies type of messages to log (Error, Warning, Information, Create and Progress).


Reuse Transform Settings

  1. In the Applications window, select a class and from the context menu, select New > Database Objects from UML Class Model.
  2. On the Specify Settings page, you can specify the transformation settings as discussed in Transform UML to Offline Database Objects, Step 5. If you make a change on the Settings page, and continue using the wizard, you can use the Back button to return to the Specify Settings page. In this case you will see the Reapply Settings option, which you can choose to change the initial settings for this wizard.

Using DatabaseProfile for UML Transformations

JDeveloper comes with a UML profile called DatabaseProfile which determines how class models are transformed to offline database models. For more information about UML profiles, see Using UML Profiles.

DatabaseProfile contains stereotype properties that control how elements are transformed. The stereotypes and their properties in this profile are described in Table 5-3.


Table 5-3 Stereotypes and Properties in DatabaseProfile

Stereotype Applied to Offline Database Type Properties Notes

Database Package

UML::Package

SCHEMA

Name after transform

 

Database Class

UML::Class

TABLE

Name after transform

 

Database Attribute

UML::Property

COLUMN

Datatypes, Primary

A UML Property can be an attribute or an association end.

Database Datatype

UML::Type

n/a

Datatype

In the metamodel, Type is the superclass for a large range of elements, including, Class, Association, PrimitiveType and so on. This stereotype can be applied to all of them. It can be read by the transformer whenever a property (attribute) is of a certain type.

Database Constraint

UML::Constraint

CONSTRAINT

Name after transform, Body

Creates a check constraint against the transformed table.

Database Association

UML:: Association

CONSTRAINT

Foreign Key naming rule

 

Database Generalization

UML:: Generalization

CONSTRAINT

Foreign Key naming rule

Certain transforms create foreign keys out of generalizations and this stereotype can apply here.


The attributes, or properties, are described in Table 5-4.


Table 5-4 Properties of Stereotypes in DatabaseProfile

Property Description Type

Name after transform

The name of the transformed database object. If blank, default naming rules are applied.

String

Body

The SQL code for the check constraint.

String

Datatype

SQL text of the datatype.

There are a number of datatypes, including default, ansi, Oracle, and other supported database types.

String

Foreign key naming rule

The rule to use when naming a foreign key from an association: use the UML name, use the databaseName property, or derive a default name from the table names.

Both Tables Database Name Owning Name UML Name

Primary

Flag to indicate that transformed column is part of the primary key for the parent table.

Boolean


Use DatabaseProfile to Transform a Class Model

You can transform a class model using DatabaseProfile.

  1. In the application window, right-click on a UML package (package.uml_pck) and choose Properties.
  2. In the Package properties Structure pane, select Profile Application and click Add (+).
  3. Select DatabaseProfile from the list of available profiles, as shown in Figure 5-30. Click OK. A new file DatabaseProfile.uml_pa is now listed in the Applications window, as shown in Figure 5-31.

    Figure 5-30 Package Properties Database Profile

    This image is described in the surrounding text

    Figure 5-31 Profile Application Properties

    This image is described in the surrounding text
  4. Now you can apply stereotypes to the various elements in the project. In the example shown in Figure 5-31, you apply stereotypes to the Employee class by right-clicking Employee.uml_cla and choosing Properties. This opens the Class Properties dialog for that element.

    To specify the name to use after transformation, select Applied Stereotype, click Add, and choose Database Class. Under Properties, enter a value next to Name after Transform, as shown in Figure 5-15.

  5. Once you have set the stereotypes to apply, proceed to transform the UML Class model following the steps in UML-Offline Database Transformation. The stereotypes and properties in DatabaseProfile you set are applied during transformation. See Table 5-2.

You can apply stereotypes to other elements as well. For example, you can specify datatypes and a primary key to attributes owned by a particular class. In the same Class Properties dialog, expand Owned Attribute. and select an existing attribute, or create one by clicking Add and entering a name for it.Expand the node for the owned attribute, select Applied Stereotype and click Add. Figure 5-32 shows that at this level you can specify a number of datatypes, whether the attribute should be transformed to a primary key, and the name after transform.

Figure 5-32 Database Attributes for Applied Stereotypes

This image is described in the surrounding text

For information about the stereotypes and properties covered by DatabaseProfile, see Table 5-3 and Table 5-4.

Logging Options

  1. Select a class diagram and from the context menu, select New > Offline Database Objects from UML Class Model. The wizard opens.
  2. On the Set Logging Options page, choose the type of actions you want logged.

UML-ADF Business Components Transformation

If you have a UML class diagram it can be transformed to ADF Business Components using much the same process described in UML-Offline Database Transformation.

  1. In the Applications window, select the project containing the UML classes to transform.
  2. Right click on the class to be transformed and select Transform from the context menu.
  3. Select the transformation type, as described in Transformation Types.
  4. You are prompted to create a database to contain the transformed components. After the database connection the creation of the ADF Business component proceeds in the same manner as the creation of a new ADF Business component diagram.

Modeling with UML Class Diagrams

In UML class diagrams classes are represented as rectangles containing class name and details. On the diagram, classes and interfaces are divided into compartments, with each compartment containing only one type of information, as shown in Figure 5-34. The possible elements are listed in Table 5-5. Classes can be displayed as compact, symbolic or expanded nodes.

Figure 5-33 UML Class Diagram with Elements

This image is described in the surrounding text

Table 5-5 Elements in Class Diagram

Elements Description

* to * Association

Defines a many‐to‐many relationship between UML classes.

1 to * Association

Defines a one‐to‐many relationship between UML classes.

1 to * Association Class

Defines a non-directed one‐to‐many association class.

Class

Represents an object. Classes form the main building blocks of an object-oriented application. Represented on the diagram as a rectangle containing three compartments stacked vertically.

Constraint

Constraints are the degree of freedom, or lack thereof that you have in modeling a system behavior, or solution.

Constraint Attachment

Attaches constraints to other UML elements.

Data Type

Data types are modeled elements that define your data values.

Directed 1 to * Association

Directed One to Many Association is represented on the diagram as a solid line with an open arrowhead in the direction of more than one association.

Directed 1 to 1 Association

Directed One to One Association is represented on the diagram as a solid line with an open arrowhead in the direction of the association.

Directed Composite Aggregation

Represented on the diagram as a solid line with an open arrowhead in the direction of the association and a filled diamond shape at the originating end of the association.

Enumeration

Enumerations are data types with a finite, and normally small, set of named literals. Enumerations contain sets of named identifiers that are its values.

Generalization

Defines generalization relationships between classifiers. Represented on the diagram as a solid line with an empty arrowhead pointing towards the specialized classifier or interface.

Interface

Interfaces are represented with a keyword in the name compartment: «interface». Interfaces can be displayed as compact, symbolic, or expanded nodes. Nested classes and interfaces can be modeled inside standard and expanded interfaces.

Package

Use to divide a system into multiple packages, which can simplify and make the system easier to understand.

Primitive Type

Primitive types or data types are data types such as boolean, byte, decimal, DateTime, Double Float, and Time.

Realization

Defines where an interface is realized by a class. Represented on the diagram as a dashed line with an empty arrowhead pointing towards the implemented interface.


Creating a UML Class Diagram

Follow these steps to create a UML class diagram:

  1. Right-click the project and select New > From Gallery.

  2. In the General category, select the UML node. In the Items pane, select Class Diagram, and click OK.

    1. Give the diagram a name that is unique within this package.

    2. Select or browse to the owning package for this diagram.

  3. Click OK.

Figure 5-34 shows an example of a typical class diagram layout. All attributes and operations display symbols to represent their visibility. The visibility symbols are: + Public, - Private, # Protected, and ~ Package.

To set the diagram display properties go to Tools > Preferences > Diagrams > Class and choose Diagram.

You can also change the way elements are represented on a diagram. An ellipsis (...) is displayed in each compartment when not large enough to display its entire contents. To display all the attributes of a modeled class, right-click the class and choose Optimize Shape Height.

Working with the Class Diagram Features

The components window contains the elements available for your class diagram, as shown in Figure 5-35 and described in Table 5-5.

Create classes and interfaces by dragging the class onto the diagram. The element is created in the location specified by the model path in your project settings and default properties. (Application > Default Project Properties). You can also model packages by clicking on the package. If you right-click a modeled package and choose Drill Down, a diagram is displayed for that package.

Class properties are added to modeled classes and interfaces on a diagram by doing one of the following:

  • Double-click the modeled class or interface to access the properties dialog.

  • Right-click the class or interface and choose Properties.

Figure 5-34 Class Diagram Components window

This image is described in the surrounding text

How to Create Classifiers, Constraints, and Packages

You can create classifiers, constraints and packages in the same way you create diagram nodes, as discussed in Working with Diagram Nodes. except choose Class from the Components window dropdown. The new object is created in a package that matches the folder in which the diagram is contained.

How to Create Attributes

There are several ways to create an attribute:

  • Double-click the modeled class or interface, then add the attribute using the element property dialog.

  • Right-click the class or interface and choose Properties, then add the attribute using the element property dialog.

  • Drag an existing attribute from one class or interface on a diagram to another class or interface on the same diagram.

To arbitrarily change the order of an attribute within a class, disable the Sort Alphabetically option and drag the attribute up or down on the screen. Select Tools > Preferences, open the Diagrams node and choose Class. From the Edit Preferences for: dropdown, select Class or Interface. Click the Attributes or Operations tab and deselect Sort Alphabetically).

How to Add Nested Classes and Nested Interfaces

Nested classes and nested interfaces are created either by creating them in the modeled class or interface using in-place create (with symbolic presentation only) and by changing shape display preferences, or by right-clicking the class and choosing View As > Expanded then creating another class inside the expanded node.

How to Add Attributes and Operations

Attributes and operations are added to modeled classes and interfaces by doing any of the following:

  • Double-click the modeled class or interface, then add the attribute or operation using the element property dialog.

  • Right-click the class or interface and choose Properties, then add the attribute or operation using the element property dialog.

  • Drag an existing attribute or operation from one class or interface on a diagram to another class or interface on the same diagram.

    The order of an attribute or operation within a class or interface is changed by dragging it up or down on the screen. The Sort Alphabetically property for attributes or operations must be deselected: (Tools >Preferences > Diagrams > Class > Edit Preferences for: Class or Interface | Attributes or Operations | Sort Alphabetically).

How to Hide Attributes and Operations

Use the right-click context menu to hide or show attributes and operations elements on your diagram.

To hide one or more attributes or operations:

  1. Select the attributes or operations to hide.
  2. Right-click the selected items and choose Hide > Selected Shapes. To show attributes or operations choose Show All Hidden Members.

How to Add Generalizations, Realizations, and Associations

Generalized structures are created on a diagram of classes by using the Generalization icon on the Class Components window.

Where an interface is realized by a class, model it using the Realization icon on the Class Components window for the diagram.

A variety of associations can be created between modeled classes and interfaces using the association icons. Associations are modified by double-clicking the modeled association and changing its properties.

Modeling with Activity Diagrams

Use activity diagrams to model your business processes. Your business processes are coordinated tasks that achieve your business goals such as order processing, shipping, checkout and payment processing flows.

Activity diagrams capture the behavior of a system, showing the coordinated execution of actions, as shown in Figure 5-36.

Figure 5-35 Sample Activity Diagram Showing Elements

This image is described in the surrounding text

Working with the Activity Diagram Features

The Components window contains the elements available for your activity diagram. An Activity is the only element that you can place directly on the diagram. You can place the other elements inside an Activity. Each of the elements is represented by unique icons as well as descriptive labels, as shown in Figure 5-37 and Table 5-6.

Figure 5-36 Components window for Activity Diagram

This image is described in the surrounding text

Table 5-6 Activity Diagram Elements

Element Description

Action

An action is the fundamental unit of behavior specification, for example, Send Invoice or Receive Payment. It represents a single step within an activity. An action takes a set of inputs and converts them into a set of outputs. The execution of an action represents some transformation or processing in the modeled system.

An action may receive inputs in the form of control flows and object flows (the latter via input pins) and passes the results of its processing or transformations to outgoing control flows or object flows (the latter via output pins) and onto downstream nodes. Execution of the action cannot begin until all its prerequisites are satisfied.

Activity

A behavior performed by a system, for example a business process. An activity is a behavior defined by its owned actions, object nodes and the flows between them.

Activity Final Node

Terminates the execution of the activity when it first receives a control token. There can be multiple final nodes in an activity. An Activity Final Node indicates that every action on this diagram has finished.

Fork/Join

Displayed as a vertical or horizontal bar. A Fork is a control node that has a single incoming flow and two or more outgoing flows. A Join is a control node that synchronizes a number of incoming flows into a single outgoing flow. Fork/Join pairs can be combined as a single diagram node.

Call Behavior Action

Maps the action inputs and outputs are simply mapped to the behavior parameters as appropriate.

Call Operation Action

Transmits an operation call request to the target object, where it may cause the invocation of associated behavior. The behavior results become the action outputs. The argument values of the action are available to the execution of the invoked behavior.

Central Buffer

A type of object node. It gives the node the capability of storing (buffering) tokens. It manages the tokens that arrive at incoming flows from one or more object nodes and selects which tokens and in what order these tokens will be presented to the downstream object nodes via the outgoing flows.

Control Flow

Shows the flow of control tokens.

Data Store

A type of object node that passes a buffer for non-transient data.

Flow Final Node

Terminates any incoming flow without terminating the execution of the entire activity.

Initial Node

The starting point for executing an activity. It has no incoming flows and one or more outgoing flows. There can be only one initial state on a diagram.

Object Flow

Connects object nodes. Object flows can be connected to actions using pins.

Merge Node

A merge node has two or more incoming flows and a single outgoing flow. A Decision has one incoming flow and two or more outgoing flows


How to Create an Activity Diagram

Use the New Gallery wizard to create your activity diagram following the steps in Creating a New Diagram.

How to Create Initial and Final Nodes

To create nodes, click the Initial Node icon, the Activity Final Node icon, or Final Flow Node icon in the Component window, then click on the diagram where you want to place the node.

How to Show Partitions

You create partitions on a diagram by selecting an action, then selecting Show Activity Partition under Display Options in the Properties window.

To show a partition on an activity diagram:

  1. In the activity diagram, select an action.
  2. In the Properties window, expand the Display Options node.
  3. Select Show Activity Partition. The action on the diagram displays the text, (No Partition).
  4. Click on the text. An editing box appears where you can enter a name for the partition.

Modeling with Sequence Diagrams

The sequence diagram describes the interactions among class instances. These interactions are modeled as exchanges of messages. At the core of a sequence diagram are class instances and the messages exchanged between them to show a behavior pattern, as shown in Figure 5-38.

Figure 5-37 Typical Sequence Diagram Example

This image is described in the surrounding text

Working with the Sequence Diagram Features

The elements you add from the Components window are laid out in a default position on your sequence diagram. Lifelines are aligned vertically, unless they are related to another Lifeline, in which case they are aligned with the create message. Synchronous and asynchronous calls and are placed in time order down the page.

Figure 5-39 displays the elements in the Components window available to use in your sequence diagram. Each element is represented by a unique icon as well as a descriptive label.

Figure 5-38 Sequence Diagram Components window

This image is described in the surrounding text

Table 5-7 Sequence Diagram Elements

Element Description

Asynchronous Call

Represented on a diagram by a diagonal line with an open arrowhead. An asynchronous call is one for which the sender does not have to wait for a response before continuing with processing.

Creation Message

Represented on a diagram by the shifting down, relative to the originating object, of the rectangle and dashed line that represents the object to be created. A creation message is a message that leads to the creation of an object

Interaction

Captures the behavior of a single case by showing the interaction of the objects in the system to accomplish the task.

Message

A message is a model element that defines a specific kind of communication between participants in an interaction. A message conveys information from one participant, which is represented by a lifeline, to another participant in an interaction.

Lifeline

Represented on a diagram by a rectangular box with a vertical dashed line descending beneath it. A Lifeline represents the existence of an object over a period of time

Return

A return message is a message that returns from an object to which a message was previously sent. Return messages are valid only from synchronous calls, and are themselves synchronous.

Stop or Destroy Message

Represented on a diagram by showing the execution specification at the end of the message with a large cross through it. A stop message is a message that leads to the deletion of an object (or to the indication that an object is no longer needed).


How to Add and Create a Sequence Diagram

Use the New Gallery wizard to create your activity diagram following the steps in Creating a New Diagram.

How to Start a Sequence Tracer

On any part of the sequence diagram, open the context menu and choose Trace Sequence. The tracer steps through each of the execution specifications and messages, highlighting each one.

Note:

Trace Sequence is available for a selected Interaction. It does not appear in the context menu for the diagram.

How to Automatically Layout Elements in an Interaction

You can right-click an Interaction and choose Sequence, then Automatic Layout to autolayout the elements within the Interaction.

How to Add Lifelines and Classifiers

You add Lifelines to a sequence diagram by first adding an interaction then clicking on the Lifeline icon, and then clicking on the interaction. An edit box opens for you to enter an instance name for the object. This can be left blank for anonymous instances.

You can add a classifier by right-clicking on the Lifeline and choosing Attach Classifier, which opens a list of elements from which you choose the one you want associated with the Lifeline. Another way to attach a classifier is to drag the classifying object from the databases window onto the Lifeline. These methods are confirmed by the appearance (in the top left of the Lifeline) of an icon representing the classifying element.

How to Create a Synch Call

You add a synchronous call by clicking on the Message icon, then clicking on the vertical dashed line or execution specification that is the starting point for the message, and then on the vertical dashed line that is the destination of the message.

Open an editing box for the text by clicking on the message line and then clicking inside the gray box that appears.

The starting point and destination point of a synchronous call can be the same Lifeline, in which case you have created a self call.

Synch calls are depicted on the sequence diagram by solid lines with filled arrowheads.

How to Work With Execution Specifications

Merge execution specifications by overlapping them on the diagram. Then right-click and choose Merge Overlapping Occurrences.

You can move an execution specification (and the messages attached to it) to a position higher or lower than its original one. In some cases this will result in an invalid diagram. When this happens, the message line will turn red and the destination object will contain an arrow icon which indicates the direction the object should be moved, to make the diagram valid.

To resize an execution specification box, drag the small black box that appears on the lower edge when you select it. An execution specification will be resized if you drag a message line extending from it.

How to Add a Create Message

Add a creation message by clicking on the Creation Message icon, then on the originating object, then on the object to create. The rectangle and dashed line that represents the object is shifted down the page relative to the originating object.

If the object to be created is not already on the diagram, click within the interaction that contains the originating object to create an Lifeline representing the object. By default, a creation message is given the name "create". You can open an edit box for the message name by clicking on the message line and then clicking inside the gray box that appears.

How to Create a Delete Message

Before you add a stop or destroy message, you must already have added an Lifeline for the object that the message deletes.

Add a stop or destroy message by clicking on the Stop or Destroy Message icon, then on the originating object, then on the lifeline to delete. If you start and end the stop message on the same object, you will create a self-deleting object. The execution specification at the end of a stop message is shown with a large cross through it. You can open an edit box for the message name (for example, close) by clicking on the message line and then clicking inside the gray box that appears.

How to Create a Reply Message

Add a return message by clicking on the Return icon, then on an end execution specification, then on the corresponding start execution specification. You will not be able to end this return message line on any other object. The return message is depicted by a dashed line with a filled arrowhead. You can open an edit box for the text of the message by clicking on the message line and then clicking inside the gray box that appears.

How to Create an Async Call

Add an asynchronous call (and the execution specifications at each end) by clicking on the Async Message icon, then clicking on the vertical dashed line or execution specification that is the starting point for the message, then on the vertical dashed line that is the destination of the message. You can open an edit box for the text of the message by clicking on the message line and then clicking inside the gray box that appears.

The starting point and destination point of an asynchronous call can be the same Lifeline, in which case you have created a self call.

Asynchronous calls are depicted on the sequence diagram using diagonal lines and open arrowheads.

Using Combined Fragments

A combined fragment defines an expression of an interaction defined by an interaction operator and corresponding interaction operands. A Combined Fragment reflects a piece or pieces of interaction (called interaction operands) controlled by an interaction operator, whose corresponding boolean conditions are known as interaction constraints. It displays as a transparent window, divided by horizontal dashed lines for each operand.

Figure 5-40 shows a loop fragment that iterates through purchase items, after the cashier requests payment. At this point, two payment options are considered and an alternative fragment is created, divided to show the two operands: cash and credit card. After the fragment completes its trace, the cashier gives a receipt to the customer, under the fulfilled condition of payment requirements met.

Figure 5-39 Typical Sequence Diagram with Combined Fragments

This image is described in the surrounding text

Figure 5-41 shows the combined fragments that display in the Components window when your diagram is open in the diagramming window.

Figure 5-40 Combined Fragments in Components window

This image is described in the surrounding text

Table 5-8 Combined Fragments Interaction Operators

Interaction Operator Description

alt

Use to divide up interaction fragments based on Boolean conditions.

assert

Use to specify the only valid fragment to occur.

Break

Use to designate that the combined fragment represents a breaking scenario in the sense that the operand is a scenario that is performed instead of the remainder of the enclosing interaction fragment.

Critical

Use to indicate a sequence that cannot be interrupted by other processing.

Loop

Use to indicate that the operand repeats a number of times, as specified by interaction constraints.

Neg

Use to assert that a fragment is invalid, and implies that all other interaction is valid.

Opt

Use to enclose an optional fragment of interaction.

Par

Indicate that operands operate in parallel.

Seq

Use to indicate that the combined fragment is weakly sequenced. This means that the ordering within operands is maintained, but the ordering between operands is undefined, so long as an occurrence specification of the first operand precedes that of the second operand, if the occurrence specifications are on the same lifeline.

Strict

Use to indicate that the behaviors of the operands must be processed in strict sequence.


On your sequence diagram interactions you will see combined fragment lock icons. Locking and unlocking an interaction allows you to keep the combined fragment behavior within that interaction on that diagram, or extend its reach to other interactions and other diagrams.

Modeling with Use Case Diagrams

Use case diagrams capture the requirements of your system, as shown in Figure 5-42.

Figure 5-41 Typical Use Case Diagram

This image is described in the surrounding text

Working with the Use Case Diagram Features

Use case diagrams express the declared behaviors of your system and how systems and entities interact with it according to subject and actor use cases.

Figure 5-42 displays the Components window with the elements available to add to your use case diagram. Each element is represented by a unique icon and descriptive label.

Figure 5-42 Use Case Elements in the Components window

This image is described in the surrounding text

Table 5-9 Use Case Elements

Component Description

Actor

Represents an abstract role within a system.

Communication

Identifies where an actor is associated with a particular use case.

Dependency

Shows a relationship between one element and another.

Extend

Shows a target use case extends the definition of a source use case.

Generalization

Identifies where one or more elements specialize another element. For example, an actor Team Member could be specialized to actors Manager and Developer.

Include

Shows a relationship in a use case that includes another use case.

Subject

Two types of subjects are available. One system usually contains sets of use cases and actors that comprise the whole system being modeled. The second type usually contains groups of use cases that comprise a coherent part of the system being developed.

Use Case

Indicates that one element requires another to perform some interaction.


Getting A Closer Look at the Use Case Diagram Elements

You can determine the appearance and other attributes for subject, actor and other objects of these types by modifying the properties in the Properties window, or by right-clicking the object and modifying the properties.

Figure 5-43 Use Case Subject, Actor and object Example

This image is described in the surrounding text

How to Add a Subject to a Use Case Diagram

You can show the system being modeled by enclosing all its actors and use cases within a subject. Show development pieces by enclosing groups of use cases within subject lines. Add a subject to a diagram by clicking on Subject in the Components window, then drag the pointer to cover the area that you want the subject to occupy. Figure 5-44 shows an accounting subject attached to their related actors. If you drop an element just inside a subject, the subject line expands to enclose the element. You also can manually resize subjects. If you reduce the size and there are elements that can no longer be seen, an ellipsis appears in the lower right corner.

How to Create Actors and Use Cases

Create actors on a diagram by clicking on the Actor icon on the Components window, and then clicking on the diagram where you want to create it.

To change the properties of an actor or use case, double-click on the modeled element and edit the element details in the editor.

How to Represent Interactions Between Actors and Use Cases

An Interaction is the only element you can add directly to the diagram. You put all of the other elements within an Interaction.

You can represent interactions between actors and use cases on a diagram using the Communication icon on the Components window. You can create generalization structures between actors and between use cases by using the Generalization icon. To represent where one use case includes another, use the Include icon, and to represent where one use case extends another use the Extension icon.

You can annotate a diagram of use cases using notes, dependency relationships and URL links. Annotation components are available at the lower part of the Components window under Diagram Annotations.

How to Represent Relationships Between Use Cases and Subjects

You can represent interactions between use cases and subjects using the Communication icon on the Components window.

Exporting a Use Case Model for the First Time

The Use Case modeler can generate a set of HTML files from a Use Case model. Each HTML file corresponds to one of the Use Case elements. The HTML files are generated in the same project as their relative UML elements, therefore, they are visible in the Application Navigator and they can be opened and edited with an editor.

To generate HTML files from an existing use case model, right-click on the diagram surface and choose Export to HTML as shown in Figure 5-45.

Figure 5-44 Export HTML from a Use Case Model

Right-click on the background and choose Export to HTML

The Exporting Model dialog displays the changes in the model that are about to be exported, as shown in Figure 5-46.

Figure 5-45 Changes to Be Exported

This table shows the UML to HTML exportation change details.

The Exporting Model dialog is a table whose rows represent the details of the changes to be exported. The right‐hand column shows the type of model change. There are three types of changes:

  • Added. The Use Case element does not have a corresponding HTML file yet.

  • Deleted. The Use Case element has been removed form the model but there is still its corresponding HTML file in the project.

  • Changed. The Use Case element has been changed in the model and thus it differs from its corresponding HTML file.

The first column of the table contains a check box that enables/disables exporting of the relative model change. Be default, all the check boxes are selected.Once the dialog is confirmed, the HTML files are generated and they will appear in the Application Navigator together with the existing Use Case model elements. The suffixes of the generated HTML files are.xhtml rather than.uml.

Figure 5-46 Exported Model

exported model has .xhtml sources

Exporting a Changed Use Case Model

When a Use Case model has been exported it is still possible to modify it and propagate the new changes to the existing generated set of HTML files. Suppose we change Figure 5-47 as shown in Figure 5-48:

Figure 5-47 Use Case Model Modified after Export to HTML

A previously exported diagram that has been modified

After export the details for the modified model are as shown in Figure 5-48:

Figure 5-48 Exporting a Changed Model

column on right shows states for exported model

As we can see, the new use case "Select Class" is added to the set of HTML files, while the use case "Select Seat" is removed. The Subject "Booking System Flight Booking" is changed because it contains a new use case, and the use case "Upgrade Flight" is changed because it includes a different use case from before. Once the dialog is confirmed, the changes are applied and they are reflected in the Application Navigator, which now lists the new use case "Select Class" but no longer lists "Select Seat," as shown in Figure 5-50.

Figure 5-49 The Changed Model Following Export

This image is described in the surrounding text

Importing a Use Case Model from a Set of HTML Files

A Use Case model can also be imported from a set of HTML files that contain the "uml" custom tags. However, creating a Use Case model first entirely in HTML and then importing it into the Use Case modeler it is not recommended. The import functionality exists mainly to allow you to make occasional small changes to the HTML files and apply them to the Use Case model. The HTML files can be edited with the built-in HTML editor in JDeveloper or with any other external text editor.

Editing the HTML Files

The HTML files can be edited by double-clicking on their entries in the Application Navigator to open them in the HTML source editor in the main editor panel. The files consist of a HTML document (precisely, XHTML), embedding the UML namespace tags.

Figure 5-50 Editing an HTML Use Case

use case in editor, communication selected

Figure 5-51 shows the editor with the content of a UseCase HTML file. It shows the Communicate association to the relative actor, which is an HTML link contained by the <uml:usecase_communicates> element. For example, if we need to remove that associations, we simply remove the anchor element from the enclosing HTML list element, as shown in Figure 5-52.

Figure 5-51 Removing Communication Use Case

remove the uml element without changing the HTML structure

To add that Communicate association to a different UseCase, open the HTML files and locate the "<uml:usecase_communicates>" element. Then insert the anchor element previously removed into the list element, as shown in Figure 5-53.

Figure 5-52 Adding the Communication Use Case

add communication association to a different use case

Importing from HTML files

Make sure all the changed HTML files have been saved before performing the import. Right-click on the diagram to display the context menu and choose Import from XHTML. The "Importing Model" dialog displays the changes to be applied to the model, as shown in Figure 5-54.

Figure 5-53 Importing a Model

Importing Model dialog displays html file changes

The dialog shows that the changes made to the two HTML files will be applied to the corresponding UseCase elements in the model. Confirming the dialog will cause a new Communicate association to be drawn between the actor and the "Upgrade Flight" UseCase, and between the same actor and the "Book Flight" UseCase removed from the diagram.

Figure 5-54 Revised Model After Import

This graphic is described in the surrounding text

Modeling with Profile Diagrams

Profiles allow adaptation of the UML metamodel for different platforms and domains or your modeled business processes.

The profile diagram is structure diagram which describes the lightweight extension mechanism to UML by defining custom stereotypes, tagged values, and constraints.Stereotypes are specific metaclasses, tagged values are standard meta-attributes, and profiles are specific kinds of packages. Metamodel customizations are defined in a profile, which is then applied to a package.

Profiles can be dynamically applied to or retracted from a model. They can also be dynamically combined so that several profiles will be applied at the same time on the same model. Profiles only allow adaptation or customization of an existing metamodel with constructs that are specific to a particular domain, platform, or method. You can't take away any of the constraints that apply to a metamodel, but using profiles, you can add new constraints.

How to create a profile diagram:

  1. Select File > New. The New Gallery opens.

  2. In the Categories panel, open the General node and select the UML node. The UML elements are listed in the Items panel.

  3. In the Items panel, select Profile Diagram, and click OK.

  4. Supply the profile diagram details and click OK. The profile diagram is added to the applications window.

See Using UML Profiles for instructions on how to export a profile as XMI, add a profile to a diagram, and apply a profile to a UML package.

Figure 5-55 Profile Diagram

Profile diagram with profile and stereotype applied

Modeling with Java Class Diagrams

The definitions of the classes on a diagram, their members, inheritance, and composition relationships are all derived directly from the Java source code for those classes. These are all created as Java code, as well as being displayed on the diagram. If you change, add to, or delete from, the source code of any class displayed on the diagram, those changes will be reflected on those classes and interfaces on the diagram. Conversely, any changes to the modeled classes are also made to the underlying source code. Some information relating to composition relationships, or references, captured on a Java class diagram is stored as Javadoc tags in the source code.

A Java class diagram can contain shapes from other diagram types (Oracle ADF Business Components, UML elements, Enterprise JavaBeans, and database objects).

How to Create Java Classes, Interfaces and Enums

Java classes, interfaces, or enums are created on a diagram by clicking on the Java Class icon, Java Interface icon or Java Enum icon on the Java Components window for the diagram, and then clicking on the diagram where you want to create the class. The Java source file for the modeled class or interface is created in the location specified by your project settings.

Java Class, Java Interface, and Java Enum icons are represented on a diagram as rectangles containing the name and details of the Java class. Java classes and interfaces are divided into compartments, with each compartment containing only one type of information.

An ellipsis (...) is displayed in each compartment that is not large enough to display its entire contents. To view a modeled class so that all the fields and methods are displayed, right-click the class and choose Optimize Shape Size, then Height and Width.

Each type of class on a diagram is identified by a stereotype in the name compartment. This is not displayed by default.

Members (fields and methods) display symbols to represent their visibility. The visibility symbols are: + Public, - Private, # Protected. If no visibility symbol is used, the field or method has package visibility.

How to Model Inner Java Classes and Interfaces

A diagram can include primary or inner classes from different packages, the current application, or from libraries. Inner Java classes and inner interfaces are defined as members of their 'owning' class. Hence, they are also referred as member classes.

Inner classes and inner interfaces are displayed in the inner classes compartment of the modeled Java class or interface on the diagram. Inner classes are prefixed with the term Class, and inner interfaces are prefixed with the term Interface, between the visibility symbol and the class or interface name.

To create an inner class or inner interface on a modeled Java class or interface, either add the inner class to the implementing Java code, or create a new Java class or interface as an internal node on an existing modeled class.

Inner Java classes and inner Java interfaces cannot have the same name as any containing Java class, Java interface or package or contain any static fields or static methods.

Modeling Composition in a Java Class Diagram

A variety of references (previously referred to as associations) can be created quickly between classes and interfaces on a diagram using the various reference icons on the Java Class Components window for the diagram. References created between modeled Java classes are represented as fields in the source code of the classes that implement the references. Compositional relationships are represented on the diagram as a solid line with an open arrowhead in the direction of the reference. Table 5-10 displays the references that can be modeled on a diagram.


Table 5-10 References Between Classes or Interfaces

Reference Description

Reference (Object)

A singular, direct reference from one class or interface to another. This is represented in the code of the reference's originating class as a field of type <destination_class>.

Reference (Array)

A reference to an array of another class or interface. This is represented in the code as an array of type <destination_class>.

Reference (Collection)

This is represented in the code as a Collection declaration, and adds an @associates <{type}> Javadoc tag to the source to identify this reference as well as the required import java.util.Collection; statement.

Reference (List)

This is represented in the code as a List declaration, and adds an @associates <{type}> Javadoc tag to the source to identify this reference as well as the required import java.util.List; statement.

Reference (Map)

This is represented in the code as a Map declaration, and adds an @associates Javadoc tag to the source to identify this reference as well as the required import java.util.Map; statement.

Reference (Set)

This is represented in the code as a Set declaration, and adds an @associates Javadoc tag to the source to identify this reference as well as the required import java.util.Set; statement.


Note:

If you want to quickly change the properties of a reference on a diagram, double-click it to display the Code Editor and change the details of the reference.

Labels are not displayed on references by default. To display the label for a reference, right-click the reference and choose Visual Properties, then select Show Label. The default label name is the field name that represents the reference. If you select this label name on the diagram and change it, an @label <label_name> Javadoc tag will be added before the field representing the reference in the code.

You can change the aggregation symbol used on a reference on a diagram by right-clicking the reference, choosing Reference Aggregation Type, then choosing None, Weak (which adds an @aggregation shared Javadoc tag to the code representing the reference), or Strong (which adds an @aggregation composite Javadoc tag to the code representing the reference). Aggregation symbols are for documentary purposes only.

Modeling Inheritance on a Java Class Diagram

Inheritance structures, which are represented in the Java source as extends statements, can be created on a diagram of Java classes using the Extends icon on the Java Class Components window for the diagram. Extends relationships are represented on the diagram as a solid line with an empty arrowhead pointing towards the extended class or interface.

Where an interface is implemented by a class, this can be created using the Implements icon on the Java Components window for the diagram. Creating an implements relationship adds implements statement to the source code for the implementing class. Implements relationships are represented on the diagram as a dashed line with an empty arrowhead pointing towards the implemented Java interface.

Extending Modeled Java Classes

Extends relationships model inheritance between elements in a class model. Extends relationships can be created between Java classes and between Java interfaces, creating an extends statement in the class definition. Enums cannot extend other classes, or be extended by other classes.

Note:

As multiple class inheritance is not supported by Java, only one extends relationship can be modeled from a Java class on a diagram. Multiple extends relationships can be modeled from a Java interface.

Implementing Modeled Java Interfaces

Implements relationships specify where a modeled Java class is used to implement a modeled Java interface. This is represented as an implements keyword in the source for the Java class. Implements relationships are represented on class diagrams as dashed lines with an empty arrowhead pointing towards the interface to be implemented. Enums can

not implement interfaces.

If the implemented interface is an extension (using an extends relationship) of other modeled interfaces, this is reflected in the Java source code for the interface.

A class that implements an interface can provide an implementation for some, or all, of the abstract methods of the interface. If an interface's methods are only partially implemented by a class, that class is then defined as abstract.

Modeling Java Fields and Methods

You can create members (fields and methods) of a Java class or interface on a diagram. The fields and methods are added to modeled Java classes and interfaces on a diagram by double-clicking the modeled Java class or interface then adding the field or method using the Java Source Editor.

  • Fields are used to encapsulate the characteristics of a modeled Java class or Java interface. All modeled fields have a name, a datatype and a specified visibility.

    When a field or method is displayed on a class on a diagram, it is prefixed with + (if declared as public), - (if declared as private) or # (if declared as protected). Static fields are underlined on the diagram.

  • Methods are defined on a class to define the behavior of the class. Methods may have return types, which may be either a scalar type or a type defined by another class.

Refactoring Class Diagrams

If you rename or move a class using the in-place edit functionality on a diagram, the source code for the class is refactored automatically. Renaming or moving a Java package on a diagram automatically refactors the contents of that package.

Deleting a field, method, or inner class on a diagram automatically applies the Delete Safely refactoring pattern. To apply a refactoring pattern to a Java class, interface, enum, or member on a diagram, select the class or member on the diagram and choose the refactoring pattern from the refactoring menu.

The following refactoring patterns are available for the Java classes, interfaces, and enums on a Java class diagram:

  • Rename

  • Move (applies to both single and multiple selections on the diagram)

  • Duplicate

  • Extract Interface

  • Extract Superclass

The following refactoring patterns are available for the Java fields and methods on a Java class diagram:

To invoke a refactoring operation:

  1. Select a program element in a source editor window, databases window, or structure pane.
  2. Right-click on the program element.
  3. Choose an operation from the context menu.
  4. You can also choose Refactor from the toolbar and select a refactoring operation from the drop-down list:
    • Rename

    • Move

    • Make Static

    • Pull Members Up

    • Push Members Down

    • Change Method (Java methods only)

Modeling with EJB Diagrams

Enterprise JavaBeans (EJBs) modeling helps you visualize your EJB entity relationships and architecture, and to quickly create a set of beans to populate with properties and methods, and to create a graphical representation of those beans and the relationships and references between them. Whenever a bean is modeled, the underlying implementation files are also created.

To model EJBs start by creating an EJB diagram. For more information, see Creating a New Diagram. You can later add other elements like UML classes, Java classes, business components, offline database tables, UML use cases and web services to the same diagram. For more information, see Working with Diagram Elements.

The following are the modeling options available:

  • Entity beans can be either Container-Managed Persistence (CMP) or Bean-Managed Persistence (BMP). Before creating entity beans with bean-managed persistence, you may want to first consider whether you will need to create relationships between those entity beans. Relationships can only be created between entity beans with container-managed persistence.

  • Session beans can be have their session type changed on a class diagram by right-clicking on the session bean and choosing Session Type, then Stateful or Session Type, then Stateless.

  • Message-driven beans are most often used to interact (using EJB References) with session and entity beans.

Working with EJB/JPA Modeling Features

Enterprise JavaBeans are created on a diagram by using the Entity Bean icon, Session Bean icon or Message-Driven Bean components on the Components window. Select the component and then click the diagram in the desired spot. The implementation files for the modeled elements are created in the location specified by your project settings.

Tip:

If you want to model the implementing Java classes for a modeled bean on a diagram, right-click the modeled bean and choose Show Implementation Files.

Properties and methods are added by either double-clicking the bean and adding the property or method using the EJB Module Editor or by creating the new property or method 'in-place' on the modeled bean itself.

Modeled session and entity beans are made up of several compartments. For example, Message-driven beans have only a name compartment containing the «message-driven bean» stereotype and the name of the bean. For EJB 3.0 beans the model looks different because there are no compartments for interfaces.

Figure 5-56 EJB/JPA Components Diagram

This image is described in the surrounding text

Notice the relationship and edges between the beans. References can be created from any bean to another bean with a remote or local interface. References can only be modeled between beans that are inside the current deployment descriptor.

Create a Diagram of EJB/JPA Classes

To create a diagram of EJB/JPA classes:

  1. Create a new EJB diagram in a project or application in the New Gallery.
  2. Create the elements for the diagram using the EJB Components window. Table 5-11 shows the EJB Components window.

    Table 5-11 EJB Components window Icons

    Drop-down List Icon Name

    EJB Nodes

    This image is described in the surrounding text

    Entity

     

    This image is described in the surrounding text

    Message-driven Bean

     

    This image is described in the surrounding text

    Session Bean

    Entity Relationships

    This image is described in the surrounding text

    Bidirectional * to * Relationship

     

    This image is described in the surrounding text

    Bidirectional * to 1 Relationship

     

    This image is described in the surrounding text

    Bidirectional 1 to 1 Relationship

     

    This image is described in the surrounding text

    Unidirectional * to * Relationship

     

    This image is described in the surrounding text

    Unidirectional * to 1 Relationship

     

    This image is described in the surrounding text

    Unidirectional 1 to * Relationship

     

    This image is described in the surrounding text

    Unidirectional 1 to 1 Relationship

    EJB Edges

    This image is described in the surrounding text

    Entity Inheritance Edge

     

    This image is described in the surrounding text

    Session Facade Edge

    Diagram Annotations

    This image is described in the surrounding text

    Attachment

     

    This image is described in the surrounding text

    Group

     

    This image is described in the surrounding text

    Link

     

    This image is described in the surrounding text

    Note


How to Model EJB/JPA Relationships

You can model a relationship between any two entities on a class diagram by dragging the relationship component from the Components window. You can also show the inheritance edge between the root and child entity.

To model a relationship between two entities on a diagram:

  1. Click the icon for the relationship to create.

    Note:

    The navigability and multiplicity of a relationship end can be changed after it has been created.If EJB component icons are not displayed, select EJB Components from the dropdown on the Components window.

  2. Click the entity at the 'owning', or 'from', end of the relationship.
  3. Click the entity bean at the 'to' end of the relationship.
  4. Click the relationship line on the diagram, then click the text fields adjacent to the association to enter the relationship name.

    Note:

    To change the multiplicity of a relationship end on the diagram, right-click on the relationship end and choose either Multiplicity > 1 or Multiplicity > *.

Reference Between Beans

References can be created from any bean to any other bean with a remote interface using the EJB Reference icon and local references can be created from any bean to any other bean with a local interface using the EJB Local Reference icon on the EJB Components window for the diagram.

A variety of relationships can be created quickly between modeled entity beans using the 1 to * Relationship icon, Directed 1 to 1 Relationship icon, Directed 1 to * Relationship and Directed Strong Aggregation icons.

Properties on Modeled Beans

Properties can be added to modeled EJBs by either double-clicking the bean and adding the property or method using the EJB Module Editor or by creating the new property or method directly on the modeled bean.

When creating a property directly on a modeled bean, enter the name and datatype of the property. For example:

name : java.lang.String

A public (+) visibility symbol is automatically added to the start of the property.

Note:

If a property type from the java.lang package is entered without a package prefix, for example, String or Long, a property type prefix of java.lang. is automatically added. If no type is given for a property, a default type of 'String' (java.lang.String) is used

Methods on Modeled Beans

Both local/remote and local/local home methods can be created on modeled beans on a class diagram.

When creating a method in-place on a modeled bean, enter the name, and optionally the parameter types and names, and return type of the method. The method return type must be preceded by a colon (:). For example:

getName(String CustNumber) : java.lang.String

A public (+) visibility symbol is automatically added to the start of the method.

Note:

If a return type from the java.lang package is entered without a package prefix, for example, String or Long, a return type prefix of java.lang. is automatically added to the Java in the method's class. If no parameter types are provided, the method will be defined with no parameters. If no return type is specified, a default return type of void is used. To change a property of the method, double-click the class on the diagram, or on the applications window, then change the details of the method using the EJB Editor.

How to Model Cross Component References

References can be created between modeled beans on a class diagram.

  • EJB References can be created from any bean to any other bean with a remote interface.

  • EJB Local References can be created from any bean to any other bean with a local interface.

Note:

References can only be made to beans that are inside the current deployment descriptor.

To model a reference between modeled beans:

  1. Click the icon from those listed on the EJB Components window:
    • EJB Reference

    • EJB Local Reference

  2. Click the bean at the 'owning', or 'from', end of the reference.
  3. Click the bean at the 'to' end of the reference.

How to Display the Implementing Classes for Modeled Beans

Each modeled bean has underlying Java source files that contain the implementation code for that element. These implementation files can be displayed on the diagram as modeled Java classes.

To display a modeled implementing Java class for a modeled bean:

  • Select the bean, the Java implementation you want to model on the diagram, then choose Model > Show > Implementation Files.

  • Or, right-click the bean and choose Show Implementation > Files.

How to Display the Source Code for a Modeled Bean

The Java source code for a modeled bean can be displayed in the source editor with simple commands on the diagram.

To display the Java source code for a model element:

  • Right-click the element on the diagram. Choose Go to Source, then choose the source file you want to view.

  • Select the element and choose Model > Go to Source.

How to Change the Accessibility of a Property or Method

You can change the accessibility of a property or method using right-click.

To change the accessibility of a property or method:

  1. Right-click the property or method you want to change.
  2. Choose the required accessibility option from the Accessible from option.

    The accessibility options are:

    • Local Interface

    • Remote Interface

    • Local and Remote Interfaces

How to Reverse Engineer a Diagrammed JPA Entity

Modeled entity beans can be reverse-engineered on a diagram of EJBs from table definitions in your application database connection.

To reverse-engineer a table definition to an entity bean:

  1. Open, or create a diagram.
  2. Expand the node in the Connections window for your database connection.
  3. Expand the user node, then the Tables nodes.
  4. Click the table, the definition to use to create an entity bean, and drag it to the current diagram.

    To reverse-engineer several tables to entity beans, hold down the Ctrl key, select the tables in the databases window and drag these tables to the diagram, then release the Ctrl key.

  5. Select the EJB version and click OK.

Modeling with Database Diagrams

Modeling your database structures gives you a visual view of your database schema and the relationships between the online or offline tables. You can also transform database tables to UML classes and vice-versa using the transformation features. For more information on database transformation see UML-Offline Database Transformation.

Working with the Database Modeling Features

With JDeveloper, you can model offline database objects as well as database objects from a live database connection. You can also create database objects such as tables and foreign key relationships right on your diagram and integrate them with an online or offline database. All of the database objects from online or offline databases, as well as the new objects you create are displayed in the Applications window.

  • Offline objects appear in the Application Navigator under the "Offline Database Sources" node.

  • Online database connections that are part of your application appear in the Application Navigator Application Resources view under the Connections > Database node.

  • Online database connections that are shared across applications appear in the Database Navigator which can be accessed from Window > Database > Databases.

Use database diagrams to view your structure of database objects and relationships, as well as create directly on your diagram components such as tables and foreign key relationships, views and join objects, materialized views, synonyms and sequences.

How to Create a Database Diagram

Create your database diagram using the New Gallery. See Creating a New Diagram.

Once your database diagram is created, you can choose from the components in the Components window, as shown in Figure 5-57.

Figure 5-57 Database Components Window

This image is described in the surrounding text

How to Create an Offline Database Object

To create an offline database object on the diagram, click on the icon on the Database Objects Components window, and then click on the diagram where you want to create the object. This process adds existing objects to a database diagram.

You can also drag objects from a database connection in the Databases window, or from an offline schema in the Applications window.

How to Create a Foreign Key

To create a Foreign Key in a database diagram, click the table from which the foreign key originates, and then click the target destination table. The Create Foreign Key dialog allows you to select an existing column in the target table, or create a new column. The target table will be the owner of the foreign key.

How to Use Templates to Create Database Objects

All templates are defined in the Offline Database Properties dialog. If the object being created has a template defined in the offline database in which it is being created, then using the <ObjectType> component creates objects based on its template. For example, if the offline database 'Database1' has a Template table 'MyTab', when you create a new table in Database1 using the table option in the Component window, the new table created is based on Template 'MyTab'. The existing objects from the offline database are added to the diagram.

How to Add and Create Private and Public Synonyms

To create Synonyms on a diagram, go to the Components window and choose Database. From the Database list, click Public Synonym or Private Synonym and then click the diagram in which you want to create the synonym. Note, both components contain a checkbox for the Public property. The box is automatically checked for the Public Synonym, and it is unchecked by default for the private synonym.

You can also drag+drop objects from an online database connection. To import objects from the database connection to the offline database, add the existing objects from the database connection to the diagram.

How to Add and Create a Sequence

To create a sequence on a diagram, go to the Database Objects components window for the diagram, and select Sequence, then click on the diagram where you want to create the sequence.

You can also drag sequences from a database connection, or from an offline database in the Applications window, and drop them on the diagram.

How to Add and Create Tables

Follow these steps to add tables to a diagram.

  1. Go to the Database Components window, click on Table, and then click on the diagram to insert the table.

    You can also drag tables from a database connection or an offline database in the Applications window, and drop them on the diagram. Existing objects from an offline DB can be added to the diagram in the same way.

    To display various attributes on a modeled table, select Preferences > Diagrams > Database, and from the "Edit Preferences for" dropdown, select Table. On the Display tab, check Use Tabular Layout and Show Icons. To view table constraints, select the Constraints tab and check any constraint attributes you want to display.

    The first column in the modeled table indicates whether the column is in a primary, unique, or foreign key. The second column indicates whether the table column is mandatory.

    Note:

    If a table column is in a primary key it will only display the primary key icon even though it may also be in a unique key or foreign key.

  2. To further define the table, click on the table and choose Properties from the context menu.

    On the left is a list of the properties you can define. At the bottom of the panel note that the Overview tab is the default view. To change the view, click the Diagram, DDL, or History tabs.

  3. To add columns, choose Columns on the left. In the Columns table, click the + button to add a row for each column you require. For each new column use the tabbed panel to specify the column's Data Type, Constraints, Indexes, LOB Parameters, Identity Column, and User Properties.
  4. To add constraints, choose Constraints on the left, and use the + dropdown menu to specify new keys or constraints. Provide the Type and Name and set the deferrable state. With the constraint selected in the Constraints table, use the tabbed panel to specify its Properties and User Properties.

    To apply a constraint to a column, select the constraint in the Constraints table, and in the Properties tab below, choose an index, then from the Available Columns area, choose a column and click the > button to move that column to the Selected list.

How to Change the Database or Schema

  1. On the database diagram, right-click and choose Create Database Objects In > Database or Schema.
  2. Complete the Specify Location dialog or Select Offline Schema dialog.

Note:

All subsequent database objects will be created in the database or schema you have chosen. Existing objects are unchanged.

How to Create Database Views and Add Database Objects

Follow these steps to create a database view:

  1. Open the diagram that needs the database view.
  2. In the Components window Database category, expand Database Objects and select the View icon.
  3. Click in the diagram. The View Object is added to the diagram.

    To define the view add tables and views from the palette, or table columns or elements of other views.

    To add an existing view, you can drag views from a database connection and drop them on the diagram. You can also drag in views from an offline database displayed in the Applications window.

  4. Right-click the view component and select Properties. Specify the schema and name, and fill out the SQL Query and Properties forms.

To import objects from a database connection to an offline database, add existing objects from the database connection to the diagram.

How to Define a Base Relation Usage

The base relation usage is a component of a FROM clause that specifies a relation to a table or view. When you define an SQL Query with a FROM clause specified (you can type it in or use the Query Builder) a Relation Usage object is automatically added to the View component.

To define a base relation for a view, go the Components window and choose Database. In the list, click on Relation Usage and then click on the View shape.

How to Create Join Objects

To create join objects between two table usages in a view, click Join Object, then click on the two table usages to be joined. The Edit Join dialog allows you to specify the join.