A Domain-Specific Language Toolkit
Upper Saddle River, NJ • Boston • Indianapolis • San Francisco
New York • Toronto • Montreal • London • Munich • Paris • Madrid
Cape Town • Sydney • Tokyo • Singapore • Mexico City
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and the publisher was aware of a trademark claim, the designations have been printed with initial capital letters or in all capitals.
The author and publisher have taken care in the preparation of this book but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for incidental or consequential damages in connection with or arising out of the use of the information or programs contained herein.
The publisher offers excellent discounts on this book when ordered in quantity for bulk purchases or special sales, which may include electronic versions and/or custom covers and content particular to your business, training goals, marketing focus, and branding interests. For more information, please contact:
U.S. Corporate and Government Sales
(800) 382-3419
[email protected]
For sales outside the United States, please contact:
International Sales
[email protected]
Visit us on the Web: informit.com/aw
Library of Congress Cataloging-in-Publication Data:
Gronback, Richard C.
Eclipse modeling project: a domain-specific language (DSL) toolkit / Richard C.
Gronback.
p. cm.
ISBN 0-321-53407-7 (pbk.: alk. paper) 1. Computer software—Development.
2. Eclipse (Electronic resource) 3. Programming languages (Electronic computers)
I. Title.
QA76.76.D47G785 2009
005.1—dc22
2008050813
Copyright © 2009 Pearson Education, Inc.
All rights reserved. Printed in the United States of America. This publication is protected by copyright, and permission must be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permissions, write to:
Pearson Education, Inc.
Rights and Contracts Department
501 Boylston Street, Suite 900
Boston, MA 02116
Fax (617) 671 3447
ISBN-13: 978-0-321-53407-1
ISBN-10: 0-321-53407-7
Text printed in the United States on recycled paper at Courier in Stoughton,
Massachusetts.
First printing March 2009
Associate Publisher
Mark Taub
Acquisitions Editor
Greg Doench
Managing Editor
Kristy Hart
Project Editor
Jovana San Nicolas-Shirley
Copy Editor
Krista Hansing Editorial
Services, Inc.
Indexer
Erika Millen
Technical Reviewer
Simon Archer
David Orme
Daniel Holt
Publishing Coordinator
Michelle Housley
Cover Designer
Sandra Schroeder
Compositor
Nonie Ratcliff
1.3 Model-Driven Software Development
1.4 Software Product Lines and Factories
1.5 The Eclipse Modeling Project
1.5.1 Abstract Syntax Development
1.5.2 Concrete Syntax Development
1.5.4 Model Development Tools (MDT)
1.5.5 Generative Modeling Technologies
Chapter 2 Modeling Project as a DSL Toolkit
Part II • Developing Domain-Specific Languages
Chapter 3 Developing a DSL Abstract Syntax
3.2 Eclipse Modeling Framework
3.3 Developing the Mindmap Domain Model
3.3.2 Creating the Mindmap Domain Model
3.3.3 Creating the Mindmap Generator Model
3.4 Developing the Requirements Domain Model
3.4.1 Requirements Generator Model
3.5 Developing the Scenario Domain Model
3.6 Developing the Business Domain Model
Chapter 4 Developing a DSL Graphical Notation
4.2 Graphical Modeling Framework
4.2.5 Sample Application Diagrams
4.3 Developing the Mindmap Diagram
4.3.1 Mindmap Graphical Definition
4.3.2 Mindmap Tooling Definition
4.3.5 Improving the Mindmap Diagram
4.4 Developing a Requirements Diagram
4.4.6 Integrating EMF and GMF Editors
4.5 Developing the Scenario Diagram
4.5.5 Generating the Figures Plug-In
4.6 Developing the Color Modeling Diagram
Chapter 5 Developing a DSL Textual Syntax
Chapter 6 Developing Model-to-Model Transformations
6.5 M2M QVT Operational Mapping Language
6.5.6 Leveraging OCL in EMF Models
6.6 Transforming a Mindmap to Requirements
6.7 Transforming a Mindmap to XHTML
6.7.2 Creating the mindmap2xhtml QVT
6.8 Transforming a Scenario to a Test Case
6.9 Transforming a Business Model to Java
Chapter 7 Developing Model-to-Text Transformations
7.1.1 Xpand, Xtend, and Workflow Components
7.3.1 Using Java Model and Dedicated Template
7.3.2 Using the DNC Model with Templates
Chapter 8 DSL Packaging and Deployment
8.1.2 Developing a User Interface Plug-In
Chapter 9 Graphical Editing Framework
9.2.2 Creating the Graphical View
Chapter 10 Graphical Modeling Framework Runtime
10.1.1 General Diagram Features
10.4.7 Marker Navigation Service
10.4.9 ModelingAssistantService
10.4.11 ContributionItemService
10.4.12 GlobalActionHandlerService
10.4.15 ElementSelectionService
10.4.17 PropertiesModifierService
10.4.18 DragDropListenerService
10.4.19 TransferAdapterService
10.4.20 DiagramEvenBroker Service
10.5 Additional Extension-Points
10.5.4 PropertiesConfigurations
10.7.2 Model Element Command Infrastructure
10.8.1 Essential Diagram Elements
10.8.2 Configuring the Properties View
10.8.4 Comparison to Generated Diagram
10.9.1 Scenario Diagram Custom View and Edit Providers
Chapter 11 Graphical Modeling Framework Tooling
11.1 Graphical Definition Model
11.3.5 Implementing Side-Affixed Nodes (Pins and Ports)
Chapter 12 Graphical Modeling Framework FAQs
Chapter 13 Query/View/Transformation Operational Mapping Language
13.1 Transformation Declaration
13.1.1 In-Place Transformations
13.1.4 Configuration Properties
13.3.3 Inheritance, Merger, and Disjunction
13.5.1 Operations and Iterators
13.5.3 Imperative Iterate Expressions
13.5.4 Object Creation and Population
13.5.7 Executing Transformations
13.6.5 Numeric Type Operations
13.8 Simple UML to RDBMS Example
Chapter 14 Xpand Template Language
Appendix A Graphical Modeling Framework Key Bindings
Appendix B Model-Driven Architecture at Eclipse Implemented Standards
Unified Modeling Language (UML)
Object Constraint Language (OCL)
XML Metadata Interchange (XMI)
MOF Query/View/Transformation (QVT)
MOF Models to Text Transformation Language
Human-Usable Textual Notation (HUTN)
Business Process Modeling Notation (BPMN)
Software Process Engineering Metamodel (SPEM)
Implementations Influencing Specifications
Just like a pearl, the Eclipse Modeling Project has grown organically as layers around a central core. From the humble beginnings of the Eclipse Modeling Framework (EMF) (initially part of the Eclipse Tools Project) along with the Graphical Modeling Framework (GMF) and the Generative Modeling Tools (GMT) (both initially part of the Eclipse Technology Project), the Modeling Project coalesced to become one of Eclipse’s most exciting and diverse projects. The depth and breadth of its technology is vast and even its rate of growth continues to increase. The Eclipse Modeling Project has truly become a Swiss Army knife for state-of-the-art model-driven software development.
The sheer volume of useful modeling technologies that the Eclipse Modeling Project includes makes mastering a significant portion of it a daunting task. Even determining which specific available technologies are useful for solving any particular problem is a challenge exacerbated by the fact that, as a rule, the documentation tends to lag far behind the development work. As such, this book fills a fundamentally important need in the modeling community: a coherent vision of how all this powerful technology can be best exploited to build domain specific languages (DSLs). In other words, the focus of this book is on pragmatic applications illustrated by way of concrete examples rather than on abstract modeling concepts and theories. This pragmatic focus reflects that of the Modeling Project overall—that is, a focus on building powerful frameworks that real programmers use every day. I’m sure this influential book—with its interesting examples and its excellent reference material—will become a key part of every toolsmith’s technical arsenal.
EMF provides a sound basis for abstract syntax development and even includes a crude but effective XML-based concrete syntax. But, that is only the start of the journey, and the second edition of the Eclipse Modeling Framework book covers this basic material well. This book effectively picks up where EMF leaves off with an in-depth exploration of alternative forms of concrete syntax, particularly graphical syntax, model-to-model transformation (such as Query View Transformation Operational Mapping Language), and model-to-text transformation (such as Xpand). It rounds out the DSL picture with a holistic view of everything it takes to build a complete model-based product line.
It has been my great pleasure and honor to work closely with Richard C. Gronback as the Modeling Project coleader for the past few years. He has a keen mind and a sharp wit. This book reflects it well. I’ve learned a great deal from him, and I’m sure readers of this book will as well.
—Ed Merks, Ph.D.
President, Macro Modeling
This book covers a relatively new collection of technologies that focus on developing domain-specific languages (DSLs) using the Eclipse Modeling Project, offering a first look at a range of Eclipse projects that have not yet been covered in detail within this context. Although the core of these technologies has been available for several years in the Eclipse Modeling Framework (EMF), diagram definition and model transformation are emerging technologies at Eclipse. These are complemented by upcoming textual syntax development frameworks, which likely will be covered in detail in subsequent editions of this book.
This book delivers a pragmatic introduction to developing a product line using a collection of DSLs. A model-based, largely generative approach is designed to accommodate future adjustments to the source models, templates, and model transformation definitions, to provide customized solutions within the context of the product line. To illustrate this approach, this book presents a set of sample projects used to define a requirements product line.
This book targets developers and architects who want to learn about developing DSLs using Eclipse Modeling Project technologies. It assumes a basic understanding of the Java programming language, Eclipse plug-in development, and familiarity with EMF. This book’s target audience are those interested in learning about the Eclipse Graphical Modeling Framework (GMF), Model-to-Model Transformation (M2M) Query/View/Transformation Operational Mapping Language (QVT OML), and Model-to-Text Transformation (M2T) Xpand project components.
The book is divided into introductory, hands on, and reference sections. Readers who want an overview of the Eclipse Modeling Project and development of DSLs in the context of an Eclipse-based product line should read Part I, “Introduction.” Readers who want to follow along in a tutorial fashion to learn how to use the projects listed earlier should read Part II, “Developing Domain-Specific Languages.” Readers also can reference the sample project solutions in this section to get an overview of the techniques. Part III, “Reference,” serves as a resource for readers who want a deeper understanding of Graphical Editing Framework (GEF), GMF, Xpand, and QVT OML while they are completing Part II or developing their own DSL-based projects.
Readers who want to experience the benefits of a commercial version of the technologies presented here can download the Borland Together product. There they will find enhanced domain modeling, refactoring, diagram development, transformation authoring and debugging, workflow, and generation capabilities in a well-integrated DSL Toolkit.
The Modeling Amalgamation Project (Amalgam) at Eclipse holds the sample code from this book and is available as sample projects in the DSL Toolkit download. This package also includes all the prerequisites required for developing the sample applications.
Visit the Amalgam project Web site for more information on obtaining the DSL Toolkit: www.eclipse.org/modeling/amalgam.
The examples in this book are maintained within the Modeling Amalgamation Project at Eclipse. Feedback on their content—and, therefore, this book’s content—is welcome on the project newsgroup, http://news.eclipse.modeling.amalgam. Alternatively, feel free to contact the author directly at [email protected].
This book would not have been possible without the help of many great people, especially because its contents are based almost exclusively on the work of others. I have worked over the years with a number of terrific people, but this book all started with a team of exceptional developers that comprised the initial Borland contingent of the GMF project: Artem Tikhomirov, Alexander “Vano” Shatalin, Boris Blajer, Dmitry Stadnik, Max Feldman, Michael “Upstairs” Golubev, and Radek Dvorak. Our small team led the way into the world of Eclipse contribution from Borland, thanks to the support of our management at the time, Raaj Shinde and Boz Elloy.
Our colleagues from IBM were also instrumental in the success of GMF and have been a pleasure to work with over the years. Thanks to Fred Plante, Anthony Hunter, Christian Damus, Linda Damus, Mohammed Mostafa, Cherie Revells, and the rest of the GMF runtime team.
I have greatly enjoyed working with Ed Merks, who helped form the top-level Eclipse Modeling and served as co-leader of its PMC. Thanks also to Kenn Hussey, Paul Elder, Jean Bezivin, Sven Efftinge, and Frederic Jouault, all on the PMC representing the breadth of projects within Modeling, for making our project the success it has become.
Today the modeling team at Borland has expanded its Eclipse contribution to other technologies covered in this book. Thanks to Artem for pushing us toward Xpand, and to the openArchitectureWare team who initially developed it, particularly Bernd Kolb who was most helpful during the writing of the Xpand chapter. Thanks to Radek for taking on the task of open sourcing and improving our QVT Operational Mapping Language implementation, along with the talented Sergey Boyko and Alexander Igdalov. Thanks to Michael for taking on the task of developing UML diagrams using GMF for contribution to the MDT project, along with the excellent help of Sergey Gribovsky and Tatiana Fesenko. It has been a privilege working with Konstantin Savvin and the rest of our team in Prague and St. Petersburg over the past few years.
This book also served as an exercise to develop requirements for our commercial DSL Toolkit—thanks to our current management team, Steve McMenamin and Pete Morowski, for providing excellent support and encouragement. Thanks also to Tom Gullion and Ian Buchanan for being fantastic stewards and product managers for the Together product line.
Thanks again to those who reviewed portions or all of this book and provided valuable feedback, particularly Karl Frank and Angel Roman. I especially want to thank Artem Tikhomirov and Alex Shatalin for their support and feedback while writing this book. At Addison-Wesley, thanks to Greg Doench for his support and encouragement during the publishing process, and to Jovana San Nicolas-Shirley and Krista Hansing for making it readable. And thanks to Ian Skerret, who introduced me to Greg during EclipseCon 2007 and got the ball rolling.
On the home front, extra special thanks go to my wife, Pam, and son, Brandon, who afforded me the time and peace to work evenings and weekends, even through the winter holiday season of 2007. And finally, I must thank my parents for providing a strong foundation and the best possible example to live by.
Richard Gronback is the chief scientist for modeling products at Borland Software Corporation, where he manages both open source and commercial product development. Richard represents Borland on the Eclipse Board of Directors and Planning and Architecture Councils, co-leads the Modeling project Project Management Committee (PMC), and leads the GMF and Amalgam projects. Richard holds a Bachelor of Software Engineering degree in computer science and engineering from the University of Connecticut. He was a reactor operator in the U.S. Navy before entering his current career in software.
18.117.196.184