[jboss-cvs] JBossAS SVN: r76040 - in projects/aop/branches/joinpoint_graph/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
Sun Jul 20 19:31:47 EDT 2008


Author: flavia.rainone at jboss.com
Date: 2008-07-20 19:31:45 -0400 (Sun, 20 Jul 2008)
New Revision: 76040

Added:
   projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/advice/CflowInterceptorChainFactory.java
   projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/advice/ClassicCflowInterceptorChainFactory.java
   projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/advice/ClassicInterceptorChainFactory.java
   projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/advice/GenadvisorCflowInterceptorChainFactory.java
   projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/advice/GenadvisorInterceptorChainFactory.java
   projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/advice/InterceptorChainFactory.java
Modified:
   projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/Advisor.java
   projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/ClassAdvisor.java
   projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/GeneratedClassAdvisor.java
   projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/MethodMatchInfo.java
   projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/ReflectiveAspectBinder.java
   projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/advice/AdviceBinding.java
   projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/instrument/InstrumentorEnum.java
   projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/instrument/InstrumentorFactory.java
   projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/standalone/XmlReport.java
Log:
[JBAOP-616] Created the interceptor chain factories, refactored advice binding (old methods were kept commented,
in case they need to be readded) and advisors.
Refactored InterceptorEnum so it now provides the interceptor chain factory instantes according to the
instrumentation mode.
Updated Xml Report, since now it cannot access internal data of AdviceBinding anymore.

Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/Advisor.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/Advisor.java	2008-07-20 23:01:45 UTC (rev 76039)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/Advisor.java	2008-07-20 23:31:45 UTC (rev 76040)
@@ -49,10 +49,7 @@
 
 import org.jboss.aop.advice.AdviceBinding;
 import org.jboss.aop.advice.AspectDefinition;
-import org.jboss.aop.advice.CFlowInterceptor;
 import org.jboss.aop.advice.Interceptor;
-import org.jboss.aop.advice.InterceptorFactory;
-import org.jboss.aop.advice.PrecedenceSorter;
 import org.jboss.aop.advice.Scope;
 import org.jboss.aop.annotation.AnnotationElement;
 import org.jboss.aop.annotation.AnnotationRepository;
@@ -60,7 +57,6 @@
 import org.jboss.aop.instrument.ConstructorExecutionTransformer;
 import org.jboss.aop.introduction.AnnotationIntroduction;
 import org.jboss.aop.introduction.InterfaceIntroduction;
-import org.jboss.aop.joinpoint.ConstructorJoinpoint;
 import org.jboss.aop.joinpoint.Invocation;
 import org.jboss.aop.joinpoint.InvocationResponse;
 import org.jboss.aop.joinpoint.Joinpoint;
@@ -1045,19 +1041,6 @@
       }
    }
 
-
-   protected void createInterceptorChain(InterceptorFactory[] factories, ArrayList<Interceptor> newinterceptors, Joinpoint joinpoint)
-   {
-      for (int i = 0; i < factories.length; i++)
-      {
-         if (factories[i].getType().isGeneratedOnly())
-         {
-            throw new RuntimeException("Before/After/Throwing is only supported for Generated Advisors");
-         }
-         if (factories[i].isDeployed()) newinterceptors.add(factories[i].create(this, joinpoint));
-      }
-   }
-
    protected void resolveMethodPointcut(AdviceBinding binding)
    {
       long[] keys = methodInfos.keys();
@@ -1140,13 +1123,13 @@
          MethodMatchInfo matchInfo = methodInfos.getMatchInfo(keys[i]);
          matchInfo.populateBindings();
          MethodInfo info = matchInfo.getInfo();
-         ArrayList<Interceptor> list = info.getInterceptorChain();
+         /*ArrayList<Interceptor> list = info.getInterceptorChain();
          Interceptor[] interceptors = null;
          if (list.size() > 0)
          {
             interceptors = applyPrecedence(list.toArray(new Interceptor[list.size()]));
          }
-         info.setInterceptors(interceptors);
+         info.setInterceptors(interceptors);*/
          
          if (maintain)
          {
@@ -1276,7 +1259,7 @@
 
    protected void finalizeChain(JoinPointInfo[] infos)
    {
-      for (int i = 0; i < infos.length; i++)
+      /*for (int i = 0; i < infos.length; i++)
       {
          JoinPointInfo info = infos[i];
          ArrayList<Interceptor> list = info.getInterceptorChain();
@@ -1286,7 +1269,7 @@
           interceptors = applyPrecedence(list.toArray(new Interceptor[list.size()]));
          }
          info.setInterceptors(interceptors);
-      }
+      }*/
    }
    
    protected void lockWriteChain(JoinPointInfo[] infos)
@@ -1340,7 +1323,8 @@
             if (AspectManager.verbose) System.err.println("[debug] constructor matched binding: " + constructor);
             adviceBindings.add(binding);
             binding.addAdvisor(this);
-            pointcutResolved(constructorInfos[i], binding, new ConstructorJoinpoint(constructor));
+            //pointcutResolved(constructorInfos[i], binding, new ConstructorJoinpoint(constructor));
+            binding.pointcutResolved(constructorInfos[i], this.manager);
          }
       }
    }
@@ -1358,7 +1342,8 @@
                if (AspectManager.verbose) System.err.println("[debug] construction matched binding: " + constructor);
                adviceBindings.add(binding);
                binding.addAdvisor(this);
-               pointcutResolved(info, binding, new ConstructorJoinpoint(constructor));
+               //pointcutResolved(info, binding, new ConstructorJoinpoint(constructor));
+               binding.pointcutResolved(info, manager);
             }
          }
       }
@@ -1378,7 +1363,7 @@
     * Default implementation adds interceptorChain directly to the info.
     * GeneratedClassAdvisor overrides this
     */
-   protected void pointcutResolved(JoinPointInfo info, AdviceBinding binding, Joinpoint joinpoint)
+   /*protected void pointcutResolved(JoinPointInfo info, AdviceBinding binding, Joinpoint joinpoint)
    {
       ArrayList<Interceptor> curr = info.getInterceptorChain();
       if (binding.getCFlow() != null)
@@ -1392,12 +1377,12 @@
       {
          createInterceptorChain(binding.getInterceptorFactories(), curr, joinpoint);
       }
-   }
+   }*/
 
-   Interceptor[] applyPrecedence(Interceptor[] interceptors)
+   /*Interceptor[] applyPrecedence(Interceptor[] interceptors)
    {
       return PrecedenceSorter.applyPrecedence(interceptors, manager);
-   }
+   }*/
 
    /**
     * Whether the type of advisor supports matching on pointcut expression, where the method is defined in a superclass only,
@@ -1579,4 +1564,12 @@
          }
       }
    }
+   
+   /**
+    * Allows this advisor to perform any actions recquired when an info has its
+    * interceptor chain updated outside the advisor.
+    * 
+    * @param info the info whose interceptor chain has been updated
+    */
+   public void interceptorChainUpdated(JoinPointInfo info) {}
 }
\ No newline at end of file

Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/ClassAdvisor.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/ClassAdvisor.java	2008-07-20 23:01:45 UTC (rev 76039)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/ClassAdvisor.java	2008-07-20 23:31:45 UTC (rev 76040)
@@ -46,18 +46,14 @@
 import org.jboss.aop.instrument.MethodExecutionTransformer;
 import org.jboss.aop.introduction.InterfaceIntroduction;
 import org.jboss.aop.joinpoint.ConstructorCalledByConstructorInvocation;
-import org.jboss.aop.joinpoint.ConstructorCalledByConstructorJoinpoint;
 import org.jboss.aop.joinpoint.ConstructorCalledByMethodInvocation;
-import org.jboss.aop.joinpoint.ConstructorCalledByMethodJoinpoint;
 import org.jboss.aop.joinpoint.ConstructorInvocation;
 import org.jboss.aop.joinpoint.FieldJoinpoint;
 import org.jboss.aop.joinpoint.FieldReadInvocation;
 import org.jboss.aop.joinpoint.FieldWriteInvocation;
 import org.jboss.aop.joinpoint.Invocation;
 import org.jboss.aop.joinpoint.MethodCalledByConstructorInvocation;
-import org.jboss.aop.joinpoint.MethodCalledByConstructorJoinpoint;
 import org.jboss.aop.joinpoint.MethodCalledByMethodInvocation;
-import org.jboss.aop.joinpoint.MethodCalledByMethodJoinpoint;
 import org.jboss.aop.joinpoint.MethodInvocation;
 import org.jboss.aop.metadata.ClassMetaDataBinding;
 import org.jboss.aop.metadata.ClassMetaDataLoader;
@@ -439,7 +435,7 @@
             if (AspectManager.verbose) System.err.println("[debug] field matched " + ((write) ? "write" : "read") + " binding: " + field);
             adviceBindings.add(binding);
             binding.addAdvisor(this);
-            pointcutResolved(newFieldInfos[i], binding, new FieldJoinpoint(field));
+            binding.pointcutResolved(newFieldInfos[i], this.manager);
          }
       }
    }
@@ -792,7 +788,7 @@
       info.clear();
       for (AdviceBinding binding : bindings)
       {
-         pointcutResolved(info, binding, new ConstructorCalledByConstructorJoinpoint(info.getCallingConstructor(), info.getConstructor()));
+         binding.pointcutResolved(info, this.manager);
       }
       finalizeConCalledByConInterceptorChain(info);
    }
@@ -814,7 +810,8 @@
       info.clear();
       for (AdviceBinding binding : bindings)
       {
-         pointcutResolved(info, binding, new MethodCalledByConstructorJoinpoint(info.getCallingConstructor(), info.getMethod()));
+         binding.pointcutResolved(info, this.manager);
+               //new MethodCalledByConstructorJoinpoint(info.getCallingConstructor(), info.getMethod()));
       }
       finalizeMethodCalledByConInterceptorChain(info);
    }
@@ -2199,7 +2196,7 @@
          info.clear();
          for (AdviceBinding binding : bindings)
          {
-            pointcutResolved(info, binding, new MethodCalledByMethodJoinpoint(info.getCallingMethod(), info.getMethod()));
+            binding.pointcutResolved(info, manager);
          }
          finalizeMethodCalledByMethodInterceptorChain(info);
       }
@@ -2445,7 +2442,7 @@
          info.clear();
          for (AdviceBinding binding : bindings)
          {
-            pointcutResolved(info, binding, new ConstructorCalledByMethodJoinpoint(info.getCallingMethod(), info.getConstructor()));
+            binding.pointcutResolved(info, ClassAdvisor.this.manager);
          }
          finalizeConCalledByMethodInterceptorChain(info);
       }

Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/GeneratedClassAdvisor.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/GeneratedClassAdvisor.java	2008-07-20 23:01:45 UTC (rev 76039)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/GeneratedClassAdvisor.java	2008-07-20 23:31:45 UTC (rev 76040)
@@ -35,10 +35,7 @@
 
 import org.jboss.aop.advice.AdviceBinding;
 import org.jboss.aop.advice.AspectDefinition;
-import org.jboss.aop.advice.GeneratedAdvisorInterceptor;
 import org.jboss.aop.advice.Interceptor;
-import org.jboss.aop.advice.InterceptorFactory;
-import org.jboss.aop.advice.PrecedenceSorter;
 import org.jboss.aop.instrument.ConByConJoinPointGenerator;
 import org.jboss.aop.instrument.ConByMethodJoinPointGenerator;
 import org.jboss.aop.instrument.ConstructionJoinPointGenerator;
@@ -50,7 +47,6 @@
 import org.jboss.aop.instrument.MethodJoinPointGenerator;
 import org.jboss.aop.joinpoint.FieldJoinpoint;
 import org.jboss.aop.joinpoint.Joinpoint;
-import org.jboss.aop.joinpoint.MethodJoinpoint;
 import org.jboss.aop.pointcut.PointcutMethodMatch;
 import org.jboss.aop.util.UnmodifiableEmptyCollections;
 
@@ -229,7 +225,7 @@
       return copy;
    }
    
-   
+   @Override
    public void interceptorChainUpdated(JoinPointInfo info)
    {
       getJoinPointGenerator(info).rebindJoinpoint(info);
@@ -284,7 +280,7 @@
                   System.err.println("method matched binding " + binding.getPointcut().getExpr() + " " + method.toString());     
                }
                binding.addAdvisor(this);
-               pointcutResolved(info, binding, new MethodJoinpoint(method));
+               binding.pointcutResolved(info, this.manager);//new MethodJoinpoint(method));
             }
          }
       }      
@@ -795,43 +791,17 @@
    {
       return advisorStrategy.getJoinPointGenerator(info);
    }
-
-   /**
-    * Override default behaviour of when a pointcut is matched, populate the factories since this
-    * is what is needed for generating the optimized invocation method
-    */
-   @Override
-   protected void pointcutResolved(JoinPointInfo info, AdviceBinding binding, Joinpoint joinpoint)
-   {
-      ArrayList<Interceptor> curr = info.getInterceptorChain();
-      if (binding.getCFlow() != null)
-      {
-         InterceptorFactory[] factories = binding.getInterceptorFactories();
-         for (int i = 0 ; i < factories.length ; i++)
-         {
-            curr.add(new GeneratedAdvisorInterceptor(factories[i], this, joinpoint, binding.getCFlowString(), binding.getCFlow()));
-         }
-      }
-      else
-      {
-         InterceptorFactory[] factories = binding.getInterceptorFactories();
-         for (int i = 0 ; i < factories.length ; i++)
-         {
-            curr.add(new GeneratedAdvisorInterceptor(factories[i], this, joinpoint));
-         }
-      }
-   }
-
+   
    private void finalizeChainAndRebindJoinPoint(Map<Joinpoint, Interceptor[]> oldInfos, JoinPointInfo info, JoinPointGenerator generator, OldInfoMaps oldInfoMapInstance)
    {
-      ArrayList<Interceptor> list = info.getInterceptorChain();
+      /*ArrayList<Interceptor> list = info.getInterceptorChain();
       GeneratedAdvisorInterceptor[] factories = null;
       if (list.size() > 0)
       {
          factories = applyPrecedence(list.toArray(new GeneratedAdvisorInterceptor[list.size()]));
       }
       info.setInterceptors(factories);
-
+       */
       if (updateOldInfo(oldInfos, info, oldInfoMapInstance))
       {
          generator.rebindJoinpoint(info);
@@ -852,10 +822,10 @@
       return sb.toString();
    }
 
-   GeneratedAdvisorInterceptor[] applyPrecedence(GeneratedAdvisorInterceptor[] interceptors)
+   /*GeneratedAdvisorInterceptor[] applyPrecedence(GeneratedAdvisorInterceptor[] interceptors)
    {
       return PrecedenceSorter.applyPrecedence(interceptors, manager);
-   }
+   }*/
 
    /**
     * If this is an instance advisor, will check with parent class advisor if the aspect
@@ -1547,10 +1517,11 @@
    private class InstanceAdvisorStrategy implements AdvisorStrategy 
    {
       GeneratedClassAdvisor parent;
-      boolean needsRebuild = true;
+      boolean needsRebuild;
       
       public InstanceAdvisorStrategy(GeneratedClassAdvisor parent)
       {
+         this.needsRebuild = AspectManager.dynamicMatchingStrategy.requiresRebuild();
          this.parent = parent;
          GeneratedClassAdvisor.this.version = parent.version;         
       }
@@ -1570,6 +1541,7 @@
          {
             doRebuildForInstance();
             needsRebuild = false;
+            GeneratedClassAdvisor.this.version = parent.version;
          }
       }
       

Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/MethodMatchInfo.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/MethodMatchInfo.java	2008-07-20 23:01:45 UTC (rev 76039)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/MethodMatchInfo.java	2008-07-20 23:31:45 UTC (rev 76040)
@@ -24,7 +24,6 @@
 import java.util.ArrayList;
 
 import org.jboss.aop.advice.AdviceBinding;
-import org.jboss.aop.joinpoint.MethodJoinpoint;
 import org.jboss.aop.pointcut.PointcutMethodMatch;
 import org.jboss.aop.util.logging.AOPLogger;
 import org.jboss.logging.Logger;
@@ -114,7 +113,7 @@
       {
          AdviceBinding binding = bindings.get(i);
          PointcutMethodMatch match = pointcutMethodMatches.get(i);
-         if (AspectManager.verbose && logger.isDebugEnabled()) logger.debug(match.getMatchLevel() + " " + match.getMatchedClass().getName() + " " + binding.getPointcut().getExpr() + " : " + binding.getInterceptorFactories().length);
+         if (AspectManager.verbose && logger.isDebugEnabled()) logger.debug(match.getMatchLevel() + " " + match.getMatchedClass().getName() + " " + binding.getPointcut().getExpr() + " : " + binding.getInterceptorFactories().size());
          
          if (minMatchLevel > match.getMatchLevel() && !match.isInstanceOf())
          {
@@ -130,7 +129,7 @@
          
          if (match.isInstanceOf() || match.getMatchLevel() == minMatchLevel)
          {
-            if (AspectManager.verbose && logger.isDebugEnabled()) logger.debug(match.getMatchLevel() + " " + match.getMatchedClass().getName() + " " + binding.getPointcut().getExpr() + " : " + binding.getInterceptorFactories().length);
+            if (AspectManager.verbose && logger.isDebugEnabled()) logger.debug(match.getMatchLevel() + " " + match.getMatchedClass().getName() + " " + binding.getPointcut().getExpr() + " : " + binding.getInterceptorFactories().size());
             applyBinding(applicableBindings, binding);
          }
       }
@@ -140,7 +139,7 @@
    {
       applicableBindings.add(binding);
       binding.addAdvisor(advisor);
-      advisor.pointcutResolved(info, binding, new MethodJoinpoint(info.getMethod()));
+      binding.pointcutResolved(info, advisor.getManager());
    }
    
    public void clear()

Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/ReflectiveAspectBinder.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/ReflectiveAspectBinder.java	2008-07-20 23:01:45 UTC (rev 76039)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/ReflectiveAspectBinder.java	2008-07-20 23:31:45 UTC (rev 76040)
@@ -31,7 +31,7 @@
 import java.security.PrivilegedActionException;
 import java.security.PrivilegedExceptionAction;
 import java.util.ArrayList;
-import java.util.Arrays;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.LinkedHashSet;
@@ -56,9 +56,9 @@
  *
  * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
  */
-public class ReflectiveAspectBinder
+class ReflectiveAspectBinder
 {
-   protected Class<?> clazz;
+  protected Class<?> clazz;
    protected HashSet<AspectDefinition> aspects = new HashSet<AspectDefinition>();
    protected HashMap<Method, ArrayList<InterceptorFactory>> methodAdvices = new HashMap<Method, ArrayList<InterceptorFactory>>();
    protected HashMap<Constructor<?>, ArrayList<InterceptorFactory>> constructorAdvices = new HashMap<Constructor<?>, ArrayList<InterceptorFactory>>();
@@ -228,10 +228,11 @@
                advices = new ArrayList<InterceptorFactory>();
                methodAdvices.put(mi, advices);
             }
-            advices.addAll(Arrays.asList(binding.getInterceptorFactories()));
-            for (int i = 0; i < binding.getInterceptorFactories().length; i++)
+            Collection<InterceptorFactory> interceptorFactories = binding.getInterceptorFactories();
+            advices.addAll(interceptorFactories);
+            for (InterceptorFactory interceptorFactory: interceptorFactories)
             {
-               aspects.add(binding.getInterceptorFactories()[i].getAspect());
+               aspects.add(interceptorFactory.getAspect());
             }
          }
       }
@@ -249,10 +250,11 @@
                advices = new ArrayList<InterceptorFactory>();
                constructorAdvices.put(mi, advices);
             }
-            advices.addAll(Arrays.asList(binding.getInterceptorFactories()));
-            for (int i = 0; i < binding.getInterceptorFactories().length; i++)
+            Collection<InterceptorFactory> interceptorFactories = binding.getInterceptorFactories();
+            advices.addAll(interceptorFactories);
+            for (InterceptorFactory interceptorFactory: interceptorFactories)
             {
-               aspects.add(binding.getInterceptorFactories()[i].getAspect());
+               aspects.add(interceptorFactory.getAspect());
             }
          }
       }
@@ -270,10 +272,11 @@
                advices = new ArrayList<InterceptorFactory>();
                fieldReadAdvices.put(mi, advices);
             }
-            advices.addAll(Arrays.asList(binding.getInterceptorFactories()));
-            for (int i = 0; i < binding.getInterceptorFactories().length; i++)
+            Collection<InterceptorFactory> interceptorFactories = binding.getInterceptorFactories();
+            advices.addAll(interceptorFactories);
+            for (InterceptorFactory interceptorFactory: interceptorFactories)
             {
-               aspects.add(binding.getInterceptorFactories()[i].getAspect());
+               aspects.add(interceptorFactory.getAspect());
             }
          }
       }
@@ -291,10 +294,11 @@
                advices = new ArrayList<InterceptorFactory>();
                fieldWriteAdvices.put(mi, advices);
             }
-            advices.addAll(Arrays.asList(binding.getInterceptorFactories()));
-            for (int i = 0; i < binding.getInterceptorFactories().length; i++)
+            Collection<InterceptorFactory> interceptorFactories = binding.getInterceptorFactories();
+            advices.addAll(interceptorFactories);
+            for (InterceptorFactory interceptorFactory: interceptorFactories)
             {
-               aspects.add(binding.getInterceptorFactories()[i].getAspect());
+               aspects.add(interceptorFactory.getAspect());
             }
          }
       }

Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/advice/AdviceBinding.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/advice/AdviceBinding.java	2008-07-20 23:01:45 UTC (rev 76039)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/advice/AdviceBinding.java	2008-07-20 23:31:45 UTC (rev 76040)
@@ -22,15 +22,20 @@
 package org.jboss.aop.advice;
 
 import java.io.StringReader;
+import java.lang.ref.WeakReference;
 import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
+import java.util.Collection;
+import java.util.Iterator;
 import java.util.Map;
 import java.util.WeakHashMap;
+import java.util.Map.Entry;
 
 import org.jboss.aop.Advisor;
 import org.jboss.aop.AspectManager;
 import org.jboss.aop.Domain;
+import org.jboss.aop.JoinPointInfo;
+import org.jboss.aop.instrument.InstrumentorEnum;
+import org.jboss.aop.instrument.InstrumentorFactory;
 import org.jboss.aop.pointcut.Pointcut;
 import org.jboss.aop.pointcut.PointcutExpression;
 import org.jboss.aop.pointcut.ast.ASTCFlowExpression;
@@ -67,12 +72,12 @@
    /**
     * A control flow restriction (in its AST form). Can be {@code null}.
     */
-   protected ASTCFlowExpression cflow;
+   //protected ASTCFlowExpression cflow;
    
    /**
     * A control flow restriction (in its string form). Can be {@code null}
     */
-   protected String cflowString;
+   //protected String cflowString;
 
    // not list because of redundancy caused by successive calls of ClassAdvisor.rebuildInterceptors
    /**
@@ -83,9 +88,13 @@
    /**
     * The factories responsible for creating the bound interceptor instances.
     */
-   protected InterceptorFactory[] interceptorFactories = new InterceptorFactory[0];
+   //protected InterceptorFactory[] interceptorFactories = new InterceptorFactory[0];
 
+   private InterceptorChainFactory interceptorChainFactory;
    
+   private Map<JoinPointInfo, Collection<Interceptor>> createdInterceptors =
+      new WeakHashMap<JoinPointInfo, Collection<Interceptor>>();
+   
    public AdviceBinding() {}
 
    /**
@@ -106,11 +115,18 @@
    public AdviceBinding(String name, Pointcut p, ASTCFlowExpression cflow, String cflowString, InterceptorFactory[] factories) throws ParseException
    {
       this.name = name;
-      interceptorFactories = factories;
-      this.cflow = cflow;
-
-      pointcut = p;
-      this.cflowString = cflowString;
+      this.pointcut = p;
+      InstrumentorEnum instrumentor = InstrumentorFactory.getInstrumentor();
+      if (cflow == null)
+      {
+         this.interceptorChainFactory = instrumentor.getInterceptorChainFactory(
+               factories);
+      }
+      else
+      {
+         this.interceptorChainFactory = instrumentor.getInterceptorChainFactory(
+               factories, cflowString, cflow);
+      }
    }
 
    /**
@@ -166,11 +182,15 @@
     */
    public AdviceBinding(String name, String pointcutExpression, String cflow) throws ParseException
    {
-      this.name = name;
-      setPointcutExpression(pointcutExpression);
-      setCFlowExpression(cflow);
-      interceptorFactories = new InterceptorFactory[0];
+      this(name, new PointcutExpression(generateIdentifier(), pointcutExpression),
+         cflow == null? null: new PointcutExpressionParser(new StringReader(cflow)).
+               CFlowExpression(), cflow, null);
    }
+   
+   private static String generateIdentifier()
+   {
+      return Long.toString(System.currentTimeMillis()) + ":" + Long.toString(counter++);
+   }
 
    /**
     * Defines a control-flow restriction to this binding.
@@ -186,7 +206,7 @@
     * @throws ParseException    when {@code cflow} is not {@code null} and contains a
     *                           syntax error
     */
-   public void setCFlowExpression(String cflow)
+   /*public void setCFlowExpression(String cflow)
            throws ParseException
    {
       if (cflow != null)
@@ -194,7 +214,7 @@
          cflowString = cflow;
          this.cflow = new PointcutExpressionParser(new StringReader(cflowString)).CFlowExpression();
       }
-   }
+   }*/
 
    /**
     * Defines the pointcut expression to be used by this binding.
@@ -209,11 +229,11 @@
     * @throws ParseException    when {@code cflow} is not {@code null} and contains a
     *                           syntax error
     */
-   public void setPointcutExpression(String pointcutExpression)
+   /*public void setPointcutExpression(String pointcutExpression)
            throws ParseException
    {
       pointcut = new PointcutExpression(Long.toString(System.currentTimeMillis()) + ":" + Long.toString(counter++), pointcutExpression);
-   }
+   }*/
 
    /**
     * Adds an interceptor to the chain.
@@ -223,10 +243,7 @@
     */
    public void addInterceptorFactory(InterceptorFactory factory)
    {
-      List<InterceptorFactory> list = Arrays.asList(interceptorFactories);
-      list = new ArrayList<InterceptorFactory>(list);
-      list.add(factory);
-      interceptorFactories = list.toArray(new InterceptorFactory[list.size()]);
+      interceptorChainFactory.addInterceptorFactory(factory);
    }
 
 
@@ -266,9 +283,9 @@
     * @see #addInterceptor(Class)
     * @see #addInterceptorFactory(InterceptorFactory)
     */
-   public InterceptorFactory[] getInterceptorFactories()
+   public Collection<InterceptorFactory> getInterceptorFactories()
    {
-      return interceptorFactories;
+      return interceptorChainFactory.getInterceptorFactories();
    }
 
    /**
@@ -301,10 +318,10 @@
     * @return the cflow condition that must be satisfied by joinpoints in order for
     *         the bound interceptors to be invoked
     */
-   public ASTCFlowExpression getCFlow()
+   /*public ASTCFlowExpression getCFlow()
    {
       return cflow;
-   }
+   }*/
 
    /**
     * Returns the cflow condition.
@@ -312,10 +329,10 @@
     * @return the cflow condition expression that must be satisfied by joinpoints in
     *         order for the bound interceptors to be invoked
     */
-   public String getCFlowString()
+   /*public String getCFlowString()
    {
       return cflowString;
-   }
+   }*/
 
    
    /**
@@ -326,6 +343,7 @@
     * @param advisor manages one or more joinpoints that are matched by
     *                the bound {@link #pointcut}.
     */
+   @SuppressWarnings("deprecation")
    public void addAdvisor(Advisor advisor)
    {
       if (AspectManager.verbose && logger.isDebugEnabled()) logger.debug("added advisor: " + advisor.getName() + " from binding: " + name);
@@ -385,8 +403,61 @@
          advisors.clear();
       }
    }
-
+   
    /**
+    * Updates {@code info}'s interceptor chain, adding to it the interceptors
+    * contained in this binding.
+    * 
+    * @param info   a joinpoint that matches the pointcut contained in this binding
+    * @param domain the domain to which {@code info} belongs
+    */
+   public synchronized void pointcutResolved(JoinPointInfo info, AspectManager domain)
+   {
+      Collection<Interceptor> created =
+         interceptorChainFactory.create(info.getAdvisor(), info.getJoinpoint());
+      ArrayList<Interceptor> curr = info.getInterceptorChain();
+      curr.addAll(created);
+      // set the chain in the appropriate order
+      info.setInterceptors(PrecedenceSorter.applyPrecedence(
+            curr.toArray(new Interceptor[curr.size()]), domain));
+      Map<Interceptor, Object> weakCreated = new WeakHashMap<Interceptor, Object>();
+      for (Interceptor interceptor: created)
+      {
+         weakCreated.put(interceptor, null);
+      }
+      this.createdInterceptors.put(info, weakCreated.keySet());
+   }
+   
+   /**
+    * Removes all the interceptors created by this binding from their respective
+    * chains.
+    */
+   public synchronized void clearChains()
+   {
+      for (Entry<JoinPointInfo, Collection<Interceptor>> entry:
+         createdInterceptors.entrySet())
+      {
+         JoinPointInfo info = entry.getKey();
+         clearChain(info, entry.getValue());
+         for (Iterator<WeakReference<JoinPointInfo>> iterator =
+            info.getCopies().iterator(); iterator.hasNext(); )
+         {
+            JoinPointInfo copy = iterator.next().get();
+            if(copy == null)
+            {
+               iterator.remove();
+               continue;
+            }
+            if (!createdInterceptors.containsKey(copy))
+            {
+               clearChain(copy, entry.getValue());
+            }
+         }
+      }
+      createdInterceptors.clear();
+   }
+   
+   /**
     * Compares this binding with {@code obj} for equality.
     * 
     * @param obj the object to be compared with this binding for equality
@@ -405,4 +476,29 @@
    {
       return name.hashCode();
    }
-}
+   
+   /**
+    * Returns a string representation of this object for xml reports.
+    */
+   public String xmlReport()
+   {
+      return "<binding pointcut=\"" + pointcut.getExpr() + "\"" +
+         interceptorChainFactory.xmlReport() + " />";
+   }
+   
+   private void clearChain(JoinPointInfo info, Collection<Interceptor> interceptors)
+   {
+      info.getInterceptorChainReadWriteLock().writeLock().lock();
+      try
+      {
+         ArrayList<Interceptor> infoInterceptors = info.getInterceptorChain();
+         infoInterceptors.removeAll(interceptors);
+         info.setInterceptors(infoInterceptors.toArray(new Interceptor[infoInterceptors.size()]));
+      }
+      finally
+      {
+         info.getAdvisor().interceptorChainUpdated(info);
+         info.getInterceptorChainReadWriteLock().writeLock().unlock();
+      }
+   }
+}
\ No newline at end of file

Added: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/advice/CflowInterceptorChainFactory.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/advice/CflowInterceptorChainFactory.java	                        (rev 0)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/advice/CflowInterceptorChainFactory.java	2008-07-20 23:31:45 UTC (rev 76040)
@@ -0,0 +1,64 @@
+/*
+ * 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.pointcut.ast.ASTCFlowExpression;
+
+/**
+ * Interceptor chain factory that creates a special chain in order to handle
+ * cflow restrictions.
+ * 
+ * @author  <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+public abstract class CflowInterceptorChainFactory extends InterceptorChainFactory
+{
+   /**
+    * A control flow restriction (in its string form). Cannot be {@code null}
+    */
+   protected String cflowString;
+   
+   /**
+    * A control flow restriction (in its AST form). Cannot be {@code null}.
+    */
+   protected ASTCFlowExpression cflow;
+   
+   /**
+    * Constructor.
+    * 
+    * @param factories   factories that will be used to create the chain
+    * @param cflowString a cflow expression (cannot be {@code null})
+    * @param cflow       the cflow parsed expression (cannot be {@code null})
+    */
+   public CflowInterceptorChainFactory(InterceptorFactory[] factories, String cflowString,
+         ASTCFlowExpression cflow)
+   {
+      super(factories);
+      this.cflowString = cflowString;
+      this.cflow = cflow;
+   }
+   
+   @Override
+   public String xmlReport()
+   {
+      return " cflow=\"" + cflowString + "\"";
+   }
+}
\ No newline at end of file

Added: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/advice/ClassicCflowInterceptorChainFactory.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/advice/ClassicCflowInterceptorChainFactory.java	                        (rev 0)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/advice/ClassicCflowInterceptorChainFactory.java	2008-07-20 23:31:45 UTC (rev 76040)
@@ -0,0 +1,67 @@
+/*
+ * 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 java.util.ArrayList;
+import java.util.Collection;
+
+import org.jboss.aop.Advisor;
+import org.jboss.aop.joinpoint.Joinpoint;
+import org.jboss.aop.pointcut.ast.ASTCFlowExpression;
+
+/**
+ * Creates an interceptor chain that handles a cflow restriction on classic
+ * instrumentation mode.
+ * 
+ * @author  <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+public class ClassicCflowInterceptorChainFactory extends CflowInterceptorChainFactory
+{
+   /**
+    * Constructor.
+    * 
+    * @param factories   factories that will be used to create the chain
+    * @param cflowString a cflow expression (cannot be {@code null})
+    * @param cflow       the cflow parsed expression (cannot be {@code null})
+    */
+   public ClassicCflowInterceptorChainFactory(InterceptorFactory[] factories, String cflowString, ASTCFlowExpression cflow)
+   {
+      super(factories, cflowString, cflow);
+   }
+
+   @Override
+   public Collection<Interceptor> create(Advisor advisor, Joinpoint joinpoint)
+   {
+      ArrayList<Interceptor> cflowChain = new ArrayList<Interceptor>();
+      for (InterceptorFactory factory: interceptorFactories)
+      {
+         cflowChain.add(factory.create(advisor, joinpoint));
+      }
+      Interceptor[] cflowInterceptors = cflowChain.toArray(
+            new Interceptor[cflowChain.size()]);
+      Interceptor interceptor = new CFlowInterceptor(cflowString, cflow,
+               cflowInterceptors);
+      Collection<Interceptor> createdInterceptor = new ArrayList<Interceptor>();
+      createdInterceptor.add(interceptor);
+      return createdInterceptor;
+   }
+}
\ No newline at end of file

Added: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/advice/ClassicInterceptorChainFactory.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/advice/ClassicInterceptorChainFactory.java	                        (rev 0)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/advice/ClassicInterceptorChainFactory.java	2008-07-20 23:31:45 UTC (rev 76040)
@@ -0,0 +1,66 @@
+/*
+ * 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 java.util.ArrayList;
+import java.util.Collection;
+
+import org.jboss.aop.Advisor;
+import org.jboss.aop.joinpoint.Joinpoint;
+
+/**
+ * Creates an interceptor chain appropriate for classic instrumentation mode.
+ * 
+ * @author  <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+public class ClassicInterceptorChainFactory extends InterceptorChainFactory
+{
+   /**
+    * Constructor.
+    * 
+    * @param interceptorFactories factories that will be used to create the chain
+    */
+   public ClassicInterceptorChainFactory(InterceptorFactory[] interceptorFactories)
+   {
+      super(interceptorFactories);
+   }
+
+   @Override
+   public Collection<Interceptor> create(Advisor advisor, Joinpoint joinpoint)
+   {
+      Collection<Interceptor> interceptors = new ArrayList<Interceptor>();
+      for (InterceptorFactory factory: interceptorFactories)
+      {
+         if (factory.getType().isGeneratedOnly())
+         {
+            throw new RuntimeException("Before/After/Throwing is only supported " +
+                  "for Generated Advisors");
+         }
+         if (factory.isDeployed())
+         {
+            Interceptor interceptor = factory.create(advisor, joinpoint);
+            interceptors.add(interceptor);
+         }
+      }
+      return interceptors;
+   }
+}
\ No newline at end of file

Added: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/advice/GenadvisorCflowInterceptorChainFactory.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/advice/GenadvisorCflowInterceptorChainFactory.java	                        (rev 0)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/advice/GenadvisorCflowInterceptorChainFactory.java	2008-07-20 23:31:45 UTC (rev 76040)
@@ -0,0 +1,63 @@
+/*
+ * 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 java.util.ArrayList;
+import java.util.Collection;
+
+import org.jboss.aop.Advisor;
+import org.jboss.aop.GeneratedClassAdvisor;
+import org.jboss.aop.joinpoint.Joinpoint;
+import org.jboss.aop.pointcut.ast.ASTCFlowExpression;
+
+/**
+ * Creates an interceptor chain that handles a cflow restriction on generated advisor
+ * instrumentation mode.
+ * 
+ * @author  <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+public class GenadvisorCflowInterceptorChainFactory extends CflowInterceptorChainFactory
+{
+   /**
+    * Constructor.
+    * 
+    * @param factories   factories that will be used to create the chain
+    * @param cflowString a cflow expression (cannot be {@code null})
+    * @param cflow       the cflow parsed expression (cannot be {@code null})
+    */
+   public GenadvisorCflowInterceptorChainFactory(InterceptorFactory[] factories, String cflowString, ASTCFlowExpression cflow)
+   {
+      super(factories, cflowString, cflow);
+   }
+
+   @Override
+   public Collection<Interceptor> create(Advisor advisor, Joinpoint joinpoint)
+   {
+      Collection<Interceptor> createdInterceptors = new ArrayList<Interceptor>();
+      for (InterceptorFactory factory: interceptorFactories)
+      {
+         createdInterceptors.add(new GeneratedAdvisorInterceptor(factory,
+               (GeneratedClassAdvisor) advisor, joinpoint, cflowString, cflow));
+      }
+      return createdInterceptors;
+   }
+}
\ No newline at end of file

Added: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/advice/GenadvisorInterceptorChainFactory.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/advice/GenadvisorInterceptorChainFactory.java	                        (rev 0)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/advice/GenadvisorInterceptorChainFactory.java	2008-07-20 23:31:45 UTC (rev 76040)
@@ -0,0 +1,71 @@
+/*
+ * 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 java.util.ArrayList;
+import java.util.Collection;
+
+import org.jboss.aop.Advisor;
+import org.jboss.aop.GeneratedClassAdvisor;
+import org.jboss.aop.joinpoint.Joinpoint;
+
+/**
+ * Creates an interceptor chain appropriate for generated advisor instrumentation
+ * mode.
+ * 
+ * @author  <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+public class GenadvisorInterceptorChainFactory extends InterceptorChainFactory
+{
+   /**
+    * Constructor.
+    * 
+    * @param interceptorFactories factories that will be used to create the chain
+    */
+   public GenadvisorInterceptorChainFactory(InterceptorFactory[] interceptorFactories)
+   {
+      super(interceptorFactories);
+   }
+
+   @Override
+   public Collection<Interceptor> create(Advisor advisor, Joinpoint joinpoint)
+   {
+      Collection<Interceptor> createdInterceptors = new ArrayList<Interceptor>();
+      if (advisor instanceof GeneratedClassAdvisor)
+      {
+         GeneratedClassAdvisor genadvisor = (GeneratedClassAdvisor) advisor;
+         for (InterceptorFactory factory: interceptorFactories)
+         {
+            createdInterceptors.add(new GeneratedAdvisorInterceptor(factory,
+                  genadvisor, joinpoint));
+         }
+      }
+      else
+      {
+         for (InterceptorFactory factory: interceptorFactories)
+         {
+            createdInterceptors.add(factory.create(advisor, joinpoint));
+         }
+      }
+      return createdInterceptors;
+   }
+}
\ No newline at end of file

Added: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/advice/InterceptorChainFactory.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/advice/InterceptorChainFactory.java	                        (rev 0)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/advice/InterceptorChainFactory.java	2008-07-20 23:31:45 UTC (rev 76040)
@@ -0,0 +1,91 @@
+/*
+ * 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 java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+
+import org.jboss.aop.Advisor;
+import org.jboss.aop.joinpoint.Joinpoint;
+
+/**
+ * Given a collection of interceptor factories, creates an interceptor chain.
+ * 
+ * @author  <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+public abstract class InterceptorChainFactory
+{
+   protected Collection<InterceptorFactory> interceptorFactories;
+   
+   /**
+    * Constructor.
+    * 
+    * @param interceptorFactories factories that will be used to create the chain
+    */
+   public InterceptorChainFactory(InterceptorFactory[] interceptorFactories)
+   {
+      this.interceptorFactories = new ArrayList<InterceptorFactory>();
+      if (interceptorFactories != null)
+      {
+         this.interceptorFactories.addAll(Arrays.asList(interceptorFactories));
+      }
+   }
+   
+   /**
+    * Adds an interceptor factory to this interceptor chain factory.
+    * 
+    * @param factory new factory, to be added to this interceptor chain factory
+    */
+   public void addInterceptorFactory(InterceptorFactory factory)
+   {
+      this.interceptorFactories.add(factory);
+   }
+   
+   /**
+    * Returns the collection of interceptor factories contained in this chain factory. 
+    * 
+    * @return an ummodifiable colllection
+    */
+   public Collection<InterceptorFactory> getInterceptorFactories()
+   {
+      return Collections.unmodifiableCollection(this.interceptorFactories);
+   }
+   
+   /**
+    * Creates an interceptor chain for {@code Joinpoint}.
+    * 
+    * @param advisor   the advisor that manages {@code Joinpoint}
+    * @param joinpoint the joinpoint
+    * @return the created chain
+    */
+   public abstract Collection<Interceptor> create(Advisor advisor, Joinpoint joinpoint);
+   
+   /**
+    * Returns a string representation of this object for xml reports.
+    */
+   public String xmlReport()
+   {
+      return "";
+   }
+}
\ No newline at end of file

Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/instrument/InstrumentorEnum.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/instrument/InstrumentorEnum.java	2008-07-20 23:01:45 UTC (rev 76039)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/instrument/InstrumentorEnum.java	2008-07-20 23:31:45 UTC (rev 76040)
@@ -21,21 +21,187 @@
 */ 
 package org.jboss.aop.instrument;
 
+import java.lang.reflect.Constructor;
+
+import org.jboss.aop.AspectManager;
+import org.jboss.aop.advice.ClassicCflowInterceptorChainFactory;
+import org.jboss.aop.advice.ClassicInterceptorChainFactory;
+import org.jboss.aop.advice.GenadvisorCflowInterceptorChainFactory;
+import org.jboss.aop.advice.GenadvisorInterceptorChainFactory;
+import org.jboss.aop.advice.InterceptorChainFactory;
+import org.jboss.aop.advice.InterceptorFactory;
+import org.jboss.aop.classpool.AOPClassPool;
+import org.jboss.aop.pointcut.ast.ASTCFlowExpression;
+
 /**
  * 
  * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
  * @version $Revision$
  */
-public class InstrumentorEnum
+public enum InstrumentorEnum
 {
-   public static final InstrumentorEnum CLASSIC = new InstrumentorEnum(1);
-   public static final InstrumentorEnum GENERATED_ADVISOR = new InstrumentorEnum(2);
-   public static final InstrumentorEnum OTHER_INSTRUMENTOR = new InstrumentorEnum(1000); //The jrockit aop instrumentor is in another jar which we should not depend on
-
-   int instrumentor;
-
-   public InstrumentorEnum(int i)
+   CLASSIC
    {
-      instrumentor = i;
+      protected void initialise(String instrumentor) {}
+      
+      public Instrumentor getInstrumentor(AspectManager manager, JoinpointClassifier joinpointClassifier)
+      {
+         return new ClassicInstrumentor(manager, joinpointClassifier);
+      }
+      
+      public Instrumentor getInstrumentor(AOPClassPool pool, AspectManager manager,
+            JoinpointClassifier joinpointClassifier, DynamicTransformationObserver observer)
+      {
+         return new ClassicInstrumentor(pool, manager, joinpointClassifier, observer);
+      }
+      
+      public String getInstrumentorName()
+      {
+         return ClassicInstrumentor.class.getName();
+      }
+      
+      public InterceptorChainFactory getInterceptorChainFactory(InterceptorFactory[] interceptorFactories)
+      {
+         return new ClassicInterceptorChainFactory(interceptorFactories);
+      }
+      
+      public InterceptorChainFactory getInterceptorChainFactory(InterceptorFactory[] interceptorFactories, String cflowString,
+               ASTCFlowExpression cflow)
+      {
+         return new ClassicCflowInterceptorChainFactory(interceptorFactories,
+               cflowString, cflow);
+      }
+   },
+   GENERATED_ADVISOR
+   {
+      protected void initialise(String instrumentor) {}
+      
+      public Instrumentor getInstrumentor(AspectManager manager, JoinpointClassifier joinpointClassifier)
+      {
+         return new GeneratedAdvisorInstrumentor(manager, joinpointClassifier);
+      }
+      
+      public Instrumentor getInstrumentor(AOPClassPool pool, AspectManager manager,
+            JoinpointClassifier joinpointClassifier, DynamicTransformationObserver observer)
+      {
+         return new GeneratedAdvisorInstrumentor(pool, manager, joinpointClassifier, observer);
+      }
+      
+      public String getInstrumentorName()
+      {
+         return GeneratedAdvisorInstrumentor.class.getName();
+      }
+            
+      public InterceptorChainFactory getInterceptorChainFactory(InterceptorFactory[] interceptorFactories)
+      {
+         return new GenadvisorInterceptorChainFactory(interceptorFactories);
+      }
+      
+      public InterceptorChainFactory getInterceptorChainFactory(InterceptorFactory[] interceptorFactories, String cflowString,
+               ASTCFlowExpression cflow)
+      {
+         return new GenadvisorCflowInterceptorChainFactory(interceptorFactories,
+               cflowString, cflow);
+      }
+   },
+   // The jrockit aop instrumentor is in another jar which we should not depend on
+   OTHER_INSTRUMENTOR
+   {
+      private final Class[] CONSTRUCTOR_SIG = new Class[] {AOPClassPool.class,
+            AspectManager.class, JoinpointClassifier.class, DynamicTransformationObserver.class};
+      private Constructor constructor;
+      
+      protected void initialise(String instrumentor)
+      {
+         try
+         {
+            // FIXME ClassLoader - why should the class be visible from the context classloader?
+            Class instrumentorClass = SecurityActions.getContextClassLoader().loadClass(
+                  instrumentor);
+            constructor = instrumentorClass.getConstructor(CONSTRUCTOR_SIG);
+         }
+         catch (ClassNotFoundException e)
+         {
+            throw new RuntimeException("Invalid instrumentor " + instrumentor +
+                  " was used");
+         }
+         catch(NoSuchMethodException e)
+         {
+            throw new RuntimeException(instrumentor +
+                  " does not have a constructor with the expected signature");
+         }
+      }
+      
+      public Instrumentor getInstrumentor(AspectManager manager, JoinpointClassifier joinpointClassifier)
+      {
+         throw new RuntimeException("Instrumentor is not set");
+      }
+      
+      public Instrumentor getInstrumentor(AOPClassPool pool, AspectManager manager,
+            JoinpointClassifier joinpointClassifier, DynamicTransformationObserver observer)
+      {
+         if (constructor == null)
+         {
+            throw new RuntimeException("Instrumentor is not set");
+         }
+         try
+         {
+            return (Instrumentor) constructor.newInstance(
+                  new Object[] {pool, manager, joinpointClassifier, observer});
+         }
+         catch (Exception e)
+         {
+            throw new RuntimeException(e);
+         }
+      }
+      
+      public String getInstrumentorName()
+      {
+         return constructor.getName();  
+      }
+      
+      public InterceptorChainFactory getInterceptorChainFactory(InterceptorFactory[] interceptorFactories)
+      {
+         return CLASSIC.getInterceptorChainFactory(interceptorFactories);
+      }
+      
+      public InterceptorChainFactory getInterceptorChainFactory(InterceptorFactory[] interceptorFactories, String cflowString,
+               ASTCFlowExpression cflow)
+      {
+         return CLASSIC.getInterceptorChainFactory(interceptorFactories,
+               cflowString, cflow);
+      }
+   };
+   
+   protected abstract void initialise(String instrumentor);
+   public abstract Instrumentor getInstrumentor(AspectManager manager,
+         JoinpointClassifier joinpointClassifier);
+   public abstract Instrumentor getInstrumentor(AOPClassPool pool,
+         AspectManager manager, JoinpointClassifier joinpointClassifier, DynamicTransformationObserver observer);
+   public abstract String getInstrumentorName();
+   public abstract InterceptorChainFactory getInterceptorChainFactory(
+         InterceptorFactory[] interceptorFactories);
+   public abstract InterceptorChainFactory getInterceptorChainFactory(
+         InterceptorFactory[] interceptorFactories, String cflowString,
+         ASTCFlowExpression cflow);
+   
+   public static InstrumentorEnum getInstance(String instrumentorName)
+   {
+      InstrumentorEnum instance = null;
+      if (instrumentorName == null || instrumentorName.equals(GENERATED_ADVISOR.getInstrumentorName()))
+      {
+         instance = GENERATED_ADVISOR;
+      }
+      else if (instrumentorName.equals(CLASSIC.getInstrumentorName()))
+      {
+         instance = CLASSIC;
+      }
+      else
+      {
+         instance = OTHER_INSTRUMENTOR;
+      }
+      instance.initialise(instrumentorName);
+      return instance;
    }
-}
+}
\ No newline at end of file

Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/instrument/InstrumentorFactory.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/instrument/InstrumentorFactory.java	2008-07-20 23:01:45 UTC (rev 76039)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/instrument/InstrumentorFactory.java	2008-07-20 23:31:45 UTC (rev 76040)
@@ -21,8 +21,6 @@
   */
 package org.jboss.aop.instrument;
 
-import java.lang.reflect.Constructor;
-
 import org.jboss.aop.AspectManager;
 import org.jboss.aop.classpool.AOPClassPool;
 import org.jboss.aop.util.logging.AOPLogger;
@@ -38,126 +36,44 @@
 {
    private static final Logger logger = AOPLogger.getLogger(InstrumentorFactory.class);
    
-   protected static InstrumentorEnum instrumentor; 
+   private static InstrumentorEnum instrumentor; 
    
-   protected static Constructor otherInstrumentorConstructor;
+   //protected static Constructor otherInstrumentorConstructor;
    
-   private static final Class[] CONSTRUCTOR_SIG = new Class[] {AOPClassPool.class, AspectManager.class, JoinpointClassifier.class, DynamicTransformationObserver.class};
-   
    public static void initialise(String property)
    {
       if (AspectManager.verbose && logger.isDebugEnabled())
       {
          logger.debug("Passed in instrumentor: " + property);
       }
-      
-      if (property != null)
+      instrumentor = InstrumentorEnum.getInstance(property);
+      if (property == null && AspectManager.verbose && logger.isDebugEnabled())
       {
-         if (property.equals(ClassicInstrumentor.class.getName()))
-         {
-            instrumentor = InstrumentorEnum.CLASSIC;
-         }
-         else if (property.equals(GeneratedAdvisorInstrumentor.class.getName()))
-         {
-            instrumentor = InstrumentorEnum.GENERATED_ADVISOR;
-         }
-         else
-         {
-            
-            try
-            {
-               // FIXME ClassLoader - why should the class be visible from the context classloader?
-               Class otherInstrumentorClass = SecurityActions.getContextClassLoader().loadClass(property);
-               otherInstrumentorConstructor = otherInstrumentorClass.getConstructor(CONSTRUCTOR_SIG);
-               instrumentor = InstrumentorEnum.OTHER_INSTRUMENTOR;
-            }
-            catch (ClassNotFoundException e)
-            {
-               throw new RuntimeException("Invalid instrumentor " + property + " was used");
-            }
-            catch(NoSuchMethodException e)
-            {
-               throw new RuntimeException(property + " does not have a constructor with the expected signature");
-            }
-         }
+         logger.debug("Defaulting instrumentor to: " + getInstrumentorName());
       }
-      else
-      {
-         instrumentor = InstrumentorEnum.GENERATED_ADVISOR;
-         if (AspectManager.verbose && logger.isDebugEnabled())
-         {
-            logger.debug("Defaulting instrumentor to: " + getInstrumentorName());
-         }
-      }
    }
    
    public static InstrumentorEnum getInstrumentor()
    {
+      if (instrumentor == null)
+      {
+         AspectManager.instance();
+      }
       return instrumentor;
    }
    
    public static Instrumentor getInstrumentor(AOPClassPool pool, AspectManager manager, JoinpointClassifier joinpointClassifier, DynamicTransformationObserver observer)
    {
-      if (instrumentor == InstrumentorEnum.CLASSIC)
-      {
-         return new ClassicInstrumentor(pool, manager, joinpointClassifier, observer);         
-      }
-      else if (instrumentor == InstrumentorEnum.GENERATED_ADVISOR)
-      {
-         return new GeneratedAdvisorInstrumentor(pool, manager, joinpointClassifier, observer);
-      }
-      else if (otherInstrumentorConstructor != null)
-      {
-         try
-         {
-            return (Instrumentor) otherInstrumentorConstructor.newInstance(new Object[] {pool, manager, joinpointClassifier, observer});
-         }
-         catch (Exception e)
-         {
-            throw new RuntimeException(e);
-         }
-      }
-      else
-      {
-         throw new RuntimeException("Instrumentor is not set");
-      }
+      return instrumentor.getInstrumentor(pool, manager, joinpointClassifier, observer);
    }
-   
 
    public static Instrumentor getInstrumentor(AspectManager manager, JoinpointClassifier joinpointClassifier)
    {
-      if (instrumentor == InstrumentorEnum.CLASSIC)
-      {
-         return new ClassicInstrumentor(manager, joinpointClassifier);
-      }
-      else if (instrumentor == InstrumentorEnum.GENERATED_ADVISOR)
-      {
-         return new GeneratedAdvisorInstrumentor(manager, joinpointClassifier);
-      }
-      else
-      {
-         throw new RuntimeException("Instrumentor is not set");
-      }
+      return instrumentor.getInstrumentor(manager, joinpointClassifier);
    }
    
    public static String getInstrumentorName()
    {
-      if (instrumentor == InstrumentorEnum.CLASSIC)
-      {
-         return ClassicInstrumentor.class.getName();
-      }
-      else if (instrumentor == InstrumentorEnum.GENERATED_ADVISOR)
-      {
-         return GeneratedAdvisorInstrumentor.class.getName();
-      }
-      else if (instrumentor == InstrumentorEnum.OTHER_INSTRUMENTOR)
-      {
-         return otherInstrumentorConstructor.getName();
-      }
-      else
-      {
-         throw new RuntimeException("Instrumentor is not set");
-      }
+      return instrumentor.getInstrumentorName();
    }
-   
-}
+}
\ No newline at end of file

Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/standalone/XmlReport.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/standalone/XmlReport.java	2008-07-20 23:01:45 UTC (rev 76039)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/standalone/XmlReport.java	2008-07-20 23:31:45 UTC (rev 76040)
@@ -420,12 +420,7 @@
                indent++;
             }
             indenter(pw, indent);
-            pw.print("<binding pointcut=\"" + binding.getPointcut().getExpr() + "\"");
-            if (binding.getCFlowString() != null)
-            {
-               pw.print(" cflow=\"" + binding.getCFlowString() + "\"");
-            }
-            pw.println(" />");
+            pw.println(binding.xmlReport());
          }
       }
       if (!first)




More information about the jboss-cvs-commits mailing list