[jboss-cvs] JBossAS SVN: r58005 - in projects/aop/trunk/aop/src: main/org/jboss/aop/advice resources/test/construction test/org/jboss/test/aop/construction

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Nov 2 06:50:46 EST 2006


Author: kabir.khan at jboss.com
Date: 2006-11-02 06:50:34 -0500 (Thu, 02 Nov 2006)
New Revision: 58005

Added:
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/construction/PerInstanceAspect.java
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/construction/PerInstancePOJO.java
Modified:
   projects/aop/trunk/aop/src/main/org/jboss/aop/advice/AbstractAdvice.java
   projects/aop/trunk/aop/src/resources/test/construction/jboss-aop.xml
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/construction/ConstructionTester.java
Log:
[JBAOP-303] Per instance construction advices should be possible

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/advice/AbstractAdvice.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/advice/AbstractAdvice.java	2006-11-02 11:18:52 UTC (rev 58004)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/advice/AbstractAdvice.java	2006-11-02 11:50:34 UTC (rev 58005)
@@ -22,6 +22,7 @@
 package org.jboss.aop.advice;
 
 import org.jboss.aop.instrument.Untransformable;
+import org.jboss.aop.joinpoint.ConstructionInvocation;
 import org.jboss.aop.joinpoint.ConstructorCalledByConstructorInvocation;
 import org.jboss.aop.joinpoint.ConstructorCalledByMethodInvocation;
 import org.jboss.aop.joinpoint.ConstructorInvocation;
@@ -46,6 +47,7 @@
    private static final Class[] INVOCATION_SIGNATURE = {Invocation.class};
    private static final Class[] METHOD_SIGNATURE = {MethodInvocation.class};
    private static final Class[] CONSTRUCTOR_SIGNATURE = {ConstructorInvocation.class};
+   private static final Class[] CONSTRUCTION_SIGNATURE = {ConstructionInvocation.class};
    private static final Class[] FIELD_SIGNATURE = {FieldInvocation.class};
    private static final Class[] FIELD_READ_SIGNATURE = {FieldReadInvocation.class};
    private static final Class[] FIELD_WRITE_SIGNATURE = {FieldWriteInvocation.class};
@@ -56,6 +58,7 @@
    protected Method invocationAdvice;
    protected Method methodAdvice;
    protected Method constructorAdvice;
+   protected Method constructionAdvice;
    protected Method fieldAdvice;
    protected Method fieldReadAdvice;
    protected Method fieldWriteAdvice;
@@ -75,6 +78,7 @@
       {
          methodAdvice = findByMethodInvocation(adviceName, aspectClass);
          constructorAdvice = findByConstructorInvocation(adviceName, aspectClass);
+         constructionAdvice = findByConstructionInvocation(adviceName, aspectClass);
          fieldAdvice = findByFieldInvocation(adviceName, aspectClass);
          if (fieldAdvice == null)
          {
@@ -166,6 +170,19 @@
       return null;
    }
 
+   protected static Method findByConstructionInvocation(String adviceName, Class clazz)
+   {
+      try
+      {
+         return clazz.getMethod(adviceName, CONSTRUCTION_SIGNATURE);
+      }
+      catch (NoSuchMethodException e)
+      {
+         // complete
+      }
+      return null;
+   }
+
    protected static Method findByMethodCalledByMethodInvocation(String adviceName, Class clazz)
    {
       try
@@ -257,6 +274,14 @@
          }
          return constructorAdvice;
       }
+      if (invocation instanceof ConstructionInvocation)
+      {
+         if (constructorAdvice == null)
+         {
+            throw new IllegalStateException("Unable to resolve ConstructionInvocation advice " + getName());
+         }
+         return constructorAdvice;
+      }
       if (invocation instanceof MethodCalledByMethodInvocation)
       {
          if (methodCalledByMethodAdvice == null)

Modified: projects/aop/trunk/aop/src/resources/test/construction/jboss-aop.xml
===================================================================
--- projects/aop/trunk/aop/src/resources/test/construction/jboss-aop.xml	2006-11-02 11:18:52 UTC (rev 58004)
+++ projects/aop/trunk/aop/src/resources/test/construction/jboss-aop.xml	2006-11-02 11:50:34 UTC (rev 58005)
@@ -4,7 +4,8 @@
 <aop>
 
    <aspect class="org.jboss.test.aop.construction.Aspect"/>
-
+   <aspect class="org.jboss.test.aop.construction.PerInstanceAspect"/>
+   
    <bind pointcut="construction(org.jboss.test.aop.construction.SuperPOJO->new(..))">
       <advice aspect="org.jboss.test.aop.construction.Aspect" name="construction"/>
    </bind>
@@ -13,5 +14,10 @@
    <bind pointcut="construction(org.jboss.test.aop.construction.DefaultSuper->new(..))">
       <advice aspect="org.jboss.test.aop.construction.Aspect" name="construction2"/>
    </bind>
+   
+   <bind pointcut="construction(org.jboss.test.aop.construction.PerInstancePOJO->new(..))">
+      <advice aspect="org.jboss.test.aop.construction.PerInstanceAspect" name="construction"/>
+      <advice aspect="org.jboss.test.aop.construction.PerInstanceAspect" name="invocation"/>
+   </bind>
 
 </aop>

Modified: projects/aop/trunk/aop/src/test/org/jboss/test/aop/construction/ConstructionTester.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/construction/ConstructionTester.java	2006-11-02 11:18:52 UTC (rev 58004)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/construction/ConstructionTester.java	2006-11-02 11:50:34 UTC (rev 58005)
@@ -63,5 +63,14 @@
       POJO pojo = new POJO();
       DefaultPOJO d = new DefaultPOJO();
    }
+   
+   public void testPerInstance()
+   {
+      PerInstanceAspect.construction = false;
+      PerInstanceAspect.invocation = false;
+      PerInstancePOJO pojo = new PerInstancePOJO();
+      assertTrue(PerInstanceAspect.construction);
+      assertTrue(PerInstanceAspect.invocation);
+   }
 }
 

Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/construction/PerInstanceAspect.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/construction/PerInstanceAspect.java	2006-11-02 11:18:52 UTC (rev 58004)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/construction/PerInstanceAspect.java	2006-11-02 11:50:34 UTC (rev 58005)
@@ -0,0 +1,47 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors. 
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.test.aop.construction;
+
+import org.jboss.aop.joinpoint.ConstructionInvocation;
+import org.jboss.aop.joinpoint.Invocation;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class PerInstanceAspect
+{
+   static boolean construction;
+   static boolean invocation;
+   public Object construction(ConstructionInvocation inv) throws Throwable
+   {
+      construction = true;
+      return inv.invokeNext();
+   }
+   
+   public Object invocation(Invocation inv) throws Throwable
+   {
+      invocation = true;
+      return inv.invokeNext();
+   }
+}

Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/construction/PerInstancePOJO.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/construction/PerInstancePOJO.java	2006-11-02 11:18:52 UTC (rev 58004)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/construction/PerInstancePOJO.java	2006-11-02 11:50:34 UTC (rev 58005)
@@ -0,0 +1,32 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors. 
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.test.aop.construction;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class PerInstancePOJO
+{
+
+}




More information about the jboss-cvs-commits mailing list