Escolar Documentos
Profissional Documentos
Cultura Documentos
Code generation
After the completion of design stage, complete class diagrams or sometimes known as
the design class diagrams would be generated within a particular model. The general
prerequisite for code generation to be done would require at least a design class
diagram. Rational Rose is a very powerful CASE tool that capable of generating
codes from a particular language based on the predefined semantics. Typically, they
are six steps by steps guidelines would be followed during code generation.
1.0 Assign Java Classes to Java Components in Your Model
2.0 Check Syntax (optional)
3.0 Check the Classpath
4.0 Set the Project Properties that affect Code Generation (optional)
5.0 Backup Your Source
6.0 Generate Java Source Code from Your Model
6.1 Generating Java source from a Class Diagram
6.2 Generating Java source from a Component Diagram
7.0 View (browse) and extend the Generated Source
1.0 Assign Java Classes to Java Components
A component may be anything perhaps the generated codes as well. Rational Rose
Java models .java files as components. Every .java file in Rose will be treated as a
component as well. Therefore, upon completion of code generation, the .java file
would be seen in the component view as a physical component.
1) Rose can automatically generate the .java physical components for you when
multiple classes are being code generated
2) To do this, the menu option from Tools > Option > Notation > Default
Language must be JAVA enabled
Page 1 of 9
Most of the time, Rose would not be able to produce a single .java file that
consists of multiple classes. If you would like to have multiple classes to reside in
a single .java file, a component must be created and all the related classes should
be placed inside (assign) and upon code generation, all the classes would appear in
the physical .java file. (Note, too, that if you place any Java classes in your newly
created package, Rose would create a mirror image in Component view. It is then
used to create directory or Java packages.)
2.0 Check Syntax (optional)
You can choose to check the syntax of your model components before you try
generating code. Note, though, that syntax checking is done automatically for you
when you generate code. Rose Javas Syntax checking is based on Java code
semantics
Page 2 of 9
Select Directory and most of the time, the JDK API library would reside in the
following address.
Click on OK and followed by checking the two option below and you are done for
checking the classpath.
Where are your files? Specifically, what are the fully qualified path names?
What are the package or import statements in the source? You must have a
Classpath entry for the leftmost directory in a package/import statement.
Page 3 of 9
Page 4 of 9
The following properties affect code generation. You set the values for these
settings via the Code Generation tab of the Rose Java Project Specification.
IDE Determines which Java environment or IDE you are working in. The
default is Internal Editor and indicates youre working in a standard JDK
environment. The other options are: IBM VisualAge for Java, Visual Caf,
Forte for Java, and JBuilder.
Stop on Error When enabled, Rose stops generating Java code at the first
error it encounters. By default, this property is not set, thus allowing code
generation to proceed even when there may be errors. Errors recognized by
Rose are written to the Log.
Page 5 of 9
Indentation You can specify whether to use spaces or tabs and the number of
spaces or tabs to use when formatting code. The default is three spaces.
Opening Braces By default, opening braces start on a new line for both
classes and method declarations.
Page 6 of 9
If this is the first time youve generated code for a model element, a mapping dialog
appears enabling you to map packages and components to your Rose Java classpath
settings. If there are errors or warnings, a message will alert you and you can view the
messages in the Rose Log window (click View > Log). Once code generation is
complete, the .java files and related directory structure are in place. You can also view
the newly generated java source from within Rose.
Note: You can enable Automatic Synchronization Mode to automatically initiate code
generation any time you create or modify a Java element in your model. This is set on
the Style tab on the Java Project Specification (Tools > Java > Project Specification).
6.1
6.2
1.
Open your model and display the class diagram that contains the
classes and packages for which you want to generate Java source.
2.
3.
Optionally, use the syntax checker before generating your Java source.
Although Rose checks syntax as part of code generation, checking
your model before generating could save you time.
4.
5.
6.
Check the Rose Log window to view the results of the Java generation,
including any errors that occurred.
7.
Correct any errors and repeat step 4 until no errors are returned.
8.
View and edit the generated code using the Internal Editor.
Open your model and display the component diagram that contains the
packages and components for which you want to generate Java source.
2.
3.
Optionally, use the syntax checker before generating your Java source..
Although Rose checks syntax as part of code generation, checking
your model before generating could save you time.
4.
5.
6.
Check the Rose Log window to view the results of the Java generation,
including any errors that occurred.
7.
Correct any errors and then repeat step 4 until no errors are returned.
Page 8 of 9
8.
7.0
View and edit the generated code using the Internal Editor.
After generating Java, you may want to view (browse) the generated source (rightclick on a class and click Java/J2EE > Edit Code) and create the actual functionality
for your application or applet.
Rose provides an Internal Editor for viewing and editing your .java files.
You can modify the generated source from within the editor. To update your model
with the changes, you need to reverse engineer the .java file back into your model.
Page 9 of 9