This content has been marked as final.
Show 3 replies
-
1. Re: Annotate class only and crosscut methods within the clas
nthx Sep 21, 2004 12:21 PM (in response to nthx)Yupiii!
And once more, I reply to my own post :)
So here is the solution with new TYPE_DEF feature:
jboss-aop.xml:<aop> <typedef name="rootable" expr="class(@root)" /> <bind pointcut="all($typedef{rootable})"> <interceptor class="RootInterceptor"/> </bind> <!-- If you annotated class with "@@root" you don't need this <annotation tag="root" class="MyRoot"> <class/> </annotation> --> </aop>
Interceptor:public class RootInterceptor implements Interceptor { public Object invoke(Invocation invocation) throws Throwable { if (invocation instanceof ConstructorInvocation) { ...put logic here for Constructor joinpoints.. } .... } }
and core code:/** @@root */ public class MyRoot { public void method1(){} public static void main(String[] args) { System.out.println("------START"); MyRoot root = new MyRoot(); root.method1(); System.out.println("------END"); } }
There is only default constructor here. But the logic from
RootInterceptor will be applied. That's great.
Output:[java] ------START [java] ==O==[main] RootInterceptor: 23: MyRoot0OptimizedConstructorInvocation@15e9756 [java] ==O==[main] RootInterceptor: 25: I'm in ConstructorInterceptor [java] ==O==[main] RootInterceptor: 23: MyRoot_method1_N4778546224999628736_ OptimizedMethodInvocation@121ab80 [java] ------END
--Tomasz -
2. Re: Annotate class only and crosscut methods within the clas
bill.burke Sep 21, 2004 3:30 PM (in response to nthx)Yikes, sorry I missed your post before....
This may be a better approach:<bind pointcut="execution(@my.root->new(..))"> <interceptor class="RootCreationInterceptor" /> </bind>
This will bind your interceptor to every constructor of every class tagged as @my.root.
Bill
-
3. Re: Annotate class only and crosscut methods within the clas
nthx Sep 22, 2004 4:59 AM (in response to nthx)Hi
And I was going to work today with a thought about posting about this simpler way that I found out yesterday evening... Ehhh :)
Tomasz