Presentation is loading. Please wait.

Presentation is loading. Please wait.

Explaining DJ with AOP. DJ ClassGraph.traverse (this,whereToGo,whatToDo) Intertype declaration Advice.

Similar presentations


Presentation on theme: "Explaining DJ with AOP. DJ ClassGraph.traverse (this,whereToGo,whatToDo) Intertype declaration Advice."— Presentation transcript:

1 Explaining DJ with AOP

2 DJ ClassGraph.traverse (this,whereToGo,whatToDo) Intertype declaration Advice

3 range of AOP languages means of … join points JPMjoin pointsidentifyingspecifying semantics at AspectJ dynamic JPM points in execution call, get, set… signatures w/ wildcards & other properties of JPs advice static JPMclass memberssignaturesadd members DemeterJ, Demeter/C++ dynamic JPM static JPM 1 static JPM 2 static JPM 3 when traversal reaches object or edge class members visitor method signatures traversal spec. s class graph g class names class graph visitor method bodies s + g (result = traversal implementation) add members class graph with tokens=grammar (result = parsing and printing implementation)

4 range of AOP languages means of … join points add memberssignaturesclass members static JPM DJ dynamic JPM 1 dynamic JPM 2 dynamic JPM 3 AspectJ dynamic JPM JPM when traversal reaches object or edge (method traverse) when traversal reaches object (methods fetch, gather, asList) nodes in object graphs points in execution call, get, set… join points visitor method signatures source and targets of traversal trav. spec. s class graph g object graph o signatures w/ wildcards & other properties of JPs identifying visitor method bodies method name (fetch, gather, asList) s+g+o(result = traversal implementation = edges to traverse at nodes in object graph) advice specifying semantics at

5 A Simple Basket Example Basket FruitPencil p f, f2 Orange Weight Color wc String s int i

6 BasketVisitor class BasketVisitor { int total; public void start() { total = 0; } public int returnValue() { return total; } void before(Weight w) { total += w.get_i(); }

7 Basket Traversal aspect BasketTraversal { ClassGraph default; ClassGraph myClassGraph = new ClassGraph(default, "from Basket to *"); Visitor BasketVisitor; declare traversal t1(myClassGraph,BasketVisitor) : "from Basket to Weight"; declare traversal t2(myClassGraph,BasketVisitor) : "from Basket via Orange to Weight"; }

8 Basket Main class BasketMain { static public void main(String args[]) throws Exception { Basket b = new Basket(new Orange(new Color("orange"), new Weight(5)), new Fruit( new Weight(10)), new Pencil() ); BasketVisitor bv = new BasketVisitor(); b.t1(bv); int totalWeight = bv.returnValue(); System.out.println("Total weight of basket = " + totalWeight); b.t2(bv); totalWeight = bv.returnValue(); System.out.println("Total weight2 of basket = " + totalWeight); }

9 Generated Code for Visitor static BasketVisitor t1_visitor; public void Basket.t1(BasketVisitor v) { t1_visitor=v; t1_visitor.start(); t1(); } before(Weight host) : call(public void t1*()) && target(host) { t1_visitor.before(host); } void Basket.t1() { t1_copy0(); }

10 Basket Class Graph Basket FruitPencil p f, f2 Orange Weight Color wc String s int i

11 Generated Code for Traversal // traversal t1 : {source: Basket -> target: Weight} with { } public void Basket.t1_copy0(){ if (f != null) t1_copy0_crossing_f(); if (f2 != null) t1_copy0_crossing_f2(); } public void Basket.t1_copy0_crossing_f() { f.t1_copy0();} public void Basket.t1_copy0_crossing_f2() { f2.t1_copy0();} public void Fruit.t1_copy0(){ if (w != null) t1_copy0_crossing_w(); } public void Fruit.t1_copy0_crossing_w() { w.t1_copy0();} public void Weight.t1_copy0(){ } public void Orange.t1_copy0(){ super.t1_copy0(); } pointcut pointcut_t1() : call(public void t1*()); before () : pointcut_t1 () { System.out.println(thisJoinPoint); }

12 Explanation for Caching Hw 3 How we would like to write the code in DJ. Only in a test version of DJ. NOT currently available.

13 class ContainerChecker extends Visitor { Object combine(Object[] values) { int total=0; for(int i=0; i<values.length; i++) { if(values[i]!=null) total+= ((Integer)values[i]).intValue(); } return new Integer(total); } Object around(Weight w,Subtraversal st) { return w.get_value(); }

14 Object around(Container c,Subtraversal st) { Integer total = (Integer)st.apply("contents"); if (total.intValue() > c.get_capacity(). get_value().intValue()) System.out.println("An Overloaded Container"); return total; }


Download ppt "Explaining DJ with AOP. DJ ClassGraph.traverse (this,whereToGo,whatToDo) Intertype declaration Advice."

Similar presentations


Ads by Google