Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Eclipse Modeling Framework


Published on

Published in: Technology, Education

Eclipse Modeling Framework

  1. 1. Eclipse Modeling Framework<br /><br /><br />EMF<br />
  2. 2. What is Eclipse ?<br />Eclipse is a Java IDE<br />Eclipse is an IDE Framework<br />Eclipse + JDT = Java IDE<br />First class framework for Java<br />Language aware editor<br />Incremental build<br />Integrated debugging<br />Eclipse + CDT = C/C++ IDE<br />First class framework for C/C++<br />Language aware editor<br />Refactoring, search<br />Eclipse + PHP = PHP IDE<br />Eclipse + JDT + CDT + PHP = Java, C/C++, PHP IDE<br />………….<br />
  3. 3. Plug-in<br />Plug-in<br />Plug-in<br />Eclipse is a Tools Framework<br />Tools extend the Eclipse platform using plug-ins<br />Business Intelligence and Reporting Tools (BIRT)<br />Eclipse Communications Framework (ECF)<br />Web Tools Project (WTP)<br />Eclipse Modelling Framework (EMF)<br />Graphical Editing Framework (GEF)<br />Test and Performance Tooling Project (TPTP<br />
  4. 4. Eclipse is a Application Framework<br />Remove the IDE elements, Java language support, team development support, … and you’re left with a pretty comprehensive general application framework<br />Support for multiple platforms<br />Linux, Windows, Mac OSX, UNIX, embedded<br />Rich widget set, graphics<br />Native-OS integration (drag and drop, OLE/XPCOM integration)<br />A platform for rich clients<br />
  5. 5. Eclipse is all these things<br />A Java IDE<br />An IDE Framework<br />A Tools Framework<br />An Application Framework<br />An Open Source Enabler<br />A community<br />An eco-system<br />A foundation<br />
  6. 6. Model Driven Architecture (MDA)<br />• A software architecture proposed by the OMG (Object Management Group)<br />• Application specified in high-level, Platform Independent Model (PIM)<br />• Transformation technologies used to convert PIM to<br />Platform Specific Model (PSM), implementation code<br />• Includes several open modeling standards:<br /> UML™ (Unified Modeling Language)<br /> MOF (Meta-Object Facility)<br /> XMI (XML Metadata Interchange)<br /> CWM (Common Warehouse Model)<br />
  7. 7. What is EMF ?<br />EMF is a simple, pragmatic approach to modeling:<br /> Allows us to generate some of the code that we write over and over, paving the way for more complex systems<br /> Models are simple, but meant to be mixed with hand-written code<br /> It’s real, proven technology (since 2002)<br />
  8. 8. What EMF is ?<br /><ul><li>A Model for describing other Model (Meta Model)
  9. 9. Runtime Emulator for your model
  10. 10. generator for Java Implementation of your Model</li></ul>EMF is a framework converting various forms of model into core model description called Ecore<br />
  11. 11. Why EMF ?<br />EMF is middle ground in the modeling vs. programming worlds<br />Focus is on class diagram subset of UML modeling (object model)<br />Transforms models into Java code<br />Provides the infrastructure to use models effectively in your application<br />Very low cost of entry <br />EMF is free and open source<br />Full scale graphical modeling tool not required<br />Reuses your knowledge of UML, XML Schema, or Java<br />It’s real, proven technology (since 2002)<br />
  12. 12. Some of Eclipse projects which are using EMF<br /><ul><li>Tools Project: UML2 and Visual Editor (VE)
  13. 13. Web Tools Platform (WTP) Project
  14. 14. Test and Performance Tools Platform (TPTP) Project
  15. 15. Business Intelligence and Reporting Tools (BIRT) Project
  16. 16. Data Tools Platform (DTP) Project
  17. 17. Modeling : Graphical Modeling Framework (GMF)</li></li></ul><li>What is an EMF “Model”?<br />• Specification of an application’s data <br /> Object attributes <br /> Relationships (associations) between objects<br /> Operations available on each object<br /> Simple constraints (e.g. multiplicity) on objects and relationships<br />• Essentially, the Class Diagram subset of UML<br />
  18. 18. EMF Architecture<br />
  19. 19. EMF Components<br />• Core Runtime<br /> Notification framework<br /> Ecore meta model<br /> Persistence (XML/XMI), validation, change model<br />• EMF.Edit<br /> Support for model-based editors and viewers<br /> Default reflective editor<br />• Codegen<br /> Code generator for application models and editors<br /> Extensible model importer/exporter framework<br />
  20. 20. The Ecore(Meta) Model<br />• EMF’s metamodel (model of a model)<br />
  21. 21.
  22. 22. Model Sources<br />• EMF models can be defined in (at least) three ways:<br />1. Java Interfaces<br />2. UML Class Diagram<br />3. XML Schema<br />
  23. 23.
  24. 24. Java Interfaces<br />public interface Item<br />{<br /> String getProductName();<br /> void setProductName(String value);<br />intgetQuantity();<br /> void setQuantity(int value)<br /> float getPrice();<br /> void setPrice(float value);<br />}<br />public interface PurchaseOrder<br />{<br /> String getShipTo();<br /> void setShipTo(String value);<br /> String getBillTo();<br /> void setBillTo(String value);<br /> List getItems(); // List of Item<br />}<br />• Classes can be defined completely by a subset of members, supplemented by annotations<br />
  25. 25. UML Class Diagram<br />• Built-in support for Rational Rose®<br />• UML2 support available with UML2 (from MDT)<br />
  26. 26. XML Schema<br />&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;<br />&lt;xsd:schemaxmlns:xsd=&quot;;<br />targetNamespace=&quot;;<br />xmlns:po=&quot;;&gt;<br />&lt;xsd:complexType name=&quot;PurchaseOrder&quot;&gt;<br />&lt;xsd:sequence&gt;<br />&lt;xsd:element name=&quot;shipTo&quot; type=&quot;xsd:string&quot;/&gt;<br />&lt;xsd:element name=&quot;billTo&quot; type=&quot;xsd:string&quot;/&gt;<br />&lt;xsd:element name=&quot;items&quot; type=“po:Item&quot;<br />minOccurs=&quot;0&quot; maxOccurs=&quot;unbounded&quot;/&gt;<br />&lt;/xsd:sequence&gt;<br />&lt;/xsd:complexType&gt;<br />&lt;xsd:complexType name=&quot;Item&quot;&gt;<br />&lt;xsd:sequence&gt;<br />&lt;xsd:element name=&quot;productName&quot; type=&quot;xsd:string&quot;/&gt;<br />&lt;xsd:element name=&quot;quantity&quot; type=&quot;xsd:int&quot;/&gt;<br />&lt;xsd:element name=&quot;price&quot; type=&quot;xsd:float&quot;/&gt;<br />&lt;/xsd:sequence&gt;<br />&lt;/xsd:complexType&gt;<br />&lt;/xsd:schema&gt;<br />
  27. 27. Direct Ecore Modeling<br />• Ecore models can be created directly<br /> Sample Ecore editor (in EMF)<br /> Ecore Tools graphical editor (from EMFT)<br />
  28. 28. Code Generation (Simple)<br />
  29. 29. Code Generation (Full)<br />
  30. 30.
  31. 31. Generated Model Code<br />• Interface and implementation for each modeled class<br /> Includes get/set accessors for attributes and references<br />Interface<br />public interface PurchaseOrder extends EObject<br />{<br />String getShipTo();<br />void setShipTo(String value);<br />String getBillTo();<br />void setBillTo(String value);<br />EList&lt;Item&gt; getItems();<br />}<br />Implementation Class<br />public class PurchaseOrderImpl extends EObjectImpl<br />implements PurchaseOrder<br />{<br />...<br />}<br />
  32. 32. Change Notification<br />• Every EObject is also a notifier<br /> Sends notification whenever an attribute<br />or reference is changed<br /> Observers can update views, dependent<br />objects<br /> Observers are also adapters<br />Adapter<br />Adapter adapter = ...<br />purchaseOrder.eAdapters().add(adapter);<br />
  33. 33. Factories and Packages<br />• Factory to create instances of model classes<br />• Package provides access to metadata<br />POFactory factory = POFactory.eINSTANCE;<br />PurchaseOrder order = factory.createPurchaseOrder();<br />POPackagepoPackage = POPackage.eINSTANCE;<br />EClassitemClass = POPackage.Literals.ITEM;<br />//or poPackage.getItem()<br />EAttributepriceAttr = POPackage.Literals.ITEM__PRICE;<br />//or poPackage.getItem_Price()<br />//or itemClass.getEStructuralFeature(POPackage.ITEM__PRICE)<br />
  34. 34. Persistence<br />• Persisted data is referred to a resource<br />• Objects can be spread out among a number of<br />resources, within a resource set<br />• Proxies represent referenced objects in other<br />resources<br />
  35. 35. Resource Set<br />• Context for multiple resources that may have references among them<br />• Usually just an instance of ResourceSetImpl<br />• Provides factory method for creating new resources in the set<br />ResourceSetrs = new ResourceSetImpl();<br />URI uri = URI.createFileURI(&quot;C:/data/po.xml&quot;);<br />Resource resource = rs.createResource(uri);<br />• Also provides access to the registries, URI converter<br />and default load options for the set<br />
  36. 36. Resource<br />• Container for objects that are to be persisted together<br /><ul><li> Convert to and from persistent form via save() and load()
  37. 37. Access contents of resource via getContents()</li></ul>URI uri = URI.createFileURI(&quot;C:/data/po.xml&quot;);<br />Resource resource = rs.createResource(uri);<br />resource.getContents().add(p1);<br />;<br />• EMF provides generic XMLResource implementation<br /><ul><li> Other, customized implementations.</li></ul>&lt;PurchaseOrder&gt;<br />&lt;shipTo&gt;John Doe&lt;/shipTo&gt;<br />&lt;next&gt;p2.xml#p2&lt;/next&gt;<br />&lt;/PurchaseOrder&gt;<br />
  38. 38. Registries<br />• Resource Factory Registry<br /><ul><li> Returns a resource factory for a given type of resource
  39. 39. Based on URI scheme, filename extension or content type
  40. 40. Determines the format for save/load
  41. 41. If no registered resource factory found locally, delegates to</li></ul> global registry: Resource.Factory.Registry.INSTANCE<br />• Package Registry<br /><ul><li> Returns the package identified by a given namespace URI
  42. 42. Used during loading to access factory for instantiating classes
  43. 43. If no registered package found locally, delegates to global</li></ul> registry: EPackage.Registry.INSTANCE<br />
  44. 44. Reflective EObject API<br />• All EMF classes implement EObject interface<br />• Provides an efficient API for manipulating objects<br />reflectively<br /> Used by framework (e.g. persistence framework, copy utility,<br />editing commands)<br />public interface EObject<br />{<br />EClasseClass();<br />Object eGet(EStructuralFeaturesf);<br />void eSet(EStructuralFeaturesf, Object val);<br />...<br />}<br />
  45. 45. Reflective EObject API<br />• Efficient generated switch-based implementation of reflective methods<br />public Object eGet(intfeatureID, ...)<br />{<br />switch (featureID)<br />{<br />case POPackage.PURCHASE_ORDER__ITEMS:<br />return getItems();<br />case POPackage.PURCHASE_ORDER__SHIP_TO:<br />return getShipTo();<br />case POPackage.PURCHASE_ORDER__BILL_TO:<br />return getBillTo();<br />...<br />}<br />...<br />}<br />
  46. 46.
  47. 47. Regeneration and Merge<br />• The EMF generator is a merging generator<br />/**<br />* &lt;!-- begin-user-doc --&gt;<br />* &lt;!-- end-user-doc --&gt;<br />* @generated<br />*/<br />public String getName()<br />{<br />return name;<br />}<br />•@generated elements are replaced/removed<br />• To preserve changes mark @generated NOT<br />
  48. 48. Recording Changes<br /> EMF provides facilities for recording the changes made to<br />instances of an Ecore model<br /> Change Model<br /> An EMF model for representing changes to objects<br /> Directly references affected objects<br /> Includes “apply changes” capability<br /> Change Recorder<br /> EMF adapter<br /> Monitors objects to produce a change description (an instance of<br />the change model)<br />
  49. 49.
  50. 50. Change Recorder<br /> Can be attached to EObjects, Resources, and ResourceSets<br /> Produces a description of the changes needed to return to the<br />original state (a reverse delta)<br />PurchaseOrder order = ...<br />order.setBillTo(&quot;123 Elm St.&quot;);<br />ChangeRecorder recorder = new ChangeRecorder();<br />recorder.beginRecording(Collections.singleton(order));<br />order.setBillTo(&quot;456 Cherry St.&quot;);<br />ChangeDescription change = recorder.endRecording();<br /> Result: a change description with one change, setting billTo to<br />“123 Elm St.”<br />
  51. 51. Diagnostician<br />• Diagnostician walks a containment tree of objects,<br />dispatching to package-specific validators<br />Diagnostician.validate() is the usual entry point<br /> Detailed results accumulated as Diagnostics<br />Diagnostician validator = Diagnostician.INSTANCE;<br />Diagnostic diagnostic = validator.validate(order);<br />if (diagnostic.getSeverity() == Diagnostic.ERROR)<br />{<br />// handle error<br />}<br />for (Diagnostic child : diagnostic.getChildren())<br />{<br />// handle child diagnostic<br />}<br />
  52. 52. Demo<br />Creation of ecore <br />Code Generation<br />Code Walkthrough<br />
  53. 53. Resources<br />• EMF documentation in Eclipse Help Overviews, tutorials, API reference<br />• EMF project Web site<br /><br /> Downloads, documentation, FAQ,newsgroup, Bugzilla, Wiki<br />• Eclipse Modeling Framework, by Frank Budinsky Ed Merks<br />