[jboss-cvs] JBossAS SVN: r60672 - projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Feb 19 15:56:34 EST 2007


Author: flavia.rainone at jboss.com
Date: 2007-02-19 15:56:34 -0500 (Mon, 19 Feb 2007)
New Revision: 60672

Modified:
   projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/AdviceInfo.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
Log:
[JBAOP-37] Activated reset of validation data, so that the same AdviceInfo can be used more than once.

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/AdviceInfo.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/AdviceInfo.java	2007-02-19 18:54:11 UTC (rev 60671)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/AdviceInfo.java	2007-02-19 20:56:34 UTC (rev 60672)
@@ -255,6 +255,11 @@
     */
    public abstract boolean validate(AdviceMethodProperties properties,
          ReturnType returnType);
+   
+   /**
+    * Resets all information that has been set during validation.
+    */
+   public abstract void resetValidation();
 
    /**
     * Returns the distance in hierarchy between the annotated parameter identified by

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-02-19 18:54:11 UTC (rev 60671)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/AdviceMethodFactory.java	2007-02-19 20:56:34 UTC (rev 60672)
@@ -145,6 +145,8 @@
                      }
                      return false;
                   }
+                  
+                  public void resetValidation() {}
 
                   public short getAssignabilityDegree(int typeIndex,
                         boolean isContextRule, AdviceMethodProperties properties)
@@ -309,13 +311,19 @@
       // verify if list is on cache
       String key =
               properties.getAspectClass().getName() + properties.getAdviceName();
+      
       WeakHashMap<ParameterAnnotationRule[], Collection<AdviceInfo>> map = 
          adviceInfoCache.get(key);
       if (map != null)
       {
          if (map.containsKey(contextRules))
          {
-            return new LinkedList<AdviceInfo> (map.get(contextRules));
+            Collection<AdviceInfo> advices = map.get(contextRules);
+            for(AdviceInfo adviceInfo: advices)
+            {
+               adviceInfo.resetValidation();
+            }
+            return new LinkedList<AdviceInfo> (advices);
          }
       }
       else
@@ -341,7 +349,7 @@
          return null;
       }
       
-      ArrayList<AdviceInfo> rankedAdvices = new ArrayList<AdviceInfo>();
+      ArrayList<AdviceInfo> rankedAdvices = new ArrayList<AdviceInfo>(methods.length);
       for (int i = 0; i < methods.length; i++)
       {
          // advice applies to signature rule

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-02-19 18:54:11 UTC (rev 60671)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/AnnotatedParameterAdviceInfo.java	2007-02-19 20:56:34 UTC (rev 60672)
@@ -116,6 +116,18 @@
       }
       return true;
    }
+
+   public void resetValidation()
+   {
+      for (int i = 0;  i < paramTypes.length; i++)
+      {
+         paramTypes[i].resetValidation();
+      }
+      for (int i = 0; i < contextParamTypes.length; i++)
+      {
+         contextParamTypes[i].resetValidation();
+      }
+   }
    
    public short getAssignabilityDegree(int annotationIndex, boolean isContextRule,
          AdviceMethodProperties properties)
@@ -140,7 +152,7 @@
       }
       properties.setFoundProperties(this.method, args);
    }
-
+   
    /**
     * Creates a parameter annotation type array correpondent to the parameter
     * annotation rules contained in <code>rules</code>.
@@ -385,6 +397,12 @@
       public abstract boolean internalValidate(AdviceMethodProperties properties);
       
       /**
+       * Resets all advice method properties information that has been set during
+       * validation.
+       */
+      public abstract void resetValidation();
+      
+      /**
        * Returns the sum of the assignability degrees of every paramater of this type.
        * 
        * @param properties       contains information about the queried advice method
@@ -456,6 +474,9 @@
          return  true;
       }
 
+      // this class doesn't set any field during validation
+      public final void resetValidation() { }
+
       public final short getAssignabilityDegree(AdviceMethodProperties properties)
       {
          if (this.index == -1)
@@ -482,6 +503,7 @@
    class MultipleParameterType extends ParameterAnnotationType
    {
       private int[][] indexes;
+      private int[] originalIndexValues; // for resetting purposes
       private int indexesLength;
       
       // maximum size is the total number of parameters
@@ -490,6 +512,7 @@
          super(rule);
          this.indexes = new int[totalParams][2];
          this.indexesLength = 0;
+         this.originalIndexValues = new int[totalParams];
       }
       
       public final void setIndex(int index, Annotation annotation)
@@ -500,7 +523,9 @@
             throw new ParameterAnnotationRuleException("Found more @Arg annotated parameters than the number of parameters available on joinpoint");
          }
          indexes[indexesLength][0] = index;
-         indexes[indexesLength++][1] = ((Arg) annotation).index();
+         originalIndexValues[indexesLength] = ((Arg) annotation).index();
+         indexes[indexesLength][1] = originalIndexValues[indexesLength];
+         indexesLength ++;
          rank += rule.getRankGrade();
       }
       
@@ -560,6 +585,7 @@
                }
                taken[indexes[i][1]] = true;
                // TODO give priority to indexes set first
+               // TODO Check on taken for indexes set
                continue;
             }
             
@@ -608,6 +634,14 @@
          }
          return true;
       }
+            
+      public void resetValidation()
+      {
+         for (int i = 0; i < indexesLength; i++)
+         {
+            indexes[i][1] = originalIndexValues[i];
+         }
+      }
       
       public short getAssignabilityDegree(AdviceMethodProperties properties)
       {
@@ -632,6 +666,6 @@
          {
             args[this.indexes[i][0]] = this.indexes[i][1];
          }
-      }  
+      }
    }
 }
\ No newline at end of file




More information about the jboss-cvs-commits mailing list