[jboss-cvs] JBossAS SVN: r59272 - 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
Tue Jan 2 07:10:57 EST 2007


Author: kabir.khan at jboss.com
Date: 2007-01-02 07:10:50 -0500 (Tue, 02 Jan 2007)
New Revision: 59272

Added:
   projects/aop/branches/arrays/aop/src/main/org/jboss/aop/array/Type.java
   projects/aop/branches/arrays/aop/src/test/org/jboss/test/aop/array/TestArrayElementReadInterceptor.java
   projects/aop/branches/arrays/aop/src/test/org/jboss/test/aop/array/TestArrayElementWriteInterceptor.java
Modified:
   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/ArrayBinding.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:
Add possibility to add different chains when reading and writing arrays

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	2007-01-02 08:50:56 UTC (rev 59271)
+++ projects/aop/branches/arrays/aop/src/main/org/jboss/aop/AspectXmlLoader.java	2007-01-02 12:10:50 UTC (rev 59272)
@@ -52,6 +52,7 @@
 import org.jboss.aop.advice.ThrowingFactory;
 import org.jboss.aop.array.ArrayBinding;
 import org.jboss.aop.array.ArrayReplacement;
+import org.jboss.aop.array.Type;
 import org.jboss.aop.introduction.AnnotationIntroduction;
 import org.jboss.aop.introduction.InterfaceIntroduction;
 import org.jboss.aop.metadata.ClassMetaDataBinding;
@@ -304,6 +305,14 @@
    public void deployArrayBinding(Element element) throws Exception
    {
       String name = getName(element, "arraybinding");
+      String type = element.getAttribute("type");
+      if (type == null || type.trim().equals(""))
+      {
+         throw new RuntimeException("Binding must have a type");
+      }
+      
+      Type theType = Type.valueOf(type);
+      
       ArrayList interceptors = loadInterceptors(element);
       InterceptorFactory[] inters = (InterceptorFactory[]) interceptors.toArray(new InterceptorFactory[interceptors.size()]);
       for (int i = 0 ; i < inters.length ; i++)
@@ -313,7 +322,7 @@
             throw new RuntimeException("Only PER_VM scoped aspects/interceptors can be used in arraybindings");
          }
       }
-      ArrayBinding binding = new ArrayBinding(name, inters);
+      ArrayBinding binding = new ArrayBinding(name, inters, theType);
       manager.addArrayBinding(binding);
    }
 
@@ -322,10 +331,6 @@
       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

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	2007-01-02 08:50:56 UTC (rev 59271)
+++ projects/aop/branches/arrays/aop/src/main/org/jboss/aop/advice/PrecedenceSorter.java	2007-01-02 12:10:50 UTC (rev 59272)
@@ -245,7 +245,6 @@
       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	2007-01-02 08:50:56 UTC (rev 59271)
+++ projects/aop/branches/arrays/aop/src/main/org/jboss/aop/array/ArrayAdvisor.java	2007-01-02 12:10:50 UTC (rev 59272)
@@ -58,11 +58,16 @@
       ChainCreator.removeBinding(arrayBinding);
    }
    
-   public static Interceptor[] getInterceptors()
+   public static Interceptor[] getReadInterceptors()
    {
-      return ChainCreator.getInterceptors();
+      return ChainCreator.getReadInterceptors();
    }
    
+   public static Interceptor[] getWriteInterceptors()
+   {
+      return ChainCreator.getWriteInterceptors();
+   }
+   
    public static void updateArrayField(Object target, String fieldName, Object oldValue, Object newValue)
    {
       ArrayRegistry registry = ArrayRegistry.getInstance();
@@ -72,7 +77,7 @@
 
    public static void arrayWriteObject(Object array, int index, Object value) throws Throwable
    {
-      Interceptor[] interceptors = getInterceptors();
+      Interceptor[] interceptors = getWriteInterceptors();
       ArrayRegistry registry = ArrayRegistry.getInstance();
       if (registry.isRegistered(array))
       {
@@ -101,7 +106,7 @@
    
    public static void arrayWriteInt(Object array, int index, int value) throws Throwable
    {
-      Interceptor[] interceptors = getInterceptors();
+      Interceptor[] interceptors = getWriteInterceptors();
       if (interceptors != null && ArrayRegistry.getInstance().isRegistered(array) && ((int[])array)[index] != value)
       {
          IntArrayElementWriteInvocation invocation = new IntArrayElementWriteInvocation(interceptors, ((int[])array), index, value);
@@ -115,7 +120,7 @@
 
    public static void arrayWriteByteOrBoolean(Object array, int index, byte value) throws Throwable
    {
-      Interceptor[] interceptors = getInterceptors();
+      Interceptor[] interceptors = getWriteInterceptors();
       if (interceptors != null && ArrayRegistry.getInstance().isRegistered(array))
       {
          if (array instanceof boolean[])
@@ -144,7 +149,7 @@
 
    public static void arrayWriteChar(Object array, int index, char value) throws Throwable
    {
-      Interceptor[] interceptors = getInterceptors();
+      Interceptor[] interceptors = getWriteInterceptors();
       if (interceptors != null && ArrayRegistry.getInstance().isRegistered(array) && ((char[])array)[index] != value)
       {
          CharArrayElementWriteInvocation invocation = new CharArrayElementWriteInvocation(interceptors, ((char[])array), index, value);
@@ -158,7 +163,7 @@
 
    public static void arrayWriteDouble(Object array, int index, double value) throws Throwable
    {
-      Interceptor[] interceptors = getInterceptors();
+      Interceptor[] interceptors = getWriteInterceptors();
       if (interceptors != null && ArrayRegistry.getInstance().isRegistered(array) && ((double[])array)[index] != value)
       {
          DoubleArrayElementWriteInvocation invocation = new DoubleArrayElementWriteInvocation(interceptors, ((double[])array), index, value);
@@ -172,7 +177,7 @@
 
    public static void arrayWriteShort(Object array, int index, short value) throws Throwable
    {
-      Interceptor[] interceptors = getInterceptors();
+      Interceptor[] interceptors = getWriteInterceptors();
       if (interceptors != null && ArrayRegistry.getInstance().isRegistered(array) && ((short[])array)[index] != value)
       {
          ShortArrayElementWriteInvocation invocation = new ShortArrayElementWriteInvocation(interceptors, ((short[])array), index, value);
@@ -186,7 +191,7 @@
 
    public static void arrayWriteFloat(Object array, int index, float value) throws Throwable
    {
-      Interceptor[] interceptors = getInterceptors();
+      Interceptor[] interceptors = getWriteInterceptors();
       if (interceptors != null && ArrayRegistry.getInstance().isRegistered(array) && ((float[])array)[index] != value)
       {
          FloatArrayElementWriteInvocation invocation = new FloatArrayElementWriteInvocation(interceptors, ((float[])array), index, value);
@@ -200,7 +205,7 @@
 
    public static void arrayWriteLong(Object array, int index, long value) throws Throwable
    {
-      Interceptor[] interceptors = getInterceptors();
+      Interceptor[] interceptors = getWriteInterceptors();
       if (interceptors != null && ArrayRegistry.getInstance().isRegistered(array) && ((long[])array)[index] != value)
       {
          LongArrayElementWriteInvocation invocation = new LongArrayElementWriteInvocation(interceptors, ((long[])array), index, value);
@@ -214,7 +219,7 @@
 
    public static Object arrayReadObject(Object array, int index) throws Throwable
    {
-      Interceptor[] interceptors = getInterceptors();
+      Interceptor[] interceptors = getReadInterceptors();
       if (interceptors != null && ArrayRegistry.getInstance().isRegistered(array))
       {
          ObjectArrayElementReadInvocation invocation = new ObjectArrayElementReadInvocation(interceptors, (Object[])array, index);
@@ -228,7 +233,7 @@
 
    public static int arrayReadInt(Object array, int index) throws Throwable
    {
-      Interceptor[] interceptors = getInterceptors();
+      Interceptor[] interceptors = getReadInterceptors();
       if (interceptors != null && ArrayRegistry.getInstance().isRegistered(array))
       {
          IntArrayElementReadInvocation invocation = new IntArrayElementReadInvocation(interceptors, (int[])array, index);
@@ -242,7 +247,7 @@
 
    public static byte arrayReadByteOrBoolean(Object array, int index) throws Throwable
    {
-      Interceptor[] interceptors = getInterceptors();
+      Interceptor[] interceptors = getReadInterceptors();
       if (interceptors != null && ArrayRegistry.getInstance().isRegistered(array))
       {
          if (array instanceof boolean[])
@@ -272,7 +277,7 @@
 
    public static char arrayReadChar(Object array, int index) throws Throwable
    {
-      Interceptor[] interceptors = getInterceptors();
+      Interceptor[] interceptors = getReadInterceptors();
       if (interceptors != null && ArrayRegistry.getInstance().isRegistered(array))
       {
          CharArrayElementReadInvocation invocation = new CharArrayElementReadInvocation(interceptors, (char[])array, index);
@@ -286,7 +291,7 @@
 
    public static double arrayReadDouble(Object array, int index) throws Throwable
    {
-      Interceptor[] interceptors = getInterceptors();
+      Interceptor[] interceptors = getReadInterceptors();
       if (interceptors != null && ArrayRegistry.getInstance().isRegistered(array))
       {
          DoubleArrayElementReadInvocation invocation = new DoubleArrayElementReadInvocation(interceptors, (double[])array, index);
@@ -300,7 +305,7 @@
 
    public static float arrayReadFloat(Object array, int index) throws Throwable
    {
-      Interceptor[] interceptors = getInterceptors();
+      Interceptor[] interceptors = getReadInterceptors();
       if (interceptors != null && ArrayRegistry.getInstance().isRegistered(array))
       {
          FloatArrayElementReadInvocation invocation = new FloatArrayElementReadInvocation(interceptors, (float[])array, index);
@@ -314,7 +319,7 @@
 
    public static long arrayReadLong(Object array, int index) throws Throwable
    {
-      Interceptor[] interceptors = getInterceptors();
+      Interceptor[] interceptors = getReadInterceptors();
       if (interceptors != null && ArrayRegistry.getInstance().isRegistered(array))
       {
          LongArrayElementReadInvocation invocation = new LongArrayElementReadInvocation(interceptors, (long[])array, index);
@@ -328,7 +333,7 @@
 
    public static short arrayReadShort(Object array, int index) throws Throwable
    {
-      Interceptor[] interceptors = getInterceptors();
+      Interceptor[] interceptors = getReadInterceptors();
       if (interceptors != null && ArrayRegistry.getInstance().isRegistered(array))
       {
          ShortArrayElementReadInvocation invocation = new ShortArrayElementReadInvocation(interceptors, (short[])array, index);
@@ -343,7 +348,8 @@
    private static class ChainCreator
    {
       private static ReadWriteLock lock = new ReentrantReadWriteLock(); 
-      static Interceptor[] interceptors;
+      static Interceptor[] readInterceptors;
+      static Interceptor[] writeInterceptors;
       public static void addBinding(ArrayBinding arrayBinding)
       {
          Lock writeLock = lock.writeLock();
@@ -373,9 +379,19 @@
             writeLock.unlock();
          }
       }
+
+      public static Interceptor[] getReadInterceptors()
+      {
+         return getInterceptors(true);
+      }
       
-      public static Interceptor[] getInterceptors()
+      public static Interceptor[] getWriteInterceptors()
       {
+         return getInterceptors(false);
+      }
+      
+      private static Interceptor[] getInterceptors(boolean read)
+      {
          Lock readLock = lock.readLock();
          readLock.lock();
          boolean lockedRead = true;
@@ -392,30 +408,31 @@
                   if (updated)
                   {
                      //Create the interceptor chains
+                     ArrayList<Interceptor> newReadInterceptors = new ArrayList<Interceptor>();
+                     ArrayList<Interceptor> newWriteInterceptors = new ArrayList<Interceptor>();
                      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);
+                              if (binding.isWrite())
+                              {
+                                 newWriteInterceptors.add(icptr);
+                              }
+                              if (binding.isRead())
+                              {
+                                 newReadInterceptors.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());
-                        }
                      }
+                     readInterceptors = finalizeChain(newReadInterceptors);
+                     writeInterceptors = finalizeChain(newWriteInterceptors);
                      updated = false;
-                     return interceptors;
+                     return (read) ? readInterceptors : writeInterceptors;
                   }
                }
                finally
@@ -423,7 +440,7 @@
                   writeLock.unlock();               
                }
             }
-            return interceptors;
+            return (read) ? readInterceptors : writeInterceptors;
          }
          finally
          {
@@ -434,6 +451,20 @@
          }
       }
       
+      private static Interceptor[] finalizeChain(ArrayList<Interceptor> newinterceptors)
+      {
+         Interceptor[] 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());
+         }
+         return interceptors;
+      }
+      
       private static Interceptor createInterceptor(InterceptorFactory factory)
       {
          if (factory instanceof GeneratedOnly)

Modified: 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	2007-01-02 08:50:56 UTC (rev 59271)
+++ projects/aop/branches/arrays/aop/src/main/org/jboss/aop/array/ArrayBinding.java	2007-01-02 12:10:50 UTC (rev 59272)
@@ -36,18 +36,16 @@
  */
 public class ArrayBinding 
 {
-   private static volatile long counter = 0;
-
    protected String name;
-//   protected Pointcut pointcut;
+   protected Type type;
 
    protected InterceptorFactory[] interceptorFactories = new InterceptorFactory[0];
 
-   public ArrayBinding(String name/*, Pointcut p*/, InterceptorFactory[] factories) throws ParseException
+   public ArrayBinding(String name, InterceptorFactory[] factories, Type type) throws ParseException
    {
       this.name = name;
       interceptorFactories = factories;
-//      pointcut = p;
+      this.type = type;
    }
 
    public void addInterceptorFactory(InterceptorFactory factory)
@@ -80,4 +78,14 @@
    {
       return name.hashCode();
    }
+   
+   public boolean isRead()
+   {
+      return type == Type.READ_ONLY || type == Type.READ_WRITE;
+   }
+
+   public boolean isWrite()
+   {
+      return type == Type.WRITE_ONLY || type == Type.READ_WRITE;
+   }
 }

Added: projects/aop/branches/arrays/aop/src/main/org/jboss/aop/array/Type.java
===================================================================
--- projects/aop/branches/arrays/aop/src/main/org/jboss/aop/array/Type.java	2007-01-02 08:50:56 UTC (rev 59271)
+++ projects/aop/branches/arrays/aop/src/main/org/jboss/aop/array/Type.java	2007-01-02 12:10:50 UTC (rev 59272)
@@ -0,0 +1,32 @@
+/*
+* 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;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public enum Type 
+{
+   READ_WRITE, READ_ONLY, WRITE_ONLY
+}

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	2007-01-02 08:50:56 UTC (rev 59271)
+++ projects/aop/branches/arrays/aop/src/resources/test/array/jboss-aop.xml	2007-01-02 12:10:50 UTC (rev 59272)
@@ -9,15 +9,23 @@
    
    <aspect class="org.jboss.test.aop.array.AspectForPrecedence"/>
    <interceptor class="org.jboss.test.aop.array.TestArrayElementInterceptor"/>
+   <interceptor class="org.jboss.test.aop.array.TestArrayElementWriteInterceptor"/>
+   <interceptor class="org.jboss.test.aop.array.TestArrayElementReadInterceptor"/>
 
    <precedence>
    	<interceptor-ref name="org.jboss.test.aop.array.TestArrayElementInterceptor"/>
    	<advice aspect="org.jboss.test.aop.array.AspectForPrecedence" name="advice"/>
    </precedence>
 
-   <arraybind>
+   <arraybind type="READ_WRITE">
    	<advice aspect="org.jboss.test.aop.array.AspectForPrecedence" name="advice"/>
    	<interceptor-ref name="org.jboss.test.aop.array.TestArrayElementInterceptor"/>
    </arraybind>
+   <arraybind type="READ_ONLY">
+	   <interceptor-ref name="org.jboss.test.aop.array.TestArrayElementReadInterceptor"/>
+   </arraybind>
+   <arraybind type="WRITE_ONLY">
+	   <interceptor-ref name="org.jboss.test.aop.array.TestArrayElementWriteInterceptor"/>
+   </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	2007-01-02 08:50:56 UTC (rev 59271)
+++ projects/aop/branches/arrays/aop/src/test/org/jboss/test/aop/array/AOPArrayTestCase.java	2007-01-02 12:10:50 UTC (rev 59272)
@@ -50,193 +50,211 @@
    public void testObjectArray()
    {
       ClassWithArrayFields obj = new ClassWithArrayFields();
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       AspectForPrecedence.invoked = false;
       obj.objects[2] = "X";
       assertEquals(2, TestArrayElementInterceptor.index);
       assertEquals("X", TestArrayElementInterceptor.value);
       assertTrue(AspectForPrecedence.invoked);
+      checkWrite();
       
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       AspectForPrecedence.invoked = false;
       Object o = obj.objects[0];
       assertEquals("1", o);
       assertEquals(0, TestArrayElementInterceptor.index);
       assertTrue(AspectForPrecedence.invoked);
+      checkRead();
    }
    
    public void testIntArray()
    {
       ClassWithArrayFields obj = new ClassWithArrayFields();
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       AspectForPrecedence.invoked = false;
       obj.ints[1] = 100; 
       assertEquals(1, TestArrayElementInterceptor.index);
       assertNotNull(TestArrayElementInterceptor.value);
       assertEquals(100, ((Integer)TestArrayElementInterceptor.value).intValue());
       assertTrue(AspectForPrecedence.invoked);
+      checkWrite();
 
       obj.ints[2] = 123;
       
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       AspectForPrecedence.invoked = false;
       int val = obj.ints[2];
       assertEquals(123, val);
       assertEquals(2, TestArrayElementInterceptor.index);
       assertNull(TestArrayElementInterceptor.value);
       assertTrue(AspectForPrecedence.invoked);
+      checkRead();
    }
    
    public void testByteArray()
    {
       ClassWithArrayFields obj = new ClassWithArrayFields();
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       AspectForPrecedence.invoked = false;
       obj.bytes[1] = 100; 
       assertEquals(1, TestArrayElementInterceptor.index);
       assertNotNull(TestArrayElementInterceptor.value);
       assertEquals(100, ((Byte)TestArrayElementInterceptor.value).byteValue());
       assertTrue(AspectForPrecedence.invoked);
+      checkWrite();
 
       obj.bytes[2] = 123;
       
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       AspectForPrecedence.invoked = false;
       byte val = obj.bytes[2];
       assertEquals(123, val);
       assertEquals(2, TestArrayElementInterceptor.index);
       assertNull(TestArrayElementInterceptor.value);
       assertTrue(AspectForPrecedence.invoked);
+      checkRead();
    }
    
    public void testBooleanArray()
    {
       ClassWithArrayFields obj = new ClassWithArrayFields();
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       AspectForPrecedence.invoked = false;
       obj.booleans[1] = true;
       assertEquals(1, TestArrayElementInterceptor.index);
       assertNotNull(TestArrayElementInterceptor.value);
       assertEquals(true, ((Boolean)TestArrayElementInterceptor.value).booleanValue());
       assertTrue(AspectForPrecedence.invoked);
+      checkWrite();
 
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       AspectForPrecedence.invoked = false;
       boolean val = obj.booleans[1];
       assertEquals(true, val);
       assertEquals(1, TestArrayElementInterceptor.index);
       assertNull(TestArrayElementInterceptor.value);
       assertTrue(AspectForPrecedence.invoked);
+      checkRead();
    }
    
    public void testCharArray()
    {
       ClassWithArrayFields obj = new ClassWithArrayFields();
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       AspectForPrecedence.invoked = false;
       obj.chars[1] = 'z'; 
       assertEquals(1, TestArrayElementInterceptor.index);
       assertNotNull(TestArrayElementInterceptor.value);
       assertEquals('z', ((Character)TestArrayElementInterceptor.value).charValue());
       assertTrue(AspectForPrecedence.invoked);
+      checkWrite();
 
       obj.chars[2] = 'x';
       
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       AspectForPrecedence.invoked = false;
       char val = obj.chars[2];
       assertEquals('x', val);
       assertEquals(2, TestArrayElementInterceptor.index);
       assertNull(TestArrayElementInterceptor.value);
       assertTrue(AspectForPrecedence.invoked);
+      checkRead();
    }
 
    public void testDoubleArray()
    {
       ClassWithArrayFields obj = new ClassWithArrayFields();
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       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);
+      checkWrite();
 
       obj.doubles[2] = 9.9d;
       
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       AspectForPrecedence.invoked = false;
       double val = obj.doubles[2];
       assertEquals(9.9d, val);
       assertEquals(2, TestArrayElementInterceptor.index);
       assertNull(TestArrayElementInterceptor.value);
       assertTrue(AspectForPrecedence.invoked);
+      checkRead();
    }
    
    public void testFloatArray()
    {
       ClassWithArrayFields obj = new ClassWithArrayFields();
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       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);
+      checkWrite();
 
       obj.floats[2] = 9.9f;
       
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       AspectForPrecedence.invoked = false;
       double val = obj.floats[2];
       assertEquals(9.9f, val);
       assertEquals(2, TestArrayElementInterceptor.index);
       assertNull(TestArrayElementInterceptor.value);
       assertTrue(AspectForPrecedence.invoked);
+      checkRead();
    }
    
    public void testLongArray()
    {
       ClassWithArrayFields obj = new ClassWithArrayFields();
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       AspectForPrecedence.invoked = false;
       obj.longs[1] = 100L; 
       assertEquals(1, TestArrayElementInterceptor.index);
       assertNotNull(TestArrayElementInterceptor.value);
       assertEquals(100L, ((Long)TestArrayElementInterceptor.value).longValue());
       assertTrue(AspectForPrecedence.invoked);
+      checkWrite();
 
       obj.longs[2] = 200L;
       
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       AspectForPrecedence.invoked = false;
       double val = obj.longs[2];
       assertEquals(200L, val);
       assertEquals(2, TestArrayElementInterceptor.index);
       assertNull(TestArrayElementInterceptor.value);
       assertTrue(AspectForPrecedence.invoked);
+      checkRead();
    }
    
    public void testShortArray()
    {
       ClassWithArrayFields obj = new ClassWithArrayFields();
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       AspectForPrecedence.invoked = false;
       obj.shorts[1] = 50; 
       assertEquals(1, TestArrayElementInterceptor.index);
       assertNotNull(TestArrayElementInterceptor.value);
       assertEquals(50, ((Short)TestArrayElementInterceptor.value).shortValue());
       assertTrue(AspectForPrecedence.invoked);
+      checkWrite();
 
       obj.shorts[2] = 100;
       
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       AspectForPrecedence.invoked = false;
       double val = obj.shorts[2];
       assertEquals(100, val);
       assertEquals(2, TestArrayElementInterceptor.index);
       assertNull(TestArrayElementInterceptor.value);
       assertTrue(AspectForPrecedence.invoked);
+      checkRead();
    }
    
    public void testMultiDimensionalTopLevelArray()
@@ -244,42 +262,49 @@
       ClassWithArrayFields obj = new ClassWithArrayFields();
       
       //Create replacement array for top level, this is not registered yet so should be unadvised
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       int[][] replacement0 = new int[][] {new int[]{11,22}, new int[] {33,44}};
       assertEquals(-1, TestArrayElementInterceptor.index);
       assertNull(TestArrayElementInterceptor.value);
-
+      checkNoReadWrite();
+      
       //Store reference to array to be replaced
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       int[][] original_0 = obj.ints3d[0];
       assertEquals(0, TestArrayElementInterceptor.index);
+      checkRead();
       
       //Replace array in top-level array, interception should happen now
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       obj.ints3d[0] = replacement0;
       assertEquals(0, TestArrayElementInterceptor.index);
       assertNotNull(TestArrayElementInterceptor.value);
       assertEquals(replacement0, TestArrayElementInterceptor.value);
+      checkWrite();
       
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       int i = obj.ints3d[0][0][1];
       assertEquals(1, TestArrayElementInterceptor.index);
       assertEquals(22, i);
+      checkRead();
       
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       obj.ints3d[0][0][1] = 99;
       assertEquals(1, TestArrayElementInterceptor.index);
       assertEquals(99, ((Integer)TestArrayElementInterceptor.value).intValue());
+      checkReadAndWrite();
       
       //The original array should no longer be registered
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       i = original_0[0][1];
       assertEquals(2, i);
       assertEquals(-1, TestArrayElementInterceptor.index);
       assertNull(TestArrayElementInterceptor.value);
+      checkNoReadWrite();   
       original_0[0][1] = 100;
       assertEquals(-1, TestArrayElementInterceptor.index);
       assertNull(TestArrayElementInterceptor.value);
+      checkNoReadWrite();   
    }
 
    public void testMultiDimensionalNestedArray()
@@ -287,194 +312,222 @@
       ClassWithArrayFields obj = new ClassWithArrayFields();
 
       //Create replacement for nested array 
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       int[] replacement_0_1 = new int[] {111,222, 333};
       assertEquals(-1, TestArrayElementInterceptor.index);
       assertNull(TestArrayElementInterceptor.value);
+      checkNoReadWrite();
 
       //Store reference to array to be replaced
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       int[] original_0_1 = obj.ints3d[0][1];
       assertEquals(1, TestArrayElementInterceptor.index);
+      checkRead();
 
       //Replace nested array, interception should happen now
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       obj.ints3d[0][1] = replacement_0_1;
       assertEquals(1, TestArrayElementInterceptor.index);
       assertNotNull(TestArrayElementInterceptor.value);
       assertEquals(replacement_0_1, TestArrayElementInterceptor.value);
+      checkReadAndWrite();
       
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       int i = obj.ints3d[0][1][2];
       assertEquals(2, TestArrayElementInterceptor.index);
       assertEquals(333, i);
+      checkRead();
 
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       obj.ints3d[0][0][1] = 99;
       assertEquals(1, TestArrayElementInterceptor.index);
       assertEquals(99, ((Integer)TestArrayElementInterceptor.value).intValue());
+      checkReadAndWrite();
       
       //The original array should no longer be registered
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       original_0_1[1] = 100;
       assertEquals(-1, TestArrayElementInterceptor.index);
       assertNull(TestArrayElementInterceptor.value);
+      checkNoReadWrite();
       i = original_0_1[0];
       assertEquals(-1, TestArrayElementInterceptor.index);
       assertNull(TestArrayElementInterceptor.value);
+      checkNoReadWrite();
    }
    
-   public static void testMultipleFieldReferences()
+   public void testMultipleFieldReferences()
    {
       ClassWithSeveralReferencesToSameArray obj = new ClassWithSeveralReferencesToSameArray();
       assertEquals(obj.one, obj.two);
       
       int[] original = obj.one;
       
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       obj.one[1] = 100;
       assertEquals(1, TestArrayElementInterceptor.index);
       assertEquals(100, TestArrayElementInterceptor.value);
-      TestArrayElementInterceptor.clear();
+      checkWrite();
+      clearInterceptors();
       int i = obj.one[1];
       assertEquals(1, TestArrayElementInterceptor.index);
       assertEquals(100, i);
-      TestArrayElementInterceptor.clear();
+      checkRead();
+      clearInterceptors();
       i = obj.two[1];
       assertEquals(1, TestArrayElementInterceptor.index);
       assertEquals(100, i);
+      checkRead();
       
       assertEquals(obj.one, obj.two);
       
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       int replacement1[] = new int[2];
       replacement1[0] = 11;
       replacement1[1] = 22;
       
       obj.one = replacement1;
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       obj.one[1] = 99;
       assertEquals(1, TestArrayElementInterceptor.index);
       assertEquals(99, TestArrayElementInterceptor.value);
+      checkWrite();
 
       //obj.two still references original, so make sure that we have interception 
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       i = original[1];
       assertEquals(1, TestArrayElementInterceptor.index);
       assertEquals(100, i);
+      checkRead();
 
       obj.two = replacement1;
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       obj.one[1] = 101;
       assertEquals(1, TestArrayElementInterceptor.index);
       assertEquals(101, TestArrayElementInterceptor.value);
+      checkWrite();
 
       //original is no longer referenced by and advised field, we should not have interception 
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       i = original[1];
       assertEquals(-1, TestArrayElementInterceptor.index);
+      checkNoReadWrite();
    }
    
-   public static void testMultipleNestedReferences()
+   public void testMultipleNestedReferences()
    {
       ClassWithSeveralReferencesToSameArray obj = new ClassWithSeveralReferencesToSameArray();
       assertEquals(obj.multi[0], obj.multi[1]);
       
       int[] original = obj.multi[0];
       
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       obj.multi[0][1] = 100;
       assertEquals(1, TestArrayElementInterceptor.index);
       assertEquals(100, TestArrayElementInterceptor.value);
-      TestArrayElementInterceptor.clear();
+      checkReadAndWrite();
+      clearInterceptors();
       int i = obj.multi[0][1];
       assertEquals(1, TestArrayElementInterceptor.index);
       assertEquals(100, i);
-      TestArrayElementInterceptor.clear();
+      checkRead();
+      clearInterceptors();
       i = obj.multi[1][1];
       assertEquals(1, TestArrayElementInterceptor.index);
       assertEquals(100, i);
+      checkRead();
       
       assertEquals(obj.multi[0], obj.multi[1]);
       
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       int replacement1[] = new int[2];
       replacement1[0] = 11;
       replacement1[1] = 22;
       
       obj.multi[0] = replacement1;
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       obj.multi[0][1] = 99;
       assertEquals(1, TestArrayElementInterceptor.index);
       assertEquals(99, TestArrayElementInterceptor.value);
+      checkReadAndWrite();
 
       //obj.multi[1] still references original, so make sure that we have interception 
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       i = original[1];
       assertEquals(1, TestArrayElementInterceptor.index);
       assertEquals(100, i);
+      checkRead();
 
       obj.multi[1] = replacement1;
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       obj.multi[0][1] = 101;
       assertEquals(1, TestArrayElementInterceptor.index);
       assertEquals(101, TestArrayElementInterceptor.value);
+      checkReadAndWrite();
 
       //original is no longer referenced by and advised field, we should not have interception 
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       i = original[1];
       assertEquals(-1, TestArrayElementInterceptor.index);
+      checkNoReadWrite();
    }
    
-   public static void testMultipleMixedReferences()
+   public void testMultipleMixedReferences()
    {
       ClassWithSeveralReferencesToSameArray obj = new ClassWithSeveralReferencesToSameArray();
       obj.multi[0] = obj.one = new int[] {8,6,4};
       
       int[] original = obj.multi[0];
       
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       obj.multi[0][1] = 100;
       assertEquals(1, TestArrayElementInterceptor.index);
       assertEquals(100, TestArrayElementInterceptor.value);
-      TestArrayElementInterceptor.clear();
+      checkReadAndWrite();
+      clearInterceptors();
       int i = obj.multi[0][1];
       assertEquals(1, TestArrayElementInterceptor.index);
       assertEquals(100, i);
-      TestArrayElementInterceptor.clear();
+      checkRead();
+      clearInterceptors();
       i = obj.one[1];
       assertEquals(1, TestArrayElementInterceptor.index);
       assertEquals(100, i);
+      checkRead();
       
       assertEquals(obj.multi[0], obj.one);
       
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       int replacement1[] = new int[2];
       replacement1[0] = 11;
       replacement1[1] = 22;
       
       obj.multi[0] = replacement1;
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       obj.multi[0][1] = 99;
       assertEquals(1, TestArrayElementInterceptor.index);
       assertEquals(99, TestArrayElementInterceptor.value);
+      checkReadAndWrite();
 
       //obj.one still references original, so make sure that we have interception 
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       i = original[1];
       assertEquals(1, TestArrayElementInterceptor.index);
       assertEquals(100, i);
+      checkRead();
 
       obj.one = replacement1;
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       obj.multi[0][1] = 101;
       assertEquals(1, TestArrayElementInterceptor.index);
       assertEquals(101, TestArrayElementInterceptor.value);
+      checkReadAndWrite();
 
       //original is no longer referenced by and advised field, we should not have interception 
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       i = original[1];
       assertEquals(-1, TestArrayElementInterceptor.index);
+      checkNoReadWrite();
    }
 
    public void testObjectArrayWithArrayAsObjectEntry()
@@ -483,28 +536,32 @@
       ClassWithArrayFields obj = new ClassWithArrayFields();
       
       //Add an array as one of the elements in the object array
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       obj.objects[0] = replacement;
       assertEquals(0, TestArrayElementInterceptor.index);
       assertEquals(replacement, TestArrayElementInterceptor.value);
+      checkWrite();
       
       //The sub array should be advised
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       replacement[1] = 5;
       assertEquals(1, TestArrayElementInterceptor.index);
       assertEquals(5, ((Integer)TestArrayElementInterceptor.value).intValue());
+      checkWrite();
       
       //Put in a string object
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       obj.objects[0] = "X";
       assertEquals(0, TestArrayElementInterceptor.index);
       assertEquals("X", TestArrayElementInterceptor.value);
+      checkWrite();
       
       //The nested array no longer is associated with array and should be unadvised
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       replacement[1] = 10;
       assertEquals(-1, TestArrayElementInterceptor.index);
       assertEquals(null, TestArrayElementInterceptor.value);
+      checkNoReadWrite();
       
    }
    
@@ -514,33 +571,37 @@
       Object[] original = obj.objects;
       obj.objects = new Object[] {new int[] {1,2,3}};
       
-      //Add an array as one of the elements in the object array
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       original[0] = "X";
       assertEquals(-1, TestArrayElementInterceptor.index);
       assertNull(TestArrayElementInterceptor.value);
+      checkNoReadWrite();
       
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       Object val = original[0];
       assertEquals("X", val);
       assertEquals(-1, TestArrayElementInterceptor.index);
       assertNull(TestArrayElementInterceptor.value);
+      checkNoReadWrite();
       
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       int[] i = (int[])obj.objects[0];
       assertEquals(0, TestArrayElementInterceptor.index);
       assertNull(TestArrayElementInterceptor.value);
+      checkRead();
       
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       i[1] = 10;
       assertEquals(1, TestArrayElementInterceptor.index);
       assertEquals(10, TestArrayElementInterceptor.value);
+      checkWrite();
       
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       int ival = i[1];
       assertEquals(10, ival);
       assertEquals(1, TestArrayElementInterceptor.index);
       assertNull(TestArrayElementInterceptor.value);
+      checkRead();
    }
    
    public void testObjectFieldWithArray()
@@ -548,30 +609,34 @@
       ClassWithArrayFields obj = new ClassWithArrayFields();
       obj.objectField = new int[] {1,2,3};
       
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       ((int[])obj.objectField)[1] = 10;
       assertEquals(1, TestArrayElementInterceptor.index);
       assertEquals(10, TestArrayElementInterceptor.value);
+      checkWrite();
       
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       int val = ((int[])obj.objectField)[2];
       assertEquals(3, val);
       assertEquals(2, TestArrayElementInterceptor.index);
       assertNull(TestArrayElementInterceptor.value);
+      checkRead();
       
       int[] array = (int[])obj.objectField;
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       val = array[2];
       assertEquals(3, val);
       assertEquals(2, TestArrayElementInterceptor.index);
       assertNull(TestArrayElementInterceptor.value);
+      checkRead();
       
       obj.objectField = null;
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       val = array[2];
       assertEquals(3, val);
       assertEquals(-1, TestArrayElementInterceptor.index);
       assertNull(TestArrayElementInterceptor.value);
+      checkNoReadWrite();
    }
    
    public void testObjectFieldWithNestedArrays()
@@ -581,95 +646,112 @@
       
       Object[] objArray = (Object[])obj.objectField;
       
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       int[] intArray = (int[])((Object[])obj.objectField)[0]; 
       assertEquals(0, TestArrayElementInterceptor.index);
+      checkRead();
       
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       Object[] objArray2 = (Object[])((Object[])obj.objectField)[1]; 
       assertEquals(1, TestArrayElementInterceptor.index);
+      checkRead();
 
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       intArray[1] = 10;
       assertEquals(1, TestArrayElementInterceptor.index);
       assertEquals(10, TestArrayElementInterceptor.value);
+      checkWrite();
       
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       int val = intArray[1];
       assertEquals(10, val);
       assertEquals(1, TestArrayElementInterceptor.index);
       assertNull(TestArrayElementInterceptor.value);
+      checkRead();
       
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       objArray2[1] = "ZZZ";
       assertEquals(1, TestArrayElementInterceptor.index);
       assertEquals("ZZZ", TestArrayElementInterceptor.value);
+      checkWrite();
       
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       Object oval = objArray2[1];
       assertEquals("ZZZ", oval);
       assertEquals(1, TestArrayElementInterceptor.index);
       assertNull(TestArrayElementInterceptor.value);
+      checkRead();
       
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       int[] intArray2 = new int[] {11, 22};
       objArray[0] = intArray2;
       assertEquals(0, TestArrayElementInterceptor.index);
       assertEquals(intArray2, TestArrayElementInterceptor.value);
+      checkWrite();
       
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       intArray2[1] = 10;
       assertEquals(1, TestArrayElementInterceptor.index);
       assertEquals(10, TestArrayElementInterceptor.value);
+      checkWrite();
       
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       val = intArray2[1];
       assertEquals(10, val);
       assertEquals(1, TestArrayElementInterceptor.index);
       assertNull(TestArrayElementInterceptor.value);
+      checkRead();
       
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       intArray[1] = 10;
       assertEquals(-1, TestArrayElementInterceptor.index);
       assertNull(TestArrayElementInterceptor.value);
+      checkNoReadWrite();
       
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       val = intArray[1];
       assertEquals(10, val);
       assertEquals(-1, TestArrayElementInterceptor.index);
       assertNull(TestArrayElementInterceptor.value);
+      checkNoReadWrite();
       
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       objArray[0] = null;
       assertEquals(0, TestArrayElementInterceptor.index);
       assertNull(TestArrayElementInterceptor.value);
+      checkWrite();
       
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       objArray[1] = null;
       assertEquals(1, TestArrayElementInterceptor.index);
       assertNull(TestArrayElementInterceptor.value);
+      checkWrite();
       
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       intArray2[1] = 10;
       assertEquals(-1, TestArrayElementInterceptor.index);
       assertNull(TestArrayElementInterceptor.value);
+      checkNoReadWrite();
       
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       val = intArray2[1];
       assertEquals(10, val);
       assertEquals(-1, TestArrayElementInterceptor.index);
       assertNull(TestArrayElementInterceptor.value);
+      checkNoReadWrite();
       
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       objArray2[1] = "ZZZ";
       assertEquals(-1, TestArrayElementInterceptor.index);
       assertNull(TestArrayElementInterceptor.value);
+      checkNoReadWrite();
       
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       oval = objArray2[1];
       assertEquals("ZZZ", oval);
       assertEquals(-1, TestArrayElementInterceptor.index);
       assertNull(TestArrayElementInterceptor.value);
+      checkNoReadWrite();
    }
    
    public void testIgnoreDoubleUpdate()
@@ -677,184 +759,249 @@
       ClassWithArrayFields obj = new ClassWithArrayFields();
       
       String sval = "X";
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       obj.objects[0] = sval;
       assertEquals(0, TestArrayElementInterceptor.index);
       assertEquals(sval, TestArrayElementInterceptor.value);
-      TestArrayElementInterceptor.clear();
+      checkWrite();
+      clearInterceptors();
       obj.objects[0] = sval;
       assertEquals(-1, TestArrayElementInterceptor.index);
       assertNull(TestArrayElementInterceptor.value);
+      checkNoReadWrite();
 
       byte byteVal = 10;
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       obj.bytes[0] = byteVal;
       assertEquals(0, TestArrayElementInterceptor.index);
       assertEquals(byteVal, TestArrayElementInterceptor.value);
-      TestArrayElementInterceptor.clear();
+      checkWrite();
+      clearInterceptors();
       obj.bytes[0] = byteVal;
       assertEquals(-1, TestArrayElementInterceptor.index);
       assertNull(TestArrayElementInterceptor.value);
+      checkNoReadWrite();
 
       //Set the value to be different
       obj.booleans[0] = false;
       boolean booleanVal = true;
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       obj.booleans[0] = booleanVal;
       assertEquals(0, TestArrayElementInterceptor.index);
       assertEquals(booleanVal, TestArrayElementInterceptor.value);
-      TestArrayElementInterceptor.clear();
+      checkWrite();
+      clearInterceptors();
       obj.booleans[0] = booleanVal;
       assertEquals(-1, TestArrayElementInterceptor.index);
       assertNull(TestArrayElementInterceptor.value);
+      checkNoReadWrite();
       booleanVal = false;
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       obj.booleans[0] = booleanVal;
       assertEquals(0, TestArrayElementInterceptor.index);
       assertEquals(booleanVal, TestArrayElementInterceptor.value);
-      TestArrayElementInterceptor.clear();
+      checkWrite();
+      clearInterceptors();
       obj.booleans[0] = booleanVal;
       assertEquals(-1, TestArrayElementInterceptor.index);
       assertNull(TestArrayElementInterceptor.value);
+      checkNoReadWrite();
       
       char charVal = 'h';
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       obj.chars[0] = charVal;
       assertEquals(0, TestArrayElementInterceptor.index);
       assertEquals(charVal, TestArrayElementInterceptor.value);
-      TestArrayElementInterceptor.clear();
+      checkWrite();
+      clearInterceptors();
       obj.chars[0] = charVal;
       assertEquals(-1, TestArrayElementInterceptor.index);
       assertNull(TestArrayElementInterceptor.value);
+      checkNoReadWrite();
       
       double doubleVal = 101.1d;
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       obj.doubles[0] = doubleVal;
       assertEquals(0, TestArrayElementInterceptor.index);
       assertEquals(doubleVal, TestArrayElementInterceptor.value);
-      TestArrayElementInterceptor.clear();
+      checkWrite();
+      clearInterceptors();
       obj.doubles[0] = doubleVal;
       assertEquals(-1, TestArrayElementInterceptor.index);
       assertNull(TestArrayElementInterceptor.value);
+      checkNoReadWrite();
       
       float floatVal = 66.6f;
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       obj.floats[0] = floatVal;
       assertEquals(0, TestArrayElementInterceptor.index);
       assertEquals(floatVal, TestArrayElementInterceptor.value);
-      TestArrayElementInterceptor.clear();
+      checkWrite();
+      clearInterceptors();
       obj.floats[0] = floatVal;
       assertEquals(-1, TestArrayElementInterceptor.index);
       assertNull(TestArrayElementInterceptor.value);
+      checkNoReadWrite();
 
       int intVal = 1000;
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       obj.ints[0] = intVal;
       assertEquals(0, TestArrayElementInterceptor.index);
       assertEquals(intVal, TestArrayElementInterceptor.value);
-      TestArrayElementInterceptor.clear();
+      checkWrite();
+      clearInterceptors();
       obj.ints[0] = intVal;
       assertEquals(-1, TestArrayElementInterceptor.index);
       assertNull(TestArrayElementInterceptor.value);
+      checkNoReadWrite();
 
       int[][] intVal2d = new int[][]{new int[]{1}, new int[]{2}};
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       obj.ints3d[0] = intVal2d;
       assertEquals(0, TestArrayElementInterceptor.index);
       assertEquals(intVal2d, TestArrayElementInterceptor.value);
-      TestArrayElementInterceptor.clear();
+      checkWrite();
+      clearInterceptors();
       obj.ints3d[0] = intVal2d;
       assertEquals(-1, TestArrayElementInterceptor.index);
       assertNull(TestArrayElementInterceptor.value);
+      checkNoReadWrite();
 
       long longVal = 10001;
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       obj.longs[0] = longVal;
       assertEquals(0, TestArrayElementInterceptor.index);
       assertEquals(longVal, TestArrayElementInterceptor.value);
-      TestArrayElementInterceptor.clear();
+      checkWrite();
+      clearInterceptors();
       obj.longs[0] = longVal;
       assertEquals(-1, TestArrayElementInterceptor.index);
       assertNull(TestArrayElementInterceptor.value);
+      checkNoReadWrite();
 
       short shortVal = 999;
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       obj.shorts[0] = shortVal;
       assertEquals(0, TestArrayElementInterceptor.index);
       assertEquals(shortVal, TestArrayElementInterceptor.value);
-      TestArrayElementInterceptor.clear();
+      checkWrite();
+      clearInterceptors();
       obj.shorts[0] = shortVal;
       assertEquals(-1, TestArrayElementInterceptor.index);
       assertNull(TestArrayElementInterceptor.value);
+      checkNoReadWrite();
 
       Object objectVal = new int[] {1,2,3};
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       obj.objects[0] = objectVal;
       assertEquals(0, TestArrayElementInterceptor.index);
       assertEquals(objectVal, TestArrayElementInterceptor.value);
-      TestArrayElementInterceptor.clear();
+      checkWrite();
+      clearInterceptors();
       obj.objects[0] = objectVal;
       assertEquals(-1, TestArrayElementInterceptor.index);
       assertNull(TestArrayElementInterceptor.value);
+      checkNoReadWrite();
       intVal = 100;
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       ((int[])objectVal)[0] = intVal;
       assertEquals(0, TestArrayElementInterceptor.index);
       assertEquals(intVal, TestArrayElementInterceptor.value);
-      TestArrayElementInterceptor.clear();
+      checkWrite();
+      clearInterceptors();
       ((int[])objectVal)[0] = intVal;
       assertEquals(-1, TestArrayElementInterceptor.index);
       assertNull(TestArrayElementInterceptor.value);
+      checkNoReadWrite();
    }
    
    public void testUnadvisedArrayFields()
    {
       ClassWithUnadvisedArrayFields obj = new ClassWithUnadvisedArrayFields();
 
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       obj.objects[0] = "X";
       assertEquals("X", obj.objects[0]);
       assertEquals(-1, TestArrayElementInterceptor.index);
+      checkNoReadWrite();
       
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       obj.bytes[0] = 1;
       assertEquals(1, obj.bytes[0]);
       assertEquals(-1, TestArrayElementInterceptor.index);
+      checkNoReadWrite();
       
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       obj.booleans[0] = true;
       assertEquals(true, obj.booleans[0]);
       assertEquals(-1, TestArrayElementInterceptor.index);
+      checkNoReadWrite();
       
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       obj.chars[0] = 'z';
       assertEquals('z', obj.chars[0]);
       assertEquals(-1, TestArrayElementInterceptor.index);
+      checkNoReadWrite();
       
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       obj.doubles[0] = 9.9d;
       assertEquals(9.9d, obj.doubles[0]);
       assertEquals(-1, TestArrayElementInterceptor.index);
+      checkNoReadWrite();
       
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       obj.floats[0] = 9.9f;
       assertEquals(9.9f, obj.floats[0]);
       assertEquals(-1, TestArrayElementInterceptor.index);
+      checkNoReadWrite();
       
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       obj.ints[0] = 100;
       assertEquals(100, obj.ints[0]);
       assertEquals(-1, TestArrayElementInterceptor.index);
+      checkNoReadWrite();
       
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       obj.longs[0] = 100;
       assertEquals(100, obj.longs[0]);
       assertEquals(-1, TestArrayElementInterceptor.index);
+      checkNoReadWrite();
       
-      TestArrayElementInterceptor.clear();
+      clearInterceptors();
       obj.shorts[0] = 100;
       assertEquals(100, obj.shorts[0]);
       assertEquals(-1, TestArrayElementInterceptor.index);
+      checkNoReadWrite();
    }
+
+   void clearInterceptors()
+   {
+      TestArrayElementInterceptor.clear();
+      TestArrayElementReadInterceptor.invoked = false;
+      TestArrayElementWriteInterceptor.invoked = false;
+   }
    
+   void checkRead()
+   {
+      assertTrue(TestArrayElementReadInterceptor.invoked);
+      assertFalse(TestArrayElementWriteInterceptor.invoked);
+   }
+   
+   void checkWrite()
+   {
+      assertFalse(TestArrayElementReadInterceptor.invoked);
+      assertTrue(TestArrayElementWriteInterceptor.invoked);
+   }
+   
+   void checkReadAndWrite()
+   {
+      assertTrue(TestArrayElementReadInterceptor.invoked);
+      assertTrue(TestArrayElementWriteInterceptor.invoked);
+   }
+   
+   void checkNoReadWrite()
+   {
+      assertFalse(TestArrayElementReadInterceptor.invoked);
+      assertFalse(TestArrayElementWriteInterceptor.invoked);
+   }
 }

Added: projects/aop/branches/arrays/aop/src/test/org/jboss/test/aop/array/TestArrayElementReadInterceptor.java
===================================================================
--- projects/aop/branches/arrays/aop/src/test/org/jboss/test/aop/array/TestArrayElementReadInterceptor.java	2007-01-02 08:50:56 UTC (rev 59271)
+++ projects/aop/branches/arrays/aop/src/test/org/jboss/test/aop/array/TestArrayElementReadInterceptor.java	2007-01-02 12:10:50 UTC (rev 59272)
@@ -0,0 +1,55 @@
+/*
+* 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 TestArrayElementReadInterceptor implements Interceptor
+{
+   public static boolean invoked;
+
+   public String getName()
+   {
+      return this.getClass().getName();
+   }
+
+   public Object invoke(Invocation invocation) throws Throwable
+   {
+      if (invocation instanceof ArrayElementWriteInvocation || !(invocation instanceof ArrayElementReadInvocation))
+      {
+         throw new RuntimeException("Should only apply to ArrayElementReadInvocations");
+      } 
+      invoked = true;
+     
+      return invocation.invokeNext();
+   }
+
+}

Added: projects/aop/branches/arrays/aop/src/test/org/jboss/test/aop/array/TestArrayElementWriteInterceptor.java
===================================================================
--- projects/aop/branches/arrays/aop/src/test/org/jboss/test/aop/array/TestArrayElementWriteInterceptor.java	2007-01-02 08:50:56 UTC (rev 59271)
+++ projects/aop/branches/arrays/aop/src/test/org/jboss/test/aop/array/TestArrayElementWriteInterceptor.java	2007-01-02 12:10:50 UTC (rev 59272)
@@ -0,0 +1,54 @@
+/*
+* 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 TestArrayElementWriteInterceptor implements Interceptor
+{
+   public static boolean invoked;
+
+   public String getName()
+   {
+      return this.getClass().getName();
+   }
+
+   public Object invoke(Invocation invocation) throws Throwable
+   {
+      if (invocation instanceof ArrayElementReadInvocation || !(invocation instanceof ArrayElementWriteInvocation))
+      {
+         throw new RuntimeException("Should only apply to ArrayElementReadInvocations");
+      } 
+      invoked = true;
+      
+      return invocation.invokeNext();
+   }
+
+}




More information about the jboss-cvs-commits mailing list