Eclipse Modeling Frameworkajaykemparaj@gmail.comhttp://www.theenmusketeers.comEMF
What is Eclipse ?Eclipse is a Java IDEEclipse is an IDE FrameworkEclipse + JDT = Java IDEFirst class framework for JavaLanguage aware editorIncremental buildIntegrated debuggingEclipse + CDT = C/C++ IDEFirst class framework for C/C++Language aware editorRefactoring, searchEclipse + PHP = PHP IDEEclipse + JDT + CDT + PHP = Java, C/C++, PHP IDE………….
Plug-inPlug-inPlug-inEclipse is a Tools FrameworkTools extend the Eclipse platform using plug-insBusiness Intelligence and Reporting Tools (BIRT)Eclipse Communications Framework (ECF)Web Tools Project (WTP)Eclipse Modelling Framework (EMF)Graphical Editing Framework (GEF)Test and Performance Tooling Project (TPTP
Eclipse is a Application FrameworkRemove the IDE elements, Java language support, team development support, … and you’re left with a pretty comprehensive general application frameworkSupport for multiple platformsLinux, Windows, Mac OSX, UNIX, embeddedRich widget set, graphicsNative-OS integration (drag and drop, OLE/XPCOM integration)A platform for rich clients
Eclipse is all these thingsA Java IDEAn IDE FrameworkA Tools FrameworkAn Application FrameworkAn Open Source EnablerA communityAn eco-systemA foundation
Model Driven Architecture (MDA)• A software architecture proposed by the OMG (Object Management Group)• Application specified in high-level, Platform Independent Model (PIM)• Transformation technologies used to convert PIM toPlatform Specific Model (PSM), implementation code• Includes several open modeling standards: UML™ (Unified Modeling Language) MOF (Meta-Object Facility) XMI (XML Metadata Interchange) CWM (Common Warehouse Model)
What is EMF ?EMF is a simple, pragmatic approach to modeling: Allows us to generate some of the code that we write over and over, paving the way for more complex systems Models are simple, but meant to be mixed with hand-written code It’s real, proven technology (since 2002)
What EMF is ?A Model for describing other Model  (Meta Model)
Runtime Emulator for  your model
generator for Java Implementation of your ModelEMF is a  framework converting various forms of model into core model description called Ecore
Why EMF ?EMF is middle ground in the modeling vs. programming worldsFocus is on class diagram subset of UML modeling (object model)Transforms models into Java codeProvides the infrastructure to use models effectively in your applicationVery low cost of entry EMF is free and open sourceFull scale graphical modeling tool not requiredReuses your knowledge of UML, XML Schema, or JavaIt’s real, proven technology (since 2002)
Some of Eclipse projects which are using EMFTools Project: UML2 and Visual Editor (VE)
Web Tools Platform (WTP) Project
Test and Performance Tools Platform (TPTP) Project
Business Intelligence and Reporting Tools (BIRT) Project
Data Tools Platform (DTP) Project
Modeling : Graphical Modeling Framework (GMF)What is an EMF “Model”?• Specification of an application’s data 	Object attributes  	Relationships (associations) between objects	Operations available on each object	 Simple constraints (e.g. multiplicity) on objects and relationships• Essentially, the Class Diagram subset of UML
EMF Architecture
EMF Components• Core Runtime 	Notification framework	 Ecore meta model 	Persistence (XML/XMI), validation, change model• EMF.Edit 	Support for model-based editors and viewers 	Default reflective editor• Codegen 	Code generator for application models and editors 	Extensible model importer/exporter framework
The Ecore(Meta) Model• EMF’s metamodel (model of a model)
Model Sources• EMF models can be defined in (at least) three ways:1. Java Interfaces2. UML Class Diagram3. XML Schema
Java Interfacespublic interface Item{  String getProductName();  void setProductName(String value);intgetQuantity();  void setQuantity(int value)  float getPrice();  void setPrice(float value);}public interface PurchaseOrder{  String getShipTo();  void setShipTo(String value);  String getBillTo();  void setBillTo(String value);  List getItems(); // List of Item}• Classes can be defined completely by a subset of members, supplemented by annotations
UML Class Diagram• Built-in support for Rational Rose®• UML2 support available with UML2 (from MDT)
XML Schema<?xml version="1.0" encoding="UTF-8"?><xsd:schemaxmlns:xsd="http://www.w3.org/2001/XMLSchema"targetNamespace="http://www.example.com/SimplePO"xmlns:po="http://www.example.com/SimplePO"><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></xsd:schema>
Direct Ecore Modeling• Ecore models can be created directly Sample Ecore editor (in EMF) Ecore Tools graphical editor (from EMFT)
Code Generation (Simple)
Code Generation (Full)
Generated Model Code• Interface and implementation for each modeled class Includes get/set accessors for attributes and referencesInterfacepublic interface PurchaseOrder extends EObject{String getShipTo();void setShipTo(String value);String getBillTo();void setBillTo(String value);EList<Item> getItems();}Implementation Classpublic class PurchaseOrderImpl extends EObjectImplimplements PurchaseOrder{...}
Change Notification• Every EObject is also a notifier Sends notification whenever an attributeor reference is changed Observers can update views, dependentobjects Observers are also adaptersAdapterAdapter adapter = ...purchaseOrder.eAdapters().add(adapter);
Factories and Packages• Factory to create instances of model classes• Package provides access to metadataPOFactory factory = POFactory.eINSTANCE;PurchaseOrder order = factory.createPurchaseOrder();POPackagepoPackage = POPackage.eINSTANCE;EClassitemClass = POPackage.Literals.ITEM;//or poPackage.getItem()EAttributepriceAttr = POPackage.Literals.ITEM__PRICE;//or poPackage.getItem_Price()//or itemClass.getEStructuralFeature(POPackage.ITEM__PRICE)
Persistence• Persisted data is referred to a resource• Objects can be spread out among a number ofresources, within a resource set• Proxies represent referenced objects in otherresources
Resource Set• Context for multiple resources that may have references among them• Usually just an instance of ResourceSetImpl• Provides factory method for creating new resources in the setResourceSetrs = new ResourceSetImpl();URI uri = URI.createFileURI("C:/data/po.xml");Resource resource = rs.createResource(uri);• Also provides access to the registries, URI converterand default load options for the set
Resource• Container for objects that are to be persisted together Convert to and from persistent form via save() and load()
 Access contents of resource via getContents()URI uri = URI.createFileURI("C:/data/po.xml");Resource resource = rs.createResource(uri);resource.getContents().add(p1);resource.save(null);• EMF provides generic XMLResource implementation Other, customized implementations.<PurchaseOrder><shipTo>John Doe</shipTo><next>p2.xml#p2</next></PurchaseOrder>
Registries• Resource Factory Registry Returns a resource factory for a given type of resource
 Based on URI scheme, filename extension or content type
 Determines the format for save/load
 If no registered resource factory found locally, delegates to	global registry: Resource.Factory.Registry.INSTANCE• Package Registry Returns the package identified by a given namespace URI

Eclipse Modeling Framework

  • 1.
  • 2.
    What is Eclipse?Eclipse is a Java IDEEclipse is an IDE FrameworkEclipse + JDT = Java IDEFirst class framework for JavaLanguage aware editorIncremental buildIntegrated debuggingEclipse + CDT = C/C++ IDEFirst class framework for C/C++Language aware editorRefactoring, searchEclipse + PHP = PHP IDEEclipse + JDT + CDT + PHP = Java, C/C++, PHP IDE………….
  • 3.
    Plug-inPlug-inPlug-inEclipse is aTools FrameworkTools extend the Eclipse platform using plug-insBusiness Intelligence and Reporting Tools (BIRT)Eclipse Communications Framework (ECF)Web Tools Project (WTP)Eclipse Modelling Framework (EMF)Graphical Editing Framework (GEF)Test and Performance Tooling Project (TPTP
  • 4.
    Eclipse is aApplication FrameworkRemove the IDE elements, Java language support, team development support, … and you’re left with a pretty comprehensive general application frameworkSupport for multiple platformsLinux, Windows, Mac OSX, UNIX, embeddedRich widget set, graphicsNative-OS integration (drag and drop, OLE/XPCOM integration)A platform for rich clients
  • 5.
    Eclipse is allthese thingsA Java IDEAn IDE FrameworkA Tools FrameworkAn Application FrameworkAn Open Source EnablerA communityAn eco-systemA foundation
  • 6.
    Model Driven Architecture(MDA)• A software architecture proposed by the OMG (Object Management Group)• Application specified in high-level, Platform Independent Model (PIM)• Transformation technologies used to convert PIM toPlatform Specific Model (PSM), implementation code• Includes several open modeling standards: UML™ (Unified Modeling Language) MOF (Meta-Object Facility) XMI (XML Metadata Interchange) CWM (Common Warehouse Model)
  • 7.
    What is EMF?EMF is a simple, pragmatic approach to modeling: Allows us to generate some of the code that we write over and over, paving the way for more complex systems Models are simple, but meant to be mixed with hand-written code It’s real, proven technology (since 2002)
  • 8.
    What EMF is?A Model for describing other Model (Meta Model)
  • 9.
  • 10.
    generator for JavaImplementation of your ModelEMF is a framework converting various forms of model into core model description called Ecore
  • 11.
    Why EMF ?EMFis middle ground in the modeling vs. programming worldsFocus is on class diagram subset of UML modeling (object model)Transforms models into Java codeProvides the infrastructure to use models effectively in your applicationVery low cost of entry EMF is free and open sourceFull scale graphical modeling tool not requiredReuses your knowledge of UML, XML Schema, or JavaIt’s real, proven technology (since 2002)
  • 12.
    Some of Eclipseprojects which are using EMFTools Project: UML2 and Visual Editor (VE)
  • 13.
    Web Tools Platform(WTP) Project
  • 14.
    Test and PerformanceTools Platform (TPTP) Project
  • 15.
    Business Intelligence andReporting Tools (BIRT) Project
  • 16.
    Data Tools Platform(DTP) Project
  • 17.
    Modeling : GraphicalModeling Framework (GMF)What is an EMF “Model”?• Specification of an application’s data Object attributes Relationships (associations) between objects Operations available on each object Simple constraints (e.g. multiplicity) on objects and relationships• Essentially, the Class Diagram subset of UML
  • 18.
  • 19.
    EMF Components• CoreRuntime Notification framework Ecore meta model Persistence (XML/XMI), validation, change model• EMF.Edit Support for model-based editors and viewers Default reflective editor• Codegen Code generator for application models and editors Extensible model importer/exporter framework
  • 20.
    The Ecore(Meta) Model•EMF’s metamodel (model of a model)
  • 22.
    Model Sources• EMFmodels can be defined in (at least) three ways:1. Java Interfaces2. UML Class Diagram3. XML Schema
  • 24.
    Java Interfacespublic interfaceItem{ String getProductName(); void setProductName(String value);intgetQuantity(); void setQuantity(int value) float getPrice(); void setPrice(float value);}public interface PurchaseOrder{ String getShipTo(); void setShipTo(String value); String getBillTo(); void setBillTo(String value); List getItems(); // List of Item}• Classes can be defined completely by a subset of members, supplemented by annotations
  • 25.
    UML Class Diagram•Built-in support for Rational Rose®• UML2 support available with UML2 (from MDT)
  • 26.
    XML Schema<?xml version="1.0"encoding="UTF-8"?><xsd:schemaxmlns:xsd="http://www.w3.org/2001/XMLSchema"targetNamespace="http://www.example.com/SimplePO"xmlns:po="http://www.example.com/SimplePO"><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></xsd:schema>
  • 27.
    Direct Ecore Modeling•Ecore models can be created directly Sample Ecore editor (in EMF) Ecore Tools graphical editor (from EMFT)
  • 28.
  • 29.
  • 31.
    Generated Model Code•Interface and implementation for each modeled class Includes get/set accessors for attributes and referencesInterfacepublic interface PurchaseOrder extends EObject{String getShipTo();void setShipTo(String value);String getBillTo();void setBillTo(String value);EList<Item> getItems();}Implementation Classpublic class PurchaseOrderImpl extends EObjectImplimplements PurchaseOrder{...}
  • 32.
    Change Notification• EveryEObject is also a notifier Sends notification whenever an attributeor reference is changed Observers can update views, dependentobjects Observers are also adaptersAdapterAdapter adapter = ...purchaseOrder.eAdapters().add(adapter);
  • 33.
    Factories and Packages•Factory to create instances of model classes• Package provides access to metadataPOFactory factory = POFactory.eINSTANCE;PurchaseOrder order = factory.createPurchaseOrder();POPackagepoPackage = POPackage.eINSTANCE;EClassitemClass = POPackage.Literals.ITEM;//or poPackage.getItem()EAttributepriceAttr = POPackage.Literals.ITEM__PRICE;//or poPackage.getItem_Price()//or itemClass.getEStructuralFeature(POPackage.ITEM__PRICE)
  • 34.
    Persistence• Persisted datais referred to a resource• Objects can be spread out among a number ofresources, within a resource set• Proxies represent referenced objects in otherresources
  • 35.
    Resource Set• Contextfor multiple resources that may have references among them• Usually just an instance of ResourceSetImpl• Provides factory method for creating new resources in the setResourceSetrs = new ResourceSetImpl();URI uri = URI.createFileURI("C:/data/po.xml");Resource resource = rs.createResource(uri);• Also provides access to the registries, URI converterand default load options for the set
  • 36.
    Resource• Container forobjects that are to be persisted together Convert to and from persistent form via save() and load()
  • 37.
    Access contentsof resource via getContents()URI uri = URI.createFileURI("C:/data/po.xml");Resource resource = rs.createResource(uri);resource.getContents().add(p1);resource.save(null);• EMF provides generic XMLResource implementation Other, customized implementations.<PurchaseOrder><shipTo>John Doe</shipTo><next>p2.xml#p2</next></PurchaseOrder>
  • 38.
    Registries• Resource FactoryRegistry Returns a resource factory for a given type of resource
  • 39.
    Based onURI scheme, filename extension or content type
  • 40.
    Determines theformat for save/load
  • 41.
    If noregistered resource factory found locally, delegates to global registry: Resource.Factory.Registry.INSTANCE• Package Registry Returns the package identified by a given namespace URI
  • 42.
    Used duringloading to access factory for instantiating classes
  • 43.
    If noregistered package found locally, delegates to global registry: EPackage.Registry.INSTANCE
  • 44.
    Reflective EObject API•All EMF classes implement EObject interface• Provides an efficient API for manipulating objectsreflectively Used by framework (e.g. persistence framework, copy utility,editing commands)public interface EObject{EClasseClass();Object eGet(EStructuralFeaturesf);void eSet(EStructuralFeaturesf, Object val);...}
  • 45.
    Reflective EObject API•Efficient generated switch-based implementation of reflective methodspublic Object eGet(intfeatureID, ...){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();...}...}
  • 47.
    Regeneration and Merge•The EMF generator is a merging generator/*** <!-- begin-user-doc -->* <!-- end-user-doc -->* @generated*/public String getName(){return name;}•@generated elements are replaced/removed• To preserve changes mark @generated NOT
  • 48.
    Recording Changes EMFprovides facilities for recording the changes made toinstances of an Ecore model Change Model An EMF model for representing changes to objects Directly references affected objects Includes “apply changes” capability Change Recorder EMF adapter Monitors objects to produce a change description (an instance ofthe change model)
  • 50.
    Change Recorder Canbe attached to EObjects, Resources, and ResourceSets Produces a description of the changes needed to return to theoriginal state (a reverse delta)PurchaseOrder order = ...order.setBillTo("123 Elm St.");ChangeRecorder recorder = new ChangeRecorder();recorder.beginRecording(Collections.singleton(order));order.setBillTo("456 Cherry St.");ChangeDescription change = recorder.endRecording(); Result: a change description with one change, setting billTo to“123 Elm St.”
  • 51.
    Diagnostician• Diagnostician walksa containment tree of objects,dispatching to package-specific validatorsDiagnostician.validate() is the usual entry point Detailed results accumulated as DiagnosticsDiagnostician validator = Diagnostician.INSTANCE;Diagnostic diagnostic = validator.validate(order);if (diagnostic.getSeverity() == Diagnostic.ERROR){// handle error}for (Diagnostic child : diagnostic.getChildren()){// handle child diagnostic}
  • 52.
    DemoCreation of ecoreCode GenerationCode Walkthrough
  • 53.
    Resources• EMF documentationin Eclipse Help Overviews, tutorials, API reference• EMF project Web site http://www.eclipse.org/modeling/emf/ Downloads, documentation, FAQ,newsgroup, Bugzilla, Wiki• Eclipse Modeling Framework, by Frank Budinsky Ed Merks