Numerous O-O CASE tools offer a built-in script language. The script language may be used to create custom reports and generate source code for C++, Eiffel, Ada, Pascal, Smalltalk and other languages. This is a text replacement script language. When a script is run, literals and text values for variables are placed into an output file. The script language described in this section is from the With Class CASE tool from MicroGold Software, Inc. There is no standard CASE tool scripting language. The script language consists of the following:
The following are the steps to use the CASE tool to create diagrams, fill-in forms, create reports, and generate source code:
A very simple script to create a text report is as
follows. This script has literals, e.g. "Class Name:".
This script has script variables, e.g. CLASS_NAME.
This script has a repeat operator, e.g. [ ].
Class Report Listing Attributes and Operations
Class Name: CLASS_NAME
Attributes: [ATTRIBUTE_NAME,]
Operations: [OPERATION_NAME,]
This script creates the following text report based
upon the class diagram showing the Car class.
Class Report Listing Attributes and Operations
Class Name: Car
Attributes: speed,
Operations: start,
The basic steps to create and execute a script are
shown below. First, create a diagram, e.g. a class diagram, object
interaction diagram, state diagram, etc. Enter information in
the appropriate fill-in form or dialog box, e.g. class form, interaction
form, state form, etc. Determine the output that you desire, e.g.
Class Report. Next run the script, e.g. REPORT.SCT. Review the
text output file, e.g. CLASSRPT.TXT. If the output has errors
or omissions, then update the diagram or the fill-in form and
re-run the script. If required, change the script. Then re-run
the script until correct output is generated.
As shown below, you create or update a script in
a text editor. The CASE tool executes a script to create text
reports and source code files. The CASE tool uses script variable
values stored in the CASE tool model repository. The text editor
may be used to update the text reports and source code files.
The source code files may be compiled in a compiler environment
such as the Microsoft or Borland C++ programming environments.
An O-O CASE tool provides a large number of graphic
symbols to represent modeling entities and relationships. These
are based upon an O-O methodology, e.g. Rumbaugh's OMT. The following
are some of the major O-O entities and relationships and their
graphic symbols: class - box with three sections, one to one association
- line, one to one aggregation - line with a diamond, generalization
- line with a triangle. Other O-O methodologies have different
symbols to represent O-O entities and relationships. Typically,
you're selecting the appropriate symbol, then placing it on the
diagram, then filling in text information on the symbol, and then
filling in text specification information in a dialog box. All
this information is collected in a model repository or database.
An O-O CASE tool provides many graphic symbols to
represent modeling entities and relationships. A sample graphic
symbol set based upon the Rumbaugh OMT is shown below. A user
selects and places these graphic symbol on the diagram page. Each
object-oriented methodology has a different symbol set. For example,
the Coad-Yourdon methodology has the semi-circle symbol to represent
generalization while the Rumbaugh OMT methodology has the triangle
to represent generalization. Many O-O CASE tools support various
O-O methodologies and their graphic notation. A few tools permit
you to shift from one graphic notation to another to display a
diagram in various notations. We are primarily using the Rumbaugh
OMT graphic notation.
O-O Entity Symbols O-O Relationship Symbols Cardinality
Symbols
For most graphic symbols there is a specification
form. The specification form appears as a dialog box in the CASE
tool display. For example, the diagram may show the Car class
with an attribute speed. There is a attribute specification form
(dialog box) which collects the information. There is a script
variable to access the information that is collected in the specification
form. A script variable is a holder for model information. For
example, there is an ATTRIBUTE_NAME
script variable which holds the name of an attribute, e.g. speed.
| Modeling Entity | Sample Value | Script Variable |
| Attribute Name | speed | ATTRIBUTE_NAME |
| Attribute Type | int | ATTRIBUTE_TYPE |
| Attribute Initial Value | 0 | ATTRIBUTE_INITIAL_VALUE |
An O-O CASE tool may have a built-in script language consisting
of literals ("This is a report"), operators (REPEAT),
and script variables (ATTRIBUTE_NAME). Some
O-O CASE tools export their script variables for manipulation
using Windows Visual Basic or other scripting language.
An O-O CASE tool provides script variables to access information in the model repository (database). Typically, there are one or more script variables for each graphic symbol. For example, a class on a diagram is tied to class information in the class specification. There are many script variables to the class graphic symbol. A scripting language may be used to create reports and to generate source code. The table below shows the basic O-O entities, graphic symbols, script variables, and C++ code form.
| O-O Entity or Relationship | Example | OMT Graphic Notation | Sample Script Variable | C++ Form |
| System | Car Simulation System | Rectangle | SYSTEM_NAME | Project |
| Class | Car | Box with 3 Sections | CLASS_NAME | Class |
| Object | car1 | Rectangle | OBJECT_NAME | Object |
| Attribute | speed | Middle Section of Class Symbol | ATTRIBUTE_NAME | Data Member |
| Operation | start | Bottom Section of Class Symbol | OPERATION_NAME | Function Member |
| Association | Car to CellularPhone | Line | ASSOCIATION_ONE_NAME | Data Member holding a pointer |
| Aggregation | Car to Motor | Line with Diamond | AGGREGATION_ONE_NAME | Data member holding an object |
| Generalization | Vehicle to Car | Line with Triangle | SUPERCLASS_NAME | Base and Derived Classes |
| Interaction | Car to Motor | Arrow | INTERACTION_OPERATION_NAME | Function Call |
Many O-O CASE tools provide direct access to this model repository
through a provided scripting language, a third party scripting
language, or Microsoft Visual Basic scripting language. The scripting
language permits you to create specialized reports and to generate
source code files. The use of a scripting language greatly increases
the usefulness and extendibility of the CASE tool. Information
attached to each O-O entity and relationship is now directly available
to the user. For example, information on a class is accessible
to the user. Typically, there are script variables, e.g. CLASS_NAME,
ATTRIBUTE_NAME, OPERATION_NAME, etc to access
information in the model repository.
The scripting language provides a means to create custom reports and C++ code files. Early O-O CASE tools had an internal data base that was accessible only from the internal program. It was difficult to make even the most minor changes to reports or generated C++. Just to provide a new C++ comment or change the indention of C++ statements required a CASE tool program. Early versions of O-O CASE tools were not extendible. Current O-O CASE tools are highly extendible, modifiable tools. With the scripting language, any user can create their own scripts to create their own customized reports and language files. Scripts can be written to generate source code for any language and library.
There are several components of a CASE tool script
language. These are from the With Class CASE tool.
Diagrams and model repository
- these hold system, class, object, and state information. The
diagrams and the model repository are the information that the
script uses to create script output files.
Script of script sentences
- a script is a set of sentences which consist of variables, literals,
repeat operator [], concatenation operator $, and other operators.
For example, SCRIPT1.SCT above is a sample script.
Script Editor - any text
editor, e.g. Windows Notepad. One uses the text editor to create
scripts.
Script Interpreter - The
"Generate" menu item executes (interprets) a script.
The script interpreter creates the script output file, e.g. REPORT.TXT,
CAR.H, etc.
Script Output File - When
a script is executed, then an output file, e.g. a report, a C++
header file, a C++ source file, or any text file is created.
Script Variables - Variables
are special terms that represent information in the internal CASE
tool Class database. Sample variables are CLASS_NAME,
BASE_CLASS, ATTRIBUTE_NAME, and OPERATION_NAME.
All variables are in upper case. When a script is executed, then
actual model information is substituted for the variable in the
output file. For example, the actual model information, e.g. Student
is substituted for the variable CLASS_NAME.
Literals - a literal is
any character or number that a user enters into a script. When
a script is executed, then the literal is placed into the output
file. For example, a literal in the above program is // Class:
.
Concatenation Operator $
- the symbol $ means to connect a literal and a variable. For
example, Get$ATTRIBUTE_NAME connects
the literal Get and the variable ATTRIBUTE_NAME.
When executed, the result is Getspeed.
Repeat Operator [] - the
symbol [] causes the variable or literal to be repeated. For example,
[ATTRIBUTE_NAME] causes a list of
attributes to be placed into the output file. Anything placed
in between the brackets will be repeated for every variable.
DELETE_LAST_SYMBOL operator
removes the trailing punctuation marks. This is useful in code
generation. Example is class CLASS_NAME [:BASE_CLASS
,DELETE_LAST_SYMBOL].
TRUNCATE_EIGHT operator
truncates a class name to eight characters using a vowel stripping
algorithm. TRUNCATE_EIGHT_CHOP operator truncates a class
name to eight characters by removing all characters after the
eighth character. Example is #include "TRUNCATE_EIGHT$CLASS_NAME$_H".
This is useful to create legal MS/DOS file names.
NO_REPEAT operator prints
a literal or punctuation symbol once without repeating it. Example
is class CLASS_NAME [NO_REPEAT: public
BASE_CLASS].
LITERAL_SYMBOL operator
treats a bracket [ as a literal. This is used for arrays. Example
is LITERAL_SYMBOL[ 10 LITERAL_SYMBOL].
NO_RETURN operator keeps
all information on a single line without a return. Example is
class CLASS_NAME [NO_RETURN
: public BASE_CLASS].
SCRIPT_NOREPEAT_HEADER_BEGIN and
SCRIPT_NOREPEAT_HEADER_END operator prints the literals and
script variables with these operators. Example is SCRIPT_NOREPEAT_HEADER_BEGIN
Beginning of the Class Report SCRIPT_NOREPEAT_HEADER_END.
SCRIPT_NOREPEAT_FOOTER_BEGIN and
SCRIPT_NOREPEAT_FOOTER_END operator prints the literals and
script variables with these operators, (e.g. SCRIPT_NOREPEAT_FOOTER_BEGIN
Ending of the Class Report SCRIPT_NOREPEAT_FOOTER_END
).
SELECT_WHEN, LOGICAL_NOT, ==, !=, ATTRIBUTE_IS_CONSTANT, ATTRIBUTE_IS_STATIC, ATTRIBUTE_IS_INDEX and ATTRIBUTE_IS_NORMAL operators provide the capability to print the literals and script variables the follow the SELECT_WHEN if the condition is true, (e.g.
SELECT_WHEN ATTRIBUTE_IS_CONSTANT [ATTRIBUTE_NAME],
SELECT_WHEN ATTRIBUTE_IS_STATIC [ATTRIBUTE_NAME],
SELECT_WHEN ATTRIBUTE_IS_NORMAL [ATTRIBUTE_NAME],
SELECT_WHEN ATTRIBUTE_IS_INDEX [ATTRIBUTE_NAME],
SELECT_WHEN ATTRIBUTE_ACCESS == private [ATTRIBUTE_NAME],
SELECT_WHEN OPERATION_ACCESS == public [ATTRIBUTE_NAME],
SELECT_WHEN OPERATION_ACCESS != public [ATTRIBUTE_NAME],
SELECT_WHEN OPERATION_IS_PROCEDURE [OPERATION_NAME],
SELECT_WHEN OPERATION_IS_FUNCTION [OPERATION_NAME]
SELECT_WHEN LOGICAL_NOT ATTRIBUTE_IS_STATIC [ATTRIBUTE_NAME])
NO_OUTPUT_BEGIN and NO_OUTPUT_END
operators provide the capability to place comments in scripts
that do not print out in the script output. e.g. NO_OUTPUT_BEGIN.
This script generates a text report listing class information
NO_OUTPUT_END. Warning
- do not place an script variables inside these operators. Place
only literals inside these operators.
CAPITALIZE_ALL capitalizes
all letters for include file names, e.g. #ifndef
__$CAPITALIZE_ALL$TRUNCATE_EIGHT$CLASS_NAME$_H.
STRIP_TO_CAPITAL strips lower case letters prior to a capital letter in class names, e.g. #ifndef __$STRIP_TO_CAPITAL$TRUNCATE_EIGHT$CLASS_NAME$_H.
The following are the steps to create a script.
Step 1. Manually create the sample output file to be generated from the script, e.g.
Class Attribute Report
Class: Student
Attributes: age, gradePointAverage
Step 2. Create the class diagram to be used with
the script. For example, create a class with the class name "Student"
with the attributes "age" and "gradePointAverage"
as shown below.
Step 3. Analyze the class diagram to identify script
variables. For example, the class diagram has the variable CLASS_NAME
and the variable ATTRIBUTE_NAME.
When the script is executed "Student" is substituted
for the variable CLASS_NAME and "age"
is substituted for the variable ATTRIBUTE_NAME.
Step 4. Analyze the sample output file to identify
literals, variables, operation symbol [], and concatenation symbol
$. For example, see the comments below:
Class Attribute Report -- Literal
Class: Student --Class: Literal; Student is Variable CLASS_NAME
Attributes: age, gradePointAverage --Attributes: Literal;
--age is value of the variable ATTRIBUTE_NAME
--comma is literal;
--gradePointAverage is Variable ATTRIBUTE_NAME
--age, gradePointAverage needs repeat symbol [] because there are multiple
` --values of ATTRIBUTE_NAME
Step 5. Create the script as follows:
- First, place literals in the script as they would appear in the output file, e.g.
Class Attribute Report
Class:
Attributes: ,
- Second, place variables in the script where actual information from the class diagram would appear in the output file, e.g.
Class Attribute Report
Class: CLASS_NAME
Attributes: ATTRIBUTE_NAME,
- Third, place operators in the script, e.g. repeat symbol [], concatenation symbol $, NO_REPEAT, DELETE_LAST_SYMBOL, and TRUNCATE_EIGHT. Use the repeat symbol [] whenever a literal or variable must be repeated. For example, since a class has many attributes then attribute name should be repeated, e.g. [ATTRIBUTE_NAME]. Use the concatenation symbol $ to put together a literal and/or variables without a space. For example, get$ATTRIBUTE_NAME will result in getage or getgradePointAverage in the output file.
Class Attribute Report
Class: CLASS_NAME
Attributes: [ATTRIBUTE_NAME,]
Step 6. Double check the script and the class diagram to ensure the following:
Step 7. Execute your script in CASE tool by selecting "Generate - Generate Code" and then selecting the file extension, e.g. h and the script file name, e.g. cpphead.sct. Ensure that you closed the script file in the text editor. Check to ensure that your generated output file is correct. If not, then update your script and/or your class diagram to generate the correct output.
There are two basic forms of reports: list reports
and table reports. A list report consists of a series of lines
containing information. To create a list report report follow
these steps.
Step 1. Open or create the diagram.
Step 2. Find or create a list report script, e.g.
RPTCLASS.SCT. The list reports are the simplest to create. To
create a list report, indicate the appropriate script variables.
The following brief script lists the CLASS_NAME, ATTRIBUTE_NAME,
and OPERATION_NAME script variables.
Class Report Listing Attributes and Operations
Class Name: CLASS_NAME
Attributes: [ATTRIBUTE_NAME,]
Operations: [OPERATION_NAME,]
Step 3. Execute the list report script to generate
the list report. For example, the following is a brief list report
that contains four lines of information.
Class Report Listing Attributes and Operations
Class Name: Car
Attributes: speed, gasQuantity
Operations: start, stop
The table report presents information in a table
form consisting of rows and columns. To create a table report
follow these steps.
Step 1. Open or create the diagram.
Step 2. Find or create a table report script, e.g.
TABCLASS.SCT. The script to create this table report is listed
below. This is a comma delineated report that has tabs between
columns and a carriage return at the end of each line. The commas
and CARRIAGE_RETURNs are explicitly shown in this report. Frequently,
it is desirable to create a comma delineated report and then import
the table into a Windows word processor, spreadsheet, or database
for analysis and formatting.
Data Dictionary Listing
Terms (Names of Modeling Entities)
Term (Name) , Type of Entity , Enclosing Class CARRIAGE_RETURN
CLASS_NAME , Class , -- CARRIAGE_RETURN
[ATTRIBUTE_NAME , Attribute , CLASS_NAME] CARRIAGE_RETURN
[OPERATION_NAME , Operation , CLASS_NAME] CARRIAGE_RETURN
Step 3. Execute the script. Examine the generated
output as shown below. Notice that the table has commas separating
each field and has a carriage return at the end of each line.
| Term (Name), | Type of Entity, | Enclosing Class |
| Car, | Class, | -- |
| speed, | Attribute, | Car |
| gasQuantity, | Attribute, | Car |
| start, | Operation, | Car |
| stop, | Operation, | Car |
Step 4. Import the generated output into a Windows word processor.
The resulting table is shown below.
Data Dictionary Listing Terms (Names of Modeling Entities)
| Term (Name) | Type of Entity | Enclosing Class |
| Car | Class | -- |
| speed | Attribute | Car |
| gasQuantity | Attribute | Car |
| start | Operation | Car |
| operate | Operation | Car |
Frequently, it is desirable to create a comma delineated report (as above) and then import the table into a Windows word processor, spreadsheet, or database for analysis and formatting.
Frequently, it is desirable to insert model information
into another Windows application. For example, it is desirable
to insert a data dictionary report (table) into a Windows word
processor (Microsoft Word) for formatting, sorting, and printing.
It is desirable to insert an information report (table) into a
Windows spreadsheet or database application (Microsoft Excel or
Access) for special analysis, sorting, and reports. The following
are the general steps to insert a generated text file into a Windows
application, e.g. Microsoft Word.
Step 1. In the CASE tool, create a class diagram
and fill-in text specifications. Ensure that the class, attribute,
operation, and relationship names are entered. Missing names may
appear as a blank in the generated text report.
Step 2. In the CASE tool, run a report to create
the COMMA delimited text file, e.g. DDCLASS.SCT. This script has
a COMMA field delimiter and a CARRIAGE RETURN record delimiter.
This script creates the text file, e.g. REPORT.TXT. Check REPORT.TXT
to ensure that there are three fields of information in each line
separated by a COMMA. Each line should end with a CARRIAGE RETURN.
You may need to remove any extra CARRIAGE RETURN's and to insert
a "--" in any blank fields. These actions are required
to ensure the information is correctly imported into the Word
document or other Windows application.
Step 3. In the Windows application, create a document,
e.g. Microsoft Word document DATADIC1.DOC. Then import the text
file into a table. In a Microsoft Word document, select "Insert
Database". Then select "Get Data" and enter REPORT.TXT.
Enter the COMMA field delimiter and the CARRIAGE RETURN record
delimiter. Select "Insert Data". A table containing
the model information is created.
Step 5. In the Windows application label the table. You may need to remove any extra CARRIAGE RETURN's and to insert a "--" in any blank fields. Sort and format the table.
A major use of scripts is to generate source code
files. The following are the steps to create source code with
a script.
Step 1. Open or create the diagram.
Step 2. Find or create a code generation script.
The following is a very short script (script1.sct) to generate
a C++ header file:
// Class: CLASS_NAME
class CLASS_NAME : public [BASE_CLASSES]
{
[ATTRIBUTE_TYPE ATTRIBUTE_NAME]
public:
[OPERATION_RETURN_TYPE OPERATION_NAME (CPP_OPERATION_PARAMETERS); ]
[ATTRIBUTE_TYPE Get$ATTRIBUTE_NAMES$() {return ATTRIBUTE_NAME;
} ]
}
Step 3. Execute the script. The following is the
sample output file based upon a class diagram with a Vehicle and
Car classes. The generated file is CAR.H.
// Class: Car
class Car : public Vehicle
{
int speed;
int gasQuantity;
public:
void start();
void stop();
Getspeed(){return speed;}
GetgasQuantity(){return gasQuantity;}
}
In this section the fundamentals of using and creating scripts with a scripting CASE tool was presented. A script language consists of script variables and script operators. Scripts are used to create text reports in list or tabular formats. Scripts are used to create source code files.