[jboss-cvs] JBossAS SVN: r75504 - in projects/aop/trunk/aop/src/main/org/jboss/aop: pointcut and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Jul 8 13:00:06 EDT 2008


Author: kabir.khan at jboss.com
Date: 2008-07-08 13:00:06 -0400 (Tue, 08 Jul 2008)
New Revision: 75504

Modified:
   projects/aop/trunk/aop/src/main/org/jboss/aop/AspectAnnotationLoader.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/AspectAnnotationLoaderStrategy.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/AspectAnnotationLoaderStrategySupport.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/AspectManagerAnnotationLoaderStrategy.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/pointcut/CFlow.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/pointcut/CFlowStack.java
Log:
Use intermediate class to define InterfaceIntroductions/Mixins and CFlows rather than using the AspectManager metadata directly

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/AspectAnnotationLoader.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/AspectAnnotationLoader.java	2008-07-08 16:58:04 UTC (rev 75503)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/AspectAnnotationLoader.java	2008-07-08 17:00:06 UTC (rev 75504)
@@ -41,19 +41,18 @@
 import javassist.bytecode.annotation.MemberValue;
 import javassist.bytecode.annotation.StringMemberValue;
 
+import org.jboss.aop.AspectAnnotationLoaderStrategy.InterfaceIntroductionInfo;
+import org.jboss.aop.AspectAnnotationLoaderStrategy.InterfaceIntroductionMixinInfo;
 import org.jboss.aop.advice.AspectFactory;
 import org.jboss.aop.advice.Interceptor;
 import org.jboss.aop.advice.PrecedenceDefEntry;
 import org.jboss.aop.advice.Scope;
 import org.jboss.annotation.factory.javassist.AnnotationProxy;
-import org.jboss.aop.introduction.InterfaceIntroduction;
 import org.jboss.aop.pointcut.CFlow;
 import org.jboss.aop.pointcut.CFlowStack;
 import org.jboss.aop.pointcut.DynamicCFlow;
 import org.jboss.aop.pointcut.ast.ASTCFlowExpression;
-import org.jboss.aop.pointcut.ast.ASTStart;
 import org.jboss.aop.pointcut.ast.PointcutExpressionParser;
-import org.jboss.aop.pointcut.ast.TypeExpressionParser;
 import org.jboss.aop.util.MethodHashing;
 import org.jboss.aop.util.logging.AOPLogger;
 import org.jboss.logging.Logger;
@@ -68,7 +67,6 @@
 {
    
    private static final Logger logger = AOPLogger.getLogger(AspectAnnotationLoader.class);
-   //TODO: We need something to undeploy everything...
 
    protected AspectManager manager;
    private ClassLoader cl; 
@@ -581,7 +579,7 @@
 
          String name = cf.getName() + "." + minfo.getName(); //Name of the method defined on
          
-         InterfaceIntroduction intro = null;
+         InterfaceIntroductionInfo intro = null;
          String construction = name;
          switch(Descriptor.numOfParameters(minfo.getDescriptor()))
          {
@@ -656,7 +654,7 @@
          //Parse the descriptor to get the returntype of the method.
          String classname = getReturnType(minfo);
          
-         intro.getMixins().add(new InterfaceIntroduction.Mixin(classname, interfaces, construction, isTransient));
+         intro.addMixin(new InterfaceIntroductionMixinInfo(classname, interfaces, construction, isTransient));
 
          loaderStrategy.deployInterfaceIntroduction(this, intro);
       }
@@ -714,7 +712,7 @@
 
          String name = cf.getName() + "." + finfo.getName(); //Name of the field defined on
 
-         InterfaceIntroduction interfaceIntro = createIntroduction(name, target, typeExpression, interfaces, null, null);
+         InterfaceIntroductionInfo interfaceIntro = createIntroduction(name, target, typeExpression, interfaces, null, null);
          loaderStrategy.deployInterfaceIntroduction(this, interfaceIntro);
       }
    }
@@ -792,13 +790,13 @@
 
          String name = getStackDefName(cf, finfo);
          CFlowDef[] cflows = stackDef.cflows();
-         CFlowStack stack = new CFlowStack(name);
+         AspectAnnotationLoaderStrategy.CFlowStackInfo stack = new AspectAnnotationLoaderStrategy.CFlowStackInfo(name);
 
          for (int i = 0; i < cflows.length; i++)
          {
             CFlowDef cflow = cflows[i];
             boolean not = !cflow.called();
-            stack.addCFlow(new CFlow(cflow.expr(), not));
+            stack.addCFlow(new AspectAnnotationLoaderStrategy.CFlowInfo(cflow.expr(), not));
          }
 
          loaderStrategy.deployCFlow(this, stack);
@@ -950,7 +948,7 @@
       return cf.getName() + "." + finfo.getName();
    }
 
-   private InterfaceIntroduction createIntroduction(String name, String target, String typeExpression, String[] interfaces,
+   private InterfaceIntroductionInfo createIntroduction(String name, String target, String typeExpression, String[] interfaces,
          String constructorClass, String constructorMethod)
    throws Exception
    {
@@ -974,19 +972,8 @@
          throw new RuntimeException("You cannot define both a target and typeExpression attribute in the same @Mixin");
       }
 
+      InterfaceIntroductionInfo intro = new InterfaceIntroductionInfo(name, interfaces, target, typeExpression, constructorClass, constructorMethod);
 
-      InterfaceIntroduction intro = null;
-
-      if (target != null)
-      {
-         intro = new InterfaceIntroduction(name, target, interfaces, constructorClass, constructorMethod);
-      }
-      else
-      {
-         ASTStart start = new TypeExpressionParser(new StringReader(typeExpression)).Start();
-         intro = new InterfaceIntroduction(name, start, interfaces, constructorClass, constructorMethod);
-      }
-
       return intro;
    }
 

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/AspectAnnotationLoaderStrategy.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/AspectAnnotationLoaderStrategy.java	2008-07-08 16:58:04 UTC (rev 75503)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/AspectAnnotationLoaderStrategy.java	2008-07-08 17:00:06 UTC (rev 75504)
@@ -21,9 +21,11 @@
 */ 
 package org.jboss.aop;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import org.jboss.aop.advice.PrecedenceDefEntry;
 import org.jboss.aop.advice.Scope;
-import org.jboss.aop.introduction.InterfaceIntroduction;
 import org.jboss.aop.pointcut.CFlowStack;
 import org.jboss.aop.pointcut.ast.ASTCFlowExpression;
 
@@ -35,7 +37,7 @@
 public interface AspectAnnotationLoaderStrategy
 {
 
-   void deployAspect(AspectAnnotationLoader loader, boolean isFactory, String name, Scope scope);
+   void deployAspect(AspectAnnotationLoader loader, boolean isFactory, String name, Scope scope) throws Exception;
    
    void deployAspectMethodBinding(
          AspectAnnotationLoader loader, 
@@ -51,7 +53,7 @@
    
    void undeployAspectMethodBinding(AspectAnnotationLoader loader, String bindingName, String className, String methodName);
    
-   void deployInterceptor(AspectAnnotationLoader loader, boolean isFactory, String name, Scope scope);
+   void deployInterceptor(AspectAnnotationLoader loader, boolean isFactory, String name, Scope scope) throws Exception;
    
    void deployInterceptorBinding(AspectAnnotationLoader loader, String name, String pointcutString, String cflow, ASTCFlowExpression cflowExpression) throws Exception;
    
@@ -59,7 +61,7 @@
    
    void undeployInterceptorBinding(AspectAnnotationLoader loader, String name);
    
-   void deployDynamicCFlow(AspectAnnotationLoader loader, String name, String clazz);
+   void deployDynamicCFlow(AspectAnnotationLoader loader, String name, String clazz) throws Exception;
    
    void undeployDynamicCFlow(AspectAnnotationLoader loader, String name);
    
@@ -67,7 +69,7 @@
    
    void undeployPointcut(AspectAnnotationLoader loader, String name);
    
-   void deployPrecedence(AspectAnnotationLoader loader, String name, PrecedenceDefEntry[] pentries);
+   void deployPrecedence(AspectAnnotationLoader loader, String name, PrecedenceDefEntry[] pentries) throws Exception;
 
    void undeployPrecedence(AspectAnnotationLoader loader, String name);
    
@@ -77,15 +79,171 @@
 
    void deployDeclare(AspectAnnotationLoader loader, String name, String expr, boolean warning, String msg) throws Exception;
    
-   void deployAnnotationIntroduction(AspectAnnotationLoader loader, String expr, String annotation, boolean invisible);
+   void deployAnnotationIntroduction(AspectAnnotationLoader loader, String expr, String annotation, boolean invisible) throws Exception;
 
    void undeployAnnotationIntroduction(AspectAnnotationLoader loader, String expr, String annotation, boolean invisible);
 
-   void deployCFlow(AspectAnnotationLoader loader, CFlowStack stack);
+   void deployCFlow(AspectAnnotationLoader loader, CFlowStackInfo stack) throws Exception;
    
    void undeployCFlow(AspectAnnotationLoader loader, String name);
    
-   void deployInterfaceIntroduction(AspectAnnotationLoader loader, InterfaceIntroduction introduction);
+   void deployInterfaceIntroduction(AspectAnnotationLoader loader, InterfaceIntroductionInfo introduction) throws Exception;
 
    void undeployInterfaceIntroduction(AspectAnnotationLoader loader, String name);
+   
+   public class InterfaceIntroductionInfo
+   {
+      private String name;
+      private String[] interfaces;
+      private String target;
+      private String expr;
+      private List<InterfaceIntroductionMixinInfo> mixins;
+      private String constructorClass;
+      private String constructorMethod;
+
+      public InterfaceIntroductionInfo(String name, String[] interfaces, String target, String expr, String constructorClass, String constructorMethod)
+      {
+         super();
+         this.name = name;
+         this.interfaces = interfaces;
+         this.target = target;
+         this.expr = expr;
+         this.constructorClass = constructorClass;
+         this.constructorMethod = constructorMethod;
+      }
+      
+      public String getName()
+      {
+         return name;
+      }
+      
+      public String[] getInterfaces()
+      {
+         return interfaces;
+      }
+      
+      public String getTarget()
+      {
+         return target;
+      }
+      
+      public String getExpr()
+      {
+         return expr;
+      }
+      
+      public void addMixin(InterfaceIntroductionMixinInfo mixin)
+      {
+         if (mixins == null)
+         {
+            mixins = new ArrayList<InterfaceIntroductionMixinInfo>();
+         }
+         mixins.add(mixin);
+      }
+      
+      public InterfaceIntroductionMixinInfo[] getMixins()
+      {
+         if (mixins == null)
+         {
+            return null;
+         }
+         return mixins.toArray(new InterfaceIntroductionMixinInfo[mixins.size()]);
+      }
+
+      public String getConstructorClass()
+      {
+         return constructorClass;
+      }
+
+      public String getConstructorMethod()
+      {
+         return constructorMethod;
+      }
+   }
+   
+   public class InterfaceIntroductionMixinInfo
+   {
+      private String classname;
+      private String[] interfaces;
+      private String construction;
+      private boolean trans;
+
+      public InterfaceIntroductionMixinInfo(String classname, String[] interfaces, String construction, boolean trans)
+      {
+         super();
+         this.classname = classname;
+         this.interfaces = interfaces;
+         this.construction = construction;
+         this.trans = trans;
+      }
+
+      public String getClassname()
+      {
+         return classname;
+      }
+
+      public String[] getInterfaces()
+      {
+         return interfaces;
+      }
+
+      public String getConstruction()
+      {
+         return construction;
+      }
+
+      public boolean isTrans()
+      {
+         return trans;
+      }
+   }
+   
+   public class CFlowStackInfo
+   {
+      String name;
+      List<CFlowInfo> cflows = new ArrayList<CFlowInfo>();
+      
+      public CFlowStackInfo(String name)
+      {
+         this.name = name;
+      }
+      
+      public void addCFlow(CFlowInfo info)
+      {
+         cflows.add(info);
+      }
+      
+      public CFlowInfo[] getCFlows()
+      {
+         return cflows.toArray(new CFlowInfo[cflows.size()]);
+      }
+      
+      public String getName()
+      {
+         return name;
+      }
+   }
+   
+   public class CFlowInfo
+   {
+      String expr;
+      boolean not;
+
+      public CFlowInfo(String expr, boolean not)
+      {
+         super();
+         this.expr = expr;
+         this.not = not;
+      }
+
+      public String getExpr()
+      {
+         return expr;
+      }
+
+      public boolean isNot()
+      {
+         return not;
+      }
+   }
 }

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/AspectAnnotationLoaderStrategySupport.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/AspectAnnotationLoaderStrategySupport.java	2008-07-08 16:58:04 UTC (rev 75503)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/AspectAnnotationLoaderStrategySupport.java	2008-07-08 17:00:06 UTC (rev 75504)
@@ -24,8 +24,6 @@
 import org.jboss.aop.advice.AdviceType;
 import org.jboss.aop.advice.PrecedenceDefEntry;
 import org.jboss.aop.advice.Scope;
-import org.jboss.aop.introduction.InterfaceIntroduction;
-import org.jboss.aop.pointcut.CFlowStack;
 import org.jboss.aop.pointcut.ast.ASTCFlowExpression;
 
 /**
@@ -52,7 +50,7 @@
    {
    }
 
-   public void deployCFlow(AspectAnnotationLoader loader, CFlowStack stack)
+   public void deployCFlow(AspectAnnotationLoader loader, CFlowStackInfo stack)
    {
    }
 
@@ -74,7 +72,7 @@
    {
    }
 
-   public void deployInterfaceIntroduction(AspectAnnotationLoader loader, InterfaceIntroduction introduction)
+   public void deployInterfaceIntroduction(AspectAnnotationLoader loader, InterfaceIntroductionInfo introduction)
    {
    }
 

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/AspectManagerAnnotationLoaderStrategy.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/AspectManagerAnnotationLoaderStrategy.java	2008-07-08 16:58:04 UTC (rev 75503)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/AspectManagerAnnotationLoaderStrategy.java	2008-07-08 17:00:06 UTC (rev 75504)
@@ -21,6 +21,8 @@
 */ 
 package org.jboss.aop;
 
+import java.io.StringReader;
+
 import org.jboss.aop.advice.AdviceBinding;
 import org.jboss.aop.advice.AdviceFactory;
 import org.jboss.aop.advice.AspectDefinition;
@@ -36,6 +38,7 @@
 import org.jboss.aop.advice.ScopedInterceptorFactory;
 import org.jboss.aop.introduction.AnnotationIntroduction;
 import org.jboss.aop.introduction.InterfaceIntroduction;
+import org.jboss.aop.pointcut.CFlow;
 import org.jboss.aop.pointcut.CFlowStack;
 import org.jboss.aop.pointcut.DeclareDef;
 import org.jboss.aop.pointcut.Pointcut;
@@ -43,6 +46,8 @@
 import org.jboss.aop.pointcut.Typedef;
 import org.jboss.aop.pointcut.TypedefExpression;
 import org.jboss.aop.pointcut.ast.ASTCFlowExpression;
+import org.jboss.aop.pointcut.ast.ASTStart;
+import org.jboss.aop.pointcut.ast.TypeExpressionParser;
 
 /**
  * 
@@ -202,8 +207,13 @@
       loader.getAspectManager().removeAnnotationIntroduction(annIntro);
    }
    
-   public void deployCFlow(AspectAnnotationLoader loader, CFlowStack stack)
+   public void deployCFlow(AspectAnnotationLoader loader, CFlowStackInfo info)
    {
+      CFlowStack stack = new CFlowStack(info.getName());
+      for (CFlowInfo cinfo : info.getCFlows())
+      {
+         stack.addCFlow(new CFlow(cinfo.getExpr(), cinfo.isNot()));
+      }
       loader.getAspectManager().addCFlowStack(stack);
    }
    
@@ -212,9 +222,28 @@
       loader.getAspectManager().removeCFlowStack(name);
    }
    
-   public void deployInterfaceIntroduction(AspectAnnotationLoader loader, InterfaceIntroduction introduction)
+   public void deployInterfaceIntroduction(AspectAnnotationLoader loader, AspectAnnotationLoaderStrategy.InterfaceIntroductionInfo introduction) throws Exception
    {
-      loader.getAspectManager().addInterfaceIntroduction(introduction);
+      InterfaceIntroduction intro = null;
+      if (introduction.getTarget() != null)
+      {
+         intro = new InterfaceIntroduction(introduction.getName(), introduction.getTarget(), introduction.getInterfaces(), introduction.getConstructorClass(), introduction.getConstructorMethod());
+      }
+      else
+      {
+         ASTStart start = new TypeExpressionParser(new StringReader(introduction.getExpr())).Start();
+         intro = new InterfaceIntroduction(introduction.getName(), start, introduction.getInterfaces(), introduction.getConstructorClass(), introduction.getConstructorMethod());
+      }
+
+      if (introduction.getMixins() != null)
+      {
+         for (AspectAnnotationLoaderStrategy.InterfaceIntroductionMixinInfo mixin : introduction.getMixins())
+         {
+            intro.getMixins().add(new InterfaceIntroduction.Mixin(mixin.getClassname(), mixin.getInterfaces(), mixin.getConstruction(), mixin.isTrans()));
+         }
+      }
+      
+      loader.getAspectManager().addInterfaceIntroduction(intro);
    }
    
    public void undeployInterfaceIntroduction(AspectAnnotationLoader loader, String name)

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/pointcut/CFlow.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/pointcut/CFlow.java	2008-07-08 16:58:04 UTC (rev 75503)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/pointcut/CFlow.java	2008-07-08 17:00:06 UTC (rev 75504)
@@ -138,16 +138,6 @@
       return true;
    }
    
-   public String getExpr()
-   {
-      return original;
-   }
-
-   public boolean isNot()
-   {
-      return not;
-   }
-
    private Class<?> loadClass(String name)
    {
       return SecurityActions.loadClass(name);

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/pointcut/CFlowStack.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/pointcut/CFlowStack.java	2008-07-08 16:58:04 UTC (rev 75503)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/pointcut/CFlowStack.java	2008-07-08 17:00:06 UTC (rev 75504)
@@ -52,11 +52,6 @@
       cflows.add(cflow);
    }
 
-   public List<CFlow> getCFlows()
-   {
-      return Collections.unmodifiableList(cflows);
-   }
-   
    public boolean matches(StackTraceElement[] stack)
    {
       int stackIndex = stack.length - 1;




More information about the jboss-cvs-commits mailing list