model driven code development using emf and jet
DESCRIPTION
Vortrag von Michal Matjuchin beim Eclipse DemoCamp November 2012/ViennaTRANSCRIPT
© 2012 IBM Corporation
Michail Matjuchin
IBM Software Group, Rational
Austria
Model-Driven Code Development using EMF and JET
IBM Software Group /
© 2010 IBM Corporation
IBM Software Group /
Michail Matjuchin © 2012 IBM Corporation 2
© 2010 IBM Corporation
IBM Software Group /
Michail Matjuchin © 2012 IBM Corporation
A little bit about JET History
3
© 2010 IBM Corporation
IBM Software Group /
Michail Matjuchin © 2012 IBM Corporation 4
Agenda
Short JET Overview
JET Demo
How IBM extends EMF with UML Front-End
Standard Transformation in Rational Software Architect (RSA)
How to use JET in order to extend standard RSA behavior
© 2010 IBM Corporation
IBM Software Group /
Michail Matjuchin © 2012 IBM Corporation
What you will see in the Demo
5
Simplest Way to use JET from Java Code
Develop and Run JET Transformation (using Authoring Tool in RSA)
Create UML Model as Front-End for EMF Model
Create UML-to-EMF Transformation
© 2010 IBM Corporation
IBM Software Group /
Michail Matjuchin © 2012 IBM Corporation
JET Installation on Eclipse
6
© 2010 IBM Corporation
IBM Software Group /
Michail Matjuchin © 2012 IBM Corporation
How Does JET work ?
7
Originally built from the source code of Tomcat’s JSP compiler
JET works similar to JSP – Templates are to JET what JSP’s are to J2EE
– Generators are to JET what JSP-generated Servlets are to J2EE
– Generated source code is to JET what HTML output is to J2EE
© 2010 IBM Corporation
IBM Software Group /
Michail Matjuchin © 2012 IBM Corporation
Simplest Way to use JET
8
© 2010 IBM Corporation
IBM Software Group /
Michail Matjuchin © 2012 IBM Corporation
JET Installation on Eclipse
9
© 2010 IBM Corporation
IBM Software Group /
Michail Matjuchin © 2012 IBM Corporation
JET Installation on Eclipse
10
© 2010 IBM Corporation
IBM Software Group /
Michail Matjuchin © 2012 IBM Corporation
What are JET, JET2, EMFT JET, …
11
JET 1 = Java Emitter Templates. – Started out as separate component of the Eclipse Modeling Project
(EMF) - 2004
JET 2 – An initiative to unify Design Pattern Toolkit (DPTK) and the JET
component of EMF
– Lives in EMF Technology (EMFT) project, hence the name EMFT JET
– JET 2 = EMFT JET
© 2010 IBM Corporation
IBM Software Group /
Michail Matjuchin © 2012 IBM Corporation
Simplest Way to use JET
12
© 2010 IBM Corporation
IBM Software Group /
Michail Matjuchin © 2012 IBM Corporation
Simplest Way to use JET
13
Out-of-the-Box Loaders:
EMF based: org.eclipse.jet.emf
XML: org.eclipse.jet.emfxml
© 2010 IBM Corporation
IBM Software Group /
Michail Matjuchin © 2012 IBM Corporation
Simplest Way to use JET
14
© 2010 IBM Corporation
IBM Software Group /
Michail Matjuchin © 2012 IBM Corporation
You need a little bit more in “real life”
15
© 2010 IBM Corporation
IBM Software Group /
Michail Matjuchin © 2012 IBM Corporation
JET Authoring Theory
16
Normal
development Pattern Recognized
Build a Reference Solution Build a JET Transformation
© 2010 IBM Corporation
IBM Software Group /
Michail Matjuchin © 2012 IBM Corporation
JET Transformation using Authoring Tool in RSA
17
© 2010 IBM Corporation
IBM Software Group /
Michail Matjuchin © 2012 IBM Corporation
Model-to-Text Transformation / Steps
18
„Backward“ move from the
Reference Solution to a JET
Transformation that can
produce it
Reference
Solution
Actions and
Templates
Generated
Solution Input Model
© 2010 IBM Corporation
IBM Software Group /
Michail Matjuchin © 2012 IBM Corporation
Important Caveats
19
JET does not help you recognize a pattern. Possible clues you have: – “I keep doing the same thing over and over again.”
– You find yourself copying code.
JET does not help you build a reference solution. This is the job of
the ADC tooling. A good reference solution: – Reflects domain knowledge.
– Employs best practices.
– Identifies and (as much as possible) separates areas where the solution
is incomplete (and would require user customization).
– Works
© 2010 IBM Corporation
IBM Software Group /
Michail Matjuchin © 2012 IBM Corporation
Steps to a complete solution
20
Reference
Solution
JET Transformation Input
Model
User
Model Front-end
1. Jet Authoring
2. Model-to-model authoring
© 2010 IBM Corporation
IBM Software Group /
Michail Matjuchin © 2012 IBM Corporation
Model-to-Text Transformation / Steps
21
Create a Reference Solution (Exemplar)
Identify Patterns in your Reference Implementation
Use JET Tooling to produce „Code Generator“ – Create EMF Model of your Reference Solution
– Create JET Templates
If graphic front-end is needed
Identify the graphical model (UML + Profiles) or UML-based DSL
Build a Model-to-Model Transformation using Mapping Editor
Invoke JET Transformation
© 2010 IBM Corporation
IBM Software Group /
Michail Matjuchin © 2012 IBM Corporation
“Out-of-the-Box” JET Functionality
22
© 2010 IBM Corporation
IBM Software Group /
Michail Matjuchin © 2012 IBM Corporation
JET & UML
23
© 2010 IBM Corporation
IBM Software Group /
Michail Matjuchin © 2012 IBM Corporation
What about Code-Merge
24
© 2010 IBM Corporation
IBM Software Group /
Michail Matjuchin © 2012 IBM Corporation
What about Code-Merge
25
© 2010 IBM Corporation
IBM Software Group /
Michail Matjuchin © 2012 IBM Corporation 26
© 2010 IBM Corporation
IBM Software Group /
Michail Matjuchin © 2012 IBM Corporation
Transformations in MDD
27
Source Model (UML)
Target Source Code
Transformations
JET & UML API
Intermediate
ECORE Model
Model-to-Model
Transformations
Mapping Editor
JET
Transformations
© 2010 IBM Corporation
IBM Software Group /
Michail Matjuchin © 2012 IBM Corporation
Standard Transformations provided by RSA
28
UML-to-EJB 3
UML-to-JPA (Java Persistence API)
UML-to-WSDL (Web Services)
UML-to-SCA (Service Component Arcitecture)
UML-to-SOA (WSDL, XSD, BPEL)
UML-to-XSD (XML Schema Definition)
UML-to-REST (JSON)
C#, C++ und VB
© 2010 IBM Corporation
IBM Software Group /
Michail Matjuchin © 2012 IBM Corporation
RSA provides “Transformation Authoring Framework” to change/modify existing Transformations
29
Model-to-Text Transformations
Model-to-Model Transformations
Transformations – Extensions
© 2010 IBM Corporation
IBM Software Group /
Michail Matjuchin © 2012 IBM Corporation 30