1 22 package org.jboss.injbossaop.lib; 23 24 import org.jboss.aop.joinpoint.ConstructorInvocation; 25 import org.jboss.aop.joinpoint.FieldReadInvocation; 26 import org.jboss.aop.joinpoint.FieldWriteInvocation; 27 import org.jboss.aop.joinpoint.Invocation; 28 import org.jboss.aop.joinpoint.MethodInvocation; 29 import org.jboss.aop.advice.Interceptor; 30 import org.jboss.aop.PointcutDef; 31 import org.jboss.aop.TypeDef; 32 import org.jboss.aop.Bind; 33 import org.jboss.aop.InterceptorDef; 34 import org.jboss.aop.pointcut.Pointcut; 35 import org.jboss.aop.pointcut.Typedef; 36 37 42 @InterceptorDef 43 @Bind (pointcut="org.jboss.injbossaop.lib.SimpleInterceptor.valueConstructors OR org.jboss.injbossaop.lib.SimpleInterceptor.valueMessage OR org.jboss.injbossaop.lib.SimpleInterceptor.service OR org.jboss.injbossaop.lib.SimpleInterceptor.sessionValue OR org.jboss.injbossaop.lib.SimpleInterceptor.mbeans") 44 public class SimpleInterceptor implements Interceptor 45 { 46 @PointcutDef ("execution(org.jboss.injbossaop.lib.ExampleValue->new(..))") 47 public static Pointcut valueConstructors; 48 49 @PointcutDef ("execution(* org.jboss.injbossaop.lib.ExampleValue->getMessage())") 50 public static Pointcut valueMessage; 51 52 @TypeDef ("class($instanceof{javax.servlet.http.HttpServlet}) AND class(org.jboss.injbossaop.web.*)") 53 public static Typedef servlets; 54 55 @PointcutDef ("execution(* $typedef{org.jboss.injbossaop.lib.SimpleInterceptor.servlets}->service(..))") 56 public static Pointcut service; 57 58 @TypeDef ("class($instanceof{javax.ejb.SessionBean}) AND class(org.jboss.injbossaop.ejb.*)") 59 public static Typedef sessionBeans; 60 61 @PointcutDef ("execution(* $typedef{org.jboss.injbossaop.lib.SimpleInterceptor.sessionBeans}->getValue(..))") 62 public static Pointcut sessionValue; 63 64 @PointcutDef ("all(org.jboss.injbossaop.mbean.*)") 65 public static Pointcut mbeans; 66 67 public String getName() { return "SimpleInterceptor"; } 68 69 public Object invoke(Invocation invocation) throws Throwable 70 { 71 try 72 { 73 System.out.println("<<< Entering SimpleInterceptor: " + invocationInfo(invocation)); 74 return invocation.invokeNext(); 75 } 76 finally 77 { 78 System.out.println(">>> Leaving SimpleInterceptor"); 79 } 80 } 81 82 private String invocationInfo(Invocation invocation) 83 { 84 StringBuffer info = new StringBuffer ("\n\tinvocation class: " + invocation.getClass().getName()); 85 86 if (invocation instanceof MethodInvocation) 87 { 88 MethodInvocation mi = (MethodInvocation)invocation; 89 info.append("\n\ttype: Method Invocation"); 90 info.append("\n\tmethod: " + mi.getMethod().getName()); 91 info.append("\n\tClass containing method: " + mi.getTargetObject().getClass().getName()); 92 } 93 else if (invocation instanceof ConstructorInvocation) 94 { 95 ConstructorInvocation ci = (ConstructorInvocation)invocation; 96 info.append("\n\ttype: Constructor Invocation"); 97 info.append("\n\tconstructor: " + ci.getConstructor()); 98 } 99 else if (invocation instanceof FieldWriteInvocation) 100 { 101 FieldWriteInvocation fi = (FieldWriteInvocation)invocation; 102 info.append("\n\ttype: Field Write Invocation"); 103 info.append("\n\tfield: " + fi.getField()); 104 105 } 106 else if (invocation instanceof FieldReadInvocation) 107 { 108 FieldReadInvocation fi = (FieldReadInvocation)invocation; 109 info.append("\n\ttype: Field Write Invocation"); 110 info.append("\n\tfield: " + fi.getField()); 111 } 112 113 return info.toString(); 114 } 115 } 116 | Popular Tags |