the emf: modeling with eclipse - concordia...
TRANSCRIPT
![Page 1: The EMF: Modeling with Eclipse - Concordia Universityusers.encs.concordia.ca/.../647PS/comp647-lecture10-EclipseEmf.pdf · 8 9-Mar-2005 The Eclipse Environment Modeling – EMF Unifying](https://reader033.vdocuments.mx/reader033/viewer/2022051509/5af860a97f8b9a8d1c916d28/html5/thumbnails/1.jpg)
The EMF: Modeling with Eclipse
![Page 2: The EMF: Modeling with Eclipse - Concordia Universityusers.encs.concordia.ca/.../647PS/comp647-lecture10-EclipseEmf.pdf · 8 9-Mar-2005 The Eclipse Environment Modeling – EMF Unifying](https://reader033.vdocuments.mx/reader033/viewer/2022051509/5af860a97f8b9a8d1c916d28/html5/thumbnails/2.jpg)
9-Mar-2005 The Eclipse Environment2
“I never met a man I didn’t like.”– Will Rodgers
metamodel
Modeling – Model Driven Architecture
Quick Summary of MDA:l Software development architecture proposed
by the OMG using open modeling standards– UML, MOF, XMI, CWM, etc.
l Desired system is specified as a platform independent model (PIM)
l PIM is transformed into a platform specific model (PSM), i.e., implementation code.
![Page 3: The EMF: Modeling with Eclipse - Concordia Universityusers.encs.concordia.ca/.../647PS/comp647-lecture10-EclipseEmf.pdf · 8 9-Mar-2005 The Eclipse Environment Modeling – EMF Unifying](https://reader033.vdocuments.mx/reader033/viewer/2022051509/5af860a97f8b9a8d1c916d28/html5/thumbnails/3.jpg)
9-Mar-2005 The Eclipse Environment3
Modeling – On the Way to MDA
Aims of EMF include:l the extraction of a description’s intrinsic “data
model” (i.e., entity objects);l the relating of these modeled concepts
directly to their implementations;l the unification of the system descriptions
(i.e., the various models);l and, the interoperability of EMF-based tools
and applications.
![Page 4: The EMF: Modeling with Eclipse - Concordia Universityusers.encs.concordia.ca/.../647PS/comp647-lecture10-EclipseEmf.pdf · 8 9-Mar-2005 The Eclipse Environment Modeling – EMF Unifying](https://reader033.vdocuments.mx/reader033/viewer/2022051509/5af860a97f8b9a8d1c916d28/html5/thumbnails/4.jpg)
9-Mar-2005 The Eclipse Environment4
Modeling – EMF and Model Unification
Using a data model in a project typicallyrequires (in some order):
l a documented representation of the entitiesand their relationships;
l code for implementing the entities;l and, a mechanism for persisting the entities.Of course, the team keeps these artifacts
perfectly in sync. Not!
![Page 5: The EMF: Modeling with Eclipse - Concordia Universityusers.encs.concordia.ca/.../647PS/comp647-lecture10-EclipseEmf.pdf · 8 9-Mar-2005 The Eclipse Environment Modeling – EMF Unifying](https://reader033.vdocuments.mx/reader033/viewer/2022051509/5af860a97f8b9a8d1c916d28/html5/thumbnails/5.jpg)
9-Mar-2005 The Eclipse Environment5
Modeling – EMF and Model Unification
The framework models a given data modelfrom which it can in turn, generate other equivalent models:
l Annotated Java codel UML class diagramsl XML schemaThe framework also provides viewers for
manipulating objects of the data model.
![Page 6: The EMF: Modeling with Eclipse - Concordia Universityusers.encs.concordia.ca/.../647PS/comp647-lecture10-EclipseEmf.pdf · 8 9-Mar-2005 The Eclipse Environment Modeling – EMF Unifying](https://reader033.vdocuments.mx/reader033/viewer/2022051509/5af860a97f8b9a8d1c916d28/html5/thumbnails/6.jpg)
9-Mar-2005 The Eclipse Environment6
Three views depicting the same data model
Essence of the data model is captured in Ecore – EMF’s metamodel language.
Modeling – EMF and Model Unification
XML
Java
UML
EMF Model(Ecore)
[Budinsky et al., Eclipse Modeling Framework]
RationalRose
Argo
FileSystem
RDB
XMI
•••
Conceptual (data) models
Canonical (core) model
Serialization through XMI (XML Metadata Interchange) connects model with XML documents.
![Page 7: The EMF: Modeling with Eclipse - Concordia Universityusers.encs.concordia.ca/.../647PS/comp647-lecture10-EclipseEmf.pdf · 8 9-Mar-2005 The Eclipse Environment Modeling – EMF Unifying](https://reader033.vdocuments.mx/reader033/viewer/2022051509/5af860a97f8b9a8d1c916d28/html5/thumbnails/7.jpg)
9-Mar-2005 The Eclipse Environment7
Modeling – EMF Unifying UML
[Budinsky et al., Eclipse Modeling Framework]
PurchaseOrdershipTo : StringbillTo : String
ItemproductName : Stringquantity : intprice : float0..*
items
0..*
![Page 8: The EMF: Modeling with Eclipse - Concordia Universityusers.encs.concordia.ca/.../647PS/comp647-lecture10-EclipseEmf.pdf · 8 9-Mar-2005 The Eclipse Environment Modeling – EMF Unifying](https://reader033.vdocuments.mx/reader033/viewer/2022051509/5af860a97f8b9a8d1c916d28/html5/thumbnails/8.jpg)
9-Mar-2005 The Eclipse Environment8
Modeling – EMF Unifying Java
/** @model */ // Annotation marks class as part of model definition.public interface PurchaseOrder {/** @model */String getShipTo();/** @model */String getBillTo();/** @model type=“Item” containment=“true” */List getItems();
}
/** @model */public interface Item {/** @model */String getProductName();/** @model */int getQuantity();/** @model */float getPrice();
}
[Budinsky et al., Eclipse Modeling Framework]
![Page 9: The EMF: Modeling with Eclipse - Concordia Universityusers.encs.concordia.ca/.../647PS/comp647-lecture10-EclipseEmf.pdf · 8 9-Mar-2005 The Eclipse Environment Modeling – EMF Unifying](https://reader033.vdocuments.mx/reader033/viewer/2022051509/5af860a97f8b9a8d1c916d28/html5/thumbnails/9.jpg)
9-Mar-2005 The Eclipse Environment9
Modeling – EMF Unifying XML
<xsd:complexType name="PurchaseOrder"><xsd:sequence>
<xsd:element name="shipTo" type="xsd:string"/><xsd:element name="billTo" type="xsd:string"/><xsd:element name="items" type="PO:Item"
minOccurs="0" maxOccurs="unbounded"/></xsd:sequence>
</xsd:complexType>
<xsd:complexType name="Item"><xsd:sequence>
<xsd:element name="productName" type="xsd:string"/><xsd:element name="quantity" type="xsd:int"/><xsd:element name="price" type="xsd:float"/>
</xsd:sequence></xsd:complexType>
[Budinsky et al., Eclipse Modeling Framework]
![Page 10: The EMF: Modeling with Eclipse - Concordia Universityusers.encs.concordia.ca/.../647PS/comp647-lecture10-EclipseEmf.pdf · 8 9-Mar-2005 The Eclipse Environment Modeling – EMF Unifying](https://reader033.vdocuments.mx/reader033/viewer/2022051509/5af860a97f8b9a8d1c916d28/html5/thumbnails/10.jpg)
9-Mar-2005 The Eclipse Environment10
Modeling – UML, MOF and Ecore
The Meta-Object Facility specializes the class modeling aspects of UML for managing and implementing metadata repositories.
Ecore is a highly efficient Java implementation of a core subset of the MOF API.
Ecore defines structure of EMF core models, which in turn define our application models.
Ecore is itself an EMF model, and thus is its own metamodel.
![Page 11: The EMF: Modeling with Eclipse - Concordia Universityusers.encs.concordia.ca/.../647PS/comp647-lecture10-EclipseEmf.pdf · 8 9-Mar-2005 The Eclipse Environment Modeling – EMF Unifying](https://reader033.vdocuments.mx/reader033/viewer/2022051509/5af860a97f8b9a8d1c916d28/html5/thumbnails/11.jpg)
9-Mar-2005 The Eclipse Environment11
Modeling – The Ecore Hierarchy
[eclipse.org]
![Page 12: The EMF: Modeling with Eclipse - Concordia Universityusers.encs.concordia.ca/.../647PS/comp647-lecture10-EclipseEmf.pdf · 8 9-Mar-2005 The Eclipse Environment Modeling – EMF Unifying](https://reader033.vdocuments.mx/reader033/viewer/2022051509/5af860a97f8b9a8d1c916d28/html5/thumbnails/12.jpg)
9-Mar-2005 The Eclipse Environment12
Modeling – The Ecore Kernel
[Budinsky et al., Eclipse Modeling Framework]
EDataTypename : String
EAttributename : String
1
eAttributeType
1
EReferencename : Stringcontainment : booleanlowerBound : intupperBound : int
0..1eOpposite 0..1
EClassname : String
0..*
eSuperTypes
0..*
0..*
eAttributes
0..*
0..*
eReferences
0..*
1 eReferenceType1
![Page 13: The EMF: Modeling with Eclipse - Concordia Universityusers.encs.concordia.ca/.../647PS/comp647-lecture10-EclipseEmf.pdf · 8 9-Mar-2005 The Eclipse Environment Modeling – EMF Unifying](https://reader033.vdocuments.mx/reader033/viewer/2022051509/5af860a97f8b9a8d1c916d28/html5/thumbnails/13.jpg)
9-Mar-2005 The Eclipse Environment13
EAttribute
name : "shipTo"EString
EAttribute
name : "billTo"
EClass
name : "PurchaseOrder"
EClass
name : "Item"
Modeling – Ecore in Use
EAttribute
name : "shipTo"EString
EAttribute
name : "billTo"
EAttribute
name : "quantity"
EInt
EAttribute
name : "price"
EAttribute
name : "productName"
EFloat
EReference
name : "items" containment : true lowerBound : 0 upperBound : -1
EReference
name : "items" containment : true lowerBound : 0 upperBound : -1
EReference
name : "owner" containment : false lowerBound : 0 upperBound : 1
eOpposite
eOpposite
![Page 14: The EMF: Modeling with Eclipse - Concordia Universityusers.encs.concordia.ca/.../647PS/comp647-lecture10-EclipseEmf.pdf · 8 9-Mar-2005 The Eclipse Environment Modeling – EMF Unifying](https://reader033.vdocuments.mx/reader033/viewer/2022051509/5af860a97f8b9a8d1c916d28/html5/thumbnails/14.jpg)
9-Mar-2005 The Eclipse Environment14
EMF Demonstration
[Budinsky et al., Eclipse Modeling Framework]
Supplier
name : String
«enumeration»OrderStatus
PENDING : 0 BACKORDER : 1 COMPLETE : 2
Customer
customerId : int
PurchaseOrder
remove(partNum : SKU) : boolean
comment : String orderDate : Date status : OrderStatus totalAmount : float
Address
name : String country : String
CaAddress
street : String city : String province : String code : String
GlobalAddress
«0..*» location : StringItem
productName : String quantity : int UsPrice : float comment : String shipDate : Date partNum : SKU
«datatype»Date
«javaclass» java.util.Date :
«datatype»SKU
«javaclass» java.lang.String :
1
0..*customer
orders
0..*
shippedOrders
1..1
0..*
order
items
1..1
0..1
billTo
1..10..1
shipTo
0..*
pendingOrders
0..1 previousOrder1..1
0..* orders1..1
0..*customers
![Page 15: The EMF: Modeling with Eclipse - Concordia Universityusers.encs.concordia.ca/.../647PS/comp647-lecture10-EclipseEmf.pdf · 8 9-Mar-2005 The Eclipse Environment Modeling – EMF Unifying](https://reader033.vdocuments.mx/reader033/viewer/2022051509/5af860a97f8b9a8d1c916d28/html5/thumbnails/15.jpg)
9-Mar-2005 The Eclipse Environment15
Generating – Data Model Classes
[Budinsky et al., Eclipse Modeling Framework]
public interface PurchaseOrder extends EObject{
...}
public class PurchaseOrderImpl extends EObjectImpimplements PurchaseOrder
{...
}
Each model class produces a Java interface and an implementation class.
![Page 16: The EMF: Modeling with Eclipse - Concordia Universityusers.encs.concordia.ca/.../647PS/comp647-lecture10-EclipseEmf.pdf · 8 9-Mar-2005 The Eclipse Environment Modeling – EMF Unifying](https://reader033.vdocuments.mx/reader033/viewer/2022051509/5af860a97f8b9a8d1c916d28/html5/thumbnails/16.jpg)
9-Mar-2005 The Eclipse Environment16
Generating – Accessor Methods
[Budinsky et al., Eclipse Modeling Framework]
public String getShipTo() {
return shipTo;}
public void setShipTo(String newShipTo) {
String oldShipTo = shipTo;shipTo = newShipTo;if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET,PoPackage.PURCHASE_ORDER__SHIPTO, oldShipTo, newshipTo));
}
Setters are generated with feature change notification using Observer design pattern.
![Page 17: The EMF: Modeling with Eclipse - Concordia Universityusers.encs.concordia.ca/.../647PS/comp647-lecture10-EclipseEmf.pdf · 8 9-Mar-2005 The Eclipse Environment Modeling – EMF Unifying](https://reader033.vdocuments.mx/reader033/viewer/2022051509/5af860a97f8b9a8d1c916d28/html5/thumbnails/17.jpg)
9-Mar-2005 The Eclipse Environment17
Classes with «datatypes» stereotype are given string conversion methods.
Enumerated types are created using the Type-safe Enum pattern.
Generating – Other Model Classes
[Budinsky et al., Eclipse Modeling Framework]
public String convertDateToString(EDataType eDataType, Object instanceValue)
{ ... }
public Date convertDateFromString(EDataType eDataType, String initialValue)
{ ... }
![Page 18: The EMF: Modeling with Eclipse - Concordia Universityusers.encs.concordia.ca/.../647PS/comp647-lecture10-EclipseEmf.pdf · 8 9-Mar-2005 The Eclipse Environment Modeling – EMF Unifying](https://reader033.vdocuments.mx/reader033/viewer/2022051509/5af860a97f8b9a8d1c916d28/html5/thumbnails/18.jpg)
9-Mar-2005 The Eclipse Environment18
Generating – One-way References
[Budinsky et al., Eclipse Modeling Framework]
public PurchaseOrder getPreviousOrder() {if (previousOrder != null && previousOrder.eIsProxy()){
PurchaseOrder oldPreviousOrder = previousOrder;previousOrder = (PurchaseOrder)
eResolveProxy((InternalEObject) previousOrder);if (previousOrder != oldPreviousOrder){
if (eNotificationRequired())eNotify(new ENotificationImpl(this,
Notification.RESOLVE, PoPackage...));}
}return previousOrder;
}
Persistence proxies resolved by lazy loading.
![Page 19: The EMF: Modeling with Eclipse - Concordia Universityusers.encs.concordia.ca/.../647PS/comp647-lecture10-EclipseEmf.pdf · 8 9-Mar-2005 The Eclipse Environment Modeling – EMF Unifying](https://reader033.vdocuments.mx/reader033/viewer/2022051509/5af860a97f8b9a8d1c916d28/html5/thumbnails/19.jpg)
9-Mar-2005 The Eclipse Environment19
Generating – Containment Refs
[Budinsky et al., Eclipse Modeling Framework]
public EList getItems(){
if (items == null){
items = new ObjectContainmentWithInverseEList(Item.class, this, PoPackage.PURCHASE_ORDER__ITEMS,PoPackage.ITEM__ORDER);
}return items;
}
Contained classes are persisted with the containing owner class, in the same resource. No proxies need to be resolved.
![Page 20: The EMF: Modeling with Eclipse - Concordia Universityusers.encs.concordia.ca/.../647PS/comp647-lecture10-EclipseEmf.pdf · 8 9-Mar-2005 The Eclipse Environment Modeling – EMF Unifying](https://reader033.vdocuments.mx/reader033/viewer/2022051509/5af860a97f8b9a8d1c916d28/html5/thumbnails/20.jpg)
9-Mar-2005 The Eclipse Environment20
Generating – Operations
[Budinsky et al., Eclipse Modeling Framework]
/*** @generated*/
public boolean remove(String partNum){
// TODO: implement this method// Remove @generated or mark it @generated NOTthrow new UnsupportedOperationException();
}
EOperation classes result in generation of empty method bodies tagged with a task list reminder to provide the code.
![Page 21: The EMF: Modeling with Eclipse - Concordia Universityusers.encs.concordia.ca/.../647PS/comp647-lecture10-EclipseEmf.pdf · 8 9-Mar-2005 The Eclipse Environment Modeling – EMF Unifying](https://reader033.vdocuments.mx/reader033/viewer/2022051509/5af860a97f8b9a8d1c916d28/html5/thumbnails/21.jpg)
9-Mar-2005 The Eclipse Environment21
Generating – Packages
l Singleton instance for each model packagel Provides access to model’s metadata objects
[Budinsky et al., Eclipse Modeling Framework]
PoPackage eINSTANCE = ca.encs.po.impl.PoPackageImpl.init();... int CUSTOMER = 1; int CUSTOMER__CUSTOMER_ID = 0;... private EClass customerEClass = null;... customerEClass = createEClass(CUSTOMER);... createEAttribute(customerEClass, CUSTOMER__CUSTOMER_ID);
public EClass getCustomer(){ return customerEClass; }
public EAttribute getCustomer_CustomerId(){ return (EAttribute)
customerEClass.getEStructuralFeatures().get(0); }
![Page 22: The EMF: Modeling with Eclipse - Concordia Universityusers.encs.concordia.ca/.../647PS/comp647-lecture10-EclipseEmf.pdf · 8 9-Mar-2005 The Eclipse Environment Modeling – EMF Unifying](https://reader033.vdocuments.mx/reader033/viewer/2022051509/5af860a97f8b9a8d1c916d28/html5/thumbnails/22.jpg)
9-Mar-2005 The Eclipse Environment22
Generating – Factories
l Singleton instance for each model packagel For creation of model objects
[Budinsky et al., Eclipse Modeling Framework]
PoFactory eINSTANCE = ca.encs.po.impl.PoFactoryImpl();
public Supplier createSupplier() {SupplierImpl supplier = new SupplierImpl();return supplier;
}
public EObject create(EClass eClass) {switch (eClass.getClassifierID()){
case PoPackage.SUPPLIER:return createSupplier();
...
![Page 23: The EMF: Modeling with Eclipse - Concordia Universityusers.encs.concordia.ca/.../647PS/comp647-lecture10-EclipseEmf.pdf · 8 9-Mar-2005 The Eclipse Environment Modeling – EMF Unifying](https://reader033.vdocuments.mx/reader033/viewer/2022051509/5af860a97f8b9a8d1c916d28/html5/thumbnails/23.jpg)
9-Mar-2005 The Eclipse Environment23
Generating – Model Reflection
Generated, reflective API allows for generic access to the model (e.g., EMF.Edit):
PoPackage po_package = PoPackage.eINSTANCE;PoFactory po_factory = PoFactory.eINSTANCE;EClass po_class = po_package.getPurchaseOrder();EAttribute ship_att = po_package.getPurchaseOrder_ShipTo();
EObject order = po_factory.create(po_class);
order.eSet(ship_att, “123 Maple Street”);
String ship_to = (String) order.eGet(ship_att);
boolean is_set = order.eIsSet(ship_att);
boolean is_set = order.eUnset(ship_att);
[Budinsky et al., Eclipse Modeling Framework]
EStructuralFeature
![Page 24: The EMF: Modeling with Eclipse - Concordia Universityusers.encs.concordia.ca/.../647PS/comp647-lecture10-EclipseEmf.pdf · 8 9-Mar-2005 The Eclipse Environment Modeling – EMF Unifying](https://reader033.vdocuments.mx/reader033/viewer/2022051509/5af860a97f8b9a8d1c916d28/html5/thumbnails/24.jpg)
9-Mar-2005 The Eclipse Environment24
Generating – EMF.Edit
[Budinsky et al., Eclipse Modeling Framework]
My.po
Item(Apples)
Item(Oranges)
PurchaseOrder
JFace viewers can be generated for your model.
l TreeViewerl TableViewerl ListViewer
![Page 25: The EMF: Modeling with Eclipse - Concordia Universityusers.encs.concordia.ca/.../647PS/comp647-lecture10-EclipseEmf.pdf · 8 9-Mar-2005 The Eclipse Environment Modeling – EMF Unifying](https://reader033.vdocuments.mx/reader033/viewer/2022051509/5af860a97f8b9a8d1c916d28/html5/thumbnails/25.jpg)
9-Mar-2005 The Eclipse Environment25
Application Demonstration
![Page 26: The EMF: Modeling with Eclipse - Concordia Universityusers.encs.concordia.ca/.../647PS/comp647-lecture10-EclipseEmf.pdf · 8 9-Mar-2005 The Eclipse Environment Modeling – EMF Unifying](https://reader033.vdocuments.mx/reader033/viewer/2022051509/5af860a97f8b9a8d1c916d28/html5/thumbnails/26.jpg)
The End: Questions?
![Page 27: The EMF: Modeling with Eclipse - Concordia Universityusers.encs.concordia.ca/.../647PS/comp647-lecture10-EclipseEmf.pdf · 8 9-Mar-2005 The Eclipse Environment Modeling – EMF Unifying](https://reader033.vdocuments.mx/reader033/viewer/2022051509/5af860a97f8b9a8d1c916d28/html5/thumbnails/27.jpg)
9-Mar-2005 The Eclipse Environment27
References
l Frank Budinsky et al, Eclipse Modeling Framework: A Developer's Guide, Addison-Wesley, 2004
l Eric Gamma and Kent Beck, Contributing to Eclipse: Principles, Patterns, and Plug-ins, Addison-Wesley, 2004
l Ed Merks, The Eclipse Modeling Framework: Introducing Modeling to the Java Technology Mainstream, JavaOne presentation, 2004
l Bill Moore et al, Eclipse Development using the Graphical Editing Framework and the Eclipse Modeling Framework, IBM Redbook, 2004
l www.eclipse.org