1 27 package ch.ethz.inf.iks.jvmai.jvmdi; 28 29 import ch.ethz.jvmai.CodeJoinPoint; 30 import ch.ethz.jvmai.MethodEntryJoinPoint; 31 import ch.ethz.jvmai.FieldAccessJoinPoint; 32 import ch.ethz.jvmai.FieldModificationJoinPoint; 33 import ch.ethz.jvmai.MethodExitJoinPoint; 34 import ch.ethz.jvmai.ExceptionJoinPoint; 35 import ch.ethz.jvmai.ExceptionCatchJoinPoint; 36 37 import java.util.*; 39 import java.io.*; 40 41 58 public 59 class ControlFlow { 60 61 private SortedMap aopMap; 62 private JoinPointContext currentContext; 63 private MethodExecutionJoinPointImpl executionJoinPoint; 64 private FieldAccessJoinPointImpl getJoinPoint; 65 private FieldModificationJoinPointImpl setJoinPoint ; 66 private ExceptionJoinPointImpl throwJoinPoint ; 67 private ExceptionCatchJoinPointImpl catchJoinPoint; 68 69 70 public ControlFlow() 71 { 72 aopMap = new TreeMap(); 73 currentContext = new JoinPointContext(); 74 executionJoinPoint = new MethodExecutionJoinPointImpl(this,currentContext); 75 getJoinPoint = new FieldAccessJoinPointImpl(this,currentContext); 76 setJoinPoint = new FieldModificationJoinPointImpl(this,currentContext); 77 throwJoinPoint = new ExceptionJoinPointImpl(this,currentContext); 78 catchJoinPoint = new ExceptionCatchJoinPointImpl(this,currentContext); 79 } 80 protected Collection getAopTags(CodeJoinPointImpl jp) 81 { 82 SortedMap headMap = aopMap.headMap(valueOf(jp.context.depth)); 83 return headMap.values(); 84 } 85 86 protected void pushJoinPoint(CodeJoinPointImpl cjp) 87 { 88 aopMap.put(valueOf(currentContext.depth),cjp.getAopTag()); 89 } 90 91 protected void popJoinPoint(int depth) 92 { 93 94 Integer intKey = valueOf(depth); 95 96 Integer lastKey = (Integer )aopMap.lastKey(); 97 98 if (lastKey.equals(intKey)) 99 aopMap.remove(lastKey); 100 else 101 { 102 SortedMap tail = aopMap.tailMap(intKey); 103 Iterator i = tail.keySet().iterator(); 104 while (i.hasNext()) 105 { 106 aopMap.remove(i.next()); 107 } 108 } 109 } 110 111 112 private static Integer [] first100Integers; 113 private Integer valueOf(int x) 114 { 115 if (first100Integers == null) 116 { 117 first100Integers = new Integer [100]; 118 for (int i =0; i<100; i++) 119 first100Integers[i]=new Integer (i); 120 } 121 122 if (x<100) 123 return first100Integers[x]; 124 else 125 return new Integer (x); 126 } 127 128 129 130 131 132 133 } 134 135 136 | Popular Tags |