View the original post : 
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3820391#3820391

Reply to the post : 
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=3820391

I just added a new feature in HEAD (cvs checkout jboss-head)



Added the ability to define Aspects.  Aspects are a Java class that contains multiple 
advices.  An advice in an Aspect class maps to a particular method.



Here's what the XML and code looks like.  POJOAspectTester is what we're interception. 
 Aspect is the class that contains advices.  The XML defines the aspect and then binds 
the advice of the aspect within a pointcut.



You can define a scope for the aspect.  This is PER_VM, PER_CLASS, or PER_INSTANCE.  
(FYI, i'll be adding this for interceptors soon too).



Note on performance.  Aspects are much slower than regular interceptors because 
reflection is required to execute the advices where regular interceptors this is not 
required.





   [aspect class="org.jboss.test.aop.bean.Aspect" scope="PER_VM"/]



   [constructor-pointcut constructor="org.jboss.test.aop.bean.POJOAspectTester()"]

      [bind]

         [advice name="interceptConstructor" aspect="org.jboss.test.aop.bean.Aspect"/]

      [/bind]

   [/constructor-pointcut]



   [method-pointcut class="org.jboss.test.aop.bean.POJOAspectTester" methodExpr="void 
someMethod()"]

      [bind]

         [advice name="interceptMethod" aspect="org.jboss.test.aop.bean.Aspect"/]

      [/bind]

   [/method-pointcut]







public class POJOAspectTester

{

   public String marker = "error";

   public int field;



   public POJOAspectTester() {}



   public void someMethod() {}

}



public class Aspect

{

   public Object interceptConstructor(ConstructorInvocation invocation) throws 
Throwable

   {

      Object rtn = invocation.invokeNext();

      POJOAspectTester pojo = (POJOAspectTester)rtn;

      pojo.marker = "interceptConstructor";

      return rtn;

   }



   public Object interceptField(FieldInvocation invocation) throws Throwable

   {

      Object rtn = invocation.invokeNext();

      POJOAspectTester pojo = (POJOAspectTester)invocation.targetObject;

      pojo.marker = "interceptField";

      return rtn;

   }



   public Object interceptMethod(MethodInvocation invocation) throws Throwable

   {

      Object rtn = invocation.invokeNext();

      POJOAspectTester pojo = (POJOAspectTester)invocation.targetObject;

      pojo.marker = "interceptMethod";

      return rtn;

   }

}






-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration
See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn
_______________________________________________
JBoss-Development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to