Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Mastering UML with Rational Rose 2002.pdf
Скачиваний:
137
Добавлен:
02.05.2014
Размер:
9.68 Mб
Скачать

Chapter 16: XML DTD Code Generation and Reverse Engineering

DTD Code−Generation Properties

Rose XML provides DTD specification windows for the classes in the model. You will see a slightly different window for each DTD stereotype supported by Rose. In this section, we'll look at the different properties you can set for classes with the various DTD stereotypes.

Regardless of the stereotype, to view the specification window, you right−click the class and select Open Specification.

You can set code−generation properties for the following items:

Project

Classes

Attributes

Roles

Components

In this section, we will use the following DTD example to discuss the different code−generation properties. This is an example of a DTD file that defines a book:

<!—The following DTD defines a book—>

<!ELEMENT book (title,tableofcontents,introduction?,section+)> <!ELEMENT chapter (title,paragraph+)>

<!ATTLIST chapter ChapterNum ID #REQUIRED Description CDATA #REQUIRED NumPages CDATA #REQUIRED

>

<!ELEMENT introduction (paragraph+)>

<!ELEMENT section (title,chapter+,paragraph+)> <!ELEMENT paragraph (#PCDATA)>

<!ELEMENT title (#PCDATA)> <!ELEMENT tableofcontents (#PCDATA)>

Project Properties

The project specifications control the editor that will be used, and set the different code−generation options for the overall project. To view the project properties, select Tools → XML_DTD → Project Specification. The window shown in Figure 16.1 will appear.

546

Chapter 16: XML DTD Code Generation and Reverse Engineering

Figure 16.1: XML Project Specification window

The XML project properties are listed in Table 16.2. The settings here will affect all classes, relationships, and other elements in the Rose model.

Table 16.2: XML Project Properties

Property

Purpose

Default

Editor

Controls the editor, which uses, views, and edits a DTD. Select

Built−In

 

from Built−In (Rose editor) or Windows Shell, or type in the

 

 

name of a third−party editor you would like to use.

 

Stop On Error

Stops the code−generation process if an error is encountered.

True

Create Missing

Create directories for the components in the model.

True

Directories

 

 

Class Properties

Rose XML provides different code−generation properties for the different types of classes you can create. Each type of class has its own stereotype, such as DTDElement or DTDEntity. In this section, we'll look at each of these stereotypes and examine the code−generation properties that can be set.

In the "Generated Code" section later in this chapter, we will take a closer look at each of these types of classes, discuss their purposes, and describe the UML notation used for the class.

Before you attempt to generate code, you should review the code−generation properties for your classes to help ensure that the code you get is the code you expected to get. Let's begin by looking at a class with a stereotype of DTDElement.

547

Chapter 16: XML DTD Code Generation and Reverse Engineering

DTDElement

A class with a stereotype of DTDElement corresponds to an ELEMENT declaration in a DTD file. To expand on our earlier example (see the "Elements" section), there are several elements: book, tableofcontents, introduction, section, chapter, paragraph, and title. Each of these is modeled as a class with a stereotype of DTDElement.

The code−generation properties for a DTD element include the element name, type, and comments. Figure 16.2 shows the Class Specification window for a DTD element.

Figure 16.2: Class Specification window for a DTD element

You can change the name of the element in the Name field. The Type field sets the stereotype of the element. The stereotypes include:

DTDEmpty, which is an empty element, suggesting that the element cannot contain text or other elements. However, these elements can still have attributes.

DTDPCDATA, which is an element that can contain text.

DTDAny, which is an element that can contain text or other elements.

Finally, you can enter a comment for the element in the DocComment field. Any comments you enter here will appear as comments in the generated DTD.

548

Chapter 16: XML DTD Code Generation and Reverse Engineering

DTDGroup

The DTDGroup stereotype is used to show a collection of elements that make up the content model of another element. In the book example:

<!ELEMENT book (title,tableofcontents,introduction?,section+)>

a DTD group is used to show the grouping of the title, table of contents, introduction, and section in the content model for a book. Figure 16.3 shows the notation. We will discuss this notation in detail in the "Generated Code" section of this chapter.

Figure 16.3: DTD group example

There are two code−generation properties on the specification window for a DTDGroup class. The first is the Grouping Type, which can be set to one of two settings:

The Choice setting will generate code in the format ELEMENT A (B|C), suggesting that element A consists of either B or C.

The Sequence setting will generate code in the format ELEMENT A (B,C), suggesting that element A consists of B and C, in that order.

The second code−generation property is set in the Occurrence field, which determines the multiplicity of the elements in the content model.

DTDEntity

A DTD entity is used as a placeholder for a single character or a string of text. It can also be used as a placeholder for video, audio, or other types of information. You can set the code−generation properties for an entity by using the specification window shown in Figure 16.4.

549

Chapter 16: XML DTD Code Generation and Reverse Engineering

Figure 16.4: Class Specification window for a DTD entity

Table 16.3 lists the entity code−generation properties and the purpose of each.

Table 16.3: DTD Entity Properties

Property

Purpose

Parameter Entity

Determines whether this is a parameter entity.

External Entity

Determines whether this is an external entity, which refers to a file

 

that is outside the XML DTD.

Internal Entity Value

Sets the character, string, or other entity to use in place of an

 

internal entity.

External Entity System ID

Location (URL) of the external file.

External Entity Public ID

Alternate location of the external file.

External Entity Notation Name

Format of the external file. If this property is set, a notation must be

 

created for the external entity (see the "DTDNotation" section on

 

the next page).

Comments

Comments for the entity. Comments will be generated in the DTD.

DTDNotation

 

An external entity can be further described with a notation. The notation specifies the format (audio, video, word processor, etc.) for the external entity. The code−generation properties for a notation are set with the specification window for the class, as shown in Figure 16.5.

550