1 27 package ch.ethz.prose.crosscut; 28 29 30 31 import java.io.Serializable ; 33 import java.lang.reflect.InvocationTargetException ; 34 import java.lang.reflect.Method ; 35 import java.lang.reflect.Modifier ; 36 import java.util.Arrays ; 37 import java.util.HashMap ; 38 import java.util.Iterator ; 39 import java.util.List ; 40 import java.util.Vector ; 41 42 import ch.ethz.jvmai.ExceptionJoinPoint; 43 import ch.ethz.jvmai.FieldAccessJoinPoint; 44 import ch.ethz.jvmai.FieldModificationJoinPoint; 45 import ch.ethz.jvmai.JoinPoint; 46 import ch.ethz.prose.engine.JoinPointRequest; 47 import ch.ethz.jvmai.MethodEntryJoinPoint; 48 import ch.ethz.jvmai.MethodExitJoinPoint; 49 import ch.ethz.prose.engine.MethodEntryRequest; 50 import ch.ethz.prose.engine.MethodExitRequest; 51 import ch.ethz.inf.util.Logger; 52 import ch.ethz.prose.filter.ANDingPointCutter; 53 import ch.ethz.prose.filter.PointCutter; 54 55 76 public 77 abstract class MethodCut extends AbstractCrosscut implements java.io.Serializable { 78 79 83 87 public void METHOD_ARGS(){} 88 89 94 95 96 transient boolean isInitialized = false; 97 transient MethodCutSpecializer mcutSpecializer = null; 98 transient MethodCutSignaturePattern adviceSignature = null; 99 String toStringSignature; 100 101 private void initState() throws MissingInformationException 102 { 103 if (isInitialized) return; 104 isInitialized=true; 105 106 adviceSignature = new MethodCutSignaturePattern(this); 107 mcutSpecializer = new MethodCutSpecializer(adviceSignature); 108 109 toStringSignature = adviceSignature.toString(); 110 } 111 112 119 protected MethodCut() throws MissingInformationException 120 { 121 initState(); 122 } 123 124 public void insertionAction(boolean beforeInsertion) 125 { 126 super.insertionAction(beforeInsertion); 127 128 initState(); 133 } 134 135 136 141 protected Class [] potentialCrosscutClasses() throws MissingInformationException 142 { 143 146 Class [] result = new Class []{}; 147 List searchList = new Vector (Arrays.asList(super.potentialCrosscutClasses())); 148 149 Class receiverClass=adviceSignature.getReceiverType(); 152 if (receiverClass!= null && !Wildcard.class.isAssignableFrom(receiverClass) && 153 !searchList.contains(receiverClass)) 154 searchList.add(receiverClass); 155 Vector resultList = new Vector (); 156 157 Iterator i = searchList.iterator(); 159 while (i.hasNext()) 160 { 161 Class crtCls=(Class )i.next(); 162 if (isPotentialCrosscutClass(crtCls)) 163 resultList.add(crtCls); 164 } 165 166 result = (Class [])resultList.toArray(new Class []{}); 168 return result; 169 } 170 171 179 protected boolean isPotentialCrosscutClass(Class crtCls) throws MissingInformationException 180 { 181 return adviceSignature.matchesTarget(crtCls); 182 } 183 184 199 protected CrosscutRequest doCreateRequest(Class theClass) 200 { 201 CrosscutRequest result = new CrosscutRequest(); 207 208 Method [] methArray = null; 212 213 try { methArray=theClass.getDeclaredMethods(); } 214 catch (NoClassDefFoundError e) 215 { 216 return result; 217 } 218 219 for(int i=0; i<methArray.length; i++) 220 { 221 Class [] params = methArray[i].getParameterTypes(); 222 JoinPointRequest crtRequest; 223 224 crtRequest = requestFactory.createJoinPointRequest(MethodEntryJoinPoint.KIND,methArray[i]); 225 if (mcutSpecializer.isSpecialRequest(crtRequest)) 226 result.add(crtRequest); 227 228 crtRequest = requestFactory.createJoinPointRequest(MethodExitJoinPoint.KIND,methArray[i]); 229 if (mcutSpecializer.isSpecialRequest(crtRequest)) 230 result.add(crtRequest); 231 } 232 233 return result; 234 } 235 236 244 public void joinPointAction(MethodEntryJoinPoint ev) throws IllegalAccessException , InvocationTargetException 245 { 246 methodAdvice(ev); 247 } 248 249 257 public void joinPointAction(MethodExitJoinPoint ev) throws IllegalAccessException , InvocationTargetException 258 { 259 methodAdvice(ev); 261 } 262 263 264 269 private void methodAdvice(JoinPoint joinPoint) 270 throws InvocationTargetException , IllegalAccessException 271 { 272 273 McutAdvice toRun= null; 275 switch(adviceSignature.signatureCathegory) 276 { 277 case SignaturePattern.SIGNATURE__EMPTY: 278 METHOD_ARGS(); 279 break; 280 case SignaturePattern.SIGNATURE__CONCRETE__CONCRETE: 281 toRun = new ConcreteConcreteMcutAdvice(this, joinPoint,(MethodCutSignaturePattern)adviceSignature); 282 break; 283 case SignaturePattern.SIGNATURE__WILDCARD__CONCRETE: 284 toRun = new WildcardConcreteMcutAdvice(this, joinPoint,(MethodCutSignaturePattern)adviceSignature); 285 break; 286 case SignaturePattern.SIGNATURE__WILDCARD__WILDCARD: 287 toRun = new WildcardWildcardMcutAdvice(this, joinPoint,(MethodCutSignaturePattern)adviceSignature); 288 break; 289 case SignaturePattern.SIGNATURE__CONCRETE__WILDCARD: 290 toRun = new ConcreteWildcardMcutAdvice(this, joinPoint,(MethodCutSignaturePattern)adviceSignature); 291 break; 292 default: 293 toRun = new DefaultMcutAdvice(this, joinPoint,(MethodCutSignaturePattern)adviceSignature); 294 break; 295 } 296 297 toRun.execute(); 298 299 } 300 301 public PointCutter equivalentSpecializer() 302 { 303 initState(); 304 if (getSpecializer() == null) 305 return mcutSpecializer; 306 else 307 return new ANDingPointCutter(mcutSpecializer,(PointCutter)getSpecializer()); 308 } 309 310 316 public Method getMethod() { 317 return adviceSignature.methodObj; 318 } 319 320 public String toString() 321 { 322 return " Crosscut: 'MethodCut' \n" + 323 " Advice:" + toStringSignature + "\n" + 324 " PointCutter: " + getSpecializer() + "\n"; 325 } 326 } 327 328 329
| Popular Tags
|