1 / 14

Explaining DJ with AOP

Explaining DJ with AOP. DJ. ClassGraph.traverse (this,whereToGo,whatToDo). Advice. Intertype declaration. range of AOP languages. means of … join points. JPM. join points. identifying. specifying semantics at. AspectJ dynamic JPM. points in execution call, get, set….

Download Presentation

Explaining DJ with AOP

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Explaining DJ with AOP

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

  3. range of AOP languages

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

  5. A Simple Basket Example Basket f, f2 p Pencil Fruit Orange w c Weight Color int i s String

  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. DAJ has now a better solution !! Only one class graph. 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 f, f2 p Pencil Fruit Orange w c Weight Color int i s String

  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; } }

More Related