[jboss-cvs] JBossAS SVN: r66077 - in projects/aop/trunk/aop/src/test/org/jboss/test/aop: array and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Oct 12 04:05:18 EDT 2007


Author: stalep
Date: 2007-10-12 04:05:17 -0400 (Fri, 12 Oct 2007)
New Revision: 66077

Added:
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/array/
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/array/AOPArrayTestCase.java
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/array/ArrayReferenceTestCase.java
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/array/AspectForPrecedence.java
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/array/ClassForReference.java
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/array/ClassWithArrayFields.java
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/array/ClassWithSeveralReferencesToSameArray.java
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/array/ClassWithUnadvisedArrayFields.java
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/array/TestArrayElementInterceptor.java
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/array/TestArrayElementReadInterceptor.java
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/array/TestArrayElementWriteInterceptor.java
Log:
[JBAOP-265] merging from array branch

Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/array/AOPArrayTestCase.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/array/AOPArrayTestCase.java	                        (rev 0)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/array/AOPArrayTestCase.java	2007-10-12 08:05:17 UTC (rev 66077)
@@ -0,0 +1,1052 @@
+/*
+* 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 junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.jboss.test.aop.AOPTestWithSetup;
+
+
+/**
+ * Test that arrays get advised properly
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class AOPArrayTestCase extends AOPTestWithSetup
+{
+   public AOPArrayTestCase(String name)
+   {
+      super(name);
+   }
+
+   public static Test suite()
+   {
+      TestSuite suite = new TestSuite("AOPArrayTestCase");
+      suite.addTestSuite(AOPArrayTestCase.class);
+      return suite;
+   }
+
+   public void testObjectArray()
+   {
+      ClassWithArrayFields obj = new ClassWithArrayFields();
+      clearInterceptors();
+      AspectForPrecedence.invoked = false;
+      obj.objects[2] = "X";
+      assertEquals(2, TestArrayElementInterceptor.index);
+      assertEquals("X", TestArrayElementInterceptor.value);
+      assertTrue(AspectForPrecedence.invoked);
+      checkWrite();
+      
+      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();
+      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;
+      
+      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();
+      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;
+      
+      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();
+      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();
+
+      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();
+      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';
+      
+      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();
+      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;
+      
+      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();
+      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;
+      
+      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();
+      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;
+      
+      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();
+      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;
+      
+      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()
+   {
+      ClassWithArrayFields obj = new ClassWithArrayFields();
+      
+      //Create replacement array for top level, this is not registered yet so should be unadvised
+      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
+      clearInterceptors();
+      int[][] original_0 = obj.ints3d[0];
+      assertEquals(0, TestArrayElementInterceptor.index);
+      checkRead();
+      
+      //Replace array in top-level array, interception should happen now
+      clearInterceptors();
+      obj.ints3d[0] = replacement0;
+      assertEquals(0, TestArrayElementInterceptor.index);
+      assertNotNull(TestArrayElementInterceptor.value);
+      assertEquals(replacement0, TestArrayElementInterceptor.value);
+      checkWrite();
+      
+      clearInterceptors();
+      int i = obj.ints3d[0][0][1];
+      assertEquals(1, TestArrayElementInterceptor.index);
+      assertEquals(22, i);
+      checkRead();
+      
+      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
+      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()
+   {
+      ClassWithArrayFields obj = new ClassWithArrayFields();
+
+      //Create replacement for nested array 
+      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
+      clearInterceptors();
+      int[] original_0_1 = obj.ints3d[0][1];
+      assertEquals(1, TestArrayElementInterceptor.index);
+      checkRead();
+
+      //Replace nested array, interception should happen now
+      clearInterceptors();
+      obj.ints3d[0][1] = replacement_0_1;
+      assertEquals(1, TestArrayElementInterceptor.index);
+      assertNotNull(TestArrayElementInterceptor.value);
+      assertEquals(replacement_0_1, TestArrayElementInterceptor.value);
+      checkReadAndWrite();
+      
+      clearInterceptors();
+      int i = obj.ints3d[0][1][2];
+      assertEquals(2, TestArrayElementInterceptor.index);
+      assertEquals(333, i);
+      checkRead();
+
+      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
+      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 void testMultipleFieldReferences()
+   {
+      ClassWithSeveralReferencesToSameArray obj = new ClassWithSeveralReferencesToSameArray();
+      assertEquals(obj.one, obj.two);
+      
+      int[] original = obj.one;
+      
+      clearInterceptors();
+      obj.one[1] = 100;
+      assertEquals(1, TestArrayElementInterceptor.index);
+      assertEquals(100, TestArrayElementInterceptor.value);
+      checkWrite();
+      clearInterceptors();
+      int i = obj.one[1];
+      assertEquals(1, TestArrayElementInterceptor.index);
+      assertEquals(100, i);
+      checkRead();
+      clearInterceptors();
+      i = obj.two[1];
+      assertEquals(1, TestArrayElementInterceptor.index);
+      assertEquals(100, i);
+      checkRead();
+      
+      assertEquals(obj.one, obj.two);
+      
+      clearInterceptors();
+      int replacement1[] = new int[2];
+      replacement1[0] = 11;
+      replacement1[1] = 22;
+      
+      obj.one = replacement1;
+      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 
+      clearInterceptors();
+      i = original[1];
+      assertEquals(1, TestArrayElementInterceptor.index);
+      assertEquals(100, i);
+      checkRead();
+
+      obj.two = replacement1;
+      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 
+      clearInterceptors();
+      i = original[1];
+      assertEquals(-1, TestArrayElementInterceptor.index);
+      checkNoReadWrite();
+   }
+   
+   public void testMultipleNestedReferences()
+   {
+      ClassWithSeveralReferencesToSameArray obj = new ClassWithSeveralReferencesToSameArray();
+      assertEquals(obj.multi[0], obj.multi[1]);
+      
+      int[] original = obj.multi[0];
+      
+      clearInterceptors();
+      obj.multi[0][1] = 100;
+      assertEquals(1, TestArrayElementInterceptor.index);
+      assertEquals(100, TestArrayElementInterceptor.value);
+      checkReadAndWrite();
+      clearInterceptors();
+      int i = obj.multi[0][1];
+      assertEquals(1, TestArrayElementInterceptor.index);
+      assertEquals(100, i);
+      checkRead();
+      clearInterceptors();
+      i = obj.multi[1][1];
+      assertEquals(1, TestArrayElementInterceptor.index);
+      assertEquals(100, i);
+      checkRead();
+      
+      assertEquals(obj.multi[0], obj.multi[1]);
+      
+      clearInterceptors();
+      int replacement1[] = new int[2];
+      replacement1[0] = 11;
+      replacement1[1] = 22;
+      
+      obj.multi[0] = replacement1;
+      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 
+      clearInterceptors();
+      i = original[1];
+      assertEquals(1, TestArrayElementInterceptor.index);
+      assertEquals(100, i);
+      checkRead();
+
+      obj.multi[1] = replacement1;
+      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 
+      clearInterceptors();
+      i = original[1];
+      assertEquals(-1, TestArrayElementInterceptor.index);
+      checkNoReadWrite();
+   }
+   
+   public void testMultipleMixedReferences()
+   {
+      ClassWithSeveralReferencesToSameArray obj = new ClassWithSeveralReferencesToSameArray();
+      obj.multi[0] = obj.one = new int[] {8,6,4};
+      
+      int[] original = obj.multi[0];
+      
+      clearInterceptors();
+      obj.multi[0][1] = 100;
+      assertEquals(1, TestArrayElementInterceptor.index);
+      assertEquals(100, TestArrayElementInterceptor.value);
+      checkReadAndWrite();
+      clearInterceptors();
+      int i = obj.multi[0][1];
+      assertEquals(1, TestArrayElementInterceptor.index);
+      assertEquals(100, i);
+      checkRead();
+      clearInterceptors();
+      i = obj.one[1];
+      assertEquals(1, TestArrayElementInterceptor.index);
+      assertEquals(100, i);
+      checkRead();
+      
+      assertEquals(obj.multi[0], obj.one);
+      
+      clearInterceptors();
+      int replacement1[] = new int[2];
+      replacement1[0] = 11;
+      replacement1[1] = 22;
+      
+      obj.multi[0] = replacement1;
+      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 
+      clearInterceptors();
+      i = original[1];
+      assertEquals(1, TestArrayElementInterceptor.index);
+      assertEquals(100, i);
+      checkRead();
+
+      obj.one = replacement1;
+      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 
+      clearInterceptors();
+      i = original[1];
+      assertEquals(-1, TestArrayElementInterceptor.index);
+      checkNoReadWrite();
+   }
+
+   public void testObjectArrayWithArrayAsObjectEntry()
+   {
+      int[] replacement = new int[] {1,2,3};
+      ClassWithArrayFields obj = new ClassWithArrayFields();
+      
+      //Add an array as one of the elements in the object array
+      clearInterceptors();
+      obj.objects[0] = replacement;
+      assertEquals(0, TestArrayElementInterceptor.index);
+      assertEquals(replacement, TestArrayElementInterceptor.value);
+      checkWrite();
+      
+      //The sub array should be advised
+      clearInterceptors();
+      replacement[1] = 5;
+      assertEquals(1, TestArrayElementInterceptor.index);
+      assertEquals(5, ((Integer)TestArrayElementInterceptor.value).intValue());
+      checkWrite();
+      
+      //Put in a string object
+      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
+      clearInterceptors();
+      replacement[1] = 10;
+      assertEquals(-1, TestArrayElementInterceptor.index);
+      assertEquals(null, TestArrayElementInterceptor.value);
+      checkNoReadWrite();
+      
+   }
+   
+   public void testObjectArrayWithArrayAsObjectEntry2()
+   {
+      ClassWithArrayFields obj = new ClassWithArrayFields();
+      Object[] original = obj.objects;
+      obj.objects = new Object[] {new int[] {1,2,3}};
+      
+      clearInterceptors();
+      original[0] = "X";
+      assertEquals(-1, TestArrayElementInterceptor.index);
+      assertNull(TestArrayElementInterceptor.value);
+      checkNoReadWrite();
+      
+      clearInterceptors();
+      Object val = original[0];
+      assertEquals("X", val);
+      assertEquals(-1, TestArrayElementInterceptor.index);
+      assertNull(TestArrayElementInterceptor.value);
+      checkNoReadWrite();
+      
+      clearInterceptors();
+      int[] i = (int[])obj.objects[0];
+      assertEquals(0, TestArrayElementInterceptor.index);
+      assertNull(TestArrayElementInterceptor.value);
+      checkRead();
+      
+      clearInterceptors();
+      i[1] = 10;
+      assertEquals(1, TestArrayElementInterceptor.index);
+      assertEquals(10, TestArrayElementInterceptor.value);
+      checkWrite();
+      
+      clearInterceptors();
+      int ival = i[1];
+      assertEquals(10, ival);
+      assertEquals(1, TestArrayElementInterceptor.index);
+      assertNull(TestArrayElementInterceptor.value);
+      checkRead();
+   }
+   
+   public void testObjectFieldWithArray()
+   {
+      ClassWithArrayFields obj = new ClassWithArrayFields();
+      obj.objectField = new int[] {1,2,3};
+      
+      clearInterceptors();
+      ((int[])obj.objectField)[1] = 10;
+      assertEquals(1, TestArrayElementInterceptor.index);
+      assertEquals(10, TestArrayElementInterceptor.value);
+      checkWrite();
+      
+      clearInterceptors();
+      int val = ((int[])obj.objectField)[2];
+      assertEquals(3, val);
+      assertEquals(2, TestArrayElementInterceptor.index);
+      assertNull(TestArrayElementInterceptor.value);
+      checkRead();
+      
+      int[] array = (int[])obj.objectField;
+      clearInterceptors();
+      val = array[2];
+      assertEquals(3, val);
+      assertEquals(2, TestArrayElementInterceptor.index);
+      assertNull(TestArrayElementInterceptor.value);
+      checkRead();
+      
+      obj.objectField = null;
+      clearInterceptors();
+      val = array[2];
+      assertEquals(3, val);
+      assertEquals(-1, TestArrayElementInterceptor.index);
+      assertNull(TestArrayElementInterceptor.value);
+      checkNoReadWrite();
+   }
+   
+   public void testObjectFieldWithNestedArrays()
+   {
+      ClassWithArrayFields obj = new ClassWithArrayFields();
+      obj.objectField = new Object[] {new int[] {1, 2}, new Object[] {"X", "Y"}};
+      
+      Object[] objArray = (Object[])obj.objectField;
+      
+      clearInterceptors();
+      int[] intArray = (int[])((Object[])obj.objectField)[0]; 
+      assertEquals(0, TestArrayElementInterceptor.index);
+      checkRead();
+      
+      clearInterceptors();
+      Object[] objArray2 = (Object[])((Object[])obj.objectField)[1]; 
+      assertEquals(1, TestArrayElementInterceptor.index);
+      checkRead();
+
+      clearInterceptors();
+      intArray[1] = 10;
+      assertEquals(1, TestArrayElementInterceptor.index);
+      assertEquals(10, TestArrayElementInterceptor.value);
+      checkWrite();
+      
+      clearInterceptors();
+      int val = intArray[1];
+      assertEquals(10, val);
+      assertEquals(1, TestArrayElementInterceptor.index);
+      assertNull(TestArrayElementInterceptor.value);
+      checkRead();
+      
+      clearInterceptors();
+      objArray2[1] = "ZZZ";
+      assertEquals(1, TestArrayElementInterceptor.index);
+      assertEquals("ZZZ", TestArrayElementInterceptor.value);
+      checkWrite();
+      
+      clearInterceptors();
+      Object oval = objArray2[1];
+      assertEquals("ZZZ", oval);
+      assertEquals(1, TestArrayElementInterceptor.index);
+      assertNull(TestArrayElementInterceptor.value);
+      checkRead();
+      
+      clearInterceptors();
+      int[] intArray2 = new int[] {11, 22};
+      objArray[0] = intArray2;
+      assertEquals(0, TestArrayElementInterceptor.index);
+      assertEquals(intArray2, TestArrayElementInterceptor.value);
+      checkWrite();
+      
+      clearInterceptors();
+      intArray2[1] = 10;
+      assertEquals(1, TestArrayElementInterceptor.index);
+      assertEquals(10, TestArrayElementInterceptor.value);
+      checkWrite();
+      
+      clearInterceptors();
+      val = intArray2[1];
+      assertEquals(10, val);
+      assertEquals(1, TestArrayElementInterceptor.index);
+      assertNull(TestArrayElementInterceptor.value);
+      checkRead();
+      
+      clearInterceptors();
+      intArray[1] = 10;
+      assertEquals(-1, TestArrayElementInterceptor.index);
+      assertNull(TestArrayElementInterceptor.value);
+      checkNoReadWrite();
+      
+      clearInterceptors();
+      val = intArray[1];
+      assertEquals(10, val);
+      assertEquals(-1, TestArrayElementInterceptor.index);
+      assertNull(TestArrayElementInterceptor.value);
+      checkNoReadWrite();
+      
+      clearInterceptors();
+      objArray[0] = null;
+      assertEquals(0, TestArrayElementInterceptor.index);
+      assertNull(TestArrayElementInterceptor.value);
+      checkWrite();
+      
+      clearInterceptors();
+      objArray[1] = null;
+      assertEquals(1, TestArrayElementInterceptor.index);
+      assertNull(TestArrayElementInterceptor.value);
+      checkWrite();
+      
+      clearInterceptors();
+      intArray2[1] = 10;
+      assertEquals(-1, TestArrayElementInterceptor.index);
+      assertNull(TestArrayElementInterceptor.value);
+      checkNoReadWrite();
+      
+      clearInterceptors();
+      val = intArray2[1];
+      assertEquals(10, val);
+      assertEquals(-1, TestArrayElementInterceptor.index);
+      assertNull(TestArrayElementInterceptor.value);
+      checkNoReadWrite();
+      
+      clearInterceptors();
+      objArray2[1] = "ZZZ";
+      assertEquals(-1, TestArrayElementInterceptor.index);
+      assertNull(TestArrayElementInterceptor.value);
+      checkNoReadWrite();
+      
+      clearInterceptors();
+      oval = objArray2[1];
+      assertEquals("ZZZ", oval);
+      assertEquals(-1, TestArrayElementInterceptor.index);
+      assertNull(TestArrayElementInterceptor.value);
+      checkNoReadWrite();
+   }
+   
+   public void testIgnoreDoubleUpdate()
+   {
+      ClassWithArrayFields obj = new ClassWithArrayFields();
+      
+      String sval = "X";
+      clearInterceptors();
+      obj.objects[0] = sval;
+      assertEquals(0, TestArrayElementInterceptor.index);
+      assertEquals(sval, TestArrayElementInterceptor.value);
+      checkWrite();
+      clearInterceptors();
+      obj.objects[0] = sval;
+      assertEquals(-1, TestArrayElementInterceptor.index);
+      assertNull(TestArrayElementInterceptor.value);
+      checkNoReadWrite();
+
+      byte byteVal = 10;
+      clearInterceptors();
+      obj.bytes[0] = byteVal;
+      assertEquals(0, TestArrayElementInterceptor.index);
+      assertEquals(byteVal, TestArrayElementInterceptor.value);
+      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;
+      clearInterceptors();
+      obj.booleans[0] = booleanVal;
+      assertEquals(0, TestArrayElementInterceptor.index);
+      assertEquals(booleanVal, TestArrayElementInterceptor.value);
+      checkWrite();
+      clearInterceptors();
+      obj.booleans[0] = booleanVal;
+      assertEquals(-1, TestArrayElementInterceptor.index);
+      assertNull(TestArrayElementInterceptor.value);
+      checkNoReadWrite();
+      booleanVal = false;
+      clearInterceptors();
+      obj.booleans[0] = booleanVal;
+      assertEquals(0, TestArrayElementInterceptor.index);
+      assertEquals(booleanVal, TestArrayElementInterceptor.value);
+      checkWrite();
+      clearInterceptors();
+      obj.booleans[0] = booleanVal;
+      assertEquals(-1, TestArrayElementInterceptor.index);
+      assertNull(TestArrayElementInterceptor.value);
+      checkNoReadWrite();
+      
+      char charVal = 'h';
+      clearInterceptors();
+      obj.chars[0] = charVal;
+      assertEquals(0, TestArrayElementInterceptor.index);
+      assertEquals(charVal, TestArrayElementInterceptor.value);
+      checkWrite();
+      clearInterceptors();
+      obj.chars[0] = charVal;
+      assertEquals(-1, TestArrayElementInterceptor.index);
+      assertNull(TestArrayElementInterceptor.value);
+      checkNoReadWrite();
+      
+      double doubleVal = 101.1d;
+      clearInterceptors();
+      obj.doubles[0] = doubleVal;
+      assertEquals(0, TestArrayElementInterceptor.index);
+      assertEquals(doubleVal, TestArrayElementInterceptor.value);
+      checkWrite();
+      clearInterceptors();
+      obj.doubles[0] = doubleVal;
+      assertEquals(-1, TestArrayElementInterceptor.index);
+      assertNull(TestArrayElementInterceptor.value);
+      checkNoReadWrite();
+      
+      float floatVal = 66.6f;
+      clearInterceptors();
+      obj.floats[0] = floatVal;
+      assertEquals(0, TestArrayElementInterceptor.index);
+      assertEquals(floatVal, TestArrayElementInterceptor.value);
+      checkWrite();
+      clearInterceptors();
+      obj.floats[0] = floatVal;
+      assertEquals(-1, TestArrayElementInterceptor.index);
+      assertNull(TestArrayElementInterceptor.value);
+      checkNoReadWrite();
+
+      int intVal = 1000;
+      clearInterceptors();
+      obj.ints[0] = intVal;
+      assertEquals(0, TestArrayElementInterceptor.index);
+      assertEquals(intVal, TestArrayElementInterceptor.value);
+      checkWrite();
+      clearInterceptors();
+      obj.ints[0] = intVal;
+      assertEquals(-1, TestArrayElementInterceptor.index);
+      assertNull(TestArrayElementInterceptor.value);
+      checkNoReadWrite();
+
+      int[][] intVal2d = new int[][]{new int[]{1}, new int[]{2}};
+      clearInterceptors();
+      obj.ints3d[0] = intVal2d;
+      assertEquals(0, TestArrayElementInterceptor.index);
+      assertEquals(intVal2d, TestArrayElementInterceptor.value);
+      checkWrite();
+      clearInterceptors();
+      obj.ints3d[0] = intVal2d;
+      assertEquals(-1, TestArrayElementInterceptor.index);
+      assertNull(TestArrayElementInterceptor.value);
+      checkNoReadWrite();
+
+      long longVal = 10001;
+      clearInterceptors();
+      obj.longs[0] = longVal;
+      assertEquals(0, TestArrayElementInterceptor.index);
+      assertEquals(longVal, TestArrayElementInterceptor.value);
+      checkWrite();
+      clearInterceptors();
+      obj.longs[0] = longVal;
+      assertEquals(-1, TestArrayElementInterceptor.index);
+      assertNull(TestArrayElementInterceptor.value);
+      checkNoReadWrite();
+
+      short shortVal = 999;
+      clearInterceptors();
+      obj.shorts[0] = shortVal;
+      assertEquals(0, TestArrayElementInterceptor.index);
+      assertEquals(shortVal, TestArrayElementInterceptor.value);
+      checkWrite();
+      clearInterceptors();
+      obj.shorts[0] = shortVal;
+      assertEquals(-1, TestArrayElementInterceptor.index);
+      assertNull(TestArrayElementInterceptor.value);
+      checkNoReadWrite();
+
+      Object objectVal = new int[] {1,2,3};
+      clearInterceptors();
+      obj.objects[0] = objectVal;
+      assertEquals(0, TestArrayElementInterceptor.index);
+      assertEquals(objectVal, TestArrayElementInterceptor.value);
+      checkWrite();
+      clearInterceptors();
+      obj.objects[0] = objectVal;
+      assertEquals(-1, TestArrayElementInterceptor.index);
+      assertNull(TestArrayElementInterceptor.value);
+      checkNoReadWrite();
+      intVal = 100;
+      clearInterceptors();
+      ((int[])objectVal)[0] = intVal;
+      assertEquals(0, TestArrayElementInterceptor.index);
+      assertEquals(intVal, TestArrayElementInterceptor.value);
+      checkWrite();
+      clearInterceptors();
+      ((int[])objectVal)[0] = intVal;
+      assertEquals(-1, TestArrayElementInterceptor.index);
+      assertNull(TestArrayElementInterceptor.value);
+      checkNoReadWrite();
+   }
+   
+   public void testUnadvisedArrayFields()
+   {
+      ClassWithUnadvisedArrayFields obj = new ClassWithUnadvisedArrayFields();
+
+      clearInterceptors();
+      obj.objects[0] = "X";
+      assertEquals("X", obj.objects[0]);
+      assertEquals(-1, TestArrayElementInterceptor.index);
+      checkNoReadWrite();
+      
+      clearInterceptors();
+      obj.bytes[0] = 1;
+      assertEquals(1, obj.bytes[0]);
+      assertEquals(-1, TestArrayElementInterceptor.index);
+      checkNoReadWrite();
+      
+      clearInterceptors();
+      obj.booleans[0] = true;
+      assertEquals(true, obj.booleans[0]);
+      assertEquals(-1, TestArrayElementInterceptor.index);
+      checkNoReadWrite();
+      
+      clearInterceptors();
+      obj.chars[0] = 'z';
+      assertEquals('z', obj.chars[0]);
+      assertEquals(-1, TestArrayElementInterceptor.index);
+      checkNoReadWrite();
+      
+      clearInterceptors();
+      obj.doubles[0] = 9.9d;
+      assertEquals(9.9d, obj.doubles[0]);
+      assertEquals(-1, TestArrayElementInterceptor.index);
+      checkNoReadWrite();
+      
+      clearInterceptors();
+      obj.floats[0] = 9.9f;
+      assertEquals(9.9f, obj.floats[0]);
+      assertEquals(-1, TestArrayElementInterceptor.index);
+      checkNoReadWrite();
+      
+      clearInterceptors();
+      obj.ints[0] = 100;
+      assertEquals(100, obj.ints[0]);
+      assertEquals(-1, TestArrayElementInterceptor.index);
+      checkNoReadWrite();
+      
+      clearInterceptors();
+      obj.longs[0] = 100;
+      assertEquals(100, obj.longs[0]);
+      assertEquals(-1, TestArrayElementInterceptor.index);
+      checkNoReadWrite();
+      
+      clearInterceptors();
+      obj.shorts[0] = 100;
+      assertEquals(100, obj.shorts[0]);
+      assertEquals(-1, TestArrayElementInterceptor.index);
+      checkNoReadWrite();
+   }
+
+   public void testBranchesStillValidFollowingInstrumentation()
+   {
+      ClassWithArrayFields obj = new ClassWithArrayFields();
+      StringBuffer sb = new StringBuffer();
+      
+      for (int i = 0 ; i < 3 ; i++)
+      {
+         int[] ints = new int[] {0, 1, 2};
+         
+         if (i >= 1)
+         {
+            sb.append("g");
+            obj.ints = ints;
+            
+            clearInterceptors();
+            int val = ints[i];
+            assertEquals(i, val);
+            assertEquals(i, TestArrayElementInterceptor.index);
+            assertNull(TestArrayElementInterceptor.value);
+            
+            clearInterceptors();
+            obj.ints[i] = i + 2;
+            assertEquals(i, TestArrayElementInterceptor.index);
+            assertEquals(i + 2, ((Integer)TestArrayElementInterceptor.value).intValue());
+         }
+         else
+         {
+            sb.append("s");
+            obj.ints = ints;
+
+            clearInterceptors();
+            obj.ints[i] = i + 2;
+            assertEquals(i, TestArrayElementInterceptor.index);
+            assertEquals(i + 2, ((Integer)TestArrayElementInterceptor.value).intValue());
+
+            clearInterceptors();
+            int val = ints[i];
+            assertEquals(i + 2, ints[i]);
+            assertEquals(i, TestArrayElementInterceptor.index);
+            assertNull(TestArrayElementInterceptor.value);
+         }
+      }
+      assertEquals("sgg", sb.toString());
+   }
+   
+   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/trunk/aop/src/test/org/jboss/test/aop/array/ArrayReferenceTestCase.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/array/ArrayReferenceTestCase.java	                        (rev 0)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/array/ArrayReferenceTestCase.java	2007-10-12 08:05:17 UTC (rev 66077)
@@ -0,0 +1,493 @@
+/*
+* 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 java.util.HashSet;
+import java.util.List;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.jboss.aop.array.ArrayReference;
+import org.jboss.aop.array.ArrayRegistry;
+import org.jboss.test.aop.AOPTestWithSetup;
+
+
+/**
+ * Test that ArrayRegistry.getArrayOwners() returns the right data
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ArrayReferenceTestCase extends AOPTestWithSetup
+{
+   public ArrayReferenceTestCase(String name)
+   {
+      super(name);
+   }
+
+   public static Test suite()
+   {
+      TestSuite suite = new TestSuite("ArrayReferenceTestCase");
+      suite.addTestSuite(ArrayReferenceTestCase.class);
+      return suite;
+   }
+
+   public void testSimpleFieldReference()
+   {
+      ArrayRegistry registry = ArrayRegistry.getInstance();
+      Object[] arr = new Object[] {"1", "2", "3"};
+      ClassForReference obj = new ClassForReference();
+      obj.fieldA = arr;
+      List<ArrayReference> references = registry.getArrayOwners(arr);
+
+      assertEquals(1, references.size());
+      ArrayReference reference = references.get(0);
+      assertEquals(obj, reference.getRootObject());
+      assertEquals("fieldA", reference.getRootField());
+      assertNull(reference.getNestedArrayIndices());
+
+      obj.fieldA = null;
+      references = registry.getArrayOwners(arr);
+      assertNull(references);
+   }
+   
+   public void testMultipleFieldReferencesSameRootObjects()
+   {
+      ArrayRegistry registry = ArrayRegistry.getInstance();
+      Object[] arr = new Object[] {"1", "2", "3"};
+      ClassForReference obj = new ClassForReference();
+      obj.fieldA = arr;
+      obj.fieldB = arr;
+      List<ArrayReference> references = registry.getArrayOwners(arr);
+      assertEquals(2, references.size());
+      
+      HashSet fields = new HashSet();
+      fields.add("fieldA");
+      fields.add("fieldB");
+      for (ArrayReference ref : references)
+      {
+         Object owner = ref.getRootObject();
+         assertEquals(obj, owner);
+         assertTrue("Expeced 'fieldA' or 'fieldB'; was " + ref.getRootField(), ref.getRootField() == "fieldA" || ref.getRootField() == "fieldB");
+         assertNull(ref.getNestedArrayIndices());
+         fields.remove(ref.getRootField());
+      }
+      
+      assertTrue("Did not find all references " + fields, fields.size() == 0);
+      
+      obj.fieldA = null;
+      references = registry.getArrayOwners(arr);
+      assertEquals(1, references.size());
+      ArrayReference reference = references.get(0);
+      assertEquals(obj, reference.getRootObject());
+      assertEquals("fieldB", reference.getRootField());
+      assertNull(reference.getNestedArrayIndices());
+      
+      obj.fieldB = null;
+      references = registry.getArrayOwners(arr);
+      assertNull(references);
+   }
+
+   public void testMultipleFieldReferencesDifferentRootObjects()
+   {
+      ArrayRegistry registry = ArrayRegistry.getInstance();
+      Object[] arr = new Object[] {"1", "2", "3"};
+      ClassForReference obj = new ClassForReference();
+      ClassForReference obj2 = new ClassForReference();
+      obj.fieldA = arr;
+      obj2.fieldB = arr;
+      List<ArrayReference> references = registry.getArrayOwners(arr);
+      assertEquals(2, references.size());
+      
+      HashSet rootObjects = new HashSet();
+      rootObjects.add(obj);
+      rootObjects.add(obj2);
+      for (ArrayReference ref : references)
+      {
+         Object owner = ref.getRootObject();
+         assertTrue("Expected " + obj + " or " + obj2 + "; was" + owner, owner == obj || owner == obj2);
+         if (owner == obj)
+         {
+            assertEquals("fieldA", ref.getRootField());
+         }
+         else if (owner == obj2)
+         {
+            assertEquals("fieldB", ref.getRootField());
+         }
+         assertNull(ref.getNestedArrayIndices());
+         rootObjects.remove(owner);
+      }
+      
+      assertTrue("Did not find all references " + rootObjects, rootObjects.size() == 0);
+      
+      obj.fieldA = null;
+      references = registry.getArrayOwners(arr);
+      assertEquals(1, references.size());
+      ArrayReference reference = references.get(0);
+      assertEquals(obj2, reference.getRootObject());
+      assertEquals("fieldB", reference.getRootField());
+      assertNull(reference.getNestedArrayIndices());
+      
+      obj2.fieldB = null;
+      references = registry.getArrayOwners(arr);
+      assertNull(references);
+   }
+
+   public void testMultipleFieldReferencesStatic()
+   {
+      ArrayRegistry registry = ArrayRegistry.getInstance();
+      Object[] arr = new Object[] {"1", "2", "3"};
+      ClassForReference.staticA = arr;
+      ClassForReference.staticB = arr;
+      List<ArrayReference> references = registry.getArrayOwners(arr);
+      assertEquals(2, references.size());
+      
+      HashSet fields = new HashSet();
+      fields.add("staticA");
+      fields.add("staticB");
+      
+      for (ArrayReference ref : references)
+      {
+         Object owner = ref.getRootObject();
+         assertEquals(ClassForReference.class, owner);
+         assertTrue("Expected 'staticA' or 'staticB'; was " + ref.getRootField(), ref.getRootField() == "staticA" || ref.getRootField() == "staticB");
+         assertNull(ref.getNestedArrayIndices());
+         fields.remove(ref.getRootField());
+      }
+      
+      assertTrue("Did not find all references " + fields, fields.size() == 0);
+      
+      ClassForReference.staticA = null;
+      references = registry.getArrayOwners(arr);
+      assertEquals(1, references.size());
+      ArrayReference reference = references.get(0);
+      assertEquals(ClassForReference.class, reference.getRootObject());
+      assertEquals("staticB", reference.getRootField());
+      assertNull(reference.getNestedArrayIndices());
+      
+      ClassForReference.staticB = null;
+      references = registry.getArrayOwners(arr);
+      assertNull(references);
+   }
+
+   public void testMultipleFieldReferencesStaticAndNonStatic()
+   {
+      ArrayRegistry registry = ArrayRegistry.getInstance();
+      Object[] arr = new Object[] {"1", "2", "3"};
+      ClassForReference obj = new ClassForReference();
+      obj.fieldA = arr;
+      ClassForReference.staticA = arr;
+      List<ArrayReference> references = registry.getArrayOwners(arr);
+      assertEquals(2, references.size());
+      
+      HashSet rootObjects = new HashSet();
+      rootObjects.add(obj);
+      rootObjects.add(ClassForReference.class);
+      
+      for (ArrayReference ref : references)
+      {
+         Object owner = ref.getRootObject();
+         assertTrue("Expected " + obj + " or " + ClassForReference.class + "; was" + owner, owner == obj || owner == ClassForReference.class);
+         if (owner == obj)
+         {
+            assertEquals("fieldA", ref.getRootField());
+         }
+         else if (owner == ClassForReference.class)
+         {
+            assertEquals("staticA", ref.getRootField());
+         }
+         assertNull(ref.getNestedArrayIndices());
+         rootObjects.remove(owner);
+      }
+      
+      assertTrue("Did not find all references " + rootObjects, rootObjects.size() == 0);
+      
+      obj.fieldA = null;
+      references = registry.getArrayOwners(arr);
+      assertEquals(1, references.size());
+      ArrayReference reference = references.get(0);
+      assertEquals(ClassForReference.class, reference.getRootObject());
+      assertEquals("staticA", reference.getRootField());
+      assertNull(reference.getNestedArrayIndices());
+      
+      ClassForReference.staticA = null;
+      references = registry.getArrayOwners(arr);
+      assertNull(references);
+   }
+   
+   public void testSimpleElementReferences()
+   {
+      ArrayRegistry registry = ArrayRegistry.getInstance();
+      Object[] arr = new Object[] {"1", "2", "3"};
+      ClassForReference obj = new ClassForReference();
+      obj.fieldA = new Object[] {arr};
+      List<ArrayReference> references = registry.getArrayOwners(arr);
+      
+      assertEquals(1, references.size());
+      ArrayReference reference = references.get(0);
+      assertEquals(obj, reference.getRootObject());
+      assertEquals("fieldA", reference.getRootField());
+      assertNotNull(reference.getNestedArrayIndices());
+      assertEquals(1, reference.getNestedArrayIndices().size()); 
+      assertEquals(new Integer(0), reference.getNestedArrayIndices().get(0));
+
+      obj.fieldA[0] = null;
+      references = registry.getArrayOwners(arr);
+      assertNull(references);
+   }
+
+   public void testMultipleElementReferencesSameArraySameRootObject()
+   {
+      ArrayRegistry registry = ArrayRegistry.getInstance();
+      Object[] arr = new Object[] {"1", "2", "3"};
+      ClassForReference obj = new ClassForReference();
+      obj.fieldA = new Object[] {arr, null, arr};
+      List<ArrayReference> references = registry.getArrayOwners(arr);
+      
+      assertEquals(2, references.size());
+      
+      HashSet indeces = new HashSet();
+      indeces.add(new Integer(0));
+      indeces.add(new Integer(2));
+      
+      for (ArrayReference ref : references)
+      {
+         Object owner = ref.getRootObject();
+         assertEquals(obj, owner);
+         assertEquals("fieldA", ref.getRootField());
+         assertNotNull(ref.getNestedArrayIndices());
+         assertEquals(1, ref.getNestedArrayIndices().size());
+         indeces.remove(ref.getNestedArrayIndices().get(0));
+      }
+      assertTrue("Did not find all references " + indeces, indeces.size() == 0);
+
+      obj.fieldA[2] = null; 
+      
+      references = registry.getArrayOwners(arr);
+      
+      assertEquals(1, references.size());
+      ArrayReference reference = references.get(0);
+      assertEquals(obj, reference.getRootObject());
+      assertEquals("fieldA", reference.getRootField());
+      assertEquals(1, reference.getNestedArrayIndices().size());
+      assertEquals(new Integer(0), reference.getNestedArrayIndices().get(0));
+
+      obj.fieldA[0] = null; 
+      references = registry.getArrayOwners(arr);
+      assertNull(references);
+   }
+
+   public void testMultipleElementReferencesSameArrayDifferentRootObject()
+   {
+      ArrayRegistry registry = ArrayRegistry.getInstance();
+      Object[] arr = new Object[] {"1", "2", "3"};
+      ClassForReference obj = new ClassForReference();
+      ClassForReference obj2 = new ClassForReference();
+      obj.fieldA = new Object[] {arr};
+      obj2.fieldA = new Object[] {arr};
+      List<ArrayReference> references = registry.getArrayOwners(arr);
+      
+      assertEquals(2, references.size());
+      
+      HashSet owners = new HashSet();
+      owners.add(obj);
+      owners.add(obj2);
+      
+      for (ArrayReference ref : references)
+      {
+         Object owner = ref.getRootObject();
+         assertEquals("fieldA", ref.getRootField());
+         assertNotNull(ref.getNestedArrayIndices());
+         assertEquals(1, ref.getNestedArrayIndices().size());
+         assertEquals(new Integer(0), ref.getNestedArrayIndices().get(0));
+         owners.remove(owner);
+      }
+      assertTrue("Did not find all references " + owners, owners.size() == 0);
+
+      obj.fieldA[0] = null; 
+      
+      references = registry.getArrayOwners(arr);
+      
+      assertEquals(1, references.size());
+      ArrayReference reference = references.get(0);
+      assertEquals(obj2, reference.getRootObject());
+      assertEquals("fieldA", reference.getRootField());
+      assertEquals(1, reference.getNestedArrayIndices().size());
+      assertEquals(new Integer(0), reference.getNestedArrayIndices().get(0));
+
+      obj2.fieldA[0] = null; 
+      references = registry.getArrayOwners(arr);
+      assertNull(references);
+   }
+
+   public void testMultipleElementReferencesStatic()
+   {
+      ArrayRegistry registry = ArrayRegistry.getInstance();
+      Object[] arr = new Object[] {"1", "2", "3"};
+      ClassForReference.staticA = new Object[] {arr};
+      ClassForReference.staticB = new Object[] {null, arr};
+      List<ArrayReference> references = registry.getArrayOwners(arr);
+      
+      assertEquals(2, references.size());
+      
+      HashSet elements = new HashSet();
+      elements.add("staticA0");
+      elements.add("staticB1");
+      
+      for (ArrayReference ref : references)
+      {
+         Object owner = ref.getRootObject();
+         assertEquals(ClassForReference.class, owner);
+         assertNotNull(ref.getNestedArrayIndices());
+         assertEquals(1, ref.getNestedArrayIndices().size());
+         elements.remove(ref.getRootField() + ref.getNestedArrayIndices().get(0));
+      }
+      assertTrue("Did not find all references " + elements, elements.size() == 0);
+
+      ClassForReference.staticA[0] = null; 
+      
+      references = registry.getArrayOwners(arr);
+      
+      assertEquals(1, references.size());
+      ArrayReference reference = references.get(0);
+      assertEquals(ClassForReference.class, reference.getRootObject());
+      assertEquals("staticB", reference.getRootField());
+      assertEquals(1, reference.getNestedArrayIndices().size());
+      assertEquals(new Integer(1), reference.getNestedArrayIndices().get(0));
+
+      ClassForReference.staticB[1] = null; 
+      references = registry.getArrayOwners(arr);
+      assertNull(references);
+   }
+   
+   public void testNestedMultipleReferences()
+   {
+      ArrayRegistry registry = ArrayRegistry.getInstance();
+      int[] arr = new int[] {1, 2, 3};
+      ClassForReference obj = new ClassForReference();
+      Object[][][][] fieldA = new Object[][][][] {null, null, new Object[][][] {null, new Object[][] {null, null, new Object[] {null, null, null, arr}}}}; //2, 1, 2, 3
+      obj.fieldA = fieldA;
+      Object[][][] staticA = new Object[][][] {new Object[][][] {null, new Object[][] {null, null, new Object[]{null, null, arr}}},null}; //0, 1, 2, 2
+      ClassForReference.staticA = staticA;
+      
+      final String FIELDA = "fieldA2123"; 
+      final String STATICA = "staticA0122";
+      
+      HashSet elements = new HashSet();
+      elements.add(FIELDA);
+      elements.add(STATICA);
+
+      List<ArrayReference> references = registry.getArrayOwners(arr);
+      
+      assertEquals(2, references.size());
+
+      for (ArrayReference ref : references)
+      {
+         Object owner = ref.getRootObject();
+         assertNotNull(ref.getNestedArrayIndices());
+         StringBuffer elem = new StringBuffer(ref.getRootField());
+         
+         List<Integer> indices = ref.getNestedArrayIndices();
+         for (Integer index : indices)
+         {
+            elem.append(index);
+         }
+         
+         System.out.println("----> elem " + elem.toString());
+         elements.remove(elem.toString());
+         if (elem.toString().equals(STATICA))
+         {
+            assertEquals(ClassForReference.class, owner);
+         }
+         else if (elem.toString().equals(FIELDA))
+         {
+            assertEquals(obj, owner);
+         }
+      }   
+      assertTrue("Did not find all references " + elements, elements.size() == 0);
+
+      fieldA[2][1][2][3] = null;
+      references = registry.getArrayOwners(arr);
+      assertEquals(1, references.size());
+      ArrayReference reference = references.get(0);
+      assertEquals(ClassForReference.class, reference.getRootObject());
+      assertEquals("staticA", reference.getRootField());
+      assertEquals(4, reference.getNestedArrayIndices().size());
+      assertEquals(new Integer(0), reference.getNestedArrayIndices().get(0));
+      assertEquals(new Integer(1), reference.getNestedArrayIndices().get(1));
+      assertEquals(new Integer(2), reference.getNestedArrayIndices().get(2));
+      assertEquals(new Integer(2), reference.getNestedArrayIndices().get(3));
+
+      ((Object[])staticA[0][1][2])[2] = null; 
+      references = registry.getArrayOwners(arr);
+      assertNull(references);
+   }
+
+   public void testNestedReferencesRemoveAtHigherLevel()
+   {
+      ArrayRegistry registry = ArrayRegistry.getInstance();
+      int[] arr = new int[] {1, 2, 3};
+      ClassForReference obj = new ClassForReference();
+      Object[][][][] fieldA = new Object[][][][] {null, null, new Object[][][] {null, new Object[][] {null, null, new Object[] {null, null, null, arr}}}}; //2, 1, 2, 3
+      obj.fieldA = fieldA;
+
+      List<ArrayReference> references = registry.getArrayOwners(arr);
+      
+      assertEquals(1, references.size());
+      
+      ArrayReference reference = references.get(0);
+      assertEquals(obj, reference.getRootObject());
+      assertEquals("fieldA", reference.getRootField());
+      assertEquals(4, reference.getNestedArrayIndices().size());
+      assertEquals(new Integer(2), reference.getNestedArrayIndices().get(0));
+      assertEquals(new Integer(1), reference.getNestedArrayIndices().get(1));
+      assertEquals(new Integer(2), reference.getNestedArrayIndices().get(2));
+      assertEquals(new Integer(3), reference.getNestedArrayIndices().get(3));
+
+      fieldA[2][1] = null; 
+      references = registry.getArrayOwners(arr);
+      assertNull(references);
+   }
+   
+   public void testArrayReferenceFromInvocation()
+   {
+      ClassForReference obj = new ClassForReference();
+      int[] arr = new int[] {1, 2, 3};
+      Object[][][][] fieldA = new Object[][][][] {null, null, new Object[][][] {null, new Object[][] {null, null, new Object[] {null, null, null, null}}}}; //2, 1, 2, 3
+      obj.fieldA = fieldA;
+      TestArrayElementInterceptor.clear();
+      fieldA[2][1][2][3] = "X";
+      assertEquals(1, TestArrayElementInterceptor.owners.size());
+      
+      ArrayReference reference = TestArrayElementInterceptor.owners.get(0);
+      assertEquals(obj, reference.getRootObject());
+      assertEquals("fieldA", reference.getRootField());
+      assertEquals(3, reference.getNestedArrayIndices().size());
+      assertEquals(new Integer(2), reference.getNestedArrayIndices().get(0));
+      assertEquals(new Integer(1), reference.getNestedArrayIndices().get(1));
+      assertEquals(new Integer(2), reference.getNestedArrayIndices().get(2));
+
+      //TODO For an ObjectArrayElementInvocation, where the value is an array belonging to a registered array,
+      //should the references be updated at the end of the invocation, or in the weaving as is done at present?
+   }
+}

Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/array/AspectForPrecedence.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/array/AspectForPrecedence.java	                        (rev 0)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/array/AspectForPrecedence.java	2007-10-12 08:05:17 UTC (rev 66077)
@@ -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/trunk/aop/src/test/org/jboss/test/aop/array/ClassForReference.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/array/ClassForReference.java	                        (rev 0)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/array/ClassForReference.java	2007-10-12 08:05:17 UTC (rev 66077)
@@ -0,0 +1,36 @@
+/*
+* 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;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ClassForReference
+{
+   public Object[] fieldA;
+   public Object[] fieldB;
+   
+   public static Object[] staticA;
+   public static Object[] staticB;
+}

Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/array/ClassWithArrayFields.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/array/ClassWithArrayFields.java	                        (rev 0)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/array/ClassWithArrayFields.java	2007-10-12 08:05:17 UTC (rev 66077)
@@ -0,0 +1,58 @@
+/*
+* 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;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ClassWithArrayFields
+{
+   public Object[] objects = new Object[] {"1", "2", "3"};
+   public byte[] bytes = new byte[] {1, 2, 3};
+   public boolean[] booleans = new boolean[] {true, true, true};
+   public char[] chars = new char[] {'a', 'b', 'c'};
+   public double[] doubles = new double[] {1.5d, 1.9d, 6.9d};
+   public float[] floats = new float[] {1.5f, 1.9f, 6.9f};
+   public int[] ints = new int[] {0, 0, 0};
+   public int[][][] ints3d = new int[][][] {
+         new int[][] {
+               new int[] {1,2,3}, 
+               new int[] {4,5,6},
+               new int[] {7,8,9}
+         },
+         new int[][] {
+               new int[] {1,2,3}, 
+               new int[] {4,5,6},
+               new int[] {7,8,9}
+         },         
+   };
+   public long[] longs = new long[] {1L, 2L, 3L};
+   public short[] shorts = new short[] {1,2,3};
+   public Object objectField = new int[] {1, 2, 3};
+   
+   public ClassWithArrayFields()
+   {
+
+   }
+}

Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/array/ClassWithSeveralReferencesToSameArray.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/array/ClassWithSeveralReferencesToSameArray.java	                        (rev 0)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/array/ClassWithSeveralReferencesToSameArray.java	2007-10-12 08:05:17 UTC (rev 66077)
@@ -0,0 +1,46 @@
+/*
+* 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;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ClassWithSeveralReferencesToSameArray
+{
+   int[] one;
+   int[] two;
+   
+   int[][] multi;
+   
+   public ClassWithSeveralReferencesToSameArray()
+   {
+      one = new int[] {1,2,3};
+      two = one;
+      
+      int[] nested = new int[] {4,5,6};
+      multi = new int[2][];
+      multi[0] = nested;
+      multi[1] = nested;
+   }
+}

Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/array/ClassWithUnadvisedArrayFields.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/array/ClassWithUnadvisedArrayFields.java	                        (rev 0)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/array/ClassWithUnadvisedArrayFields.java	2007-10-12 08:05:17 UTC (rev 66077)
@@ -0,0 +1,41 @@
+/*
+* 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;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ClassWithUnadvisedArrayFields
+{
+   public Object[] objects = new Object[] {"1", "2", "3"};
+   public byte[] bytes = new byte[] {1, 2, 3};
+   public boolean[] booleans = new boolean[] {true, true, true};
+   public char[] chars = new char[] {'a', 'b', 'c'};
+   public double[] doubles = new double[] {1.5d, 1.9d, 6.9d};
+   public float[] floats = new float[] {1.5f, 1.9f, 6.9f};
+   public int[] ints = new int[] {0, 0, 0};
+   public long[] longs = new long[] {1L, 2L, 3L};
+   public short[] shorts = new short[] {1,2,3};
+
+}

Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/array/TestArrayElementInterceptor.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/array/TestArrayElementInterceptor.java	                        (rev 0)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/array/TestArrayElementInterceptor.java	2007-10-12 08:05:17 UTC (rev 66077)
@@ -0,0 +1,141 @@
+/*
+* 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 java.util.List;
+
+import junit.framework.Assert;
+
+import org.jboss.aop.advice.Interceptor;
+import org.jboss.aop.array.ArrayElementReadInvocation;
+import org.jboss.aop.array.ArrayElementWriteInvocation;
+import org.jboss.aop.array.ArrayReference;
+import org.jboss.aop.array.ArrayRegistry;
+import org.jboss.aop.array.BooleanArrayElementWriteInvocation;
+import org.jboss.aop.array.ByteArrayElementWriteInvocation;
+import org.jboss.aop.array.CharArrayElementWriteInvocation;
+import org.jboss.aop.array.DoubleArrayElementWriteInvocation;
+import org.jboss.aop.array.FloatArrayElementWriteInvocation;
+import org.jboss.aop.array.IntArrayElementWriteInvocation;
+import org.jboss.aop.array.LongArrayElementWriteInvocation;
+import org.jboss.aop.array.ObjectArrayElementWriteInvocation;
+import org.jboss.aop.array.ShortArrayElementWriteInvocation;
+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 List<ArrayReference> owners;
+   
+   public static void clear()
+   {
+      index = -1;
+      value = null;
+      owners = 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();
+         checkType((ArrayElementWriteInvocation)invocation);
+      } 
+      owners = ArrayRegistry.getInstance().getArrayOwners(invocation.getTargetObject());
+      invocation.getMetaData().addMetaData("test", "invoked", "TestArrayElementInterceptor");
+      return invocation.invokeNext();
+   }
+
+   public static class Value
+   {
+      public Object value;
+   }
+   
+   private void checkType(ArrayElementWriteInvocation invocation)
+   {
+      if (invocation instanceof ObjectArrayElementWriteInvocation)
+      {
+         
+      }
+      else if (invocation instanceof ByteArrayElementWriteInvocation)
+      {
+         byte b = ((ByteArrayElementWriteInvocation)invocation).getByteValue();
+         Assert.assertEquals(b, ((Byte)invocation.getValue()).byteValue());
+      }
+      else if (invocation instanceof BooleanArrayElementWriteInvocation)
+      {
+         boolean b = ((BooleanArrayElementWriteInvocation)invocation).getBooleanValue();
+         Assert.assertEquals(b, ((Boolean)invocation.getValue()).booleanValue());
+      }
+      else if (invocation instanceof CharArrayElementWriteInvocation)
+      {
+         char c = ((CharArrayElementWriteInvocation)invocation).getCharValue();
+         Assert.assertEquals(c, ((Character)invocation.getValue()).charValue());
+      }
+      else if (invocation instanceof DoubleArrayElementWriteInvocation)
+      {
+         double d = ((DoubleArrayElementWriteInvocation)invocation).getDoubleValue();
+         Assert.assertEquals(d, ((Double)invocation.getValue()).doubleValue());         
+      }
+      else if (invocation instanceof FloatArrayElementWriteInvocation)
+      {
+         float f = ((FloatArrayElementWriteInvocation)invocation).getFloatValue();
+         Assert.assertEquals(f, ((Float)invocation.getValue()).floatValue());         
+      }
+      else if (invocation instanceof IntArrayElementWriteInvocation)
+      {
+         int i = ((IntArrayElementWriteInvocation)invocation).getIntValue();
+         Assert.assertEquals(i, ((Integer)invocation.getValue()).intValue());         
+      }
+      else if (invocation instanceof LongArrayElementWriteInvocation)
+      {
+         long l = ((LongArrayElementWriteInvocation)invocation).getLongValue();
+         Assert.assertEquals(l, ((Long)invocation.getValue()).longValue());         
+      }
+      else if (invocation instanceof ShortArrayElementWriteInvocation)
+      {
+         short s = ((ShortArrayElementWriteInvocation)invocation).getShortValue();
+         Assert.assertEquals(s, ((Short)invocation.getValue()).shortValue());         
+      }
+      else
+      {
+         throw new RuntimeException("Dodgy invocation type " + invocation.getClass().getName());
+      }
+   }
+}

Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/array/TestArrayElementReadInterceptor.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/array/TestArrayElementReadInterceptor.java	                        (rev 0)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/array/TestArrayElementReadInterceptor.java	2007-10-12 08:05:17 UTC (rev 66077)
@@ -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/trunk/aop/src/test/org/jboss/test/aop/array/TestArrayElementWriteInterceptor.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/array/TestArrayElementWriteInterceptor.java	                        (rev 0)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/array/TestArrayElementWriteInterceptor.java	2007-10-12 08:05:17 UTC (rev 66077)
@@ -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