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

Chapter 16: XML DTD Code Generation and Reverse Engineering

The Default Value and Initial Value fields determine whether or not the attribute is required and what the initial value in the attribute will be. Neither the initial value nor the default value is required. The possible settings include the following:

The #REQUIRED default value suggests that the attribute is required to have a value on every occurrence of the element in the document. The initial value may or may not be entered if #REQUIRED is set. If an initial value is entered, it will be generated in the code as the initial value for the attribute.

The #IMPLIED default value suggests that the attribute is not required and an initial value is not present.

The #FIXED default value means that the attribute is not required, but if it is present, it must match the initial value.

No default value means that an initial value should be entered. The attribute will not be required in the document, but if it is not present, the initial value will be assumed.

Reverse Engineering DTD

While generating a DTD can be useful, it may be even more valuable to reverse engineer existing DTD files into your Rose models. Many projects have a number of large and complex DTD structures, and Rose is an excellent way of visualizing these structures. This can be particularly useful when trying to analyze the structure of a complex DTD that you didn't create.

In this section, we'll discuss how to reverse engineer a DTD or group of DTD files into your Rose model.

1.

To begin, create a new model or open an existing model.

2.

Select Tools → XML_DTD → Reverse Engineer XML DTD.

3.

Rose will display the XML/DTD Reverse Engineering dialog box, as shown in Figure 16.18.

4.

Select the files you wish to reverse engineer in the upper−right portion of the screen, and press Add.

5.

Select the files to reverse engineer from the list in the bottom portion of the screen, and press Reverse.

6.

When finished, press Done.

564

Chapter 16: XML DTD Code Generation and Reverse Engineering

Rose will create a folder in the Logical view called NewPackage. All reverse−engineered items will be placed in this folder.

Figure 16.18: XML/DTD Reverse Engineering dialog box

Summary

In this chapter, we discussed how Rose can be used to model and generate an XML DTD file. We examined how DTD elements, attributes, entities, and content models can be structured in Rose, and how Rose can create the DTD file. Finally, we discussed the reverse engineering of a DTD file into a Rose model.

To review, these steps should be followed to generate a DTD:

1.

Set the code−generation properties.

2.

Select Tools → XML_DTD → Syntax Check.

3.

Create a component to represent the DTD file, and map the classes to the DTD component.

4.

Select the class(es) you wish to generate.

5.

Select Tools → XML_DTD → Generate Code.

6.

To view the generated DTD for a class, right−click the class on a diagram and select XML_DTD → Browse DTD Source.

The following steps should be followed to reverse engineer a DTD:

1.

565

Chapter 16: XML DTD Code Generation and Reverse Engineering

Select Tools → XML_DTD → Reverse Engineer XML DTD.

2.

Select the files you wish to reverse engineer in the upper−right portion of the screen, and press Add.

3.

Select the files to reverse engineer from the list in the bottom portion of the screen, and press Reverse.

4.

When finished, press Done.

In the next chapter, we'll examine the creation and reverse engineering of CORBA elements using Rose. CORBA is an interface standard that helps components communicate, even if the components are programmed in different languages. Using Rose, you can design CORBA elements, set up relationships between the CORBA classes and classes in other languages, and generate the CORBA classes. Or, you can reverse engineer an application with CORBA elements to analyze the application architecture.

566

Chapter 17: CORBA/IDL Code Generation and

Reverse Engineering

Rounding out the powerful code−generation abilities of Rose is the CORBA/IDL add−in. From your Rose model, you can forward engineer code through the Component diagrams. In order to create the code, however, Rose will examine the properties of the classes—including the code−generation properties, attributes, operations, relationships, and packages—in the Logical view.

Setting IDL code−generation properties

Generating IDL code from your Rose model

Mapping Rose elements to IDL constructs

Reverse engineering IDL source code

CORBA/IDL Code−Generation Properties

CORBA (Common Object Request Broker Architecture) is a specification that supports the use of distributed objects. Through the interface definition language (IDL), a developer can create language−independent interfaces for components. The developer can then create components in multiple languages, and use IDL to help the objects communicate. The CORBA/IDL that is generated from your Rose model is controlled by a series of code−generation property sets. Rose includes a property set for attributes, classes, dependencies, aggregations, module bodies, module specifications, operations, associations, subsystems, and for the overall project.

You can view and set all of these properties by selecting Tools → Options, then selecting the CORBA tab.

567