Bit and Pieces Again Presentation for CAMPaM workshop by Anneke Kleppe
Contents � OCL � Using OCL in UML � Semantics: Denotational meta-modeling � Grasland: Defining languages � Concrete textual syntax � Future work � Sideline: MDA/MDE 4/27/2006 1
Object Constraint Language Version 2.0 Part 1
OCL � What is OCL? � Query language on UML models based on set theory and first order logic context Program::findType(name: String) : Type body : types-> any ( t : Type | t.name = name ) 4/27/2006 3
2001-2003: OCL version 2 � OMG only wanted definition of abstract syntax � We gave them: � Abstract syntax � Concrete syntax, plus mapping to abstract � Semantics � Formal by Mark Richters, Hamburg Univ. � UML-based by AK. 4/27/2006 4
OCL 2.0 Abstract syntax � Defined using meta-model � Explicitly defines the associations with meta-classes in the UML meta-model 4/27/2006 5
Types Package elementType Classifier OclModelElementType DataType VoidType OclMessageType TupleType Primitive CollectionType OrderedSetType SetType SequenceType BagType 4/27/2006 6
Expressions PACKAGE ModelElement body type OclExpression Classifier type PropertyCallExp LiteralExp OclMessageExp IfExp VariableExp referredVariable ModelPropertyCallExp LoopExp VariableDeclaration iterators IteratorExp IterateExp 4/27/2006 7
Direct Integration With UML ModelPropertyCallExp NavigationCallExp AttributeCallExp Attribute AssociationEndCallExp AssociationEnd AssociationClassCallExp AssociationClass OclExpression arguments OperationCallExp Operation 4/27/2006 8
Abstract vs. Concrete Syntax � This is an example of the concrete syntax: context getYoungCustomers() : Set(Customer) body: customers->select( c | c.age < 18 ) � Formal mapping from concrete to abstract syntax using attribute grammar mapping Concrete Abstract Syntax Syntax 4/27/2006 9
Abstract vs. Concrete Syntax Alternative Concrete Syntax 1 mappings mapping Standard OCL Alternative Concrete Abstract Concrete Syntax Syntax Syntax 2 Alternative Concrete Syntax 3 4/27/2006 10
Alternative Concrete Syntax � Business Modeling Syntax: context getYoungCustomers() : Set(Customer) body: customers->select( c | c.age < 18 ) body: SELECT c : Customer FROM customers WHERE c.age < 18 � See: � The Object Constraint Language, Getting Your Models Ready for MDA � Octopus: an Eclipse based IDE for OCL 4/27/2006 11
OCL Text Files � Concrete syntax for OCL files formalized package OclBoek::RandL context LoyaltyAccount::points init: 0 context LoyaltyProgram::getServices(): Set(Service) body: partners.deliveredServices->asSet() context CustomerCard::myLevel : ServiceLevel derive: Membership.currentLevel endpackage 4/27/2006 12
Using OCL in UML Part 2
Where to use OCL in UML � Anywhere UML talks about Expression � Specific examples: � Pre- and post-conditions � Invariants � Initial values of attributes and associations � Derivation rules � Bodies of query operations � State invariants � Definition of additional attributes and operations � Guards in state machines � Choice or guard expressions in interaction diagrams � Choice expressions in activity diagrams � Etc. etc. 4/27/2006 14
Pre- and Postconditions � Used to specify operations context Order::place() pre : checkOk() and status = OrderStatus::InPreparation post: status = OrderStatus::Placed «enumeration» Order OrderStatus + date: String + InPreparation: +/ extra: Integer + Paid: +/ price: Integer + number: Integer + Placed: + status: OrderStatus + Delivered: + checkOk() : Boolean + place() 4/27/2006 15
Invariants � Used to specify invariants context Order inv: price > 0 inv: disks->isUnique(label) Dvd Order + duration: Integer + date: String +order + label: String 1..* +/ extra: Integer + price: Integer +/ price: Integer +disks 1 + maxDuration: Integer + number: Integer + status: OrderStatus + checkOk() : Boolean context Dvd + place() inv : duration <= Dvd::maxDuration 4/27/2006 16
Initial values and derivation rules � Used to specify initial values context DVD::label Dvd Order init: ‘default title’ + duration: Integer + date: String +order + label: String 1..* +/ extra: Integer + price: Integer +/ price: Integer +disks 1 + maxDuration: Integer + number: Integer + status: OrderStatus � Used to specify derived values + checkOk() : Boolean + place() context Order::price derive: disks.price->sum() + extra context Order::extra derive: if clips.price->sum() < 15 then 2 else 0 endif 4/27/2006 17
Body values � Used to specify the full body of operations context Order::checkOk() : Boolean Artist + name: String body: self.customer.creditcard.expiration. + solo: Boolean +artist 0..* isAfter(Date::today()) +clips 0..* Clip context Order::getArtists() : Set(Artist) + genre: Genre + duration: Integer + price: Integer body: disks.clips.artist->asSet() + title: String + play(Integer) : Boolean Order +clips 1..* 0..* «datatype» + date: String Date +customer 1 +orders +dvd 0..* +/ extra: Integer +customer + day: Integer +/ price: Integer +creditcard 1 Customer Dvd + number: Integer + month: Month 1 +order 1..* + status: OrderStatus + year: Integer + address: String Creditcard + duration: Integer + age: Integer +disks 1 + label: String + checkOk() : Boolean + isBefore(Date) : Boolean + expiration: Date + name: String + price: Integer + place() + isAfter(Date) : Boolean + name: String + maxDuration: Integer + getArtists() : set(Artist) + today() : Date + number: Integer + allDelivered() : Boolean 4/27/2006 18
State charts «enumeration» OrderStatus «Invariant» + InPreparation: {status = OrderStatus::InPreparation} + Paid: + Placed: + Delivered: preliminary Order Initial + date: String place() [self.checkOk()] +/ extra: Integer +/ price: Integer + number: Integer final + status: OrderStatus + checkOk() : Boolean «Invariant» + place() + getArtists() : set(Artist) {status <> OrderStatus::InPreparation} 4/27/2006 19
20 clip :Clip Sequence Diagrams play [clip.duration > 0] Actor1 opt play example 4/27/2006
Defining additional attributes context Order::price Order derive: disks.price->sum() + extra + date: String +/ extra: Integer context Order::extra +/ price: Integer + number: Integer derive: if disks.price->sum() < 15 then 2 + status: OrderStatus else 0 + checkOk() : Boolean endif + place() context Order def: basePrice : Integer = disks.price->sum() context Order::price derive: basePrice + extra context Order::extra derive: if basePrice < 15 then 2 else 0 endif 4/27/2006 21
22 refuse and send message to Customer [not self.checkOk()] Activity Models place order initialize [self.checkOk()] 4/27/2006
Defining semantics Part 3
UML-based semantics � Denotational metamodeling (pUML group) � Build UML model of semantic domain and map the abstract syntax to it using UML associations � Report: Unification of static and dynamic semantics of UML (http://www.klasse.nl/research/uml- semantics.html) 4/27/2006 24
Semantics for OCL OCL Abtract Syntax OCL Domain Types Values Expressions Evaluations OCL AS Domain Mapping Type-Value Expression-Evaluation 4/27/2006 25
Example 1 +myValue +myType Type Value +semantic mapping (from abstract syntax) (from semantic domain) 0..n 0..n 1 0..1 0..1 Class Object +semantic mapping (from abstract syntax) (from semantic domain) 0..n 0..n 0..n 0..n +attributes 0..n 0..n +attrSlots Attribute Slot +semantic mapping (from abstract syntax) (from semantic domain) 0..n 0..n 4/27/2006 26
Example 2 OperDecl OperExecution (from abstract syntax) (from semantic domain) +calls OperCall (from abstract syntax) 4/27/2006 27
Weakness � How to model the dynamics of the semantic domain (SD)? � Answer J.H. Hausmann: Dynamic Denotational Metamodeling � SD model contains operations which are defined by graph transformation rules � Needs explicit calling of these operations � Our answer: Operational Denotational Metamodeling ??? � TAAL project 4/27/2006 28
TAAL project � Abstract syntax is captured in program graph � Semantic domain is captured in execution graph � Execution graph = value graph + frame graph � Value graph: objects and their links � Frame graph: info on running processes � Graph transformation rules specify changes in execution graph � Based on occurences of nodes and edges in both program and execution graph 4/27/2006 29
Example: abstract syntax Expression +type CreateExp ObjectType 1 1 0..1 0..1 +superType 4/27/2006 30
Example: semantic domain +caller +self 0..1 0..1 0..1 0..1 Frame Value +auxiliaries (from framegraph) (from valuegraph) 0..n 0..n +self 0..1 0..1 ObjectVal ConstrFrame OperFrame (from v aluegraph) (from framegraph) (from framegraph) 4/27/2006 31
Example rule � Black: required � Green: created � Blue: deleted 4/27/2006 32
Recommend
More recommend