Code Generation

I l @ ve RuBoard

Step 1: Create Needed Property Sets

There are code-generation properties associated with the project, the class, roles, attributes, and operations. The properties applying to the project as a whole involve file name , default container names , and placement of the generated code. Class properties involve the generation of constructors, destructors, copy constructors, equality operators, and get/set methods. The property set for roles deals with the construction of get/set methods, visibility of the methods , and the container class to be used. Operation properties deal with the operation kind (common, virtual, abstract, static, or friend) and allow the operation to be made constant. These property sets may be edited, and new sets may be created to specify the C++ features needed for the project. Two files are generated for each classa header (.h) file and a specification (.cpp) file.

For a typical project, a few people are responsible for the creation of code generation property sets that are used by the entire development team. This enables each developer to generate the needed code for the components . Some typical property sets are Virtual destructor, Virtual operation, Abstract operation, Static operation, No get member function, and Forward reference.

CREATING PROPERTY SETS IN RATIONAL ROSE

graphics/quatranirose_icon.gif
  1. Select the Tools:Options menu choice.

  2. Select the C++ tab.

  3. Click the arrow in the Type field to make the drop-down menu visible.

  4. Select the desired type of property set.

  5. Click the Clone button to make the Clone Property Set window visible.

  6. Enter the name of the new property set.

  7. Click the OK button to close the Clone Property Set window.

  8. Click to select the property to change.

  9. Click the value.

  10. Enter the new value or select the new value from the drop-down menu if one is provided.

  11. Repeat steps 8 through 10 for each property to be changed.

  12. Click the Apply button to apply the changes.

  13. Repeat the preceding steps for each new property set.

  14. Click the OK button to close the Options window.

The property set Virtual Destructor is shown in Figure A-1.

Figure A-1. Virtual Destructor Property Set

graphics/afig01.jpg

Step 2: Create Body Components in the Component Diagram

Rational Rose generates code based on the components and their stereotypes present in the diagram. For components without a stereotype, Rose will generate a .h file containing definition and declaration information for the class. For components with a stereotype of Package Specification, Rose will generate a .h file containing the definition information for the class. If there is a corresponding component with a stereotype of Package Body, Rose will generate a .cpp file containing declaration information for the class.

ASSIGNING STEREOTYPES TO COMPONENTS IN RATIONAL ROSE

graphics/quatranirose_icon.gif
  1. Double-click on a component diagram to open the diagram.

  2. Click right on the component to make the shortcut menu visible.

  3. Select the Open Specification menu command.

  4. Enter the desired stereotype in the stereotype field or click the arrow in the Stereotype field to make the drop-down menu visible and select the desired stereotype.

  5. Click the OK button to close the Specification.

The Component Specification is shown in Figure A-2.

CREATING COMPONENT HEADERS AND BODIES IN RATIONAL ROSE

graphics/quatranirose_icon.gif
  1. Double-click on a component diagram to open the diagram.

  2. Click right on the component to make the shortcut menu visible.

  3. Select the Open Specification menu command.

  4. To create a stereotype for a header file, select the Package Specification stereotype.

  5. To create a stereotype for a component body, select the Package Body stereotype.

  6. Click the OK button to close the Specification.

Figure A-2. Component Specification

graphics/afig02.jpg

A component diagram with components for C++ .h and .cpp files is shown in Figure A-3.

Figure A-3. Updated Component Diagram

graphics/afig03.jpg

Step 3: Assign the C++ Language to the Components

Once the components for the header and body are created, they must be assigned the C++ language. If the default language for a model is set to C++ (Tools:Options menu, notation tab), Rational Rose automatically will assign the C++ to components in the model.

ASSIGNING A LANGUAGE TO A COMPONENT IN RATIONAL ROSE

graphics/quatranirose_icon.gif
  1. Right-click to select the component in the Browser or on a diagram and make the shortcut menu visible.

  2. Select the Open Specification menu command.

  3. Click the arrow in the Language field to make the drop-down menu visible.

  4. Select C++.

  5. Click the OK button to close the Specification.

The Component Specification for the Course class is shown in Figure A-4.

Figure A-4. Assigning a Language to a Component

graphics/afig04.jpg

Step 4: Assign Classes to Components

Once components have been created, classes are assigned to the components representing the header file.

ASSIGNING CLASSES TO COMPONENTS IN RATIONAL ROSE

graphics/quatranirose_icon.gif
  1. Double-click on the component diagram containing the components representing the .h and .cpp files to open the diagram.

  2. Click to select the class in the Browser and drag it onto the component representing the .h file.

Step 5: Attach Property Sets to Modeling Elements

Each modeling element (e.g., class, attribute, or role) is examined to determine its code needs. If a property set other than the default set is needed, it is attached to the modeling element.

ATTACHING A PROPERTY SET TO A SELECTED ELEMENT IN RATIONAL ROSE

graphics/quatranirose_icon.gif
  1. Right-click to select the element in the Browser or on a diagram and make the shortcut menu visible.

  2. Select the Open Specification menu choice.

  3. Select the C++ tab.

  4. Click the arrow in the Set field to make the drop-down menu visible.

  5. Select the desired property set.

  6. Click the OK button to close the Specification.

The property set VirtualDestructor has been attached to the RegistrationUser class as shown in Figure A-5.

Figure A-5. Property Set Attachment

graphics/afig05.jpg

Since there are not property sets for every combination of elements, any property may also be overridden for a particular element. This is true even if the property is part of the default property set for the element.

OVERRIDING A PROPERTY IN RATIONAL ROSE

graphics/quatranirose_icon.gif
  1. Right-click to select the element in the Browser or on a diagram and make the shortcut menu visible.

  2. Select the Open Specification menu choice.

  3. Select the C++ tab.

  4. Click the arrow in the Set field to make the drop-down menu visible.

  5. Select the desired property set.

  6. Click to select the value to be changed.

  7. Enter the new value or select the new value from the drop-down menu if one is provided.

  8. Repeat steps 6 and 7 for each property to be changed.

  9. Click the OK button to close the specification button.

Step 6: Select the Components and Generate the Code

Code may be generated for an entire package, a component, or a set of components. The name of the component is used to generate the name of the file containing the code. The code is placed in a directory structure that corresponds to the package names in the component view.

GENERATING CODE IN RATIONAL ROSE

graphics/quatranirose_icon.gif
  1. Click to select the package, component, or set of components.

  2. Select the Tools:C++:Code Generation menu choice.

  3. Rose will display the status in the Code Generation Status window.

The Code Generation Status window is shown in Figure A-6.

Figure A-6. Code Generation Status

graphics/afig06.jpg

Step 7: Evaluate the Code Generation Errors

Rose writes all warnings and errors to the Log window. If a part of the design for the class is not complete, Rose will write a warning message to the log and use a default value. This is especially important if an iterative approach to development is being followed since an entire class may not be implemented in one iteration.

The common warnings and errors output from the code generator are

  • Error: Missing attribute data type. Void is assumed.

  • Warning: Unspecified multiplicity/cardinality indicators. One is assumed.

  • Warning: Missing operation return type. Void is assumed.

The Log window is shown in Figure A-7.

Figure A-7. Rational Rose Log Window

graphics/afig07.jpg

I l @ ve RuBoard


Visual Modeling with Rational Rose 2002 and UML
Visual Modeling with Rational Rose 2002 and UML (3rd Edition)
ISBN: 0201729326
EAN: 2147483647
Year: 2002
Pages: 134

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net