1 8 package test.args; 9 10 import org.codehaus.aspectwerkz.definition.Pointcut; 11 import org.codehaus.aspectwerkz.joinpoint.JoinPoint; 12 import test.Loggable; 13 14 17 public class ArgsAspect { 18 19 21 24 Pointcut in_scope; 25 26 29 Pointcut pc_matchAll; 30 31 34 Pointcut pc_matchAllWithWildcard; 35 36 39 void pc_getFirst(String s) { 40 ; 41 } 43 46 Pointcut pc_changeArg(StringBuffer s) { 47 return null; 48 } 50 53 Pointcut pc_orderChangedInPointcutSignature(String s1, String s0) { 54 return null; 55 } 56 57 60 Pointcut pc_orderChangedInAdviceSignature(String s0, String s1) { 61 return null; 62 } 63 64 67 Pointcut pc_orderChangedInPointcutAndAdviceSignature(String s1, String s0) { 68 return null; 69 } 70 71 74 public void singleAndDotDot(JoinPoint joinPoint, int i) { 75 ((Loggable) joinPoint.getTarget()).log("before " + i + " "); 76 } 77 78 81 public void withArray(JoinPoint joinPoint, long l, String s, int[][] matrix) { 82 String iis = ""; 83 for (int i = 0; i < matrix.length; i++) { 84 for (int j = 0; j < matrix[i].length; j++) { 85 iis += ""+matrix[i][j]+"-"; 86 } 87 } 88 ((Loggable) joinPoint.getTarget()).log("before " + l + " " + s + " " + iis + " "); 89 } 90 91 94 public void matchAllBefore(JoinPoint joinPoint) { 95 ((Loggable) joinPoint.getTarget()).log("before "); 96 } 97 98 101 public void matchAllAfter(JoinPoint joinPoint) { 102 ((Loggable) joinPoint.getTarget()).log("after "); 103 } 104 105 108 public Object matchAllAround(JoinPoint joinPoint) throws Throwable { 109 ((Loggable) joinPoint.getTarget()).log("before1 "); 110 Object res = joinPoint.proceed(); 111 ((Loggable) joinPoint.getTarget()).log("after1 "); 112 return res; 113 } 114 115 116 119 public void getFirstBefore(JoinPoint joinPoint, String as) { 120 ((Loggable) joinPoint.getTarget()).log("before " + as + " "); 121 } 122 123 126 public void getFirstAfter(String as, JoinPoint joinPoint) { ((Loggable) joinPoint.getTarget()).log("after " + as + " "); 128 } 129 130 133 public Object getFirstAround(JoinPoint joinPoint, String as) throws Throwable { 134 ((Loggable) joinPoint.getTarget()).log("before1 " + as + " "); 135 Object res = joinPoint.proceed(); 136 ((Loggable) joinPoint.getTarget()).log("after1 " + as + " "); 137 return res; 138 } 139 140 143 public void getFirstAnonymousBefore(JoinPoint joinPoint, String as) { 144 ((Loggable) joinPoint.getTarget()).log("before " + as + " "); 145 } 146 147 150 public void getFirstAnonymousAfter(String as, JoinPoint joinPoint) { 151 ((Loggable) joinPoint.getTarget()).log("after " + as + " "); 152 } 153 154 157 public Object getFirstAnonymousAround(JoinPoint joinPoint, String as) throws Throwable { 158 ((Loggable) joinPoint.getTarget()).log("before1 " + as + " "); 159 Object res = joinPoint.proceed(); 160 ((Loggable) joinPoint.getTarget()).log("after1 " + as + " "); 161 return res; 162 } 163 164 167 public void changeArgBefore(JoinPoint joinPoint, StringBuffer as) { 168 as.append("x"); 169 ((Loggable) joinPoint.getTarget()).log("before " + as.toString() + " "); 170 } 171 172 175 public void changeArgAfter(JoinPoint joinPoint, StringBuffer as) { 176 as.append("x"); 177 ((Loggable) joinPoint.getTarget()).log("after " + as.toString() + " "); 178 } 179 180 183 public Object changeArgAround(StringBuffer as, JoinPoint joinPoint) throws Throwable { as.append("x"); 185 ((Loggable) joinPoint.getTarget()).log("before1 " + as.toString() + " "); 186 Object res = joinPoint.proceed(); 187 as.append("x"); 188 ((Loggable) joinPoint.getTarget()).log("after1 " + as.toString() + " "); 189 return res; 190 } 191 192 193 196 public void orderChangedInPointcutSignatureBefore(JoinPoint joinPoint, String as0, String as1) { 197 ((Loggable) joinPoint.getTarget()).log("before " + as0 + " " + as1 + " "); 198 } 199 200 203 public void orderChangedInPointcutSignatureAfter(JoinPoint joinPoint, String as0, String as1) { 204 ((Loggable) joinPoint.getTarget()).log("after " + as0 + " " + as1 + " "); 205 } 206 207 210 public Object orderChangedInPointcutSignatureAround(JoinPoint joinPoint, String as0, String as1) throws Throwable { 211 ((Loggable) joinPoint.getTarget()).log("before1 " + as0 + " " + as1 + " "); 212 Object res = joinPoint.proceed(); 213 ((Loggable) joinPoint.getTarget()).log("after1 " + as0 + " " + as1 + " "); 214 return res; 215 } 216 217 218 221 public void orderChangedInAdviceSignatureBefore(JoinPoint joinPoint, String as0, String as1) { 222 ((Loggable) joinPoint.getTarget()).log("before " + as0 + " " + as1 + " "); 223 } 224 225 228 public void orderChangedInAdviceSignatureAfter(JoinPoint joinPoint, String as0, String as1) { 229 ((Loggable) joinPoint.getTarget()).log("after " + as0 + " " + as1 + " "); 230 } 231 232 235 public Object orderChangedInAdviceSignatureAround(JoinPoint joinPoint, String as0, String as1) throws Throwable { 236 ((Loggable) joinPoint.getTarget()).log("before1 " + as0 + " " + as1 + " "); 237 Object res = joinPoint.proceed(); 238 ((Loggable) joinPoint.getTarget()).log("after1 " + as0 + " " + as1 + " "); 239 return res; 240 } 241 242 243 246 public void orderChangedInPointcutAndAdviceSignatureBefore(JoinPoint joinPoint, String as0, String as1) { 247 ((Loggable) joinPoint.getTarget()).log("before " + as0 + " " + as1 + " "); 248 } 249 250 253 public void orderChangedInPointcutAndAdviceSignatureAfter(JoinPoint joinPoint, String as0, String as1) { 254 ((Loggable) joinPoint.getTarget()).log("after " + as0 + " " + as1 + " "); 255 } 256 257 260 public Object orderChangedInPointcutAndAdviceSignatureAround(JoinPoint joinPoint, String as0, String as1) 261 throws Throwable { 262 ((Loggable) joinPoint.getTarget()).log("before1 " + as0 + " " + as1 + " "); 263 Object res = joinPoint.proceed(); 264 ((Loggable) joinPoint.getTarget()).log("after1 " + as0 + " " + as1 + " "); 265 return res; 266 } 267 268 270 273 void pc_callGetFirstAndSecond(long l, String [] s) { 274 }; 275 276 279 public void callGetFirstAndSecondBefore(JoinPoint joinPoint, long l, String [] s) { 280 ((Loggable) joinPoint.getTarget()).log("before " + l + " " + s[0] + "," + s[1] + " "); 281 } 282 283 286 public void callGetFirstAndSecondAfter(JoinPoint joinPoint, long l, String [] s) { 287 ((Loggable) joinPoint.getTarget()).log("after " + l + " " + s[0] + "," + s[1] + " "); 288 } 289 290 293 public Object callGetFirstAndSecondAround(JoinPoint joinPoint, long l, String [] s) throws Throwable { 294 ((Loggable) joinPoint.getTarget()).log("before1 " + l + " " + s[0] + "," + s[1] + " "); 295 Object res = joinPoint.proceed(); 296 ((Loggable) joinPoint.getTarget()).log("after1 " + l + " " + s[0] + "," + s[1] + " "); 297 return res; 298 } 299 300 303 306 void pc_ctorExecutionGetFirst(String s) { 307 }; 308 309 312 public void ctorExecutionGetFirstBefore(JoinPoint joinPoint, String s) { 313 ((Loggable) joinPoint.getTarget()).log("before " + s + " "); 314 } 315 316 319 public void ctorExecutionGetFirstAfter(JoinPoint joinPoint, String s) { 320 ((Loggable) joinPoint.getTarget()).log("after " + s + " "); 321 } 322 323 326 public Object ctorExecutionGetFirstAround(JoinPoint joinPoint, String s) throws Throwable { 327 ((Loggable) joinPoint.getTarget()).log("before1 " + s + " "); 328 Object res = joinPoint.proceed(); 329 ((Loggable) joinPoint.getTarget()).log("after1 " + s + " "); 330 return res; 331 } 332 333 336 339 void pc_ctorCallGetFirst(String s) { 340 }; 341 342 345 public void ctorCallGetFirstBefore(JoinPoint joinPoint, String s) { 346 ArgsAdviceTest.logStatic("before " + s + " "); 347 } 348 349 352 public void ctorCallGetFirstAfter(JoinPoint joinPoint, String s) { 353 ArgsAdviceTest.logStatic("after " + s + " "); 354 } 355 356 359 public Object ctorCallGetFirstAround(JoinPoint joinPoint, String s) throws Throwable { 360 ArgsAdviceTest.logStatic("before1 " + s + " "); 361 Object res = joinPoint.proceed(); 362 ArgsAdviceTest.logStatic("after1 " + s + " "); 363 return res; 364 } 365 366 370 void pc_mfield(String s) { 371 }; 372 373 376 public void mfieldBefore(JoinPoint joinPoint, String s) { 377 String fieldValue = ((ArgsAdviceTest) joinPoint.getTarget()).getField(); 378 ((Loggable) joinPoint.getTarget()).log("before " + fieldValue + "," + s + " "); 379 } 380 381 384 public void mfieldAfter(JoinPoint joinPoint, String s) { 385 String fieldValue = ((ArgsAdviceTest) joinPoint.getTarget()).getField(); 386 ((Loggable) joinPoint.getTarget()).log("after " + fieldValue + "," + s + " "); 387 } 388 389 392 public Object mfieldAround(JoinPoint joinPoint, String s) throws Throwable { 393 String fieldValue = ((ArgsAdviceTest) joinPoint.getTarget()).getField(); 394 ((Loggable) joinPoint.getTarget()).log("before1 " + fieldValue + "," + s + " "); 395 s = "changed"; Object res = joinPoint.proceed(); 397 fieldValue = ((ArgsAdviceTest) joinPoint.getTarget()).getField(); 398 ((Loggable) joinPoint.getTarget()).log("after1 " + fieldValue + "," + s + " "); 399 return "ignored"; 400 } 401 402 406 void pc_sfield(String s) { 407 }; 408 409 412 public void sfieldBefore(JoinPoint joinPoint, String s) { 413 String fieldValue = ArgsAdviceTest.getStaticField(); 414 ArgsAdviceTest.logStatic("before " + fieldValue + "," + s + " "); 415 } 416 417 420 public void sfieldAfter(JoinPoint joinPoint, String s) { 421 String fieldValue = ArgsAdviceTest.getStaticField(); 422 ArgsAdviceTest.logStatic("after " + fieldValue + "," + s + " "); 423 } 424 425 428 public Object sfieldAround(JoinPoint joinPoint, String s) throws Throwable { 429 String fieldValue = ArgsAdviceTest.getStaticField(); 430 ArgsAdviceTest.logStatic("before1 " + fieldValue + "," + s + " "); 431 s = "changed"; Object res = joinPoint.proceed(); 433 fieldValue = ArgsAdviceTest.getStaticField(); 434 ArgsAdviceTest.logStatic("after1 " + fieldValue + "," + s + " "); 435 return "ignored"; 436 } 437 438 } 439 | Popular Tags |