EMF - Beyond The Basics
Upcoming SlideShare
Loading in...5
×
 

EMF - Beyond The Basics

on

  • 8,231 views

Talk at the JAX 2009 in Mainz (Germany)

Talk at the JAX 2009 in Mainz (Germany)

Statistics

Views

Total Views
8,231
Views on SlideShare
8,176
Embed Views
55

Actions

Likes
12
Downloads
324
Comments
0

3 Embeds 55

http://www.slideshare.net 51
http://webcache.googleusercontent.com 2
http://www.linkedin.com 2

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />

EMF - Beyond The Basics EMF - Beyond The Basics Presentation Transcript

  • Dr. Jan Köhnlein, itemis AG EMF – Beyond the Basics
  • Eclipse Modeling Framework
  • Eclipse Modeling Framework • Create Ecore models
  • Eclipse Modeling Framework • Create Ecore models • from Java, XSD, UML, MOF
  • Eclipse Modeling Framework • Create Ecore models • from Java, XSD, UML, MOF • or from scratch
  • Eclipse Modeling Framework • Create Ecore models • from Java, XSD, UML, MOF • or from scratch • Generate Java-Code from Ecore
  • 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
  • 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
  • Ecore Instances
  • Ecore Instances • EObject
  • Ecore Instances • EObject • Instance of an EClass
  • Ecore Instances • EObject • Instance of an EClass • Values for EAttributes
  • Ecore Instances • EObject • Instance of an EClass • Values for EAttributes • References for EReferences
  • Ecore Instances • EObject • Instance of an EClass • Values for EAttributes • References for EReferences • Ecore is self-describing
  • Ecore Instances • EObject • Instance of an EClass • Values for EAttributes • References for EReferences • Ecore is self-describing • EClass, EPackage etc. extend EObject
  • 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
  • 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
  • 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);
  • 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
  • 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);
  • References
  • References
  • 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
  • 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
  • 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
  • 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
  • Big Models
  • Lots of elements... Big Models
  • Lots of elements... Big Models ...and lots of references
  • Divide & Conquer
  • 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
  • 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
  • Lazy Loading
  • 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)
  • Proxy Resolution ResourceSet Resource PROXY Element Element Element Element
  • Proxy Resolution ResourceSet Resource PROXY Element Element Element Element
  • Proxy Resolution ResourceSet Resource Resource PROXY Element Element Element Element
  • Proxy Resolution ResourceSet Resource Resource Element PROXY Element Element Element Element Element Element Element Element
  • Proxy Resolution ResourceSet Resource Resource Element PROXY Element Element Element Element Element Element Element Element
  • How about unloading? ResourceSet Resource Resource Resource (unloaded) PROXY Element Element PROXY Element Element Element Element PROXY PROXY Element Element PROXY Element
  • How about unloading? ResourceSet Resource Resource Resource (unloaded) PROXY Element Element PROXY Element Element Element Element PROXY PROXY Element Element PROXY Element
  • 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
  • Lazy Loading • Proxy Resolution / Lazy Loading • Transparently when navigating references • Unload • Proxifies elements • Keeps elements connected by default
  • Enabling Proxies • For cross-references • Set EResource.isResolveProxies • For containment references • Additionally set GenModel.isContainmentProxies
  • 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
  • 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)
  • Fragment Strategies
  • 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
  • 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;
  • 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
  • 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;
  • Tracking Inverse References
  • ECrossReferenceAdapter Adapter notifyChanged(Notification) isAdapterForType(Object): boolean • Works for loaded Resources within EContentAdapter a ResourceSet ECrossReferenceAdapter getInverseReferences(EObject): List<Setting> getNonNavigableReferences(EObject): List<Setting>
  • EMF Index • Indexes all resources in workspace • Query elements and cross-references
  • EMF Index • Indexes all resources in workspace • Query elements and cross-references Load Resources
  • EMF Transactions
  • EMF Transactions
  • EMF Transactions TransactionChangeRecorder beginRecording() ResourceSet endRecording() CommandStack TransactionalEditingDomain execute(Command) runExclusive(Runnable): Object undo() redo() RecordingCommand execute()
  • Global Singletons
  • Global Singletons
  • Global Singletons • Configured with Eclipse extensions
  • Global Singletons • Configured with Eclipse extensions • EPackage.Registry: Dynamic and static Ecore models
  • Global Singletons • Configured with Eclipse extensions • EPackage.Registry: Dynamic and static Ecore models • Resource.Factory.Registry Resource implementations
  • Global Singletons • Configured with Eclipse extensions • EPackage.Registry: Dynamic and static Ecore models • Resource.Factory.Registry Resource implementations • (Extensible)URIConverter
  • Global Singletons • Configured with Eclipse extensions • EPackage.Registry: Dynamic and static Ecore models • Resource.Factory.Registry Override Resource implementations in • (Extensible)URIConverter Resource Set
  • Questions?