SlideShare a Scribd company logo
Fundamentals of the Eclipse Modeling Framework Dave Steinberg IBM Rational Software Toronto, Canada EMF Committer
Goal ,[object Object]
Agenda ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Model Driven Architecture (MDA) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
MDA – Are We There Yet? ,[object Object],[object Object],[object Object],[object Object]
Enter EMF! ,[object Object],[object Object],[object Object],[object Object]
Model Driven Development with EMF ,[object Object],[object Object],[object Object],[object Object],[object Object]
EMF at Eclipse.org ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Agenda ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
What is an EMF “Model”? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Model Sources ,[object Object],[object Object],[object Object],[object Object],[object Object]
Java Interfaces ,[object Object],public interface  PurchaseOrder { String  getShipTo (); void setShipTo(String value); String  getBillTo (); void setBillTo(String value); List<Item>  getItems ();  // containment } public interface  Item { String  getProductName (); void setProductName(String value); int  getQuantity (); void setQuantity(int value) float  getPrice (); void setPrice(float value); }
UML Class Diagram ,[object Object],[object Object]
XML Schema <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> <xsd:schema xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot; targetNamespace=&quot;http://www.example.com/SimplePO&quot; xmlns:po=&quot;http://www.example.com/SimplePO&quot;> <xsd:complexType name=&quot; PurchaseOrder &quot;> <xsd:sequence> <xsd:element name=&quot; shipTo &quot; type=&quot;xsd:string&quot;/> <xsd:element name=&quot; billTo &quot; type=&quot;xsd:string&quot;/> <xsd:element name=&quot; items &quot;  type=“po:Item&quot;  minOccurs=&quot;0&quot; maxOccurs=&quot;unbounded&quot;/> </xsd:sequence> </xsd:complexType> <xsd:complexType name=&quot; Item &quot;> <xsd:sequence> <xsd:element name=&quot; productName &quot; type=&quot;xsd:string&quot;/> <xsd:element name=&quot; quantity &quot; type=&quot;xsd:int&quot;/> <xsd:element name=&quot; price &quot; type=&quot;xsd:float&quot;/> </xsd:sequence> </xsd:complexType> </xsd:schema>
Unifying UML, XML and Java ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Agenda ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
EMF Architecture EMF Runtime EMF Tools Core Edit Codegen Model Editor Application Generates Eclipse Platform
EMF Components ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Ecore ,[object Object]
Ecore ,[object Object],EClass (name=&quot;PurchaseOrder&quot;) EClass (name=&quot;Item&quot;) EAttribute (name=&quot;shipTo&quot;) EAttribute (name=&quot;billTo&quot;) EReference (name=&quot;items&quot;) eReferenceType EAttribute (name=“productName&quot;)
Ecore ,[object Object],[object Object],<eClassifiers xsi:type=&quot;ecore:EClass&quot; name=&quot; PurchaseOrder &quot;> <eStructuralFeatures xsi:type=&quot;ecore:EReference&quot; name=&quot; items &quot; eType=&quot;#//Item&quot;  upperBound=&quot;-1&quot; containment=&quot;true&quot;/> <eStructuralFeatures xsi:type=&quot;ecore:EAttribute&quot; name=&quot; shipTo &quot;  eType=&quot;ecore:EDataType http:...Ecore#//EString&quot;/> ... </eClassifiers>
Model Import and Generation Ecore Model UML XML  Schema Java Model ,[object Object],[object Object],[object Object],[object Object],I M P O R T Java Edit Java Editor GENERATE
Direct Ecore Modeling ,[object Object],[object Object],[object Object]
EMF and Java 5.0 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Agenda ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Generated Model Code ,[object Object],[object Object],public interface  PurchaseOrder  extends EObject { String getShipTo(); void setShipTo(String value); String getBillTo(); void setBillTo(String value); EList<Item> getItems(); } public class  PurchaseOrderImpl  extends EObjectImpl implements PurchaseOrder { ... }
Change Notification ,[object Object],[object Object],[object Object],[object Object],Adapter adapter = ... purchaseOrder.eAdapters().add(adapter);
Change Notification: Feature Accessors ,[object Object],public String getBillTo() { return billTo; } public void setBillTo(String newBillTo) { String oldBillTo = BillTo; billTo = newBillTo; if (eNotificationRequired()) eNotify(new ENotificationImpl(this, ... , oldBillTo, billTo); }
Bidirectional References public interface  PurchaseOrder { ... PurchaseOrder  getNext (); void  setNext (PurchaseOrder value); PurchaseOrder  getPrevious (); void  setPrevious (PurchaseOrder value); } Bidirectional reference imposes invariant:  po.getNext().getPrevious() == po
Bidirectional Reference Handshaking ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Bidirectional Reference Handshaking p1.setNext(p3); p2 p1 p2 p3 change notification  next previous previous next next previous next previous
Reflective EObject API ,[object Object],[object Object],[object Object],[object Object],public interface  EObject { EClass eClass(); Object  eGet (EStructuralFeature sf); void  eSet (EStructuralFeature sf, Object val); ... }
Reflective EObject API ,[object Object],public Object eGet(int featureID, ...) { switch  (featureID) { case POPackage.PURCHASE_ORDER__ITEMS: return  getItems (); case POPackage.PURCHASE_ORDER__SHIP_TO: return  getShipTo (); case POPackage.PURCHASE_ORDER__BILL_TO: return  getBillTo (); ... } ... }
Typesafe Enums ,[object Object],public  enum  Status implements Enumerator { PENDING(0, &quot;Pending&quot;, &quot;Pending&quot;), BACK_ORDER(1, &quot;BackOrder&quot;, &quot;BackOrder&quot;), COMPLETE(2, &quot;Complete&quot;, &quot;Complete&quot;); public static final int PENDING_VALUE = 0; public static final int BACK_ORDER_VALUE = 1; public static final int COMPLETE_VALUE = 2; private final int value; private final String name; private final String literal; private Status(int value, String name, String literal) { ... } ... }
Factories and Packages ,[object Object],[object Object],POFactory factory =  POFactory.eINSTANCE ; PurchaseOrder order = factory. createPurchaseOrder (); POPackage poPackage =  POPackage.eINSTANCE ; EClass itemClass =  POPackage.Literals.ITEM ; //or poPackage. getItem () EAttribute priceAttr =  POPackage.Literals.ITEM__PRICE ; //or poPackage. getItem_Price () //or itemClass.getEStructuralFeature( POPackage.ITEM__PRICE )
Summary of Generated Artifacts ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Regeneration and Merge ,[object Object],[object Object],[object Object],/** * <!-- begin-user-doc --> * <!-- end-user-doc --> *  @generated */ public String getName() { return name; }
Regeneration and Merge ,[object Object],public String  getName () { return format(getNameGen()); } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> *  @generated */ public String  getNameGen () { return name; }
Agenda ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Persistence ,[object Object],[object Object],[object Object]
Resource Set ,[object Object],[object Object],[object Object],[object Object],ResourceSet  rs = new  ResourceSetImpl (); URI uri = URI.createFileURI(&quot;C:/data/po.xml&quot;); Resource resource = rs. createResource (uri);
Registries ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Resource ,[object Object],[object Object],[object Object],[object Object],[object Object],URI uri = URI.createFileURI(&quot;C:/data/po.xml&quot;); Resource resource = rs.createResource(uri); resource. getContents ().add(p1); resource. save (null); <PurchaseOrder> <shipTo> John Doe </shipTo> <next> p2.xml#p2 </next> </PurchaseOrder>
Proxy Resolution and Demand Load proxyURI=&quot;p2.xml#p2&quot; proxyURI=&quot; p2.xml #p2&quot; p1 p1.xml PurchaseOrder p2 = p1.getNext(); next p2 next p2.xml
XML Schema-Conformant Serialization ,[object Object],[object Object],<xsd:schema ... > <xsd:element name=&quot; order &quot; type=&quot;po:PurchaseOrder&quot;> <xsd:element name=&quot; item &quot; type=&quot;po:Item&quot;> ... </xsd:schema>
XML Schema-Conformant Serialization ,[object Object],[object Object],[object Object],[object Object],PurchaseOrder p1 = ... URI uri = URI.createFileURI(&quot;C:/data/order.po&quot;); resource resource = rs.createResource(uri); DocumentRoot root = POFactory.eINSTANCE.createDocumentRoot(); resource. getContents ().add( root ); root. setOrder ( p1 ); resource.save(null);
Reflection ,[object Object],[object Object],PurchaseOrder po = ... po. setBillTo (&quot;123 Elm St.&quot;); EObject po = ...  EClass poClass = po.eClass(); po. eSet (poClass.getEStructuralFeature(&quot;billTo&quot;), &quot;123 Elm St.&quot;);
Dynamic EMF ,[object Object],[object Object],[object Object],[object Object],[object Object]
Change Recording ,[object Object]
Change Recording ,[object Object],[object Object],[object Object],ChangeRecorder changeRecorder = new ChangeRecorder(resourceSet); try { // modifications within resource set } catch (Exception e) { changeRecorder.endRecording().apply(); }
Validation ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Automatically Implemented Constraints ,[object Object],[object Object],[object Object],[object Object],<xsd:simpleType name=&quot;SKU&quot;> <xsd:restriction base=&quot;xsd:string&quot;> <xsd:pattern value=&quot;{3}-[A-Z]{2}&quot;/> </xsd:restriction> </xsd:simpleType>
Diagnostician ,[object Object],[object Object],[object Object],Diagnostician validator =  Diagnostician.INSTANCE ; Diagnostic diagnostic = validator. validate (order); if (diagnostic.getSeverity() == Diagnostic.ERROR) { // handle error } for (Diagnostic child : diagnostic.getChildren()) { // handle child diagnostic }
EMF Utilities ,[object Object],[object Object],[object Object],[object Object],EObject copy = EcoreUtil.copy(original); boolean equal = EcoreUtil.equals(eObject1, eObject2);
Agenda ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Summary ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Resources ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Legal Notices ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

More Related Content

What's hot

Eqela Core API and Utilities
Eqela Core API and UtilitiesEqela Core API and Utilities
Eqela Core API and Utilities
jobandesther
 
Graphical User Interface Development with Eqela
Graphical User Interface Development with EqelaGraphical User Interface Development with Eqela
Graphical User Interface Development with Eqela
jobandesther
 
Introduction to Eqela development
Introduction to Eqela developmentIntroduction to Eqela development
Introduction to Eqela development
jobandesther
 
Application package
Application packageApplication package
Application package
JAYAARC
 

What's hot (10)

Modelling and Programming: Isn&rsquo;t it all the same?
Modelling and Programming: Isn&rsquo;t it all the same?Modelling and Programming: Isn&rsquo;t it all the same?
Modelling and Programming: Isn&rsquo;t it all the same?
 
Eqela Core API and Utilities
Eqela Core API and UtilitiesEqela Core API and Utilities
Eqela Core API and Utilities
 
Graphical User Interface Development with Eqela
Graphical User Interface Development with EqelaGraphical User Interface Development with Eqela
Graphical User Interface Development with Eqela
 
Introduction to Eqela development
Introduction to Eqela developmentIntroduction to Eqela development
Introduction to Eqela development
 
Executable UML and SysML Workshop
Executable UML and SysML WorkshopExecutable UML and SysML Workshop
Executable UML and SysML Workshop
 
UML as a Programming Language
UML as a Programming LanguageUML as a Programming Language
UML as a Programming Language
 
UML: Once More with Meaning
UML: Once More with MeaningUML: Once More with Meaning
UML: Once More with Meaning
 
Programming in UML: An Introduction to fUML and Alf
Programming in UML: An Introduction to fUML and AlfProgramming in UML: An Introduction to fUML and Alf
Programming in UML: An Introduction to fUML and Alf
 
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...
 
Application package
Application packageApplication package
Application package
 

Similar to EclipseCon 2008: Fundamentals of the Eclipse Modeling Framework

WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
Fabio Franzini
 
NEOOUG 2010 Oracle Data Integrator Presentation
NEOOUG 2010 Oracle Data Integrator PresentationNEOOUG 2010 Oracle Data Integrator Presentation
NEOOUG 2010 Oracle Data Integrator Presentation
askankit
 

Similar to EclipseCon 2008: Fundamentals of the Eclipse Modeling Framework (20)

EclipseCon 2007: Effective Use of the Eclipse Modeling Framework
EclipseCon 2007: Effective Use of the Eclipse Modeling FrameworkEclipseCon 2007: Effective Use of the Eclipse Modeling Framework
EclipseCon 2007: Effective Use of the Eclipse Modeling Framework
 
EclipseCon 2005: Everything You Always Wanted to do with EMF (But were Afraid...
EclipseCon 2005: Everything You Always Wanted to do with EMF (But were Afraid...EclipseCon 2005: Everything You Always Wanted to do with EMF (But were Afraid...
EclipseCon 2005: Everything You Always Wanted to do with EMF (But were Afraid...
 
Entity Framework 4
Entity Framework 4Entity Framework 4
Entity Framework 4
 
닷넷 개발자를 위한 패턴이야기
닷넷 개발자를 위한 패턴이야기닷넷 개발자를 위한 패턴이야기
닷넷 개발자를 위한 패턴이야기
 
Introduction to JSF
Introduction toJSFIntroduction toJSF
Introduction to JSF
 
EMF - The off beat path
EMF - The off beat pathEMF - The off beat path
EMF - The off beat path
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
 
Intro To Spring Python
Intro To Spring PythonIntro To Spring Python
Intro To Spring Python
 
NEOOUG 2010 Oracle Data Integrator Presentation
NEOOUG 2010 Oracle Data Integrator PresentationNEOOUG 2010 Oracle Data Integrator Presentation
NEOOUG 2010 Oracle Data Integrator Presentation
 
Lerman Vvs14 Ef Tips And Tricks
Lerman Vvs14  Ef Tips And TricksLerman Vvs14  Ef Tips And Tricks
Lerman Vvs14 Ef Tips And Tricks
 
Programming in UML: Why and How
Programming in UML: Why and HowProgramming in UML: Why and How
Programming in UML: Why and How
 
Why hibernater1
Why hibernater1Why hibernater1
Why hibernater1
 
EGL Conference 2011 - EGL Open
EGL Conference 2011 - EGL OpenEGL Conference 2011 - EGL Open
EGL Conference 2011 - EGL Open
 
Generalized Functors - Realizing Command Design Pattern in C++
Generalized Functors - Realizing Command Design Pattern in C++Generalized Functors - Realizing Command Design Pattern in C++
Generalized Functors - Realizing Command Design Pattern in C++
 
Entity Framework V1 and V2
Entity Framework V1 and V2Entity Framework V1 and V2
Entity Framework V1 and V2
 
Implementing the Genetic Algorithm in XSLT: PoC
Implementing the Genetic Algorithm in XSLT: PoCImplementing the Genetic Algorithm in XSLT: PoC
Implementing the Genetic Algorithm in XSLT: PoC
 
Entity Framework v2 Best Practices
Entity Framework v2 Best PracticesEntity Framework v2 Best Practices
Entity Framework v2 Best Practices
 
Editing XML data with XForms
Editing XML data with XFormsEditing XML data with XForms
Editing XML data with XForms
 
RomaFramework Tutorial Basics
RomaFramework Tutorial BasicsRomaFramework Tutorial Basics
RomaFramework Tutorial Basics
 
Silverlight 2 for Developers - TechEd New Zealand 2008
Silverlight 2 for Developers - TechEd New Zealand 2008Silverlight 2 for Developers - TechEd New Zealand 2008
Silverlight 2 for Developers - TechEd New Zealand 2008
 

Recently uploaded

Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
Bhaskar Mitra
 
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Peter Udo Diehl
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 

Recently uploaded (20)

Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutes
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and Planning
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
 
UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1
 
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone KomSalesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
 
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
Powerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaPowerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara Laskowska
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 

EclipseCon 2008: Fundamentals of the Eclipse Modeling Framework

  • 1. Fundamentals of the Eclipse Modeling Framework Dave Steinberg IBM Rational Software Toronto, Canada EMF Committer
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14. XML Schema <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> <xsd:schema xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot; targetNamespace=&quot;http://www.example.com/SimplePO&quot; xmlns:po=&quot;http://www.example.com/SimplePO&quot;> <xsd:complexType name=&quot; PurchaseOrder &quot;> <xsd:sequence> <xsd:element name=&quot; shipTo &quot; type=&quot;xsd:string&quot;/> <xsd:element name=&quot; billTo &quot; type=&quot;xsd:string&quot;/> <xsd:element name=&quot; items &quot; type=“po:Item&quot; minOccurs=&quot;0&quot; maxOccurs=&quot;unbounded&quot;/> </xsd:sequence> </xsd:complexType> <xsd:complexType name=&quot; Item &quot;> <xsd:sequence> <xsd:element name=&quot; productName &quot; type=&quot;xsd:string&quot;/> <xsd:element name=&quot; quantity &quot; type=&quot;xsd:int&quot;/> <xsd:element name=&quot; price &quot; type=&quot;xsd:float&quot;/> </xsd:sequence> </xsd:complexType> </xsd:schema>
  • 15.
  • 16.
  • 17. EMF Architecture EMF Runtime EMF Tools Core Edit Codegen Model Editor Application Generates Eclipse Platform
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29. Bidirectional References public interface PurchaseOrder { ... PurchaseOrder getNext (); void setNext (PurchaseOrder value); PurchaseOrder getPrevious (); void setPrevious (PurchaseOrder value); } Bidirectional reference imposes invariant: po.getNext().getPrevious() == po
  • 30.
  • 31. Bidirectional Reference Handshaking p1.setNext(p3); p2 p1 p2 p3 change notification next previous previous next next previous next previous
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44. Proxy Resolution and Demand Load proxyURI=&quot;p2.xml#p2&quot; proxyURI=&quot; p2.xml #p2&quot; p1 p1.xml PurchaseOrder p2 = p1.getNext(); next p2 next p2.xml
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.

Editor's Notes

  1. Welcome…
  2. I hope to help you learn about modeling and convince you that EMF can help you write just about any application in significantly less time, simply by leveraging the data model you’ve probably already defined (even though you might not know it yet).
  3. Here’s our agenda. We’ll also be doing a couple of exercises… I’ll start with some philosophy.
  4. What is modeling? The Object Management Group, an industry consortium, has tried to answer that question by proposing MDA – Model Driven Architecture…
  5. MDA initiative began in 2001. Some people are wondering not just “are we there yet?” but “are we ever going to get there?”…
  6. This is the environment in which EMF was introduced and took hold…
  7. EMF’s take is that models are everywhere, and we just need to find them, extract them, and leverage them…
  8. Where does EMF fit into the Eclipse “big picture”? EMF was one of the first projects at Eclipse outside of the Eclipse Project itself, starting in 2002 as part of the Tools project. Since then, the modeling project has formed around it…
  9. Now, let’s talk some more about models in EMF: what they consist of and where they come from.
  10. I’ve mentioned that EMF’s view of modeling favours simplicity over expressiveness. But, to be more concrete, here’s what we mean by a “model” in EMF…
  11. EMF is very much intended to be a unifying technology. It expects models to be expressed in any number of different ways, and aims to extract its core view of the model from those different representations. Out of the box, it supports what we consider to be the most important ones…  To dwell for a moment on the notion of equivalence of different model representations, let’s consider a simple, familiar example. Imagine we wanted to represent the data in a purchase order. The non-modeler would probably start by writing some Java interfaces…
  12. An interface for each type, accessors for each attribute or association (reference). This really is a definition of the model. But, it’s not quite expressive enough that we could generate a complete implementation from it…
  13. A graphical representation of the model is more concise. Here, we’re using UML notation…
  14. There’s another important way of coming at this: by asking “how do we want to instances of the model to look when they’re serialized?” That’s what XML Schema is all about… Notice that there’s additional information in this one…
  15. To reiterate, these different forms all provide the same core information about the model, or structure, of the application’s data. EMF allows you to capture this information and use it to, among other things, generate code.
  16. Now that I’ve hopefully motivated and introduced EMF, I’ll talk a bit about EMF’s architecture.
  17. I guess we need to start with a block diagram. EMF includes a runtime… The last thing to note is that the EMF core runtime’s dependency on the platform is optional…
  18. If we were to zoom in on those blocks, we’d see that EMF includes these components… The component I’ll focus on most is Ecore. If EMF’s purpose is to capture the core information about an application’s data model, the big question is how…
  19. Not surprisingly, it uses a model. Because it’s a model for models… Here is a simplified picture…
  20. The way EMF defines your application model, such as the purchase order we discussed previously, is by instantiating Ecore. So, when the purchase order application is running, there will actually be an instance of EClass present representing class PurchaseOrder…
  21. Ecore is persisted as XML, using the OMG’s standard for metadata serialization, XML Metadata Interchange… EMOF is the OMG’s equivalent to Ecore. Based on experience with EMF, MOF, the Meta-Object Facility, was split into to two layers, where EMOF is the minimal core. Because of their similarity, EMF also supports saving Ecore directly as EMOF XMI and loading EMOF XMI into Ecore.
  22. Here’s another pretty block diagram that will hopefully tie everything together…
  23. Another option is to model directly using Ecore. EMF provides…
  24. One last architectural note: as of last summer’s Europa release, EMF provides support for Java 5… Generics support includes the ability to model generic types within Ecore.
  25. I’ve mentioned more than once that EMF lets you generate code from a model. But what does that code look like?
  26. First off, for each modeled class, an interface/implementation pair is generated. Notice that the interface looks like the Java model representation. Using interfaces allows us to support multiple inheritance. Interfaces extend EObject, the EMF equivalent of java.lang.Object. Getter/setter pairs are included for single-valued attribute and references. Multiplicity-many features are manipulated directly through a list API, so there’s just a getter.
  27. Change notification is built right into EMF. Every EObject is also a Notifier… To attach an observer, which we call an adapter, to a notifier, we’d do this…
  28. Looking in the implementation class at the accessors, we can see how that’s done. It’s still a very simple implementation…
  29. Things get a bit more complicated if you model bidirectional associations, in order to ensure that referential integrity is maintained. To illustrate…
  30. EMF implements this using a handshaking pattern… It’s not possible to turn off this handshaking bahavior or stop it part-way, without significantly altering generated code.
  31. Now, looking at the example, let’s follow the whole handshaking process. If we have three purchase orders arranged like this…
  32. Earlier, I mentioned the EObject interface. Primarily, it provides an API for manipulating objects reflectively…
  33. These generic accessor methods are implemented using an efficient switch, so as to only impose a small constant-time overhead… Metadata in EMF is represented in two ways…
  34. Ecore includes enumerated types, which are realized with Java 5 enums. Previously, a class-based type-safe enum pattern was used.
  35. A couple of really important interfaces and classes are generated for each modeled package…
  36. Obviously, there’s not enough time to talk about every artifact that EMF generates, so here’s a quick list. Notice that the code is divided into four projects…
  37. As I mentioned in the intro, Ecore is simple by design. Instead of trying to provide a modeling vocabulary that’s as expressive as Java…
  38. The generator also supports a pattern for extending generated methods, analogous to overriding a method in a subclass…
  39. [8:35] Let’s get into the exercises… [8:55] I’d like to talk a bit about how you can use all this code you generated, and then I’ll let you do the second exercise.
  40. We’ll start with EMF’s resource-based persistence framework. A resource in EMF is just a container for a bunch of objects that will be persisted together. Objects can be spread out among a number of different resources, and demand-loading is used for cross-resource references. That allows…
  41. A resource set provides a context for multiple resources that may have references among them. You’ll use the resource set to create and manage those resources…
  42. There are a couple of registries you’ll need to know about… A resource factory registry is used by a resource set to decide what type of resource to create, so it determines the persistence format… A package registry is used to locate metadata during loading. Persisted data specifies a namespace URI…
  43. As I mentioned earlier, a resource is just a container for objects that are persisted together… Out of the box, EMF provides a generic XML resource and a number of different specializations of it…
  44. To expand on EMF’s demand-load model for cross-resource references, let’s look at another simple example…
  45. When you’re working with a model created from XML Schema, there are a couple of extra details you’ll need to worry about. In the first exercise, we saw that the model included…
  46. To serialize an instance document that conforms to the schema, you’ll need to use an instance of… Also, you’ll need to ensure that…
  47. The reflective EObject interface is a powerful mechanism for data integration, as it allows your application to discover the model for objects at runtime and modify them accordingly. If you know the model ahead of time…
  48. Built on the reflective API is dynamic EMF. Rather than generating code, you can define an Ecore model at runtime and instantiate it immediately, using a generic implementation. All of the behaviours of the generated code are emulated by this implementation. You can define the model…
  49. EMF provides a facility for representing and recording changes to data. As we’re big believers in eating our own dog food…
  50. A change recorder is a special adapter that attaches to an entire content tree and, based on the change notifications it receives…
  51. The EMF core also has a built-in framework for validation of invariants and constraints…
  52. There are a couple of cases where constraints will actually be implemented automatically… For example, in our purchase order schema, there is a SKU type that’s a restriction of string. It specifies a regular expression that any valid value must match…h
  53. The API for invoking validation is the Diagnostician class…
  54. Finally, the runtime provides a whole bunch of convenience utilities, mostly in the class EcoreUtil. There you’ll find…
  55. [9:15] I’ll stop talking again now and let you work on the second exercise. I’ll stop you a few minutes before the session ends to sum things up. [9:55] Let’s sum up…