[jboss-cvs] JBossAS SVN: r62494 - in projects/aop/trunk/aop/src/main/org/jboss/aop: advice and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Apr 23 16:23:57 EDT 2007


Author: flavia.rainone at jboss.com
Date: 2007-04-23 16:23:57 -0400 (Mon, 23 Apr 2007)
New Revision: 62494

Added:
   projects/aop/trunk/aop/src/main/org/jboss/aop/advice/AdviceType.java
Removed:
   projects/aop/trunk/aop/src/main/org/jboss/aop/advice/AfterFactory.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/advice/BeforeFactory.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/advice/GeneratedOnly.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/advice/ThrowingFactory.java
Modified:
   projects/aop/trunk/aop/src/main/org/jboss/aop/Advisor.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/AspectXmlLoader.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/GeneratedInstanceAdvisorMixin.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/advice/AdviceFactory.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/advice/AdviceStack.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/advice/GeneratedAdvisorInterceptor.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/advice/GenericInterceptorFactory.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/advice/InterceptorFactory.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/advice/ScopedInterceptorFactory.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/AdviceMethodFactory.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/AnnotatedParameterAdviceInfo.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/ParameterAnnotationRule.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/JoinPointGenerator.java
Log:
[JBAOP-381] First version of implementation (untested)

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/Advisor.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/Advisor.java	2007-04-23 18:09:51 UTC (rev 62493)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/Advisor.java	2007-04-23 20:23:57 UTC (rev 62494)
@@ -49,7 +49,6 @@
 import org.jboss.aop.advice.AdviceBinding;
 import org.jboss.aop.advice.AspectDefinition;
 import org.jboss.aop.advice.CFlowInterceptor;
-import org.jboss.aop.advice.GeneratedOnly;
 import org.jboss.aop.advice.Interceptor;
 import org.jboss.aop.advice.InterceptorFactory;
 import org.jboss.aop.advice.PrecedenceSorter;
@@ -770,7 +769,7 @@
    {
       for (int i = 0; i < factories.length; i++)
       {
-         if (factories[i] instanceof GeneratedOnly)
+         if (factories[i].getType().isGeneratedOnly())
          {
             throw new RuntimeException("Before/After/Throwing is only supported for Generated Advisors");
          }

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/AspectXmlLoader.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/AspectXmlLoader.java	2007-04-23 18:09:51 UTC (rev 62493)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/AspectXmlLoader.java	2007-04-23 20:23:57 UTC (rev 62494)
@@ -28,6 +28,7 @@
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.StringTokenizer;
+
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
@@ -35,12 +36,11 @@
 import org.jboss.aop.advice.AdviceBinding;
 import org.jboss.aop.advice.AdviceFactory;
 import org.jboss.aop.advice.AdviceStack;
-import org.jboss.aop.advice.AfterFactory;
+import org.jboss.aop.advice.AdviceType;
 import org.jboss.aop.advice.AspectDefinition;
 import org.jboss.aop.advice.AspectFactory;
 import org.jboss.aop.advice.AspectFactoryDelegator;
 import org.jboss.aop.advice.AspectFactoryWithClassLoader;
-import org.jboss.aop.advice.BeforeFactory;
 import org.jboss.aop.advice.DynamicCFlowDefinition;
 import org.jboss.aop.advice.GenericAspectFactory;
 import org.jboss.aop.advice.InterceptorFactory;
@@ -49,7 +49,6 @@
 import org.jboss.aop.advice.Scope;
 import org.jboss.aop.advice.ScopeUtil;
 import org.jboss.aop.advice.ScopedInterceptorFactory;
-import org.jboss.aop.advice.ThrowingFactory;
 import org.jboss.aop.introduction.AnnotationIntroduction;
 import org.jboss.aop.introduction.InterfaceIntroduction;
 import org.jboss.aop.metadata.ClassMetaDataBinding;
@@ -225,24 +224,26 @@
       if (def == null) throw new RuntimeException("advice " + name + " cannot find aspect " + aspect);
       
       String tagName = element.getTagName();
-      
       AdviceFactory factory = null;
       if (tagName.equals("advice"))
       {
+         // default advice type
          factory = new AdviceFactory(def, name);
       }
-      else if (tagName.equals("before"))
+      else
       {
-         factory = new BeforeFactory(def, name);
+         AdviceType type = null;
+         try
+         {
+            type = Enum.valueOf(AdviceType.class, tagName.toUpperCase());
+         }
+         catch (IllegalArgumentException e)
+         {
+            throw new RuntimeException(" cannot find advice tag " + tagName);
+         }
+         factory = new AdviceFactory(def, name, type);
       }
-      else if (tagName.equals("after"))
-      {
-         factory = new AfterFactory(def, name);
-      }
-      else if (tagName.equals("throwing"))
-      {
-         factory = new ThrowingFactory(def, name);
-      }
+      
       manager.addInterceptorFactory(factory.getName(), factory);
       return factory;
    }

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/GeneratedInstanceAdvisorMixin.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/GeneratedInstanceAdvisorMixin.java	2007-04-23 18:09:51 UTC (rev 62493)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/GeneratedInstanceAdvisorMixin.java	2007-04-23 20:23:57 UTC (rev 62494)
@@ -22,6 +22,7 @@
 package org.jboss.aop;
 
 import org.jboss.aop.advice.AdviceStack;
+import org.jboss.aop.advice.AdviceType;
 import org.jboss.aop.advice.AspectDefinition;
 import org.jboss.aop.advice.Interceptor;
 import org.jboss.aop.advice.InterceptorFactory;
@@ -440,5 +441,10 @@
       {
          return true;
       }
+
+      public AdviceType getType()
+      {
+         return AdviceType.AROUND;
+      }
    }
 }
\ No newline at end of file

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/advice/AdviceFactory.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/advice/AdviceFactory.java	2007-04-23 18:09:51 UTC (rev 62493)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/advice/AdviceFactory.java	2007-04-23 20:23:57 UTC (rev 62494)
@@ -37,23 +37,61 @@
 {
    private String advice;
    private AspectDefinition aspect;
-
+   private AdviceType type;
+   
+   /**
+    * Creates a factory that generates advice interceptors.
+    * Use this constructor if you want to record an advice of the 
+    * (@link {@link AdviceType#AROUND default type}.
+    * 
+    * @param aspect     definition of the aspect that contains the advice method
+    * @param adviceName name of the advice method
+    */
    public AdviceFactory(AspectDefinition aspect, String adviceName)
    {
+      this(aspect, adviceName, AdviceType.AROUND);
+   }
+   
+   /**
+    * Creates a factory that generates advice interceptors.
+    * Use this constructor if you want specify the advice type.
+    * 
+    * @param aspect     definition of the aspect that contains the advice method
+    * @param adviceName name of the advice method
+    * @param type       the type of the advice
+    */
+   public AdviceFactory(AspectDefinition aspect, String adviceName, AdviceType type)
+   {
       this.aspect = aspect;
       this.advice = adviceName;
+      this.type = type;
    }
-
+   
+   /**
+    * Returns the definition of the aspect that contains this advice method.
+    */
    public AspectDefinition getAspect()
    {
       return aspect;
    }
 
+   /**
+    * Returns the name of the advice method.
+    */
    public String getAdvice()
    {
       return advice;
    }
 
+   /**
+    * Returns the type of the advice.
+    */
+   public AdviceType getType()
+   {
+      return type;
+   }
+   
+   
    public boolean isDeployed()
    {
       return aspect.isDeployed();
@@ -157,4 +195,4 @@
 
       return true;
    }
-}
+}
\ No newline at end of file

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/advice/AdviceStack.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/advice/AdviceStack.java	2007-04-23 18:09:51 UTC (rev 62493)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/advice/AdviceStack.java	2007-04-23 20:23:57 UTC (rev 62494)
@@ -33,9 +33,9 @@
 public class AdviceStack
 {
    protected String name;
-   protected ArrayList interceptorFactories;
+   protected ArrayList<InterceptorFactory> interceptorFactories;
 
-   public AdviceStack(String name, ArrayList factories)
+   public AdviceStack(String name, ArrayList<InterceptorFactory> factories)
    {
       this.name = name;
       interceptorFactories = factories;
@@ -43,18 +43,18 @@
 
    public String getName() { return name; }
 
-   public ArrayList getInterceptorFactories() { return interceptorFactories; }
+   public ArrayList<InterceptorFactory> getInterceptorFactories() { return interceptorFactories; }
 
 
    public Interceptor[] createInterceptors(Advisor advisor, Joinpoint jp)
    {
-      ArrayList interceptors = new ArrayList();
+      ArrayList<Interceptor> interceptors = new ArrayList<Interceptor>();
       for (int i = 0; i < interceptorFactories.size(); i++)
       {
          InterceptorFactory factory = (InterceptorFactory) interceptorFactories.get(i);
          if (factory.isDeployed()) interceptors.add(factory.create(advisor, jp));
       }
-      return (Interceptor[])interceptors.toArray(new Interceptor[interceptors.size()]);
+      return interceptors.toArray(new Interceptor[interceptors.size()]);
    }
 
    public Interceptor[] createInterceptors()

Added: projects/aop/trunk/aop/src/main/org/jboss/aop/advice/AdviceType.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/advice/AdviceType.java	                        (rev 0)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/advice/AdviceType.java	2007-04-23 20:23:57 UTC (rev 62494)
@@ -0,0 +1,99 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.aop.advice;
+
+import org.jboss.aop.advice.annotation.AdviceMethodFactory;
+
+/**
+ * Indicates whether the type of an advice is <i>before</i>, <i>around</i>,
+ * <i>after</i>, <i>throwing</i> or <i>finally</i>.
+ * 
+ * Notice that interceptors are a special type of <i>around</i> advices.
+ * 
+ * @author  <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+public enum AdviceType
+{
+   BEFORE("before", AdviceMethodFactory.BEFORE, true),
+   AROUND("around", AdviceMethodFactory.AROUND, false),
+   AFTER("after", AdviceMethodFactory.AFTER, false),
+   THROWING("throwing", AdviceMethodFactory.THROWING, false),
+   FINALLY("finally", AdviceMethodFactory.FINALLY, false);
+   
+   private String description;
+   private String accessor;
+   private AdviceMethodFactory factory;
+   private boolean generatedOnly;
+   
+   AdviceType(String description, AdviceMethodFactory factory, boolean generatedOnly)
+   {
+      this.description = description;
+      this.accessor = "get" + Character.toUpperCase(description.charAt(0))
+         + description.substring(1);
+      this.factory = factory;
+      this.generatedOnly = generatedOnly;
+   }
+   
+   /**
+    * Returns a lower case description of this type.
+    */
+   public final String getDescription()
+   {
+      return this.description;
+   }
+   
+   /**
+    * Returns an accessor string for this type.
+    * 
+    * This accessor is built by concatenating <code>"get"</code> with the
+    * the {@link #getDescription() description} starting with an upper case.
+    * 
+    * @return an accessor string for this type.
+    */
+   public final String getAccessor()
+   {
+      return this.accessor;
+   }
+   
+   /**
+    * An advice method factory for this type. Notice this factory is for use on
+    * generated mode only.
+    * 
+    * @return an advice method factory
+    */
+   public final AdviceMethodFactory getFactory()
+   {
+      return this.factory;
+   }
+   
+   /**
+    * Indicates if the use of this advice type is restrictive to the generated
+    * advisor mode, or if can be used on all instrumentation modes.
+    * 
+    * @return <code>true</code> only if this advice type must be used on generated
+    *         advisor mode.
+    */
+   public final boolean isGeneratedOnly()
+   {
+      return this.generatedOnly;
+   }
+}
\ No newline at end of file

Deleted: projects/aop/trunk/aop/src/main/org/jboss/aop/advice/AfterFactory.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/advice/AfterFactory.java	2007-04-23 18:09:51 UTC (rev 62493)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/advice/AfterFactory.java	2007-04-23 20:23:57 UTC (rev 62494)
@@ -1,37 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt 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.aop.advice;
-
-/**
- * 
- * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
- * @version $Revision$
- */
-public class AfterFactory extends AdviceFactory implements GeneratedOnly
-{
-
-   public AfterFactory(AspectDefinition aspect, String adviceName)
-   {
-      super(aspect, adviceName);
-   }
-
-}

Deleted: projects/aop/trunk/aop/src/main/org/jboss/aop/advice/BeforeFactory.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/advice/BeforeFactory.java	2007-04-23 18:09:51 UTC (rev 62493)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/advice/BeforeFactory.java	2007-04-23 20:23:57 UTC (rev 62494)
@@ -1,37 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt 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.aop.advice;
-
-/**
- * 
- * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
- * @version $Revision$
- */
-public class BeforeFactory extends AdviceFactory implements GeneratedOnly
-{
-
-   public BeforeFactory(AspectDefinition aspect, String adviceName)
-   {
-      super(aspect, adviceName);
-   }
-
-}

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/advice/GeneratedAdvisorInterceptor.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/advice/GeneratedAdvisorInterceptor.java	2007-04-23 18:09:51 UTC (rev 62493)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/advice/GeneratedAdvisorInterceptor.java	2007-04-23 20:23:57 UTC (rev 62494)
@@ -338,26 +338,11 @@
       }
    }
    
-   public boolean isBefore()
+   public AdviceType getType()
    {
-      return factory instanceof BeforeFactory;
+      return factory.getType();
    }
    
-   public boolean isAfter()
-   {
-      return factory instanceof AfterFactory;
-   }
-   
-   public boolean isThrowing()
-   {
-      return factory instanceof ThrowingFactory;
-   }
-   
-   public boolean isAround()
-   {
-      return !isBefore() && !isAfter() && ! isThrowing(); 
-   }
-   
    public boolean isInterceptor()
    {
       if (factory instanceof AdviceFactory)
@@ -425,9 +410,9 @@
          {
             if (lazyInterceptor == null)
             {
-               if (factory instanceof GeneratedOnly)
+               if (factory.getType().isGeneratedOnly())
                {
-                  lazyInterceptor = new GeneratedOnlyInterceptor(factory.getName(), (GeneratedOnly)factory); 
+                  lazyInterceptor = new GeneratedOnlyInterceptor(factory.getName(), factory); 
                }
                else
                {
@@ -483,26 +468,26 @@
       if (adviceString == null)
       {
          StringBuffer buf = new StringBuffer();
-         if (isAround())
+         switch(getType())
          {
-            buf.append("R");
+            case AROUND:
+               buf.append("R");
+               break;
+            case BEFORE:
+               buf.append("B");
+               break;
+            case AFTER:
+               buf.append("A");
+               break;
+            case THROWING:
+               buf.append("T");
+               break;
+            case FINALLY:
+               buf.append("F");
+               break;
+            default:
+               throw new RuntimeException("No such interceptor");
          }
-         else if (isBefore())
-         {
-            buf.append("B");
-         }
-         else if (isAfter())
-         {
-            buf.append("A");
-         }
-         else if (isThrowing())
-         {
-            buf.append("T");
-         }
-         else 
-         {
-            throw new RuntimeException("No such interceptor");
-         }
          
          buf.append("~#$%");
          buf.append(getAspectClassName());
@@ -517,25 +502,13 @@
    private class GeneratedOnlyInterceptor implements Interceptor
    {
       String name;
-      String type;
       
-      GeneratedOnlyInterceptor(String name, GeneratedOnly factory)
+      GeneratedOnlyInterceptor(String name, InterceptorFactory factory)
       {
          this.name = name;
-
-         if (factory instanceof BeforeFactory)
-         {
-            type = "before";
-         }
-         else if (factory instanceof AfterFactory)
-         {
-            type = "after";
-         }
-         else if (factory instanceof ThrowingFactory)
-         {
-            type = "throwing";
-         }
-         System.out.println("[warn] " + type + " interceptor:s'" + name + "' is ignored for dynamic invocation. Adding null GeneratedOnlyInterceptor in its place");
+         System.out.println("[warn] " + factory.getType().getDescription() +
+               " interceptor:s'" + name +
+               "' is ignored for dynamic invocation. Adding null GeneratedOnlyInterceptor in its place");
       }
       
       public String getName()
@@ -548,4 +521,4 @@
          return invocation.invokeNext();
       }
    }
-}
+}
\ No newline at end of file

Deleted: projects/aop/trunk/aop/src/main/org/jboss/aop/advice/GeneratedOnly.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/advice/GeneratedOnly.java	2007-04-23 18:09:51 UTC (rev 62493)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/advice/GeneratedOnly.java	2007-04-23 20:23:57 UTC (rev 62494)
@@ -1,32 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt 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.aop.advice;
-
-/**
- * 
- * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
- * @version $Revision$
- */
-public interface GeneratedOnly
-{
-
-}

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/advice/GenericInterceptorFactory.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/advice/GenericInterceptorFactory.java	2007-04-23 18:09:51 UTC (rev 62493)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/advice/GenericInterceptorFactory.java	2007-04-23 20:23:57 UTC (rev 62494)
@@ -105,5 +105,9 @@
       
       return true;
    }
-}
 
+   public AdviceType getType()
+   {
+      return AdviceType.AROUND;
+   }
+}
\ No newline at end of file

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/advice/InterceptorFactory.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/advice/InterceptorFactory.java	2007-04-23 18:09:51 UTC (rev 62493)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/advice/InterceptorFactory.java	2007-04-23 20:23:57 UTC (rev 62494)
@@ -30,9 +30,43 @@
  */
 public interface InterceptorFactory
 {
+   /**
+    * Returns the aspect definition, a record of the class that contains
+    * the interceptor method.
+    */
    public AspectDefinition getAspect();
+   
+   /**
+    * Returns the advice method name.
+    */
    public String getAdvice();
+   
+   /**
+    * Creates an interceptor that represents this advice and that delegates
+    * execution to this advice.
+    * 
+    * @param advisor   advisor, indicates an instance or class where the interception
+    *                  will occur
+    * @param joinpoint the joinpoint that will be intercepted
+    * @return          an interceptor. Notice this can be an instance of the aspect
+    *                  class itself, if this class is an interceptor.
+    */
    public Interceptor create(Advisor advisor, Joinpoint joinpoint);
+   
+   /**
+    * Indicates whether this interceptor/advice is deployed.
+    */
    public boolean isDeployed();
+   
+   /**
+    * Returns the name that identifies this interceptor/advice.
+    * 
+    * @return
+    */
    public String getName();
-}
+   
+   /**
+    * Returns the type of this advice.
+    */
+   public AdviceType getType();   
+}
\ No newline at end of file

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/advice/ScopedInterceptorFactory.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/advice/ScopedInterceptorFactory.java	2007-04-23 18:09:51 UTC (rev 62493)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/advice/ScopedInterceptorFactory.java	2007-04-23 20:23:57 UTC (rev 62494)
@@ -53,6 +53,11 @@
    {
       return "invoke";
    }
+   
+   public AdviceType getType()
+   {
+      return AdviceType.AROUND;
+   }
 
    public boolean isDeployed()
    {

Deleted: projects/aop/trunk/aop/src/main/org/jboss/aop/advice/ThrowingFactory.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/advice/ThrowingFactory.java	2007-04-23 18:09:51 UTC (rev 62493)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/advice/ThrowingFactory.java	2007-04-23 20:23:57 UTC (rev 62494)
@@ -1,37 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt 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.aop.advice;
-
-/**
- * 
- * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
- * @version $Revision$
- */
-public class ThrowingFactory extends AdviceFactory implements GeneratedOnly
-{
-
-   public ThrowingFactory(AspectDefinition aspect, String adviceName)
-   {
-      super(aspect, adviceName);
-   }
-
-}

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/AdviceMethodFactory.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/AdviceMethodFactory.java	2007-04-23 18:09:51 UTC (rev 62493)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/AdviceMethodFactory.java	2007-04-23 20:23:57 UTC (rev 62494)
@@ -68,8 +68,15 @@
     */
    public static final AdviceMethodFactory THROWING = new AdviceMethodFactory (null,
          new ParameterAnnotationRule[]{ParameterAnnotationRule.JOIN_POINT,
-         ParameterAnnotationRule.THROWABLE}, ReturnType.VOID, null);
+         ParameterAnnotationRule.THROWN}, ReturnType.VOID, null);
    /**
+    * Factory that selects advice methods for <i>finally</i> interception.
+    */
+   public static final AdviceMethodFactory FINALLY = new AdviceMethodFactory (null,
+         new ParameterAnnotationRule[]{ParameterAnnotationRule.JOIN_POINT,
+         ParameterAnnotationRule.THROWN, ParameterAnnotationRule.RETURN},
+         ReturnType.VOID, new int[][]{{2, 1}});
+   /**
     * Factory that selects advice methods for <i>aroung</i> interception.
     */
    public static final AdviceMethodFactory AROUND = new AdviceMethodFactory (
@@ -210,7 +217,7 @@
    private ReturnType returnType;
    private AdviceSignatureRule adviceSignatureRule;
    private ParameterAnnotationRule[] rules;
-   private int[][] implication;
+   private int[][] compulsory;
    
    
    /**
@@ -222,16 +229,19 @@
     *                            this factory on the advice method matching.
     * @param returnType          indicates whether the queried advice methods can return
     *                            a value to overwrite the join point execution result.
+    * @param compulsory          a list of the annotated parameters whose use is
+    *                            compulsory only if the precondition annotation is
+    *                            present among the annotated parameters.
     */
    private AdviceMethodFactory(AdviceSignatureRule adviceSignatureRule,
-         ParameterAnnotationRule[] rules, ReturnType returnType, int[][] implication)
+         ParameterAnnotationRule[] rules, ReturnType returnType, int[][] compulsory)
    {
       this.adviceSignatureRule = adviceSignatureRule;
       this.rules = rules;
       this.returnType = returnType;
       this.adviceInfoCache = new HashMap
          <String, WeakHashMap<ParameterAnnotationRule[], Collection<AdviceInfo>>>();
-      this.implication = implication;
+      this.compulsory = compulsory;
    }
    
    /**
@@ -243,6 +253,7 @@
     */
    public final AdviceMethodProperties findAdviceMethod(AdviceMethodProperties properties)
    {
+      System.out.println(">>>FINDING ADVICE " + properties.getAdviceName());
       if (AspectManager.verbose)
       {
          adviceMatchingMessage = new StringBuffer();
@@ -379,7 +390,7 @@
                   // advice applies to annotated parameter rules
                   rankedAdvices.add(new AnnotatedParameterAdviceInfo(properties,
                         methods[i], rules, contextRules, mutuallyExclusive,
-                        implication));
+                        compulsory));
                }catch (ParameterAnnotationRuleException pare)
                {
                   // no need to print messages -> 

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/AnnotatedParameterAdviceInfo.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/AnnotatedParameterAdviceInfo.java	2007-04-23 18:09:51 UTC (rev 62493)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/AnnotatedParameterAdviceInfo.java	2007-04-23 20:23:57 UTC (rev 62494)
@@ -21,9 +21,11 @@
    private ParameterAnnotationType contextParamTypes[];
    // muttually exclusive context parameter rules
    private int[][] mutuallyExclusive;
+   // compusloriness rules: for each subarray, the first element is the precondition;
+   // the following elements are the annotations whose use is compulsory given
+   // that precondition is present among the annotated parameters
+   private int[][] compulsory;
    
-   private int[][] implication;
-   
    /**
     * Creates an annotated parameter advice info.
     * 
@@ -34,6 +36,9 @@
     *                          comply with
     * @param contextRules      second priority rules this method should comply with
     * @param mutuallyExclusive a list of mutually exclusive context parameter rules
+    * @param compulsory        a list of the annotated parameters whose use is
+    *                          compulsory only if the precondition annotation is
+    *                          present among the annotated parameters.
     * 
     * @throws ParameterAnnotationRuleException thrown when the advice method does not
     *         comply with a parameter annotation rule.
@@ -41,14 +46,14 @@
    public AnnotatedParameterAdviceInfo(AdviceMethodProperties properties,
          Method method, ParameterAnnotationRule[] rules,
          ParameterAnnotationRule[] contextRules, int[][] mutuallyExclusive,
-         int[][] implication)
+         int[][] compulsory)
       throws ParameterAnnotationRuleException
    {
       super(method, 0);
       this.paramTypes = createParameterAnnotationTypes(rules);
       this.contextParamTypes = createParameterAnnotationTypes(contextRules);
       this.mutuallyExclusive = mutuallyExclusive;
-      this.implication = implication;
+      this.compulsory = compulsory;
       this.applyRules(properties);
    }
       
@@ -119,23 +124,24 @@
          }
       }
       
-      if (implication != null)
+      if (compulsory != null)
       {
-    	  for (int i = 0; i < implication.length; i++)
+    	  for (int i = 0; i < compulsory.length; i++)
     	  {
-    		  ParameterAnnotationType implicator = paramTypes[implication[i][0]];
-    		  if (implicator.isSet())
+    		  ParameterAnnotationType precondition = paramTypes[compulsory[i][0]];
+    		  if (precondition.isSet())
     		  {
-    			  for (int j = 1; j < implication[i].length; j++)
+    			  for (int j = 1; j < compulsory[i].length; j++)
     			  {
-    				  if (!paramTypes[implication[i][j]].isSet())
+    				  if (!paramTypes[compulsory[i][j]].isSet())
     				  {
     					  if (AspectManager.verbose)
     	                  {
-    	                     AdviceMethodFactory.adviceMatchingMessage.append("\n[warn] - the use of parameter annotation ");
-    	                     AdviceMethodFactory.adviceMatchingMessage.append(paramTypes[implication[i][0]].rule.getAnnotation());
-    	                     AdviceMethodFactory.adviceMatchingMessage.append(" implies in the mandatory use of parameter annotation ");
-    	                     AdviceMethodFactory.adviceMatchingMessage.append(paramTypes[implication[i][j]].rule.getAnnotation());
+    	                     AdviceMethodFactory.adviceMatchingMessage.append("\n[warn] - if parameter annotation ");
+    	                     AdviceMethodFactory.adviceMatchingMessage.append(precondition.rule.getAnnotation());
+    	                     AdviceMethodFactory.adviceMatchingMessage.append(" is used, the use of parameter annotation ");
+    	                     AdviceMethodFactory.adviceMatchingMessage.append(paramTypes[compulsory[i][j]].rule.getAnnotation());
+                             AdviceMethodFactory.adviceMatchingMessage.append(" is compulsory");
     	                  }
     	                  return false;
     				  }

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/ParameterAnnotationRule.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/ParameterAnnotationRule.java	2007-04-23 18:09:51 UTC (rev 62493)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/ParameterAnnotationRule.java	2007-04-23 20:23:57 UTC (rev 62494)
@@ -76,7 +76,7 @@
    /**
     * Rule for parameter annotation {@link Thrown}.
     */
-   THROWABLE (
+   THROWN (
          Thrown.class, Throwable.class, AdviceMethodProperties.THROWABLE_ARG, 50, true,
          true),
    

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/JoinPointGenerator.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/JoinPointGenerator.java	2007-04-23 18:09:51 UTC (rev 62493)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/JoinPointGenerator.java	2007-04-23 20:23:57 UTC (rev 62494)
@@ -21,7 +21,6 @@
   */
 package org.jboss.aop.instrument;
 
-import java.lang.ref.WeakReference;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Field;
 import java.security.AccessController;
@@ -46,11 +45,11 @@
 
 import org.jboss.aop.AspectManager;
 import org.jboss.aop.CallerConstructorInfo;
-import org.jboss.aop.ConByConInfo;
 import org.jboss.aop.GeneratedClassAdvisor;
 import org.jboss.aop.InstanceAdvisor;
 import org.jboss.aop.JoinPointInfo;
 import org.jboss.aop.advice.AdviceMethodProperties;
+import org.jboss.aop.advice.AdviceType;
 import org.jboss.aop.advice.GeneratedAdvisorInterceptor;
 import org.jboss.aop.advice.Scope;
 import org.jboss.aop.advice.annotation.AdviceMethodFactory;
@@ -59,7 +58,6 @@
 import org.jboss.aop.pointcut.ast.ClassExpression;
 import org.jboss.aop.util.JavassistUtils;
 import org.jboss.aop.util.ReflectToJavassist;
-import org.jboss.util.collection.temp.WeakValueHashMap;
 
 /**
  * Creates the Joinpoint invocation replacement classes used with Generated advisors
@@ -82,6 +80,7 @@
    public static final String JOINPOINT_CLASS_PREFIX = "JoinPoint_";
    private static final String RETURN_VALUE = "ret";
    private static final String THROWABLE = "t";
+   private static final String THROWABLE_FOR_FINALLY = "throwableForFinally";
    protected static final String ARGUMENTS= "arguments";
    private static final String GET_ARGUMENTS= OptimizedBehaviourInvocations.GET_ARGUMENTS + "()";
    protected static final CtClass[] EMPTY_CTCLASS_ARRAY = new CtClass[0];
@@ -97,13 +96,15 @@
    private String joinpointFqn;
    private Field joinpointField;
    private boolean initialised;
+   
    private ThreadLocal<Set<Integer>> inconsistentTypeArgs;
    
    /**
     * A cache of the generated joinpoint classes indexed by the interceptor chains for the info to 
     * avoid having to generate a new class on every single rebind
     */
-   private HashMap generatedJoinPointClassCache = new HashMap();
+   private HashMap<String, GeneratedClassInfo> generatedJoinPointClassCache =
+      new HashMap<String, GeneratedClassInfo>();
    
    protected JoinPointGenerator(GeneratedClassAdvisor advisor, JoinPointInfo info,
          JoinPointParameters parameters, int argumentsSize)
@@ -209,6 +210,8 @@
     */
    private void doGenerateJoinPointClass(ClassLoader classloader, JoinPointInfo info)
    {
+      
+      System.out.println("GENERATING JOINPOINT CLASS " + info);
       try
       {
          if (classloader  == null)
@@ -318,7 +321,7 @@
          clazz.setSuperclass(superClass);
          addUntransformableInterface(pool, clazz);
   
-         AdviceSetupsByType setups = initialiseAdviceInfosAndAddFields(pool, clazz, newInfo);
+         AdviceSetups setups = initialiseAdviceInfosAndAddFields(pool, clazz, newInfo);
          
          createConstructors(pool, superClass, clazz, setups);
          createJoinPointInvokeMethod(
@@ -328,10 +331,10 @@
                setups,
                newInfo);
   
-         createInvokeNextMethod(clazz, isVoid(), setups.getAroundSetups(), newInfo);
+         createInvokeNextMethod(clazz, isVoid(), setups, newInfo);
   
          overrideDispatchMethods(superClass, clazz, newInfo);
-         return new GeneratedClassInfo(clazz, setups.getAroundSetups());
+         return new GeneratedClassInfo(clazz, setups);
       }
       catch (NotFoundException e)
       {
@@ -417,7 +420,7 @@
       }
    }
 
-   private AdviceSetupsByType initialiseAdviceInfosAndAddFields(ClassPool pool, CtClass clazz, JoinPointInfo info) throws ClassNotFoundException, NotFoundException, CannotCompileException
+   private AdviceSetups initialiseAdviceInfosAndAddFields(ClassPool pool, CtClass clazz, JoinPointInfo info) throws ClassNotFoundException, NotFoundException, CannotCompileException
    {
       HashMap<String, Integer> cflows = new HashMap<String, Integer>();
       AdviceSetup[] setups = new AdviceSetup[info.getInterceptors().length];
@@ -429,7 +432,7 @@
          addCFlowFieldsAndGetters(pool, setups[i], clazz, cflows);
       }
    
-      return new AdviceSetupsByType(info, setups);
+      return new AdviceSetups(info, setups);
    }
    
    private void addAspectFieldAndGetter(ClassPool pool, CtClass clazz, AdviceSetup setup) throws NotFoundException, CannotCompileException
@@ -529,7 +532,7 @@
       }
    }
    
-   private void createJoinPointInvokeMethod(CtClass superClass, CtClass clazz, boolean isVoid, AdviceSetupsByType setups, JoinPointInfo info) throws CannotCompileException, NotFoundException
+   private void createJoinPointInvokeMethod(CtClass superClass, CtClass clazz, boolean isVoid, AdviceSetups setups, JoinPointInfo info) throws CannotCompileException, NotFoundException
    {
       CtMethod superInvoke = superClass.getDeclaredMethod(INVOKE_JOINPOINT);
       String code = null;
@@ -555,10 +558,14 @@
    }
    
    private String createJoinpointInvokeBody(CtClass joinpointClass,
-         AdviceSetupsByType setups, CtClass[] declaredExceptions, CtClass[] parameterTypes, JoinPointInfo info)throws NotFoundException
+         AdviceSetups setups, CtClass[] declaredExceptions, CtClass[] parameterTypes, JoinPointInfo info)throws NotFoundException
    {
+      AdviceCallStrategy defaultCall = DefaultAdviceCallStrategy.getInstance();
+      AdviceCallStrategy afterCall = AfterAdviceCallStrategy.getInstance();
+      
       StringBuffer code = new StringBuffer();
       code.append("{");
+
       if (!isVoid())
       {
          String ret = null;
@@ -576,10 +583,15 @@
          }
          code.append("   " + ClassExpression.simpleType(getReturnType()) + "  " + RETURN_VALUE + " = " + ret + ";");
       }
+      
+      // declare the throwable in an outer variable (this is needed for finally)
+      code.append("Throwable ").append(THROWABLE).append(" = null;");
+      
+      
       code.append("   try");
       code.append("   {");
-      boolean argsFoundBefore = DefaultAdviceCallStrategy.getInstance().
-         addInvokeCode(this, setups.getBeforeSetups(), code, info);
+      boolean argsFoundBefore = defaultCall.
+         addInvokeCode(this, setups.getByType(AdviceType.BEFORE), code, info);
       
       // add around according to whether @Args were found before
       boolean joinPointCreated = addAroundInvokeCode(code, setups, joinpointClass,
@@ -587,14 +599,28 @@
       
       // generate after code
       StringBuffer afterCode = new StringBuffer();
-      boolean argsFoundAfter = AfterAdviceCallStrategy.getInstance().addInvokeCode(
-            this, setups.getAfterSetups(), afterCode, info);
+      boolean argsFoundAfter = afterCall.addInvokeCode(this,
+            setups.getByType(AdviceType.AFTER), afterCode, info);
       afterCode.append("   }");
-      afterCode.append("   catch(java.lang.Throwable " + THROWABLE + ")");
+      afterCode.append("   catch(java.lang.Throwable throwable)");
       afterCode.append("   {");
-      argsFoundAfter = DefaultAdviceCallStrategy.getInstance().addInvokeCode(this,
-            setups.getThrowingSetups(), afterCode, info) || argsFoundAfter;
+      // store throwable in THROWABLE variable
+      afterCode.append(THROWABLE).append(" = ").append("throwable;");
+      argsFoundAfter = defaultCall.addInvokeCode(this,
+            setups.getByType(AdviceType.THROWING), afterCode, info) || argsFoundAfter;
       
+      addHandleExceptionCode(afterCode, declaredExceptions);
+      afterCode.append("   }");
+      
+      AdviceSetup[] finallySetups = setups.getByType(AdviceType.FINALLY);
+      if (finallySetups!= null && finallySetups.length > 0)
+      {
+         afterCode.append("   finally {");
+         argsFoundAfter = afterCall.addInvokeCode(this, finallySetups, afterCode,
+               info) || argsFoundAfter;
+         afterCode.append("}");
+      }
+      
       // if joinpoint has been created for around,
       // need to update arguments variable when this variable is used,
       // which happens in one of both cases
@@ -603,7 +629,6 @@
       //   to update the variable value according to what is contained in joinpoint)
       if (joinPointCreated &&  (argsFoundAfter ||
             inconsistentTypeArgs.get().size() < joinPointArguments.size()))
-         // TODO ((argsFoundAfter || argsFoundBefore) && joinPointCreated) ||
       {
          code.append(ARGUMENTS);
          code.append(" = jp.").append(GET_ARGUMENTS).append(";");
@@ -612,14 +637,12 @@
       
       // add after code
       code.append(afterCode.toString());
-      // finish code body
-      addHandleExceptionCode(code, declaredExceptions);
-      code.append("   }");
+      
       if (!isVoid())
       {
          code.append("   return " + RETURN_VALUE + ";");
       }
-      code.append("}");;
+      code.append("}");
       
       // declare arguments array if necessary
       if (argsFoundBefore || argsFoundAfter)
@@ -629,11 +652,11 @@
       return code.toString();
    }
 
-   private boolean addAroundInvokeCode(StringBuffer code, AdviceSetupsByType setups,
+   private boolean addAroundInvokeCode(StringBuffer code, AdviceSetups setups,
          CtClass joinpointClass, boolean argsFoundBefore, CtClass[] parameterTypes)
    throws NotFoundException
    {
-      if (setups.getAroundSetups() != null)
+      if (setups.getByType(AdviceType.AROUND) != null)
       {
          StringBuffer aspects = new StringBuffer();
          StringBuffer cflows = new StringBuffer();
@@ -737,8 +760,9 @@
       code.append("throw new java.lang.RuntimeException(t);");
    }
 
-   private void createInvokeNextMethod(CtClass jp, boolean isVoid, AdviceSetup[] aroundSetups, JoinPointInfo info) throws NotFoundException, CannotCompileException
+   private void createInvokeNextMethod(CtClass jp, boolean isVoid, AdviceSetups setups, JoinPointInfo info) throws NotFoundException, CannotCompileException
    {
+      AdviceSetup[] aroundSetups = setups.getByType(AdviceType.AROUND);
       if (aroundSetups == null) return;
       
       CtMethod method = jp.getSuperclass().getSuperclass().getDeclaredMethod("invokeNext");
@@ -779,7 +803,7 @@
       return body.toString();
    }
    
-   private void createConstructors(ClassPool pool, CtClass superClass, CtClass clazz, AdviceSetupsByType setups) throws NotFoundException, CannotCompileException
+   private void createConstructors(ClassPool pool, CtClass superClass, CtClass clazz, AdviceSetups setups) throws NotFoundException, CannotCompileException
    {
       CtConstructor[] superCtors = superClass.getDeclaredConstructors();
       if (superCtors.length != 3 && superCtors.length != 2 && !this.getClass().equals(MethodJoinPointGenerator.class)
@@ -853,7 +877,7 @@
     * This is the constructor that will be called by the GeneratedClassAdvisor, make sure it
     * initialises all the non-per-instance aspects
     */
-   private void createPublicConstructor(CtConstructor superCtor, CtClass clazz, AdviceSetupsByType setups)throws CannotCompileException, NotFoundException
+   private void createPublicConstructor(CtConstructor superCtor, CtClass clazz, AdviceSetups setups)throws CannotCompileException, NotFoundException
    {
       StringBuffer body = new StringBuffer();
       try
@@ -888,7 +912,7 @@
     * make sure it copies across all the non-per-instance aspects
     */
    private void createProtectedConstructors(ClassPool pool, CtConstructor superCtor1,
-         CtConstructor superCtor2, CtClass clazz, AdviceSetupsByType setups)
+         CtConstructor superCtor2, CtClass clazz, AdviceSetups setups)
          throws CannotCompileException, NotFoundException
    {
       
@@ -1147,9 +1171,8 @@
       String cflowString;
       ASTCFlowExpression cflowExpr;
       int cflowIndex;
-      boolean isBefore;
-      boolean isAfter;
-      boolean isThrowing;
+      AdviceType type;
+      
       AdviceMethodProperties adviceMethodProperties;
       
       AdviceSetup(int index, GeneratedAdvisorInterceptor ifw, JoinPointInfo info) throws ClassNotFoundException, NotFoundException
@@ -1171,9 +1194,7 @@
          }
          aspectCtClass = ReflectToJavassist.classToJavassist(aspectClass);
 
-         isBefore = ifw.isBefore();
-         isAfter = ifw.isAfter();
-         isThrowing = ifw.isThrowing();
+         type = ifw.getType();
       }
       
       String getAdviceName()
@@ -1210,26 +1231,7 @@
       String getAspectFieldName()
       {
          StringBuffer name = new StringBuffer();
-         if (isAround())
-         {
-            name.append("around");
-         }
-         else if (isBefore())
-         {
-            name.append("before");
-         }
-         else if (isAfter())
-         {
-            name.append("after");
-         }
-         else if (isThrowing())
-         {
-            name.append("throwing");
-         }
-         else
-         {
-            if (AspectManager.verbose) System.out.println("[warn] Unsupported type of advice");
-         }
+         name.append(type.getDescription());
          name.append(index + 1);
          return name.toString();
       }
@@ -1237,26 +1239,7 @@
       String getAspectInitialiserName()
       {
          StringBuffer name = new StringBuffer();
-         if (isAround())
-         {
-            name.append("getAround");
-         }
-         else if (isBefore())
-         {
-            name.append("getBefore");
-         }
-         else if (isAfter())
-         {
-            name.append("getAfter");
-         }
-         else if (isThrowing())
-         {
-            name.append("getThrowing");
-         }
-         else
-         {
-            if (AspectManager.verbose) System.out.println("[warn] Unsupported type of advice");
-         }
+         name.append(type.getAccessor());
          name.append(index + 1);
          return name.toString();
       }
@@ -1306,26 +1289,11 @@
          return (getCFlowString() != null && index == cflowIndex);
       }
 
-      boolean isAfter()
+      public AdviceType getType()
       {
-         return isAfter;
+         return this.type;
       }
 
-      boolean isBefore()
-      {
-         return isBefore;
-      }
-
-      boolean isThrowing()
-      {
-         return isThrowing;
-      }
-      
-      boolean isAround()
-      {
-         return !isAfter && !isBefore && !isThrowing;
-      }
-
       public AdviceMethodProperties getAdviceMethodProperties()
       {
          return adviceMethodProperties;
@@ -1342,10 +1310,10 @@
       CtClass generated;
       AdviceSetup[] aroundSetups;
       
-      GeneratedClassInfo(CtClass generated, AdviceSetup[] aroundSetups)
+      GeneratedClassInfo(CtClass generated, AdviceSetups setups)
       {
          this.generated = generated;
-         this.aroundSetups = aroundSetups;
+         this.aroundSetups = setups.getByType(AdviceType.AROUND);
       }
       
       CtClass getGenerated()
@@ -1359,108 +1327,62 @@
       }
    }
    
-   private class AdviceSetupsByType
+   private class AdviceSetups
    {
-      AdviceSetup[] allSetups; 
-      AdviceSetup[] beforeSetups;
-      AdviceSetup[] afterSetups;
-      AdviceSetup[] throwingSetups;
-      AdviceSetup[] aroundSetups;
-
-      AdviceSetupsByType(JoinPointInfo info, AdviceSetup[] setups)
+      AdviceSetup[] allSetups;
+      AdviceSetup[][] setups;
+      
+      AdviceSetups(JoinPointInfo info, AdviceSetup[] allSetups)
       {
-         allSetups = setups;
-         ArrayList<AdviceSetup> beforeAspects = null;
-         ArrayList<AdviceSetup> afterAspects = null;
-         ArrayList<AdviceSetup> throwingAspects = null;
-         ArrayList<AdviceSetup> aroundAspects = null;
-
-         for (int i = 0 ; i < setups.length ; i++)
+         this.allSetups = allSetups;
+         int length = AdviceType.values().length;
+         ArrayList<AdviceSetup>[] aspects = (ArrayList<AdviceSetup>[]) new ArrayList<?>[length];
+         for (int i = 0 ; i < allSetups.length ; i++)
          {
-            if (setups[i].isBefore())
+            
+            AdviceMethodProperties properties = getAdviceMethodProperties(info, allSetups[i]);
+            AdviceType type = allSetups[i].getType();
+            int index = type.ordinal();
+            if (aspects[index] == null)
             {
-               if (beforeAspects == null) beforeAspects = new ArrayList<AdviceSetup>();
-               
-               AdviceMethodProperties properties = AdviceMethodFactory.BEFORE.findAdviceMethod(getAdviceMethodProperties(info, setups[i]));
-               if (properties != null)
-               {
-                  setups[i].setAdviceMethodProperties(properties);
-                  beforeAspects.add(setups[i]);
-                  continue;
-               }
+               aspects[index] = new ArrayList<AdviceSetup>();
             }
-            else if (setups[i].isAfter())
-            {
-               if (afterAspects == null) afterAspects = new ArrayList<AdviceSetup>();
-               AdviceMethodProperties properties = AdviceMethodFactory.AFTER.findAdviceMethod(getAdviceMethodProperties(info, setups[i]));
-               if (properties != null)
-               {
-                  setups[i].setAdviceMethodProperties(properties);
-                  afterAspects.add(setups[i]);
-                  continue;
-               }
-            }
-            else if (setups[i].isThrowing())
-            {
-               if (throwingAspects == null) throwingAspects = new ArrayList<AdviceSetup>();
-               AdviceMethodProperties properties = AdviceMethodFactory.THROWING.findAdviceMethod(getAdviceMethodProperties(info, setups[i]));
-               if (properties != null)
-               {
-                  setups[i].setAdviceMethodProperties(properties);
-                  throwingAspects.add(setups[i]);
-                  continue;
-               }
-            }
-            else
-            {
-               if (aroundAspects == null) aroundAspects = new ArrayList<AdviceSetup>();
-               AdviceMethodProperties properties = AdviceMethodFactory.AROUND.findAdviceMethod(getAdviceMethodProperties(info, setups[i]));
-               if (properties != null)
-               {
-                  setups[i].setAdviceMethodProperties(properties);
-                  aroundAspects.add(setups[i]);
-                  continue;
-               }
-            }
             
-            if (AspectManager.verbose)
+            properties = type.getFactory().findAdviceMethod(properties);
+            if (properties != null)
             {
-               System.out.print("[warn] No matching advice called '" + setups[i].getAdviceName() + 
-                     "' could be found in " + setups[i].getAspectClass().getName() +
-                     " for joinpoint " + info + ":");
-               System.out.println(AdviceMethodFactory.getAdviceMatchingMessage());
+               allSetups[i].setAdviceMethodProperties(properties);
+               aspects[index].add(allSetups[i]);
             }
          }
-         beforeSetups = (beforeAspects == null) ? null : (AdviceSetup[])beforeAspects.toArray(new AdviceSetup[beforeAspects.size()]);
-         afterSetups = (afterAspects == null) ? null : (AdviceSetup[])afterAspects.toArray(new AdviceSetup[afterAspects.size()]);
-         throwingSetups = (throwingAspects == null) ? null : (AdviceSetup[])throwingAspects.toArray(new AdviceSetup[throwingAspects.size()]);
-         aroundSetups = (aroundAspects == null) ? null : (AdviceSetup[])aroundAspects.toArray(new AdviceSetup[aroundAspects.size()]);
+         
+         this.setups = new AdviceSetup[length][];
+         for (int i = 0; i < length; i++)
+         {
+            this.setups[i] = (aspects[i] == null)? null: (AdviceSetup[])
+                  aspects[i].toArray(new AdviceSetup[aspects[i].size()]);
+         }
       }
 
+      /**
+       * Returns the list of all advice setups, regardless of the advice type.
+       */
       public AdviceSetup[] getAllSetups()
       {
          return allSetups;
       }
       
-      public AdviceSetup[] getAfterSetups()
+      /**
+       * Returns the setups list corresponding to the advice type.
+       * 
+       * @param type the advice type
+       * 
+       * @return an array of <code>AdviceSetup</code> instances.
+       */
+      public AdviceSetup[] getByType(AdviceType type)
       {
-         return afterSetups;
+         return this.setups[type.ordinal()];
       }
-
-      public AdviceSetup[] getAroundSetups()
-      {
-         return aroundSetups;
-      }
-
-      public AdviceSetup[] getBeforeSetups()
-      {
-         return beforeSetups;
-      }
-
-      public AdviceSetup[] getThrowingSetups()
-      {
-         return throwingSetups;
-      }
    }
 
    private interface GenerateJoinPointClassAction
@@ -1532,8 +1454,7 @@
            StringBuffer beforeCall, StringBuffer call, JoinPointGenerator generator, JoinPointInfo info) throws NotFoundException;
       
       private final boolean appendAdviceCall(AdviceSetup setup,
-            StringBuffer beforeCall, StringBuffer call,
-            boolean isAround, JoinPointGenerator generator) 
+            StringBuffer beforeCall, StringBuffer call, JoinPointGenerator generator) 
       {
          AdviceMethodProperties properties = setup.getAdviceMethodProperties();
          if (properties == null)
@@ -1634,85 +1555,6 @@
          }
          return false;
       }
-      
-//      private final boolean appendParameters(StringBuffer code, final int arg,
-//            final Class adviceParam, boolean isAround,
-//            AdviceMethodProperties properties, JoinPointGenerator generator)
-//      {
-//         code.append("(");
-//         // In case of overloaded methods javassist sometimes seems to pick up the wrong method - use explicit casts to get hold of the parameters
-//         code.append(ClassExpression.simpleType(adviceParam));
-//         code.append(")");
-//         switch(arg)
-//         {
-//         case AdviceMethodProperties.INVOCATION_ARG:
-//            code.append("this");
-//            break;
-//         case AdviceMethodProperties.JOINPOINT_ARG:
-//            code.append(INFO_FIELD);
-//            break;
-//         case AdviceMethodProperties.RETURN_ARG:
-//            code.append(RETURN_VALUE);
-//            break;
-//         case AdviceMethodProperties.THROWABLE_ARG:
-//            code.append(THROWABLE);
-//            break;
-//         case AdviceMethodProperties.TARGET_ARG:
-//            if (!generator.parameters.hasTarget())
-//            {
-//               code.append("null");
-//            }
-//            else if (isAround)
-//            {
-//               code.append(TARGET_FIELD);
-//            }
-//            else
-//            {
-//               code.append('$');
-//               code.append(generator.parameters.getTargetIndex());
-//            }
-//            break;
-//         case AdviceMethodProperties.CALLER_ARG:
-//            if (!generator.parameters.hasCaller())
-//            {
-//               code.append("null");
-//            }
-//            else if (isAround)
-//            {
-//               code.append(CALLER_FIELD);
-//            }
-//            else
-//            {
-//               code.append('$');
-//               code.append(generator.parameters.getCallerIndex());
-//            }
-//            break;
-//         case AdviceMethodProperties.ARGS_ARG:
-//            if (isAround)
-//            {
-//               code.append(GET_ARGUMENTS);
-//            }
-//            else
-//            {
-//               code.append(ARGUMENTS);
-//            }
-//            // return true when args has been found; false otherwise
-//            return true;
-//         default:
-//            if (isAround)
-//            {
-//               code.append("this.arg");
-//               code.append(arg);
-//            }
-//            else 
-//            {
-//               //The parameter array is 1-based, and the invokeJoinPoint method may also take the target and caller objects
-//               code.append("$");
-//               code.append(arg + generator.parameters.getFirstArgIndex());
-//            }
-//         }
-//         return false;
-//      }
    }
    
    private static class AroundAdviceCallStrategy extends AdviceCallStrategy
@@ -1811,8 +1653,7 @@
          call.append("   ");
          call.append(returnStr);
          call.append(" ");
-         boolean result = super.appendAdviceCall(setup, beforeCall, call, true,
-               generator);
+         boolean result = super.appendAdviceCall(setup, beforeCall, call, generator);
          
          if (!firstParamIsInvocation)
          {
@@ -1883,7 +1724,7 @@
       public boolean appendAdviceCall(AdviceSetup setup, String key,
             StringBuffer beforeCall, StringBuffer call, JoinPointGenerator generator, JoinPointInfo info)
       {
-         return super.appendAdviceCall(setup, beforeCall, call, false, generator);
+         return super.appendAdviceCall(setup, beforeCall, call, generator);
       }
    }
    
@@ -1916,7 +1757,7 @@
          {
             call.append(key);
          }
-         return super.appendAdviceCall(setup, beforeCall, call, false, generator);
+         return super.appendAdviceCall(setup, beforeCall, call, generator);
       }
    }
 
@@ -2097,6 +1938,5 @@
             code.append("]");
          }
       }
-   }
-   
-}
+   }  
+}
\ No newline at end of file




More information about the jboss-cvs-commits mailing list