Successfully reported this slideshow.
Your SlideShare is downloading. ×

OCL in EMF

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Upcoming SlideShare
Enrich Your Models With OCL
Enrich Your Models With OCL
Loading in …3
×

Check these out next

1 of 30 Ad
Advertisement

More Related Content

Advertisement
Advertisement

OCL in EMF

  1. 1. OCL in EMF<br />Ashwani Kr Sharma, SAP Labs India<br />
  2. 2. Agenda<br /><ul><li>Why OCL ?
  3. 3. What is OCL ?
  4. 4. When OCL ?
  5. 5. OCL in EMF ?</li></li></ul><li>Why OCL ?<br /><ul><li> There are different categories of jobs,
  6. 6. Each category requires different skills.
  7. 7. Each plumber may have a different </li></ul>repertoire of skills<br />Business Rule:<br />Each Job's assignee's skills include all the Job's category's requirements.<br />….<br />
  8. 8. UML Solutions<br /><ul><li>UML 1.x Use your favorite programming language
  9. 9. Ada/C/...
  10. 10. Magically inserted by proprietary code generator
  11. 11. UML 2.x Use a neutral specification language
  12. 12. The Object Constraint Language
  13. 13. State machine guards/actions
  14. 14. Class invariants
  15. 15. Operation bodies, pre/post conditions
  16. 16. Property initial/derived values</li></li></ul><li>Why OCL ?<br />Business Rule:<br />Each Job's assignee's skills include all the Job's category's requirements.<br />OCL-<br />Job ::assignee.skills-->includes (category.requirements)<br />
  17. 17. Why OCL ?<br /><ul><li>In object-oriented modeling, a graphical model, like a class model, is not enough for a precise and unambiguous specification
  18. 18. The business rules are not captured.
  19. 19. Natural languages are ambiguous.
  20. 20. Formal languages is are useable to persons with a string mathematical background, but difficult for the average business or system modeler to use</li></li></ul><li>What is OCL ?<br /><ul><li>Object Constraint Language (OCL), is a formal language to express side effect-free constraints. Users of the Unified Modeling Language and other languages can use OCL to specify constraints and other expressions attached to their models.
  21. 21. OCL is an add-on feature of UML, used to describe constraints, rules, specifications.</li></li></ul><li>What is OCL ?<br /><ul><li>Natural/Formal Language compromise
  22. 22. natural language error prone
  23. 23. formal language unapproachable to many
  24. 24. Specification (not Programming) Language
  25. 25. declarative, modeling language
  26. 26. side effect free, no model changes, atomic execution
  27. 27. strongly typed, using UML generalization</li></li></ul><li>OCL is typed !<br />OCL is a typed language, so each OCL expression has a type. In a correct OCL expression all types used must be type conformant<br />
  28. 28. OCL is a pure expression language<br /> OCL expression is guaranteed to be without side effect; it cannot change anything in the model<br />Whenever an OCL expression is evaluated, it simply delivers a value.<br />
  29. 29. Mathematical operators<br />Infix: +, -, *, /<br /> and, or, xor, implies =, <>, <, >, <=, >= , =, <><br />Prefix: not, -<br />4.0 * -5<br /> 'a' + 'b'<br />Operators: mod, div, max, min, ...<br />4.max(5)<br />
  30. 30. OCL Expressions<br /><ul><li>IfExpressions</li></ul>if gender = Gender::MALE then 'he' else 'she'endif<br /><ul><li>Let Expressions</li></ul>let jack : Person = child('Jack'), jill : Person = child('Jill') in jack <> null and jill <> null<br />
  31. 31. Object Navigation<br />Properties<br /><ul><li>self.name or just name (this.getName() or getName())</li></ul>Operations<br /><ul><li>self.child('John') or just child('John') (cf. this.child('John') or child('John'))</li></li></ul><li>OCL: So far !<br />Business rules and requirements can be stated unambiguously<br />OCL provides a programming-language-neutral way of stating requirements<br />OCL removes inconsistencies and holes in the less formal requirements documents, forcing important issues to be clarified at an early stage.<br />OCL is formal language that remains easy to read and write<br />
  32. 32. OCL in EMF<br />EMF is based on eMOF, a variant of MOF standard from OMG<br />OCL specification is part of UML specification and is implemented for EMF we well<br />OCL statements specified as part of EMF Model or invoked directly from programming language e.g. java<br />Contributed as part of Eclipse MDTCL<br />MDTCL provides support to UML and EMF based models.<br />
  33. 33. Eclipse MDTCL<br />Original code contribution by IBM<br />Java callable API<br />Parse/evaluate OCL 1.x against Ecore meta-models<br />Ecore or UML meta-models<br />Example Interactive Console<br />For OCL 2.0 as far possible<br />Towards OCL 2.2<br />Example Xtext editors (Ecore only)<br />OMG OCL 1.x<br />EMFT/OCL 1.0<br />OMG OCL 2.0<br />MDT/OCL 1.2<br />OMG OCL 2.2<br />MDT/OCL 3.0<br />
  34. 34. Validation History<br />Use of OCL to define model validation<br />EMF Validation Framework, Embed OCL in XML CDATA<br />EMF, OCL EAnnotations<br />Embed OCL in Eannotation, Genmodel to integrate<br />Delegates, Embed OCL in EAnnotation<br />EObject.eInvoke() for dynamic invocation<br />OCLinEcore editor for semi-validated editing <br />OMG OCL 1.x<br />EMFT/OCL 1.0<br />OMG OCL 2.0<br />MDT/OCL 1.2<br />OMG OCL 2.2<br />MDT/OCL 3.0<br />
  35. 35. OCL IDE: OCLinEcore Editor<br /><ul><li>Open with -> OCLinEcore
  36. 36. Save As *.ecore
  37. 37. Loses formatting and comments
  38. 38. Save As *.oclinecore
  39. 39. Text file preserves comments
  40. 40. Useful for plain Ecore too:
  41. 41. Printable/reviewable text
  42. 42. Searchable/replaceable text</li></li></ul><li>OCL IDE: OCLinEcore Editor<br /><ul><li>Maintains EAnnotations automatically Provides OCL syntax checking In future will provide OCL semantic checking</li></li></ul><li>OCL IDE: Interactive OCL console<br />Used to run OCL queries and OCL expresssions<br />Window->Show View->Other... Console. <br />Console: New: Interactive OCL<br />
  43. 43. OCL Collections<br />Typed Collections partially reify multiplicities<br />Collections are different to objects<br />Navigation from a Collection uses -><br />[Navigation from an Object (OclAny) uses .]<br />Collections have type parameters<br />Collections have useful operations<br />Collections have very useful iterations<br />© SAP 2007 / Page 21<br />
  44. 44. OCL Collections<br /><ul><li>a : Set(String) b : String c : Set(String)
  45. 45. a = c a <> c
  46. 46. a->size() a->count(b)
  47. 47. a->excludes(b) a->excludesAll(c)
  48. 48. a->includes(b) a->includesAll(c)
  49. 49. a->isEmpty() a->notEmpty()
  50. 50. a->sum() -- contents are of type supporting +</li></li></ul><li>OCL Collections<br /><ul><li>OCL supports a wide range of Collection operations that vary by Collection type.
  51. 51. first(), last(), at(i : Integer), etc. for {ordered} collections
  52. 52. union(), -, asSet(), including(), symmetricDifference(collection : Collection) are a sample</li></li></ul><li>OCL Collections<br />OCL supports an iterate() operation for Collections. On top of that idea, OCL provides a set of Collection operations that accept expression.<br />Examples:<br />any(expression) exists(expression)<br />collect(expression) one(expression)<br />select(expression) reject(expression)<br />
  53. 53. OCL Collections::select<br /><ul><li>Children</li></ul>self.children<br /><ul><li> Sons</li></ul>self.children->select(gender = Gender::MALE) self.children->select(child | child.gender = Gender::MALE) self.children->select(child : Person | child.gender = Gender::MALE)<br /><ul><li>select(iterator : type | body)</li></ul>filters to select elements for which the body is true<br /><ul><li>reject(iterator : type | body)</li></ul>filters to reject elements for which the body is true<br />
  54. 54. OCL Collections::iterator<br /><ul><li>Children</li></ul>self.children<br /><ul><li>Grandchildren</li></ul>self.children->collect(children) self.children->collect(child | child.children) self.children->collect(child : Person | child.children)<br /><ul><li>collect(iterator : type | body)</li></ul>creates a new collection comprising all the bodies<br /><ul><li>any, exists, forAll, isUnique, iterate, one,</li></li></ul><li>More Queries<br /><ul><li>parents.parents->asSet()->sortedBy(name)</li></ul>->asSet() converts to Set(Person), removes duplicates<br />->sortedBy(name) alphabeticizes<br />
  55. 55. Other OCL Capabilities<br />Other iterators, operations<br />Tuples<br />post statement<br />Association Classes/Qualifiers<br />@pre values<br />Messages<br />States<br />
  56. 56. When OCL ?<br />None<br /><ul><li>Very simple modeling
  57. 57. Java augmented modeling</li></ul>A little<br /><ul><li>OCL (and Java) augmented modeling</li></ul>A lot<br /><ul><li>OCL as a powerful formal specification language
  58. 58. OMG's UML, OCL, QVT, ... specifications
  59. 59. OCL as the foundation of a transformation language
  60. 60. MOFM2T (Acceleo), QVT
  61. 61. OCL as a portable implementation language</li></li></ul><li>OCL Downloads<br /><ul><li>Install MDT/OCL 3.0.1 Examples and Editors
  62. 62. For links to slides and to zip file comprising, model,edit,editor,diagram projects: use link: http://www.eclipsecon.org/summiteurope2010/sessions/?page=sessions&id=1710
  63. 63. Import ... Existing Projects from Archive
  64. 64. ESEExampleTree/model/People1.ecore
  65. 65. Run nested Eclipse, Import ESEExampleTree
  66. 66. ESEExampleTree/model/default.people_diagram</li>

Editor's Notes

  • Not associated with NWIts an 8.0 topic

×