good for dj over java extending traversals for b..* returning a single object instead of a...

24

Upload: sara-parker

Post on 18-Jan-2018

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Good for DJ over Java Extending traversals for b..* returning a single object instead of a collection (Find) modifying the collection (Add, Delete)
Page 2: Good for DJ over Java Extending traversals for b..* returning a single object instead of a collection (Find) modifying the collection (Add, Delete)

Good for DJ over Java

• Extending traversals for b..* – returning a single object instead of a collection

(Find)– modifying the collection (Add, Delete)

Page 3: Good for DJ over Java Extending traversals for b..* returning a single object instead of a collection (Find) modifying the collection (Add, Delete)
Page 4: Good for DJ over Java Extending traversals for b..* returning a single object instead of a collection (Find) modifying the collection (Add, Delete)

UML Class Diagram

Library Book

0..*

books

User

users

0..*

Copycopies

0..*

bookcheckOutItems

0..*

Boolean

avail

bN

BookName

UserId

uId

Page 5: Good for DJ over Java Extending traversals for b..* returning a single object instead of a collection (Find) modifying the collection (Add, Delete)

UML Class Diagram

Library Book

0..*

books

User

users

0..*

Copycopies

0..*book

checkOutItems0..*

Boolean

avail

bN

BookName

UserId

uIdCheckOutItem

copy

Page 6: Good for DJ over Java Extending traversals for b..* returning a single object instead of a collection (Find) modifying the collection (Add, Delete)

How can addition be expressed with ACs

• Required: participant graph• Provided: modified participant graph: has

all the paths in original but may have more

Page 7: Good for DJ over Java Extending traversals for b..* returning a single object instead of a collection (Find) modifying the collection (Add, Delete)

Interaction schema CheckOut { Library( Find-> Book Find(avail==true)-> c:Copy; Find-> u:User;) addCopy { u:User Add-> Copy; c:Copy Set(avail,false)-> Boolean }}//participants: Library, Book, Copy, User

Checkout a book for a user

Page 8: Good for DJ over Java Extending traversals for b..* returning a single object instead of a collection (Find) modifying the collection (Add, Delete)

CheckOut (Library lib,BookName bN, UserId uId){ lib:Library( Find(this.bN==bN))->-> Book Book Find(avail==true)->Find(avail==true)->c:Copy; Find(this.uId==uId)-> u:User;) addCopy { u:User Add(c)-> Copy; c:Copy Set(avail,false)-> Boolean }}

Compiler asks for information or determines it by rules

Page 9: Good for DJ over Java Extending traversals for b..* returning a single object instead of a collection (Find) modifying the collection (Add, Delete)

class Library { Copy CheckOut (Library lib,BookName bN, UserId uId){ Book b = lib.Find(“Book”,“bN”,bN); Copy c = b.Find (“Copy”,“avail”,true);Copy c = b.Find (“Copy”,“avail”,true); User u = lib.FindUser u = lib.Find(“User”,“uId”,uId)(“User”,“uId”,uId);; u.Add(“Copy”,c); c.Set(“avail”,false); return c; }}

Compiler asks for information or determines it by rules

Page 10: Good for DJ over Java Extending traversals for b..* returning a single object instead of a collection (Find) modifying the collection (Add, Delete)

class Library { Copy CheckOut (Library lib,BookName bN, UserId uId){ Book b = cg.Find(lib,“to Book”,“bN”,bN); Copy c = cg.Find (b,“to Copy”,“avail”,true);Copy c = cg.Find (b,“to Copy”,“avail”,true); User u = cg.FindUser u = cg.Find(lib,“to User”,“uId”,uId)(lib,“to User”,“uId”,uId);; cg.Add(u,“to Copy”,c); cg.Set(c,“to Boolean”,”avail”,false); return c; }}

For DJ

Page 11: Good for DJ over Java Extending traversals for b..* returning a single object instead of a collection (Find) modifying the collection (Add, Delete)

Book b = cg.Find(lib,“to Book”,“bN”,bN); Copy c = cg.Find (b,“to Copy”,“avail”,true);Copy c = cg.Find (b,“to Copy”,“avail”,true); User u = cg.FindUser u = cg.Find(lib,“to User”,“uId”,uId)(lib,“to User”,“uId”,uId);; cg.Add(u,“to Copy”,c); Copy cg.Delete(u,“to Copy”, “avail”,true“avail”,true); cg.Set(c,“to Boolean”,”avail”,false); Boolean cg.Get(c,“to Boolean”,”avail”); int cg.Traverse(company,”to Salary”,v);

For DJ/paper

Page 12: Good for DJ over Java Extending traversals for b..* returning a single object instead of a collection (Find) modifying the collection (Add, Delete)

0..*, 1..*: Book b = cg.Find(lib,“to Book”,“bN”,bN); cg.Add(u,“to Copy”,c); cg.Delete(u,“to Copy”, “avail”,true“avail”,true); cg.Traverse(company,”to Salary”,v); cg.Gather(company,”to Salary”);0..1, 1..1 cg.Set(c,“to Boolean”,”avail”,false); cg.Get(c,“to Boolean”,”avail”);

For DJ/paper/constraints

Page 13: Good for DJ over Java Extending traversals for b..* returning a single object instead of a collection (Find) modifying the collection (Add, Delete)

0..*, 1..*:Book cg.Find(lib,“to Book”,“bN”,bN); Find in library lib a book with data member “bN” = bN.void cg.Add(u,“to Copy”,c); Add to user u a copy cCopy cg.Delete(u,“to Copy”, “avail”,true“avail”,true); Delete from user u a copy with avail == true

For DJ/paper/constraints

Page 14: Good for DJ over Java Extending traversals for b..* returning a single object instead of a collection (Find) modifying the collection (Add, Delete)

0..*, 1..*:int cg.Traverse(company,”to Salary”,v); traverse from company to Salary and perform visiting actions of v.Vector cg.Gather(company,”to Salary”); collect all Salary-objects reachable from company 0..1, 1..1Boolean cg.Set(c,“to Boolean”,”avail”,false);Boolean cg.Get(c,“to Boolean”,”avail”);

For DJ/paper/constraints

Page 15: Good for DJ over Java Extending traversals for b..* returning a single object instead of a collection (Find) modifying the collection (Add, Delete)

CheckOut { Find(this.bN==bN))->-> Book Book Find(avail==true)->Find(avail==true)->Copy; Find(this.uId==uId)-> User; addCopy { u:User Add(c)-> Copy; }}

Aspect Language: don’t use

Page 16: Good for DJ over Java Extending traversals for b..* returning a single object instead of a collection (Find) modifying the collection (Add, Delete)

CheckOut (lib,bN,uId){ lib:Library( Find(this.bN==bN))-> -> Book Book Find(avail==true)->Find(avail==true)-> c:Copy; Find(this.uId==uId)-> u:User;) addCopy { only one choice u:User Add(c)-> Copy; c:Copy Set(avail,false)-> Boolean }}

Compiler asks for information or determines it by rules

Definition: an interaction schema is a sequenceof navigation statements of the formo1:T1 -Action1-> o2:T2 -Action2-> o3:T3 ...

Page 17: Good for DJ over Java Extending traversals for b..* returning a single object instead of a collection (Find) modifying the collection (Add, Delete)

Advantages

• High-level description of behavior in terms of an ideal UML class diagram

• Behavior can be adapted to many concrete class diagrams – Some details of action parameters may be filled

in under compiler control

Page 18: Good for DJ over Java Extending traversals for b..* returning a single object instead of a collection (Find) modifying the collection (Add, Delete)

Generalized Traversals

Library Find-> BookTraversal from Library to Book must have upper cardinality > 1, e.g., 0..*, 1..*.

Compiler will ask for properties to select a book. Rule: if an object of the class of a data member of Book is available, it will choose that one as default

Page 19: Good for DJ over Java Extending traversals for b..* returning a single object instead of a collection (Find) modifying the collection (Add, Delete)

Generalized traversals

lib:Library Find-> b:BookDJ: Book b = cg.Find(lib, new Strategy(“from Library to Book”), “property bN”,bookName);Book b = cg.Find(lib, new Strategy(“from Library to Book”), “property isbn”,isbnNumber);

Page 20: Good for DJ over Java Extending traversals for b..* returning a single object instead of a collection (Find) modifying the collection (Add, Delete)

Connection actions/class graph

lib:Library Find-> b:Booku:User Add(c)-> Copylib:Library Delete-> b:Book0..*, 1..*

Page 21: Good for DJ over Java Extending traversals for b..* returning a single object instead of a collection (Find) modifying the collection (Add, Delete)

Connection actions/class graph

c:Copy Set(avail,false)-> Booleanc:Copy Get(avail)-> b:Boolean== c:Copy Fetch(avail)-> b:Boolean1..1, 0..1--- traverse a little differentc:Company Traverse(v1)-> r:Resulttraverses to all classes mentioned in v1and performs visiting action. There must be a path to each such class?

Page 22: Good for DJ over Java Extending traversals for b..* returning a single object instead of a collection (Find) modifying the collection (Add, Delete)

Generalized traversals

lib:Library Find-> b:BookDJ: Book b = cg.Find(lib, new Strategy(“from Library to Book”), “property author”,authorName);Find is like a generalized fetch

Page 23: Good for DJ over Java Extending traversals for b..* returning a single object instead of a collection (Find) modifying the collection (Add, Delete)

Generalized traversals

u:User Add(c)-> Copy;cg.Add(u,new Strategy (“from User to Copy”), c);Expects a unique path from User to Copythat is “insertable” and it adds c at end. Insertable means ...

Page 24: Good for DJ over Java Extending traversals for b..* returning a single object instead of a collection (Find) modifying the collection (Add, Delete)

New Operations for DJ

• Find, Delete, Add• Set, Get=Fetch• Traverse, Gatherc:Copy Set(avail,false)-> Booleancg.Set(c, new Strategy( “from Copy through -> *,avail,* to Boolean”), false);