EMF - Beyond The Basics

5,559 views
5,441 views

Published on

Talk at the JAX 2009 in Mainz (Germany)

Published in: Technology
0 Comments
12 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
5,559
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
338
Comments
0
Likes
12
Embeds 0
No embeds

No notes for slide




































































  • EMF - Beyond The Basics

    1. 1. Dr. Jan Köhnlein, itemis AG EMF – Beyond the Basics
    2. 2. Eclipse Modeling Framework
    3. 3. Eclipse Modeling Framework • Create Ecore models
    4. 4. Eclipse Modeling Framework • Create Ecore models • from Java, XSD, UML, MOF
    5. 5. Eclipse Modeling Framework • Create Ecore models • from Java, XSD, UML, MOF • or from scratch
    6. 6. Eclipse Modeling Framework • Create Ecore models • from Java, XSD, UML, MOF • or from scratch • Generate Java-Code from Ecore
    7. 7. Eclipse Modeling Framework • Create Ecore models • from Java, XSD, UML, MOF • or from scratch • Generate Java-Code from Ecore • Runtime library to process Ecore models and instances
    8. 8. Ecore EPackage EClassifer * name:String name: String eClassifiers nsURI: String eSuperTypes * EClass EDatatype abstract: boolean eReferenceType eAttributeType * eStructuralFeatures EStructuralFeature name: String lowerBound: int upperBound: int EReference EAttribute containment: boolean * eOpposite
    9. 9. Ecore Instances
    10. 10. Ecore Instances • EObject
    11. 11. Ecore Instances • EObject • Instance of an EClass
    12. 12. Ecore Instances • EObject • Instance of an EClass • Values for EAttributes
    13. 13. Ecore Instances • EObject • Instance of an EClass • Values for EAttributes • References for EReferences
    14. 14. Ecore Instances • EObject • Instance of an EClass • Values for EAttributes • References for EReferences • Ecore is self-describing
    15. 15. Ecore Instances • EObject • Instance of an EClass • Values for EAttributes • References for EReferences • Ecore is self-describing • EClass, EPackage etc. extend EObject
    16. 16. Example Ecore/Instance << EPackage >> <<Node>> TreePackage parent parent myNode0 name: quot;Treequot; nsURI: quot;http://www.itemis..quot; <<EClass>> Node name: quot;Nodequot; children abstract: false <<EReference>> << EReference >> children parent name: quot;childrenquot; name: quot;parentquot; containment: true containment: false << Node >> << Node >> upperBound: -1 upperBound: 1 myNode2 myNode1 lowerBound: 0 lowerBound: 0 eOpposite eOpposite
    17. 17. Example: Java View TreePackage::EPackage name: quot;Treequot; myNode0::Node nsURI: quot;http://www.itemis..quot; parent Node::EClass name: quot;Nodequot; children abstract: false ::EList children::EReference parent::EReference name: quot;childrenquot; name: quot;parentquot; containment: true containment: false upperBound: -1 upperBound: 1 myNode1::Node lowerBound: 0 lowerBound: 0 eOpposite eOpposite
    18. 18. Example: Java View TreePackage::EPackage name: quot;Treequot; myNode0::Node nsURI: quot;http://www.itemis..quot; parent Node::EClass name: quot;Nodequot; children abstract: false ::EList children::EReference parent::EReference name: quot;childrenquot; name: quot;parentquot; containment: true containment: false upperBound: -1 upperBound: 1 myNode1::Node lowerBound: 0 lowerBound: 0 eOpposite eOpposite Node myNode0 = TreeFactory.eINSTANCE.createNode(); Node myNode1 = TreeFactory.eINSTANCE.createNode(); myNode0.getChildren().add(myNode1);
    19. 19. Ecore Reflection EStructuralFeature * eStructuralFeatures EClass EObject eContents eClass getEStructuralFeature(String): eGet(EStructuralFeature): Object EStructuralFeature eSet(EStructuralFeature, Object) * * eClassifiers eContainer EPackage EFactory eFactory getEClassifier(String):EClassifier create(EClass):EObject
    20. 20. Dynamic EMF // load Ecore file URI resourceURI = URI.createPlatformResourceURI( quot;de.itemis.treemodel/model/treemodel.ecorequot;, true); Resource resource = new XMIResourceImpl(resourceURI); // extract Ecore model EPackage treePackage = (EPackage) resource.getContents().get(0); EFactory factory = treePackage.getEFactoryInstance(); EClass nodeClass = (EClass) treePackage.getEClassifier(quot;Nodequot;); EStructuralFeature childrenReference = nodeClass.getEStructuralFeature(quot;childrenquot;); // create instances using reflective API EObject myNode0 = factory.create(nodeClass); EObject myNode1 = factory.create(nodeClass); ((EList) myNode0.eGet(childrenReference)).add(myNode1);
    21. 21. References
    22. 22. References
    23. 23. References Resource Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element
    24. 24. References Resource Element Element Element Element Element Containment Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element
    25. 25. References Resource Element Element Element Element Element Containment Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Cross-References
    26. 26. References Resource Resource Containment Element Element Element Element Element Containment Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Cross-References
    27. 27. Big Models
    28. 28. Lots of elements... Big Models
    29. 29. Lots of elements... Big Models ...and lots of references
    30. 30. Divide & Conquer
    31. 31. Resource Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element
    32. 32. ResourceSet Resource Resource Resource Resource Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element Element
    33. 33. Lazy Loading
    34. 34. Proxy EObject • Not yet loaded EObject eIsProxy(): boolean • Instantiated on load for InternalEObject external reference eProxyURI(): String eSetProxyURI(String) • eProxyURI attribute set • Replaced on resolution EObjectImpl EcoreUtil resolve(EObject, ResourceSet) resolve(EObject, Resource) resolve(EObject, EObject)
    35. 35. Proxy Resolution ResourceSet Resource PROXY Element Element Element Element
    36. 36. Proxy Resolution ResourceSet Resource PROXY Element Element Element Element
    37. 37. Proxy Resolution ResourceSet Resource Resource PROXY Element Element Element Element
    38. 38. Proxy Resolution ResourceSet Resource Resource Element PROXY Element Element Element Element Element Element Element Element
    39. 39. Proxy Resolution ResourceSet Resource Resource Element PROXY Element Element Element Element Element Element Element Element
    40. 40. How about unloading? ResourceSet Resource Resource Resource (unloaded) PROXY Element Element PROXY Element Element Element Element PROXY PROXY Element Element PROXY Element
    41. 41. How about unloading? ResourceSet Resource Resource Resource (unloaded) PROXY Element Element PROXY Element Element Element Element PROXY PROXY Element Element PROXY Element
    42. 42. How about unloading? ResourceSet Resource Resource Resource (unloaded) PROXY Element PROXY Element PROXY Element PROXY Element Element Element PROXY PROXY Element Element PROXY PROXY PROXY Element PROXY
    43. 43. Lazy Loading • Proxy Resolution / Lazy Loading • Transparently when navigating references • Unload • Proxifies elements • Keeps elements connected by default
    44. 44. Enabling Proxies • For cross-references • Set EResource.isResolveProxies • For containment references • Additionally set GenModel.isContainmentProxies
    45. 45. eProxyURI • Resource URI + Fragment [scheme:][//authority][/path][#fragment] • Examples: http://www.itemis.de/files/model.ecore#/ file:/Users/koehnlein/test.xmi#/children.0 platform:/resource/myproject/m2.uml#12345126
    46. 46. Resource URIs • Relative or absolute URIConverter normalize(URI): URI createInputStream(URI): InputStream createOutputStream(URI): OutputStream • URIConverter exists(URI) delete(URI) getURIMap(): Map<URI, URI> • Resolves URIs • Access to resources ExtensibleURIConverter • Abstraction on * URIHandler canHandle(URI): boolean createInputStream(URI): InputStream I/O Access createOutputStream(URI): OutputStream exists(URI) delete(URI)
    47. 47. Fragment Strategies
    48. 48. Fragment Paths ::Resource uri=quot;http://www.itemis.de/model.treequot; • Example 0 ::Node • #/0/children.3 • Compact children • Fragile with respect .1 .2 .3 ::Node to reorderig ::Node ::Node
    49. 49. Fragment Paths With Keys • Define EAttribute as key ::Resource uri=quot;http://www.itemis.de/model.treequot; for EReference 0 • Example ::Node name=quot;rootquot; • name key of children children • .Sven .Peter .Ed #/0/children.Ed ::Node name=quot;Svenquot; • Assert no collisions ! ::Node name=quot;Peterquot; ::Node name=quot;Edquot;
    50. 50. EAttributes as ID ::Resource uri=quot;http://www.itemis.de/model.treequot; • Set ID flag on EAttribute 0 • Example ::Node index=0 • index defined as ID • #3 1 2 3 ::Node • Initialize without collisions index=1 ::Node index=2 ::Node index=3
    51. 51. Extrinsic IDs ::Resource uri=quot;http://www.itemis.de/model.treequot; eObjectToIDMap = {...} • Resource manages IDs ::Node index=0 • Example quot;ab3827d8quot; • #276fe78d • UUIDs in UML2 ::Node ::Node quot;37fe34c2quot; ::Node quot;87f33bd2quot; quot;276fe78dquot;
    52. 52. Tracking Inverse References
    53. 53. ECrossReferenceAdapter Adapter notifyChanged(Notification) isAdapterForType(Object): boolean • Works for loaded Resources within EContentAdapter a ResourceSet ECrossReferenceAdapter getInverseReferences(EObject): List<Setting> getNonNavigableReferences(EObject): List<Setting>
    54. 54. EMF Index • Indexes all resources in workspace • Query elements and cross-references
    55. 55. EMF Index • Indexes all resources in workspace • Query elements and cross-references Load Resources
    56. 56. EMF Transactions
    57. 57. EMF Transactions
    58. 58. EMF Transactions TransactionChangeRecorder beginRecording() ResourceSet endRecording() CommandStack TransactionalEditingDomain execute(Command) runExclusive(Runnable): Object undo() redo() RecordingCommand execute()
    59. 59. Global Singletons
    60. 60. Global Singletons
    61. 61. Global Singletons • Configured with Eclipse extensions
    62. 62. Global Singletons • Configured with Eclipse extensions • EPackage.Registry: Dynamic and static Ecore models
    63. 63. Global Singletons • Configured with Eclipse extensions • EPackage.Registry: Dynamic and static Ecore models • Resource.Factory.Registry Resource implementations
    64. 64. Global Singletons • Configured with Eclipse extensions • EPackage.Registry: Dynamic and static Ecore models • Resource.Factory.Registry Resource implementations • (Extensible)URIConverter
    65. 65. Global Singletons • Configured with Eclipse extensions • EPackage.Registry: Dynamic and static Ecore models • Resource.Factory.Registry Override Resource implementations in • (Extensible)URIConverter Resource Set
    66. 66. Questions?

    ×