Tải bản đầy đủ (.pdf) (474 trang)

John wiley sons mastering xmi java programming with xmi xml and uml

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (1.62 MB, 474 trang )

Mastering XMI: Java Programming with XMI, XML, and UML
by Timothy J. Grose (Author), Gary C. Doney (Author), Stephen A.
Brodsky (Author)
Paperback: 480 pages ;
Publisher: John Wiley & Sons;
ISBN: 0471384291


Mastering XMI
Java Programming with
XMI, XML, and UML
Timothy J. Grose
Gary C. Doney
Stephen A. Brodsky, Ph.D.

Wiley Computer Publishing

John Wiley & Sons, Inc.
N EW YOR K • CH ICH ESTER • WEI N H EI M • B R ISBAN E • SI NGAPOR E • TORONTO



Mastering XMI
Java Programming with
XMI, XML, and UML



Mastering XMI
Java Programming with
XMI, XML, and UML


Timothy J. Grose
Gary C. Doney
Stephen A. Brodsky, Ph.D.

Wiley Computer Publishing

John Wiley & Sons, Inc.
N EW YOR K • CH ICH ESTER • WEI N H EI M • B R ISBAN E • SI NGAPOR E • TORONTO


Publisher: Robert Ipsen
Executive Editor: Robert M. Elliott
Developmental Editor: Emilie Herman
Managing Editor: John Atkins
New Media Editor: Brian Snapp
Text Design & Composition: MacAllister Publishing Services, LLC
Designations used by companies to distinguish their products are often claimed as trademarks. In all instances where John Wiley & Sons, Inc., is aware of a claim, the product names
appear in initial capital or ALL CAPITAL LETTERS. Readers, however, should contact the
appropriate companies for more complete information regarding trademarks and registration.
IBM, DB2, VisualAge, and WebSphere are trademarks or registered trademarks of IBM Corporation in the United States, other countries, or both.
Java and all Java-based trademarks and logos are trademarks of Sun Microsystems, Inc. in
the United States and/or other countries.
Microsoft, Windows, and Windows NT are either registered trademarks or trademarks of
Microsoft Corporation in the United States and/or other countries.
OMG, Object Management Group, OMG IDL, CORBA, XMI, MOF, CWM, Unified Modeling Language, UML, the UML Cube Logo, Model Driven Architecture, MDA, OMG Model
Driven Architecture, OMG MDA, and IIOP are trademarks or registered trademarks of the
Object Management Group, Inc., in the United States and other countries. All other names
and marks that may appear are used for identification purposes only and may be trademarks of their respective owners.
Pentium is a registered trademark of Intel Corporation.
Walkman is a registered trademark of Sony Corporation.

This book is printed on acid-free paper.
Copyright © 2002 by IBM. All rights reserved.
Published by John Wiley & Sons, Inc.
Published simultaneously in Canada.
No part of this publication may be reproduced, stored in a retrieval system or transmitted
in any form or by any means, electronic, mechanical, photocopying, recording, scanning or
otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization
through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222
Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 750-4744. Requests to the
Publisher for permission should be addressed to the Permissions Department, John Wiley
& Sons, Inc., 605 Third Avenue, New York, NY 10158-0012, (212) 850-6011, fax (212) 8506008, e-mail:
This publication is designed to provide accurate and authoritative information in regard to
the subject matter covered. It is sold with the understanding that the publisher is not
engaged in professional services. If professional advice or other expert assistance is
required, the services of a competent professional person should be sought.
Library of Congress Cataloging-in-Publication Data:
ISBN: 0-471-38429-1
Printed in the United States of America.
10 9 8 7 6 5 4 3 2 1


Advance Praise for
Mastering XMI

“XMI is a powerful standard for representing objects in XML and it plays key
roles in IBM’s WebSphere servers and WebSphere Studio application development tools. This book takes the mystery out of XMI, tells why it is important,
and shows Java programmers how to use it. Its authors made XMI work for
WebSphere and they build on that experience to explain the hows and whys of
XMI in an eminently readable and practical way.”
Lee R. Nackman

IBM Vice President, Application Development Tools
Member, IBM Academy of Technology
“Model Driven Architecture (MDA) is an appealing vision of how to develop
software, but there is little information readily available on how to apply these
somewhat abstract ideas in practice. Timothy Grose, Gary Doney, and Stephen
Brodsky remedy this deficiency by producing a comprehensive, grounded,
and detailed handbook on how to use XMI to create and integrate MDA applications using Java, XML, and UML. The CD contains a wealth of supporting
information, including a full-featured trial edition of IBM’s WebSphere Studio
Application Developer. This book is an essential read for any developer serious about applying the principles of Model Driven Architecture in real software development projects.”
Steve J. Cook
IBM Distinguished Engineer
Member, IBM Academy of Technology

v


vi

Advance Praise for Mastering XMI

“The convergence of modeling technologies into the UML that the OMG drove
home in 1997 has finally made software design and architecture a mainstream
activity. The convergence of the UML itself with the startling rise of XML is the
obvious next step: the communication of metamodels (and objects in general)
clearly relies on universal data formats such as XML. This explains the rapid
uptake of XMI in the software development community. This masterful book
gives everything the serious application developer needs, start to finish—from
motivation, through explanation, to clear, concise examples using XMI with
Java. As the Model Driven Architecture (MDA) sweeps the mess of software
heterogeneity under the rug, XMI at MDA’s core ensures interoperability

across tools and applications. And there’s no better way to learn the details
than this book.”
Richard Mark Soley, Ph.D.
Chairman and CEO, Object Management Group, Inc.


2001 OMG Press
Advisory Board

Karen D. Boucher

Jon Siegel, Ph.D.

Executive Vice President

Director, Technology Transfer

The Standish Group

Object Management Group, Inc.

Carol C. Burt

Richard Mark Soley, Ph.D.

President and Chief Executive
Officer

Chairman and Chief Executive
Officer


2AB, Inc.

Object Management Group, Inc.

Sridhar Iyengar

Sheldon C. Sutton

Unisys Fellow

Principal Information Systems
Engineer

Unisys Corporation

The MITRE Corporation
Cris Kobryn
Chief Technologist

Ron Zahavi

Telelogic

Chief Technology Officer
AxTechnology

Nilo Mitra, Ph.D.
Principal System Engineer
Ericsson


vii



OMG Press Books in Print

(For complete information about current and upcoming titles, go to
www.wiley.com/compbooks/omg/.)
■■

Building Business Objects by Peter Eeles and Oliver Sims, ISBN: 0-47119176-0.

■■

Business Component Factory: A Comprehensive Overview of Component-Based Development for the Enterprise by Peter Herzum and
Oliver Sims, ISBN: 0-471-32760-3.

■■

Business Modeling with UML: Business Patterns at Work by Hans-Erik
Eriksson and Magnus Penker, ISBN: 0-471-29551-5.

■■

CORBA 3 Fundamentals and Programming, 2nd Edition by Jon Siegel,
ISBN: 0-471-29518-3.

■■


CORBA Design Patterns by Thomas J. Mowbray and Raphael C.
Malveau, ISBN: 0-471-15882-8.

■■

Enterprise Application Integration with CORBA: Component and WebBased Solutions by Ron Zahavi, ISBN: 0-471-32720-4.

■■

Enterprise Java with UML by C.T. Arrington, ISBN: 0-471-38680-4.

■■

Enterprise Security with EJB and CORBA by Bret Hartman, Donald J.
Flinn, and Konstantin Beznosov, ISBN: 0-471-15076-2.

■■

The Essential CORBA: Systems Integration Using Distributed Objects
by Thomas J. Mowbray and Ron Zahavi, ISBN: 0-471-10611-9.

■■

Instant CORBA by Robert Orfali, Dan Harkey, and Jeri Edwards,
ISBN: 0-471-18333-4.

ix


x


OMG Press Books in Print

■■

Integrating CORBA and COM Applications by Michael Rosen and
David Curtis, ISBN: 0-471-19827-7.

■■

Java Programming with CORBA, Third Edition by Gerald Brose,
Andreas Vogel, and Keith Duddy, ISBN: 0-471-24765-0.

■■

The Object Technology Casebook: Lessons from Award-Winning Business Applications by Paul Harmon and William Morrisey, ISBN: 0-47114717-6.

■■

The Object Technology Revolution by Michael Guttman and Jason
Matthews, ISBN: 0-471-60679-0.

■■

Programming with Enterprise JavaBeans, JTS, and OTS: Building Distributed Transactions with Java and Cϩϩ by Andreas Vogel and Madhavan Rangarao, ISBN: 0-471-31972-4.

■■

Programming with Java IDL by Geoffrey Lewis, Steven Barber, and
Ellen Siegel, ISBN: 0-471-24797-9.


■■

Quick CORBA 3 by Jon Siegel, ISBN: 0-471-38935-8.

■■

UML Toolkit by Hans-Erik Eriksson and Magnus Penker, ISBN: 0-47119161-2.


About the OMG

The Object Management Group (OMG) is an open membership, not-for-profit
consortium that produces and maintains computer industry specifications for
interoperable applications. To achieve this goal, the OMG specifies open standards for every aspect of distributed computing from analysis and design,
through infrastructure, to application objects and components defined on virtually every enterprise middleware platform. OMG’s membership roster
includes virtually every large company in the computer industry, and hundreds of smaller ones. Most of the companies that shape enterprise and Internet computing today are represented on OMG’s Board of Directors.
OMG’s flagship specification, and the basis for future OMG specifications, is
the multi-platform Model Driven Architecture (MDA). Unifying the modeling
and middleware spaces, the MDA supports applications over their entire lifecycle from Analysis and Design, through implementation and deployment, to
maintenance and evolution. Based on normative, platform-independent Unified
Modeling Language (UML) models, MDA-based applications and standards
may be expressed and implemented, equivalently, on multiple middleware platforms; implementation are produced automatically, for the most part, by MDAenabled tools that also generate cross-platform invocations, making for a truly
interoperable environment. Because the UML models remain stable as the technological landscape changes around them over time, MDA-based development
maximizes software ROI as it integrates applications across the enterprise, and
one enterprise with another. Adopted by members as the basis for OMG specifications in September 2001, the MDA is truly a unique advance in distributed
computing. To learn more about the MDA, see www.omg.org/mda.
OMG’s modeling specifications form the foundation for the MDA. These
include the UML, the MetaObject Facility (MOF), XML Metadata Interchange
(XMI), and the Common Warehouse Metamodel (CWM). The industry’s

xi


xii

About the OMG

standard for representation of analysis and design, the UML defines Use Case
and Activity diagrams for requirements gathering, Class and Object diagrams
for design, Package and Subsystem diagrams for deployment, and six other
diagram types. The MOF defines a standard metamodel for applications,
allowing UML models to be interchanged among tools and repositories; and
XMI standardizes the format for these interchanges. Finally, CWM establishes
metamodels in the field of data warehousing, completing OMG’s standardization in the modeling space.
The Common Object Request Broker Architecture (CORBA) is OMG’s
vendor-neutral, system-independent middleware standard. Based on the
OMG/ISO Interface Definition language (OMG IDL) and the Internet InterORB Protocol (IIOP), CORBA is a mature technology represented on the market by more than 70 ORBs (Object Request Brokers) plus hundreds of other
products. Scalable to Internet and Enterprise levels, CORBA more than meets
business computing requirements through its robust services-providing directory, distributed event handling, transactionality, fault tolerance, and security.
Specialized versions of CORBA form the basis for distributed Realtime computing, and distributed embedded systems.
Building on this foundation, OMG Domain Facilities standardize common
objects throughout the supply and service chains in industries such as Telecommunications, Healthcare, Manufacturing, Transportation, Finance/
Insurance, Biotechnology, Utilities, Space, and Military and Civil Defense
Logistics. OMG members are now extending these Domain Facilities, originally written in OMG IDL and restricted to CORBA, into the MDA by constructing UML models corresponding to their underlying architecture;
standard MDA procedures will then produce standards and implementations
on such platforms as Web Services, XML/SOAP, Enterprise JavaBeans, and
others. OMG’s first MDA-based specification, the Gene Expression Facility,
was adopted less than six months after the organization embraced the MDA;
based on a detailed UML model, this specification is implemented entirely in
the popular language XML.

In summary, the OMG provides the computing industry with an open,
vendor-neutral, proven process for establishing and promoting standards.
OMG makes all of its specifications available without charge from its Web site,
www.omg.org. Delegates from the hundreds of OMG member companies convene at week-long meetings held five times each year at varying sites around
the world, to advance OMG technologies. The OMG welcomes guests to their
meetings; for an invitation, send your email request to or see
www.omg.org/news/meetings/tc/guest.htm.
Membership in OMG is open to any company, educational institution, or
government agency. For more information on the OMG, contact OMG headquarters by telephone at +1-781-444-0404, by fax at +1-781-444-0320, by email
to , or on the Web at www.omg.org.


For Nancy
—Tim Grose
For my mother and father
—Gary Doney
For Sharon and Alicia
—Stephen Brodsky



Contents

List of Figures, Tables, and Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xxi
Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xxvii
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xxix

Part 1

XMI Explained . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1


Chapter 1

XMI: Representing Objects in XML . . . . . . . . . . . . . . . . . . . . . . . . .3
The Importance of Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4
The Importance of XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5
The Gap between XML and Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7
How XMI Bridges the Gap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8
Benefits of XMI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10
XMI Uses XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10
Modeling and XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12
Creating Schemas from Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12
Working with Objects and XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .13
Exchanging XML Documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .13
Evolving Your XML Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .14
XMI Is Flexible . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .15
XMI and Meta Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .15
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .16

Chapter 2

Related Standards: XML and UML . . . . . . . . . . . . . . . . . . . . . . . .17
XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .18
The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .18

xv


xvi


Contents

Namespaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .20
XML Element Relationships . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .21
Document Type Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .23
Schemas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .25
Schema Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .26
Element and Type Declarations . . . . . . . . . . . . . . . . . . . . . . . . . . . . .26
Element Content . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .27
Attribute Declarations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .31
Attribute Groups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .32
Namespaces in Schemas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .32
Type Extension . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .34
Schema Import . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .35
Mapping Data to XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .35

UML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .37
The Java Object Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .38
The UML Object Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .39
Object Identity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .51
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .53
Chapter 3

XMI Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .55
UML Terminology and Use . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .56
Writing Objects Using XMI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .58
Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .58
XMI Documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .58
XML Documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .60
Object Identity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .61

Attribute Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .62
Data Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .63
Object Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .64
Namespaces and Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .67
References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .67
Representing References Using XML Attributes . . . . . . . . . . . . . . .68
Representing References Using XML Elements . . . . . . . . . . . . . . . .69
Namespaces and References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .69
Objects in Different Documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .70
Object Values in Different Documents . . . . . . . . . . . . . . . . . . . . . . .70
Referenced Objects in Different Documents . . . . . . . . . . . . . . . . . .71
Additional Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .72

Generating Schemas from Models . . . . . . . . . . . . . . . . . . . . . . . . . .74
Default XMI Schemas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .75
Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .75
Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .76
Datatypes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .77
Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .78
Association Ends . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .80
Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .81


Contents

Tailoring XMI Schemas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .82
Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .82
Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .83
Datatypes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .86
Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .87

Association Ends . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .95
Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .100
Tagged Value Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .101

The XMI Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .104
XML Attribute Declarations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .105
Extension Element . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .105
Identifying Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .106
Describing a Document . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .108
Differences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .108
XMI XML Element . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .115
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .116

Part 2

How to Use XMI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .117

Chapter 4

Creating Your XMI Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . .119
Overview of the XMI Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .120
Define Your Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .122
Create an XMI Schema . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .123
Design Your Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .125
Describing Your Documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .126
Cross-File References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .126
Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .127
Embedding XMI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .128
Recommendations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .128
Generate the Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .129

Implement the System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .129

XMI Process Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .130
The Situation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .131
Defining the Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .132
Creating an XMI Schema . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .135
Designing the Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .138
Generating the Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .138
Implementing the System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .141
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .141
Chapter 5

Creating Models for XMI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .143
UML Modeling Issues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .144
Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .144
Multiplicities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .145
Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .145
Datatypes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .146

xvii


xviii

Contents

Association Ends . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .147

Reverse Engineering Models from XML . . . . . . . . . . . . . . . . . . . .147
XML Documents to UML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .149

XML DTDs to UML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .152
XMI DTDs to UML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .157
XML Schemas to UML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .162
XMI Schemas to UML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .163
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .164
Chapter 6

Creating and Reading Simple XMI Documents with
Standard XML APIs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .165
Car Rental Agency Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .166
Using Standard XML APIs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .168
Using DOM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .168
Overview Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .170
Object Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .172
Using SAX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .180
CRAHandler1: Accessing and Printing Data in the XMI File . . . .190
CRAHandler2: Making Java Instances of the XMI
Document Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .192
CRAHandler3: Setting the Fields of the Java Instances . . . . . . . .196
CRAHandler4: Dealing with References . . . . . . . . . . . . . . . . . . . . .199

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .204
Chapter 7

Creating and Reading Simple XMI Documents with
the XMI Framework . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .205
Using the Java Object Bridge (JOB) . . . . . . . . . . . . . . . . . . . . . . . . . . . . .206
Creating an XMI Document . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .206
Reading an XMI Document . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .215


Using the XMI Framework . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .216
Creating an XMI Document . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .217
Using the Framework Object Model . . . . . . . . . . . . . . . . . . . . . . . .217
Using Your Own Java Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .223
Reading an XMI Document . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .230
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .248
Chapter 8

Creating and Reading Advanced XMI Documents
with the XMI Framework . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .251
A Quick Review . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .252
Namespaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .253
Describing Your Documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .261
Documentation Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .261
Model Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .263

XMI Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .273


Contents

ZIP Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .277
Cross-File References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .280
Code Generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .290
How to Generate Java Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .292
The Generated Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .293
Using the Generated Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .295
Understanding the
Implementation Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .301


Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .305
Chapter 9

XMI Schemas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .307
Creating XMI Schemas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .308
Creating an XMI Schema with the XMISchema
Framework Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .308
Validating Documents with the Framework . . . . . . . . . . . . . . . . . . . .311

Validating with XMI Schemas . . . . . . . . . . . . . . . . . . . . . . . . . . . . .314
XML Validation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .314
Errors Detected by Default XMI Schemas . . . . . . . . . . . . . . . . . . . . . .316
Errors Detected by Tailored XMI Schemas . . . . . . . . . . . . . . . . . . . . .317
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .325
Chapter 10 Model Driven Architecture (MDA) and XMI . . . . . . . . . . . . . . . .327
What Is the Model Driven Architecture? . . . . . . . . . . . . . . . . . . . . . . . . .328
Benefits of Modeling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .329
Information Representations and Modeling . . . . . . . . . . . . . . . . . . . . . .331
XMI and MOF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .332
Model Information Hierarchy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .333

The Flow Composition Model (FCM) . . . . . . . . . . . . . . . . . . . . . .335
Using FCM with the Car Broker Application . . . . . . . . . . . . . . . . . . . . . .336
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .350
Chapter 11 A Real-World Use of XMI: WebSphere Studio
Application Developer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .351
The XML to XML Mapping Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .352
The CD Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .353
The Source Schema . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .354
The Target Schema . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .354

The Mapping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .355
The Mapping Metamodel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .361

Using Models and EJBs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .361
Meta Data in WebSphere Studio . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .364
EJB XMI Mapping Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .372
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .373

xix


xx

Contents

Appendix A The XMI Framework: Supplemental Documentation . . . . . . . .375

Purpose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .376
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .377
Framework Object Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .377
XMI Files, DTDs, and Schemas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .378
Adapters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .380
Helper Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .380
Suggestions for Using the Framework . . . . . . . . . . . . . . . . . . . . .380
Framework Object Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .381
Objects and Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .381
XMIObjects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .382
Attribute Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .383
Link Ends . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .384
Creating and Setting Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .386

Classes and Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .388
Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .388
Definers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .392
Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .392
Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .393
Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .393
XMI Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .393
Namespaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .395
Encoding Non-XMI Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .396
Implementing Framework Object Model Interfaces . . . . . . . . . . . . .396

XMI Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .398
Creating Single XMI Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .398
Default Write Option . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .399
Other Write Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .401
Loading Single XMI Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .402
Header Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .403
Related XMI Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .404
Registering Models with the Framework . . . . . . . . . . . . . . . . . . . . . . .404

XMI DTDs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .405
XMI Schemas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .405
Code Generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .406
Using the Framework by Implementing Adapters . . . . . . . . . . .407
DeclarationFactory Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .407
Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .409
References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .413
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .417



List of Figures,
Code and Tables

Figures
Figure 1.1

An XML representation of car data . . . . . . . . . . . . . . . . . . . . . . . .6

Figure 1.2

The bridges required for different XML representations . . . . . . .7

Figure 1.3

Transforming objects to XML elements . . . . . . . . . . . . . . . . . . . . .8

Figure 1.4

Using XMI software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9

Figure 1.5

The relationship between a UML model, an XMI document,
and an XMI schema . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9

Figure 1.6

XMI builds upon XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11

Figure 1.7


XMI documents and schemas are XML documents
and schemas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11

Figure 1.8

Using XMI to exchange objects among tools . . . . . . . . . . . . . . .14

Figure 2.1

UML class notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .41

Figure 2.2

Classes F and G . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .42

Figure 2.3

UML inheritance notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .43

Figure 2.4

UML package notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .44

Figure 2.5

UML association notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .45

Figure 2.6


UML unidirectional association notation . . . . . . . . . . . . . . . . . .45

Figure 2.7

UML aggregation notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .46

Figure 2.8

UML composition notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .47

Figure 2.9

UML attribute representing composition . . . . . . . . . . . . . . . . . .48

Figure 2.10

A simple object diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .48
xxi


xxii

List of Figures, Code and Tables

Figure 2.11

Attribute values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .49

Figure 2.12


Object links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .50

Figure 2.13

UML datatype notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .50

Figure 2.14

UML enumeration notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .51

Figure 3.1

The Car class with a part object attribute . . . . . . . . . . . . . . . . .57

Figure 3.2

The Car class with the style object attribute . . . . . . . . . . . . . . .65

Figure 3.3

A car with three kinds of parts . . . . . . . . . . . . . . . . . . . . . . . . . . .66

Figure 3.4

A car has drivers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .68

Figure 3.5

The Driver class inherits from the Person class . . . . . . . . . . . .82


Figure 3.6

The Car class with attributes and association ends . . . . . . . . .85

Figure 3.7

The Car class with the available attribute . . . . . . . . . . . . . . . . .89

Figure 3.8

A Car with passengers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .97

Figure 3.9

A Car has a driver and a Person has a car . . . . . . . . . . . . . . . . .98

Figure 3.10

The Extension class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .106

Figure 3.11

Class declarations for identifying models . . . . . . . . . . . . . . . . .107

Figure 3.12

The Documentation class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .109

Figure 3.13


Difference classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .110

Figure 3.14

The Car, Part, Engine, and Cylinder model . . . . . . . . . . . . . .111

Figure 3.15

The XMI class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .115

Figure 4.1

The XMI process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .121

Figure 4.2

Dave’s model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .132

Figure 4.3

Bob’s model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .133

Figure 4.4

The final model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .134

Figure 5.1

Attribute multiplicity specified using a UML stereotype . . . . .146


Figure 5.2

A UML attribute corresponding to a nested XML element . . .151

Figure 5.3

A UML association corresponding to a nested
XML element . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .152

Figure 5.4

A UML attribute corresponding to text in an
XML document . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .152

Figure 5.5

A UML enumeration corresponding to an
XML enumeration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .155

Figure 5.6

A UML association corresponding to an XML
attribute of type IDREFS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .157

Figure 5.7

Two unidirectional associations between the
Person and Car classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .158

Figure 5.8


The class hierarchy for classes O, M, and N . . . . . . . . . . . . . . .162


×