the eclipse series Image

SERIES EDITORS Erich Gamma • Lee Nackman • John Wiegand

Eclipse is a universal tool platform, an open extensible integrated development environment (IDE) for anything and nothing in particular. Eclipse represents one of the most exciting initiatives hatched from the world of application development in a long time, and it has the considerable support of the leading companies and organizations in the technology sector. Eclipse is gaining widespread acceptance in both the commercial and academic arenas.

The Eclipse Series from Addison-Wesley is the definitive series of books dedicated to the Eclipse platform. Books in the series promise to bring you the key technical information you need to analyze Eclipse, high-quality insight into this powerful technology, and the practical advice you need to build tools to support this evolutionary Open Source platform. Leading experts Erich Gamma, Lee Nackman, and John Wiegand are the series editors.

Titles in the Eclipse Series

Richard C. Gronback, Eclipse Modeling Project: A Domain-Specific Language (DSL) Toolkit
978-0-321-53407-1

Diana Peh, Nola Hague, and Jane Tatchell, BIRT: A Field Guide to Reporting, Second Edition
978-0-321-58027-6

Dave Steinberg, Frank Budinsky, Marcelo Paternostro, and Ed Merks, EMF: Eclipse Modeling
Framework

978-0-321-33188-5

Jason Weathersby,Tom Bondur, Iana Chatalbasheva, and Don French, Integrating and Extending
BIRT, Second Edition
978-0-321-58030-6

Naci Dai, Lawrence Mandel, and Arthur Ryman, Eclipse Web Tools Platform: Developing Java
Web Applications
978-0-321-39685-3

David Carlson, Eclipse Distilled,
978-0-321-28815-8

Eric Clayberg and Dan Rubel, Eclipse Plug-ins,Third Edition,
978-0-321-42672-7

Jeff McAffer and Jean-Michel Lemieux,Eclipse Rich Client Platform: Designing, Coding, and Packaging JavaApplications
978-0-321-33461-9

Erich Gamma and Kent Beck, Contributing to Eclipse: Principles, Patterns, and Plug-Ins
978-0-321-20575-9

For more information on books in this series visit www.informit.com/series/eclipse

Eclipse Modeling Project

A Domain-Specific Language Toolkit

Richard C. Gronback

image

Upper Saddle River, NJ • Boston • Indianapolis • San Francisco
New York • Toronto • Montreal • London • Munich • Paris • Madrid
Cape Town • Sydney • Tokyo • Singapore • Mexico City

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

Dedicated to my father, Philip Richard Gronback, Sr.
November 2, 1948–December 8, 1997

Contents

Foreword

Preface

Acknowledgments

About the Author

Part I • Introduction

Chapter 1   Introduction

1.1 About Modeling

1.2 Domain-Specific Languages

1.2.1 Why Develop a DSL?

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.3 Model Transformation

1.5.4 Model Development Tools (MDT)

1.5.5 Generative Modeling Technologies

1.5.6 Amalgamation

1.5.7 Project Interaction

1.6 Summary

Chapter 2   Modeling Project as a DSL Toolkit

2.1 Installation

2.2 The Sample Projects

2.3 Summary

Part II • Developing Domain-Specific Languages

Chapter 3   Developing a DSL Abstract Syntax

3.1 DSL Considerations

3.2 Eclipse Modeling Framework

3.2.1 Ecore Metamodel

3.2.2 Runtime Features

3.2.3 Code Generation

3.2.4 Applying OCL

3.2.5 Dynamic Instances

3.3 Developing the Mindmap Domain Model

3.3.1 Project Setup

3.3.2 Creating the Mindmap Domain Model

3.3.3 Creating the Mindmap Generator Model

3.3.4 Generate and Run

3.3.5 Adding OCL

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

3.7 Summary

Chapter 4   Developing a DSL Graphical Notation

4.1 Design Considerations

4.1.1 Notation Design

4.1.2 Filters and Layers

4.1.3 Layout

4.1.4 Synchronization

4.1.5 Shortcuts

4.2 Graphical Modeling Framework

4.2.1 GMF Runtime Component

4.2.2 GMF Tooling Component

4.2.3 Customization Options

4.2.4 Dashboard

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.3 Mindmap Mapping Model

4.3.4 Mindmap Generator Model

4.3.5 Improving the Mindmap Diagram

4.4 Developing a Requirements Diagram

4.4.1 Diagram Definition

4.4.2 Tooling Definition

4.4.3 Mapping Definition

4.4.4 Generation

4.4.5 ToolTips

4.4.6 Integrating EMF and GMF Editors

4.5 Developing the Scenario Diagram

4.5.1 Graphical Definition

4.5.2 Tooling Definition

4.5.3 Mapping Definition

4.5.4 Generation

4.5.5 Generating the Figures Plug-In

4.5.6 Diagram Partitioning

4.5.7 Database Persistence

4.6 Developing the Color Modeling Diagram

4.6.1 Diagram Definition

4.6.2 Tooling Definition

4.6.3 Mapping Definition

4.6.4 Generation

4.6.5 Gradient Figures

4.6.6 Color Preferences

4.6.7 Custom Parsers

4.7 Summary

Chapter 5   Developing a DSL Textual Syntax

5.1 Xtext

5.2 TCS

5.3 Summary

Chapter 6   Developing Model-to-Model Transformations

6.1 Transformation Techniques

6.2 Model Refactoring

6.3 Model Migration

6.4 Model Merge

6.5 M2M QVT Operational Mapping Language

6.5.1 QVT Project

6.5.2 QVT OML Editor

6.5.3 Metamodel Explorer

6.5.4 Launch Configuration

6.5.5 Trace Model

6.5.6 Leveraging OCL in EMF Models

6.5.7 Ant Tasks

6.6 Transforming a Mindmap to Requirements

6.7 Transforming a Mindmap to XHTML

6.7.1 Importing an XSD

6.7.2 Creating the mindmap2xhtml QVT

6.8 Transforming a Scenario to a Test Case

6.9 Transforming a Business Model to Java

6.10 Summary

Chapter 7   Developing Model-to-Text Transformations

7.1 M2T Project

7.1.1 Xpand, Xtend, and Workflow Components

7.2 Generating CSV Files

7.3 Generating Java

7.3.1 Using Java Model and Dedicated Template

7.3.2 Using the DNC Model with Templates

7.4 Generating HTML

7.5 Summary

Chapter 8   DSL Packaging and Deployment

8.1 Deployment Preparation

8.1.1 Artwork

8.1.2 Developing a User Interface Plug-In

8.1.3 Generation Models

8.2 Defining a Product

8.2.1 Deploying Source

8.3 Summary

Part III • Reference

Chapter 9   Graphical Editing Framework

9.1 Draw2d

9.1.1 Figures

9.1.2 Text

9.1.3 Painting

9.1.4 Layout

9.1.5 Connections and Routing

9.1.6 Coordinate Systems

9.2 GEF

9.2.1 EditParts

9.2.2 Creating the Graphical View

9.2.3 Editing

9.2.4 The EditPart Life Cycle

9.2.5 Tools and the Palette

9.2.6 Interactions

9.3 Summary

Chapter 10   Graphical Modeling Framework Runtime

10.1 Overview

10.1.1 General Diagram Features

10.2 Notation Model

10.3 Extensibility Mechanisms

10.3.1 Extension-Points

10.4 Services

10.4.1 ViewService

10.4.2 EditPartService

10.4.3 Edit PolicyService

10.4.4 Palette Service

10.4.5 Decoration Service

10.4.6 Icon Service

10.4.7 Marker Navigation Service

10.4.8 ParserService

10.4.9 ModelingAssistantService

10.4.10 LayoutService

10.4.11 ContributionItemService

10.4.12 GlobalActionHandlerService

10.4.13 ActionFilterService

10.4.14 EditorService

10.4.15 ElementSelectionService

10.4.16 PropertiesService

10.4.17 PropertiesModifierService

10.4.18 DragDropListenerService

10.4.19 TransferAdapterService

10.4.20 DiagramEvenBroker Service

10.5 Additional Extension-Points

10.5.1 ElementTypes

10.5.2 ElementTypeBindings

10.5.3 LogListeners

10.5.4 PropertiesConfigurations

10.5.5 Document Providers

10.5.6 RenderedImageFactory

10.5.7 ClipboardSupport

10.5.8 Pathmaps

10.6 Element Creation

10.7 Command Infrastructure

10.7.1 Command Infrastructure

10.7.2 Model Element Command Infrastructure

10.8 Developing a Diagram

10.8.1 Essential Diagram Elements

10.8.2 Configuring the Properties View

10.8.3 Connections

10.8.4 Comparison to Generated Diagram

10.9 Extending Diagrams

10.9.1 Scenario Diagram Custom View and Edit Providers

10.9.2 Custom Style

10.9.3 Custom EditPolicy

10.9.4 Custom Decorator

10.10 Beyond GEF and Draw2d

10.11 Summary

Chapter 11   Graphical Modeling Framework Tooling

11.1 Graphical Definition Model

11.1.1 The Canvas

11.1.2 The Figure Gallery

11.1.3 Diagram Elements

11.2 Tooling Definition Model

11.3 Mapping Model

11.3.1 Canvas Mapping

11.3.2 Top Node Reference

11.3.3 Node Mapping

11.3.4 Feature Initialization

11.3.5 Implementing Side-Affixed Nodes (Pins and Ports)

11.3.6 Link Mapping

11.3.7 Audits and Metrics

11.4 Generator Model

11.4.1 Gen Editor Generator

11.4.2 Gen Diagram

11.4.3 Gen Link

11.4.4 Custom Behavior

11.4.5 Open Diagram Behavior

11.4.6 Gen Plugin

11.4.7 Gen Editor View

11.4.8 Gen Navigator

11.4.9 Gen Diagram Updater

11.4.10 Property Sheet

11.4.11 Gen Application

11.5 Summary

Chapter 12   Graphical Modeling Framework FAQs

12.1 General FAQs

12.2 Diagramming FAQs

12.3 Tooling FAQs

12.4 Summary

Chapter 13   Query/View/Transformation Operational Mapping Language

13.1 Transformation Declaration

13.1.1 In-Place Transformations

13.1.2 Extends and Access

13.1.3 Intermediate Elements

13.1.4 Configuration Properties

13.1.5 Renaming Elements

13.1.6 Predefined Variables

13.1.7 Null

13.2 Libraries

13.3 Mapping Operations

13.3.1 Mapping Body

13.3.2 Entry Operation

13.3.3 Inheritance, Merger, and Disjunction

13.4 Helper Operations

13.5 Implementing Operations

13.5.1 Operations and Iterators

13.5.2 Imperative Operations

13.5.3 Imperative Iterate Expressions

13.5.4 Object Creation and Population

13.5.5 Mapping Invocation

13.5.6 Resolution Operators

13.5.7 Executing Transformations

13.6 Library Operations

13.6.1 Object Operations

13.6.2 Element Operations

13.6.3 Model Operations

13.6.4 List Operations

13.6.5 Numeric Type Operations

13.6.6 String Operations

13.7 Syntax Notes

13.7.1 Comments

13.7.2 Strings

13.7.3 Shorthand

13.7.4 OCL Synonyms

13.8 Simple UML to RDBMS Example

13.9 Summary

Chapter 14   Xpand Template Language

14.1 Xpand Language

14.1.1 IMPORT

14.1.2 DEFINE

14.1.3 EXPAND

14.1.4 FILE

14.1.5 FOREACH

14.1.6 EXTENSION

14.1.7 IF

14.1.8 PROTECT

14.1.9 LET

14.1.10 ERROR

14.1.11 REM

14.1.12 AROUND

14.1.13 Type System

14.1.14 Expression Language

14.1.15 Xtend Language

14.1.16 Workflow Engine

14.2 Summary

Part IV • Appendixes

Appendix A   Graphical Modeling Framework Key Bindings

Appendix B   Model-Driven Architecture at Eclipse Implemented Standards

Meta-Object Facility (MOF)

Unified Modeling Language (UML)

Object Constraint Language (OCL)

Diagram Interchange (DI)

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)

Working Relationship

Membership

Specification Delivery

Specification Compliance

Implementations Influencing Specifications

Open and Transparent Nature

Future Outlook

References

Index

Foreword

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

Preface

About This Book

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.

Audience

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.

Sample Code

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.

Feedback

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].

Acknowledgments

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.

About the Author

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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.196.184