[jboss-cvs] JBossAS SVN: r59243 - in projects/aop/branches/arrays/aop/src: main/org/jboss/aop main/org/jboss/aop/advice main/org/jboss/aop/array resources/test/array test/org/jboss/test/aop/array

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Dec 28 18:35:23 EST 2006


Author: kabir.khan at jboss.com
Date: 2006-12-28 18:35:15 -0500 (Thu, 28 Dec 2006)
New Revision: 59243

Added:
   projects/aop/branches/arrays/aop/src/main/org/jboss/aop/array/ArrayBinding.java
   projects/aop/branches/arrays/aop/src/test/org/jboss/test/aop/array/AspectForPrecedence.java
   projects/aop/branches/arrays/aop/src/test/org/jboss/test/aop/array/TestArrayElementInterceptor.java
Removed:
   projects/aop/branches/arrays/aop/src/main/org/jboss/aop/array/TestArrayElementInterceptor.java
Modified:
   projects/aop/branches/arrays/aop/src/main/org/jboss/aop/AspectManager.java
   projects/aop/branches/arrays/aop/src/main/org/jboss/aop/AspectXmlLoader.java
   projects/aop/branches/arrays/aop/src/main/org/jboss/aop/advice/PrecedenceSorter.java
   projects/aop/branches/arrays/aop/src/main/org/jboss/aop/array/ArrayAdvisor.java
   projects/aop/branches/arrays/aop/src/main/org/jboss/aop/array/ArrayElementInvocation.java
   projects/aop/branches/arrays/aop/src/resources/test/array/jboss-aop.xml
   projects/aop/branches/arrays/aop/src/test/org/jboss/test/aop/array/AOPArrayTestCase.java
Log:
Make the interceptors/advices applied to arrays configurable via the <arraybind> element, and enable precedence for the chains

Modified: projects/aop/branches/arrays/aop/src/main/org/jboss/aop/AspectManager.java
===================================================================
--- projects/aop/branches/arrays/aop/src/main/org/jboss/aop/AspectManager.java	2006-12-28 23:32:30 UTC (rev 59242)
+++ projects/aop/branches/arrays/aop/src/main/org/jboss/aop/AspectManager.java	2006-12-28 23:35:15 UTC (rev 59243)
@@ -42,7 +42,6 @@
 import org.jboss.aop.advice.AdviceBinding;
 import org.jboss.aop.advice.AdviceStack;
 import org.jboss.aop.advice.AspectDefinition;
-import org.jboss.aop.advice.AspectFactory;
 import org.jboss.aop.advice.AspectFactoryWithClassLoader;
 import org.jboss.aop.advice.DynamicCFlowDefinition;
 import org.jboss.aop.advice.InterceptorFactory;
@@ -50,6 +49,8 @@
 import org.jboss.aop.advice.PrecedenceDefEntry;
 import org.jboss.aop.advice.PrecedenceSorter;
 import org.jboss.aop.advice.Scope;
+import org.jboss.aop.array.ArrayAdvisor;
+import org.jboss.aop.array.ArrayBinding;
 import org.jboss.aop.array.ArrayReplacement;
 import org.jboss.aop.classpool.AOPClassPoolRepository;
 import org.jboss.aop.classpool.AOPScopedClassLoaderHelper;
@@ -118,6 +119,7 @@
 
    protected final LinkedHashMap interfaceIntroductions = new LinkedHashMap();
    protected final LinkedHashMap arrayReplacements = new LinkedHashMap();
+   protected final LinkedHashMap arrayBindings = new LinkedHashMap();
    protected final LinkedHashMap annotationIntroductions = new LinkedHashMap();
    protected final LinkedHashMap annotationOverrides = new LinkedHashMap();
    protected final LinkedHashMap bindings = new LinkedHashMap();
@@ -130,7 +132,7 @@
    protected final ConcurrentReaderHashMap dynamicCFlows = new ConcurrentReaderHashMap();
    protected final ConcurrentReaderHashMap aspectDefinitions = new ConcurrentReaderHashMap();
    protected final ConcurrentReaderHashMap perVMAspects = new ConcurrentReaderHashMap();
-
+   
    /** class name prefixes to explicitly exclude unless contained in include. Maintained by top-level AspectManager */
    protected final ArrayList exclude = new ArrayList();
 
@@ -1545,6 +1547,43 @@
    }
 
    /**
+    * Retrieve an introduction pointcut of a certain name
+    */
+   public InterfaceIntroduction getArrayBinding(String name)
+   {
+      synchronized (arrayBindings)
+      {
+         return (InterfaceIntroduction) arrayBindings.get(name);
+      }
+   }
+
+   /**
+    * Register an introduction pointcut
+    */
+   public synchronized void addArrayBinding(ArrayBinding binding)
+   {
+      removeArrayBinding(binding.getName());
+      synchronized (arrayBindings)
+      {
+         arrayBindings.put(binding.getName(), binding);
+         ArrayAdvisor.addBinding(binding);
+      }
+   }
+
+   /**
+    * remove an introduction pointcut of a certain name
+    */
+   public void removeArrayBinding(String name)
+   {
+      synchronized (arrayBindings)
+      {
+         ArrayBinding pointcut = (ArrayBinding) arrayBindings.remove(name);
+         if (pointcut == null) return;
+         ArrayAdvisor.removeBinding(pointcut);
+      }
+   }
+
+   /**
     * Register an annotation introduction
     */
    public synchronized void addAnnotationIntroduction(AnnotationIntroduction pointcut)

Modified: projects/aop/branches/arrays/aop/src/main/org/jboss/aop/AspectXmlLoader.java
===================================================================
--- projects/aop/branches/arrays/aop/src/main/org/jboss/aop/AspectXmlLoader.java	2006-12-28 23:32:30 UTC (rev 59242)
+++ projects/aop/branches/arrays/aop/src/main/org/jboss/aop/AspectXmlLoader.java	2006-12-28 23:35:15 UTC (rev 59243)
@@ -50,6 +50,7 @@
 import org.jboss.aop.advice.ScopeUtil;
 import org.jboss.aop.advice.ScopedInterceptorFactory;
 import org.jboss.aop.advice.ThrowingFactory;
+import org.jboss.aop.array.ArrayBinding;
 import org.jboss.aop.array.ArrayReplacement;
 import org.jboss.aop.introduction.AnnotationIntroduction;
 import org.jboss.aop.introduction.InterfaceIntroduction;
@@ -300,6 +301,33 @@
       manager.removePointcut(pointcut);
    }
 
+   public void deployArrayBinding(Element element) throws Exception
+   {
+      String name = getName(element, "arraybinding");
+      ArrayList interceptors = loadInterceptors(element);
+      InterceptorFactory[] inters = (InterceptorFactory[]) interceptors.toArray(new InterceptorFactory[interceptors.size()]);
+      for (int i = 0 ; i < inters.length ; i++)
+      {
+         if (!inters[i].getAspect().getScope().equals(Scope.PER_VM))
+         {
+            throw new RuntimeException("Only PER_VM scoped aspects/interceptors can be used in arraybindings");
+         }
+      }
+      ArrayBinding binding = new ArrayBinding(name, inters);
+      manager.addArrayBinding(binding);
+   }
+
+   public void undeployArrayBinding(Element element) throws Exception
+   {
+      String binding = getName(element, "arraybinding");
+      if (binding == null) throw new RuntimeException("undeploying Arraybinding that is null!");
+      manager.removeArrayBinding(binding);//done in bulkUndeploy() step
+//      bindings.add(binding);
+//      unloadInterceptors(element);
+      String pointcut = getName("pointcut");
+      manager.removePointcut(pointcut);
+   }
+
    private void deployPrecedence(Element element) throws Exception
    {
       String name = getName(element, "precedence");
@@ -1124,6 +1152,10 @@
             {
                deployArrayReplacement(element);
             }
+            else if (tag.equals("arraybind"))
+            {
+               deployArrayBinding(element);
+            }
             else
             {
                throw new IllegalArgumentException("Unknown AOP tag: " + tag);
@@ -1242,6 +1274,10 @@
             {
                undeployArrayReplacement(element);
             }
+            else if (tag.equals("arraybind"))
+            {
+               undeployArrayBinding(element);
+            }
          }
       }
    }

Modified: projects/aop/branches/arrays/aop/src/main/org/jboss/aop/advice/PrecedenceSorter.java
===================================================================
--- projects/aop/branches/arrays/aop/src/main/org/jboss/aop/advice/PrecedenceSorter.java	2006-12-28 23:32:30 UTC (rev 59242)
+++ projects/aop/branches/arrays/aop/src/main/org/jboss/aop/advice/PrecedenceSorter.java	2006-12-28 23:35:15 UTC (rev 59243)
@@ -245,6 +245,7 @@
       if (interceptors.length == 0)
          return interceptors;
       
+      System.out.println(interceptors[0].getClass().getName());
       ArrayList all = new ArrayList(interceptors.length);
       ArrayList precedence = new ArrayList(interceptors.length);
       PrecedenceDefEntry[] precedenceEntries = manager.getSortedPrecedenceDefEntries();

Modified: projects/aop/branches/arrays/aop/src/main/org/jboss/aop/array/ArrayAdvisor.java
===================================================================
--- projects/aop/branches/arrays/aop/src/main/org/jboss/aop/array/ArrayAdvisor.java	2006-12-28 23:32:30 UTC (rev 59242)
+++ projects/aop/branches/arrays/aop/src/main/org/jboss/aop/array/ArrayAdvisor.java	2006-12-28 23:35:15 UTC (rev 59243)
@@ -21,7 +21,22 @@
 */ 
 package org.jboss.aop.array;
 
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+import org.jboss.aop.AspectManager;
+import org.jboss.aop.advice.AdviceFactory;
+import org.jboss.aop.advice.GeneratedAdvisorInterceptor;
+import org.jboss.aop.advice.GeneratedOnly;
 import org.jboss.aop.advice.Interceptor;
+import org.jboss.aop.advice.InterceptorFactory;
+import org.jboss.aop.advice.PerVmAdvice;
+import org.jboss.aop.advice.PrecedenceSorter;
+import org.jboss.aop.advice.ScopedInterceptorFactory;
 
 /**
  * 
@@ -30,19 +45,24 @@
  */
 public class ArrayAdvisor
 {
-   //TODO Make configurable
-   static Interceptor[] interceptors = new Interceptor[] {new TestArrayElementInterceptor()};
-   public static Object array;
-   public static String value;
-   public static int index;
+   static HashSet<ArrayBinding> bindings = new LinkedHashSet<ArrayBinding>();
+   static boolean updated;
    
-   public static void clear()
+   public static void addBinding(ArrayBinding arrayBinding)
    {
-      array = null;
-      value = null;
-      index = -1;
+      ChainCreator.addBinding(arrayBinding);
    }
    
+   public static void removeBinding(ArrayBinding arrayBinding)
+   {
+      ChainCreator.removeBinding(arrayBinding);
+   }
+   
+   public static Interceptor[] getInterceptors()
+   {
+      return ChainCreator.getInterceptors();
+   }
+   
    public static void updateArrayField(Object target, String fieldName, Object oldValue, Object newValue)
    {
       ArrayRegistry registry = ArrayRegistry.getInstance();
@@ -52,6 +72,7 @@
 
    public static void arrayWriteObject(Object array, int index, Object value) throws Throwable
    {
+      Interceptor[] interceptors = getInterceptors();
       ArrayRegistry registry = ArrayRegistry.getInstance();
       if (registry.isRegistered(array))
       {
@@ -67,9 +88,12 @@
             {
                registry.addElementReference(array, index, value);
             }
-            ObjectArrayElementWriteInvocation invocation = new ObjectArrayElementWriteInvocation(interceptors, (Object[])array, index, value);
-            invocation.invokeNext();
-            return;
+            if (interceptors != null)
+            {
+               ObjectArrayElementWriteInvocation invocation = new ObjectArrayElementWriteInvocation(interceptors, (Object[])array, index, value);
+               invocation.invokeNext();
+               return;
+            }
          }
       }
       ((Object[])array)[index] = value;
@@ -77,7 +101,8 @@
    
    public static void arrayWriteInt(Object array, int index, int value) throws Throwable
    {
-      if (ArrayRegistry.getInstance().isRegistered(array) && ((int[])array)[index] != value)
+      Interceptor[] interceptors = getInterceptors();
+      if (interceptors != null && ArrayRegistry.getInstance().isRegistered(array) && ((int[])array)[index] != value)
       {
          IntArrayElementWriteInvocation invocation = new IntArrayElementWriteInvocation(interceptors, ((int[])array), index, value);
          invocation.invokeNext();
@@ -90,7 +115,8 @@
 
    public static void arrayWriteByteOrBoolean(Object array, int index, byte value) throws Throwable
    {
-      if (ArrayRegistry.getInstance().isRegistered(array))
+      Interceptor[] interceptors = getInterceptors();
+      if (interceptors != null && ArrayRegistry.getInstance().isRegistered(array))
       {
          if (array instanceof boolean[])
          {
@@ -118,7 +144,8 @@
 
    public static void arrayWriteChar(Object array, int index, char value) throws Throwable
    {
-      if (ArrayRegistry.getInstance().isRegistered(array) && ((char[])array)[index] != value)
+      Interceptor[] interceptors = getInterceptors();
+      if (interceptors != null && ArrayRegistry.getInstance().isRegistered(array) && ((char[])array)[index] != value)
       {
          CharArrayElementWriteInvocation invocation = new CharArrayElementWriteInvocation(interceptors, ((char[])array), index, value);
          invocation.invokeNext();
@@ -131,7 +158,8 @@
 
    public static void arrayWriteDouble(Object array, int index, double value) throws Throwable
    {
-      if (ArrayRegistry.getInstance().isRegistered(array) && ((double[])array)[index] != value)
+      Interceptor[] interceptors = getInterceptors();
+      if (interceptors != null && ArrayRegistry.getInstance().isRegistered(array) && ((double[])array)[index] != value)
       {
          DoubleArrayElementWriteInvocation invocation = new DoubleArrayElementWriteInvocation(interceptors, ((double[])array), index, value);
          invocation.invokeNext();
@@ -144,7 +172,8 @@
 
    public static void arrayWriteShort(Object array, int index, short value) throws Throwable
    {
-      if (ArrayRegistry.getInstance().isRegistered(array) && ((short[])array)[index] != value)
+      Interceptor[] interceptors = getInterceptors();
+      if (interceptors != null && ArrayRegistry.getInstance().isRegistered(array) && ((short[])array)[index] != value)
       {
          ShortArrayElementWriteInvocation invocation = new ShortArrayElementWriteInvocation(interceptors, ((short[])array), index, value);
          invocation.invokeNext();
@@ -157,7 +186,8 @@
 
    public static void arrayWriteFloat(Object array, int index, float value) throws Throwable
    {
-      if (ArrayRegistry.getInstance().isRegistered(array) && ((float[])array)[index] != value)
+      Interceptor[] interceptors = getInterceptors();
+      if (interceptors != null && ArrayRegistry.getInstance().isRegistered(array) && ((float[])array)[index] != value)
       {
          FloatArrayElementWriteInvocation invocation = new FloatArrayElementWriteInvocation(interceptors, ((float[])array), index, value);
          invocation.invokeNext();
@@ -170,7 +200,8 @@
 
    public static void arrayWriteLong(Object array, int index, long value) throws Throwable
    {
-      if (ArrayRegistry.getInstance().isRegistered(array) && ((long[])array)[index] != value)
+      Interceptor[] interceptors = getInterceptors();
+      if (interceptors != null && ArrayRegistry.getInstance().isRegistered(array) && ((long[])array)[index] != value)
       {
          LongArrayElementWriteInvocation invocation = new LongArrayElementWriteInvocation(interceptors, ((long[])array), index, value);
          invocation.invokeNext();
@@ -183,7 +214,8 @@
 
    public static Object arrayReadObject(Object array, int index) throws Throwable
    {
-      if (ArrayRegistry.getInstance().isRegistered(array))
+      Interceptor[] interceptors = getInterceptors();
+      if (interceptors != null && ArrayRegistry.getInstance().isRegistered(array))
       {
          ObjectArrayElementReadInvocation invocation = new ObjectArrayElementReadInvocation(interceptors, (Object[])array, index);
          return invocation.invokeNext();
@@ -196,7 +228,8 @@
 
    public static int arrayReadInt(Object array, int index) throws Throwable
    {
-      if (ArrayRegistry.getInstance().isRegistered(array))
+      Interceptor[] interceptors = getInterceptors();
+      if (interceptors != null && ArrayRegistry.getInstance().isRegistered(array))
       {
          IntArrayElementReadInvocation invocation = new IntArrayElementReadInvocation(interceptors, (int[])array, index);
          return ((Integer)invocation.invokeNext()).intValue();
@@ -209,7 +242,8 @@
 
    public static byte arrayReadByteOrBoolean(Object array, int index) throws Throwable
    {
-      if (ArrayRegistry.getInstance().isRegistered(array))
+      Interceptor[] interceptors = getInterceptors();
+      if (interceptors != null && ArrayRegistry.getInstance().isRegistered(array))
       {
          if (array instanceof boolean[])
          {
@@ -238,7 +272,8 @@
 
    public static char arrayReadChar(Object array, int index) throws Throwable
    {
-      if (ArrayRegistry.getInstance().isRegistered(array))
+      Interceptor[] interceptors = getInterceptors();
+      if (interceptors != null && ArrayRegistry.getInstance().isRegistered(array))
       {
          CharArrayElementReadInvocation invocation = new CharArrayElementReadInvocation(interceptors, (char[])array, index);
          return ((Character)invocation.invokeNext()).charValue();
@@ -251,7 +286,8 @@
 
    public static double arrayReadDouble(Object array, int index) throws Throwable
    {
-      if (ArrayRegistry.getInstance().isRegistered(array))
+      Interceptor[] interceptors = getInterceptors();
+      if (interceptors != null && ArrayRegistry.getInstance().isRegistered(array))
       {
          DoubleArrayElementReadInvocation invocation = new DoubleArrayElementReadInvocation(interceptors, (double[])array, index);
          return ((Double)invocation.invokeNext()).doubleValue();
@@ -264,7 +300,8 @@
 
    public static float arrayReadFloat(Object array, int index) throws Throwable
    {
-      if (ArrayRegistry.getInstance().isRegistered(array))
+      Interceptor[] interceptors = getInterceptors();
+      if (interceptors != null && ArrayRegistry.getInstance().isRegistered(array))
       {
          FloatArrayElementReadInvocation invocation = new FloatArrayElementReadInvocation(interceptors, (float[])array, index);
          return ((Float)invocation.invokeNext()).floatValue();
@@ -277,7 +314,8 @@
 
    public static long arrayReadLong(Object array, int index) throws Throwable
    {
-      if (ArrayRegistry.getInstance().isRegistered(array))
+      Interceptor[] interceptors = getInterceptors();
+      if (interceptors != null && ArrayRegistry.getInstance().isRegistered(array))
       {
          LongArrayElementReadInvocation invocation = new LongArrayElementReadInvocation(interceptors, (long[])array, index);
          return ((Long)invocation.invokeNext()).longValue();
@@ -290,7 +328,8 @@
 
    public static short arrayReadShort(Object array, int index) throws Throwable
    {
-      if (ArrayRegistry.getInstance().isRegistered(array))
+      Interceptor[] interceptors = getInterceptors();
+      if (interceptors != null && ArrayRegistry.getInstance().isRegistered(array))
       {
          ShortArrayElementReadInvocation invocation = new ShortArrayElementReadInvocation(interceptors, (short[])array, index);
          return ((Short)invocation.invokeNext()).shortValue();
@@ -300,4 +339,128 @@
          return ((short[])array)[index];
       }
    }
+   
+   private static class ChainCreator
+   {
+      private static ReadWriteLock lock = new ReentrantReadWriteLock(); 
+      static Interceptor[] interceptors;
+      public static void addBinding(ArrayBinding arrayBinding)
+      {
+         Lock writeLock = lock.writeLock();
+         writeLock.lock();
+         try
+         {
+            bindings.add(arrayBinding);
+            updated = true;
+         }
+         finally
+         {
+            writeLock.unlock();
+         }
+      }
+      
+      public static void removeBinding(ArrayBinding arrayBinding)
+      {
+         Lock writeLock = lock.writeLock();
+         writeLock.lock();
+         try
+         {
+            bindings.remove(arrayBinding);
+            updated = true;
+         }
+         finally
+         {
+            writeLock.unlock();
+         }
+      }
+      
+      public static Interceptor[] getInterceptors()
+      {
+         Lock readLock = lock.readLock();
+         readLock.lock();
+         boolean lockedRead = true;
+         try
+         {
+            if (updated)
+            {
+               readLock.unlock();
+               lockedRead = false;
+               Lock writeLock = lock.writeLock();
+               writeLock.lock();
+               try
+               {
+                  if (updated)
+                  {
+                     //Create the interceptor chains
+                     for (ArrayBinding binding : bindings)
+                     {
+                        InterceptorFactory[] factories = binding.getInterceptorFactories();
+                        ArrayList<Interceptor> newinterceptors = new ArrayList<Interceptor>();
+                        for (int i = 0; i < factories.length; i++)
+                        {
+                           Interceptor icptr = createInterceptor(factories[i]);
+                           if (icptr != null)
+                           {
+                              newinterceptors.add(icptr);
+                           }
+                        }
+                        interceptors = (newinterceptors.size() > 0) ? newinterceptors.toArray(new Interceptor[newinterceptors.size()]) : null;
+                        if (interceptors != null)
+                        {
+                           if (interceptors[0] instanceof GeneratedAdvisorInterceptor)
+                           {
+                              
+                           }
+                           interceptors = PrecedenceSorter.applyPrecedence(interceptors, AspectManager.instance());
+                        }
+                     }
+                     updated = false;
+                     return interceptors;
+                  }
+               }
+               finally
+               {
+                  writeLock.unlock();               
+               }
+            }
+            return interceptors;
+         }
+         finally
+         {
+            if (lockedRead)
+            {
+               readLock.unlock();
+            }
+         }
+      }
+      
+      private static Interceptor createInterceptor(InterceptorFactory factory)
+      {
+         if (factory instanceof GeneratedOnly)
+         {
+            throw new RuntimeException("Before/After/Throwing is only supported for Generated Advisors");
+         }
+
+         try
+         {
+            if (factory.isDeployed())
+            {
+               if (factory instanceof AdviceFactory)
+               {
+                  return PerVmAdvice.generateOptimized(null, AspectManager.instance(), factory.getAdvice(), factory.getAspect());
+               }
+               else if (factory instanceof ScopedInterceptorFactory)
+               {
+                  return (Interceptor) AspectManager.instance().getPerVMAspect(factory.getAspect());
+               }
+            }
+            
+            return null;
+         }
+         catch (Exception e)
+         {
+            throw new RuntimeException(e);
+         }
+      }
+   }
 }

Added: projects/aop/branches/arrays/aop/src/main/org/jboss/aop/array/ArrayBinding.java
===================================================================
--- projects/aop/branches/arrays/aop/src/main/org/jboss/aop/array/ArrayBinding.java	2006-12-28 23:32:30 UTC (rev 59242)
+++ projects/aop/branches/arrays/aop/src/main/org/jboss/aop/array/ArrayBinding.java	2006-12-28 23:35:15 UTC (rev 59243)
@@ -0,0 +1,83 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors. 
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.aop.array;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.jboss.aop.advice.InterceptorFactory;
+import org.jboss.aop.pointcut.Pointcut;
+import org.jboss.aop.pointcut.ast.ParseException;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ArrayBinding 
+{
+   private static volatile long counter = 0;
+
+   protected String name;
+//   protected Pointcut pointcut;
+
+   protected InterceptorFactory[] interceptorFactories = new InterceptorFactory[0];
+
+   public ArrayBinding(String name/*, Pointcut p*/, InterceptorFactory[] factories) throws ParseException
+   {
+      this.name = name;
+      interceptorFactories = factories;
+//      pointcut = p;
+   }
+
+   public void addInterceptorFactory(InterceptorFactory factory)
+   {
+      List list = Arrays.asList(interceptorFactories);
+      list = new ArrayList(list);
+      list.add(factory);
+      interceptorFactories = (InterceptorFactory[]) list.toArray(new InterceptorFactory[list.size()]);
+   }
+
+
+   public String getName()
+   {
+      return name;
+   }
+
+   public InterceptorFactory[] getInterceptorFactories()
+   {
+      return interceptorFactories;
+   }
+
+   public boolean equals(Object obj)
+   {
+      if (obj == this) return true;
+      if (!(obj instanceof ArrayBinding)) return false;
+      return ((ArrayBinding) obj).getName().equals(name);
+   }
+
+   public int hashCode()
+   {
+      return name.hashCode();
+   }
+}

Modified: projects/aop/branches/arrays/aop/src/main/org/jboss/aop/array/ArrayElementInvocation.java
===================================================================
--- projects/aop/branches/arrays/aop/src/main/org/jboss/aop/array/ArrayElementInvocation.java	2006-12-28 23:32:30 UTC (rev 59242)
+++ projects/aop/branches/arrays/aop/src/main/org/jboss/aop/array/ArrayElementInvocation.java	2006-12-28 23:35:15 UTC (rev 59243)
@@ -96,12 +96,6 @@
    }
 
    @Override
-   public MetaDataResolver getInstanceResolver()
-   {
-      throw new NotImplementedException();
-   }
-
-   @Override
    public Object getResponseAttachment(Object key)
    {
       throw new NotImplementedException();

Deleted: projects/aop/branches/arrays/aop/src/main/org/jboss/aop/array/TestArrayElementInterceptor.java
===================================================================
--- projects/aop/branches/arrays/aop/src/main/org/jboss/aop/array/TestArrayElementInterceptor.java	2006-12-28 23:32:30 UTC (rev 59242)
+++ projects/aop/branches/arrays/aop/src/main/org/jboss/aop/array/TestArrayElementInterceptor.java	2006-12-28 23:35:15 UTC (rev 59243)
@@ -1,64 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source.
-* Copyright 2006, Red Hat Middleware LLC, and individual contributors
-* as indicated by the @author tags. See the copyright.txt file in the
-* distribution for a full listing of individual contributors. 
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/ 
-package org.jboss.aop.array;
-
-import org.jboss.aop.advice.Interceptor;
-import org.jboss.aop.joinpoint.Invocation;
-
-/**
- * 
- * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
- * @version $Revision: 1.1 $
- */
-public class TestArrayElementInterceptor implements Interceptor
-{
-   public static int index;
-   public static Object value;
-   
-   public static void clear()
-   {
-      index = -1;
-      value = null;
-   }
-   
-   public String getName()
-   {
-      return this.getClass().getName();
-   }
-
-   public Object invoke(Invocation invocation) throws Throwable
-   {
-      if (invocation instanceof ArrayElementReadInvocation)
-      {
-         index = ((ArrayElementReadInvocation)invocation).getIndex();
-         value = null;
-      }
-      else if (invocation instanceof ArrayElementWriteInvocation)
-      {
-         index = ((ArrayElementWriteInvocation)invocation).getIndex();
-         value = ((ArrayElementWriteInvocation)invocation).getValue();
-      } 
-      
-      return invocation.invokeNext();
-   }
-
-}

Modified: projects/aop/branches/arrays/aop/src/resources/test/array/jboss-aop.xml
===================================================================
--- projects/aop/branches/arrays/aop/src/resources/test/array/jboss-aop.xml	2006-12-28 23:32:30 UTC (rev 59242)
+++ projects/aop/branches/arrays/aop/src/resources/test/array/jboss-aop.xml	2006-12-28 23:35:15 UTC (rev 59243)
@@ -5,6 +5,19 @@
    <arrayreplacement expr="class($instanceof{org.jboss.test.aop.array.ClassForReference})"/>
    <prepare expr="field(* org.jboss.test.aop.array.ClassWithArrayFields->*)"/>
    <prepare expr="field(* org.jboss.test.aop.array.ClassWithSeveralReferencesToSameArray->*)"/> 
-   <prepare expr="field(* org.jboss.test.aop.array.ClassForReference->*)"/> 
+   <prepare expr="field(* org.jboss.test.aop.array.ClassForReference->*)"/>
+   
+   <aspect class="org.jboss.test.aop.array.AspectForPrecedence"/>
+   <interceptor class="org.jboss.test.aop.array.TestArrayElementInterceptor"/>
+
+   <precedence>
+   	<interceptor-ref name="org.jboss.test.aop.array.TestArrayElementInterceptor"/>
+   	<advice aspect="org.jboss.test.aop.array.AspectForPrecedence" name="advice"/>
+   </precedence>
+
+   <arraybind>
+   	<advice aspect="org.jboss.test.aop.array.AspectForPrecedence" name="advice"/>
+   	<interceptor-ref name="org.jboss.test.aop.array.TestArrayElementInterceptor"/>
+   </arraybind>
 </aop>
 

Modified: projects/aop/branches/arrays/aop/src/test/org/jboss/test/aop/array/AOPArrayTestCase.java
===================================================================
--- projects/aop/branches/arrays/aop/src/test/org/jboss/test/aop/array/AOPArrayTestCase.java	2006-12-28 23:32:30 UTC (rev 59242)
+++ projects/aop/branches/arrays/aop/src/test/org/jboss/test/aop/array/AOPArrayTestCase.java	2006-12-28 23:35:15 UTC (rev 59243)
@@ -24,7 +24,6 @@
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
-import org.jboss.aop.array.TestArrayElementInterceptor;
 import org.jboss.test.aop.AOPTestWithSetup;
 
 
@@ -52,156 +51,192 @@
    {
       ClassWithArrayFields obj = new ClassWithArrayFields();
       TestArrayElementInterceptor.clear();
+      AspectForPrecedence.invoked = false;
       obj.objects[2] = "X";
       assertEquals(2, TestArrayElementInterceptor.index);
       assertEquals("X", TestArrayElementInterceptor.value);
+      assertTrue(AspectForPrecedence.invoked);
       
       TestArrayElementInterceptor.clear();
+      AspectForPrecedence.invoked = false;
       Object o = obj.objects[0];
       assertEquals("1", o);
       assertEquals(0, TestArrayElementInterceptor.index);
+      assertTrue(AspectForPrecedence.invoked);
    }
    
    public void testIntArray()
    {
       ClassWithArrayFields obj = new ClassWithArrayFields();
       TestArrayElementInterceptor.clear();
+      AspectForPrecedence.invoked = false;
       obj.ints[1] = 100; 
       assertEquals(1, TestArrayElementInterceptor.index);
       assertNotNull(TestArrayElementInterceptor.value);
       assertEquals(100, ((Integer)TestArrayElementInterceptor.value).intValue());
+      assertTrue(AspectForPrecedence.invoked);
 
       obj.ints[2] = 123;
       
       TestArrayElementInterceptor.clear();
+      AspectForPrecedence.invoked = false;
       int val = obj.ints[2];
       assertEquals(123, val);
       assertEquals(2, TestArrayElementInterceptor.index);
       assertNull(TestArrayElementInterceptor.value);
+      assertTrue(AspectForPrecedence.invoked);
    }
    
    public void testByteArray()
    {
       ClassWithArrayFields obj = new ClassWithArrayFields();
       TestArrayElementInterceptor.clear();
+      AspectForPrecedence.invoked = false;
       obj.bytes[1] = 100; 
       assertEquals(1, TestArrayElementInterceptor.index);
       assertNotNull(TestArrayElementInterceptor.value);
       assertEquals(100, ((Byte)TestArrayElementInterceptor.value).byteValue());
+      assertTrue(AspectForPrecedence.invoked);
 
       obj.bytes[2] = 123;
       
       TestArrayElementInterceptor.clear();
+      AspectForPrecedence.invoked = false;
       byte val = obj.bytes[2];
       assertEquals(123, val);
       assertEquals(2, TestArrayElementInterceptor.index);
       assertNull(TestArrayElementInterceptor.value);
+      assertTrue(AspectForPrecedence.invoked);
    }
    
    public void testBooleanArray()
    {
       ClassWithArrayFields obj = new ClassWithArrayFields();
       TestArrayElementInterceptor.clear();
+      AspectForPrecedence.invoked = false;
       obj.booleans[1] = true;
       assertEquals(1, TestArrayElementInterceptor.index);
       assertNotNull(TestArrayElementInterceptor.value);
       assertEquals(true, ((Boolean)TestArrayElementInterceptor.value).booleanValue());
+      assertTrue(AspectForPrecedence.invoked);
 
       TestArrayElementInterceptor.clear();
+      AspectForPrecedence.invoked = false;
       boolean val = obj.booleans[1];
       assertEquals(true, val);
       assertEquals(1, TestArrayElementInterceptor.index);
       assertNull(TestArrayElementInterceptor.value);
+      assertTrue(AspectForPrecedence.invoked);
    }
    
    public void testCharArray()
    {
       ClassWithArrayFields obj = new ClassWithArrayFields();
       TestArrayElementInterceptor.clear();
+      AspectForPrecedence.invoked = false;
       obj.chars[1] = 'z'; 
       assertEquals(1, TestArrayElementInterceptor.index);
       assertNotNull(TestArrayElementInterceptor.value);
       assertEquals('z', ((Character)TestArrayElementInterceptor.value).charValue());
+      assertTrue(AspectForPrecedence.invoked);
 
       obj.chars[2] = 'x';
       
       TestArrayElementInterceptor.clear();
+      AspectForPrecedence.invoked = false;
       char val = obj.chars[2];
       assertEquals('x', val);
       assertEquals(2, TestArrayElementInterceptor.index);
       assertNull(TestArrayElementInterceptor.value);
+      assertTrue(AspectForPrecedence.invoked);
    }
 
    public void testDoubleArray()
    {
       ClassWithArrayFields obj = new ClassWithArrayFields();
       TestArrayElementInterceptor.clear();
+      AspectForPrecedence.invoked = false;
       obj.doubles[1] = 2.1d; 
       assertEquals(1, TestArrayElementInterceptor.index);
       assertNotNull(TestArrayElementInterceptor.value);
       assertEquals(2.1d, ((Double)TestArrayElementInterceptor.value).doubleValue());
+      assertTrue(AspectForPrecedence.invoked);
 
       obj.doubles[2] = 9.9d;
       
       TestArrayElementInterceptor.clear();
+      AspectForPrecedence.invoked = false;
       double val = obj.doubles[2];
       assertEquals(9.9d, val);
       assertEquals(2, TestArrayElementInterceptor.index);
       assertNull(TestArrayElementInterceptor.value);
+      assertTrue(AspectForPrecedence.invoked);
    }
    
    public void testFloatArray()
    {
       ClassWithArrayFields obj = new ClassWithArrayFields();
       TestArrayElementInterceptor.clear();
+      AspectForPrecedence.invoked = false;
       obj.floats[1] = 2.1f; 
       assertEquals(1, TestArrayElementInterceptor.index);
       assertNotNull(TestArrayElementInterceptor.value);
       assertEquals(2.1f, ((Float)TestArrayElementInterceptor.value).floatValue());
+      assertTrue(AspectForPrecedence.invoked);
 
       obj.floats[2] = 9.9f;
       
       TestArrayElementInterceptor.clear();
+      AspectForPrecedence.invoked = false;
       double val = obj.floats[2];
       assertEquals(9.9f, val);
       assertEquals(2, TestArrayElementInterceptor.index);
       assertNull(TestArrayElementInterceptor.value);
+      assertTrue(AspectForPrecedence.invoked);
    }
    
    public void testLongArray()
    {
       ClassWithArrayFields obj = new ClassWithArrayFields();
       TestArrayElementInterceptor.clear();
+      AspectForPrecedence.invoked = false;
       obj.longs[1] = 100L; 
       assertEquals(1, TestArrayElementInterceptor.index);
       assertNotNull(TestArrayElementInterceptor.value);
       assertEquals(100L, ((Long)TestArrayElementInterceptor.value).longValue());
+      assertTrue(AspectForPrecedence.invoked);
 
       obj.longs[2] = 200L;
       
       TestArrayElementInterceptor.clear();
+      AspectForPrecedence.invoked = false;
       double val = obj.longs[2];
       assertEquals(200L, val);
       assertEquals(2, TestArrayElementInterceptor.index);
       assertNull(TestArrayElementInterceptor.value);
+      assertTrue(AspectForPrecedence.invoked);
    }
    
    public void testShortArray()
    {
       ClassWithArrayFields obj = new ClassWithArrayFields();
       TestArrayElementInterceptor.clear();
+      AspectForPrecedence.invoked = false;
       obj.shorts[1] = 50; 
       assertEquals(1, TestArrayElementInterceptor.index);
       assertNotNull(TestArrayElementInterceptor.value);
       assertEquals(50, ((Short)TestArrayElementInterceptor.value).shortValue());
+      assertTrue(AspectForPrecedence.invoked);
 
       obj.shorts[2] = 100;
       
       TestArrayElementInterceptor.clear();
+      AspectForPrecedence.invoked = false;
       double val = obj.shorts[2];
       assertEquals(100, val);
       assertEquals(2, TestArrayElementInterceptor.index);
       assertNull(TestArrayElementInterceptor.value);
+      assertTrue(AspectForPrecedence.invoked);
    }
    
    public void testMultiDimensionalTopLevelArray()

Added: projects/aop/branches/arrays/aop/src/test/org/jboss/test/aop/array/AspectForPrecedence.java
===================================================================
--- projects/aop/branches/arrays/aop/src/test/org/jboss/test/aop/array/AspectForPrecedence.java	2006-12-28 23:32:30 UTC (rev 59242)
+++ projects/aop/branches/arrays/aop/src/test/org/jboss/test/aop/array/AspectForPrecedence.java	2006-12-28 23:35:15 UTC (rev 59243)
@@ -0,0 +1,49 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors. 
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.test.aop.array;
+
+import org.jboss.aop.joinpoint.Invocation;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class AspectForPrecedence
+{
+   public static boolean invoked = false;
+   public Object advice(Invocation invocation) throws Throwable
+   {
+      Object o = invocation.getMetaData("test", "invoked");
+      if (o == null)
+      {
+         throw new RuntimeException("Expected some metadata");
+      }
+      if (!o.equals("TestArrayElementInterceptor"))
+      {
+         throw new RuntimeException("Expected metadata to be 'TestArrayElementInterceptor', it was " + o);
+      }
+      invoked = true;
+      return invocation.invokeNext();
+   }
+
+}

Added: projects/aop/branches/arrays/aop/src/test/org/jboss/test/aop/array/TestArrayElementInterceptor.java
===================================================================
--- projects/aop/branches/arrays/aop/src/test/org/jboss/test/aop/array/TestArrayElementInterceptor.java	2006-12-28 23:32:30 UTC (rev 59242)
+++ projects/aop/branches/arrays/aop/src/test/org/jboss/test/aop/array/TestArrayElementInterceptor.java	2006-12-28 23:35:15 UTC (rev 59243)
@@ -0,0 +1,67 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors. 
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.test.aop.array;
+
+import org.jboss.aop.advice.Interceptor;
+import org.jboss.aop.array.ArrayElementReadInvocation;
+import org.jboss.aop.array.ArrayElementWriteInvocation;
+import org.jboss.aop.joinpoint.Invocation;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class TestArrayElementInterceptor implements Interceptor
+{
+   public static int index;
+   public static Object value;
+   
+   public static void clear()
+   {
+      index = -1;
+      value = null;
+   }
+   
+   public String getName()
+   {
+      return this.getClass().getName();
+   }
+
+   public Object invoke(Invocation invocation) throws Throwable
+   {
+      if (invocation instanceof ArrayElementReadInvocation)
+      {
+         index = ((ArrayElementReadInvocation)invocation).getIndex();
+         value = null;
+      }
+      else if (invocation instanceof ArrayElementWriteInvocation)
+      {
+         index = ((ArrayElementWriteInvocation)invocation).getIndex();
+         value = ((ArrayElementWriteInvocation)invocation).getValue();
+      } 
+      
+      invocation.getMetaData().addMetaData("test", "invoked", "TestArrayElementInterceptor");
+      return invocation.invokeNext();
+   }
+
+}




More information about the jboss-cvs-commits mailing list