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

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sat Dec 30 16:52:54 EST 2006


Author: kabir.khan at jboss.com
Date: 2006-12-30 16:52:49 -0500 (Sat, 30 Dec 2006)
New Revision: 59250

Modified:
   projects/aop/branches/arrays/aop/src/main/org/jboss/aop/array/ArrayElementInvocation.java
   projects/aop/branches/arrays/aop/src/main/org/jboss/aop/array/ArrayReference.java
   projects/aop/branches/arrays/aop/src/main/org/jboss/aop/array/ArrayRegistry.java
   projects/aop/branches/arrays/aop/src/test/org/jboss/test/aop/array/ArrayReferenceTestCase.java
   projects/aop/branches/arrays/aop/src/test/org/jboss/test/aop/array/TestArrayElementInterceptor.java
Log:
A bit of tidying up

Modified: projects/aop/branches/arrays/aop/src/main/org/jboss/aop/array/ArrayElementInvocation.java
===================================================================
--- projects/aop/branches/arrays/aop/src/main/org/jboss/aop/array/ArrayElementInvocation.java	2006-12-30 19:37:19 UTC (rev 59249)
+++ projects/aop/branches/arrays/aop/src/main/org/jboss/aop/array/ArrayElementInvocation.java	2006-12-30 21:52:49 UTC (rev 59250)
@@ -21,6 +21,7 @@
 */ 
 package org.jboss.aop.array;
 
+import java.util.List;
 import java.util.Map;
 
 import org.jboss.aop.Advisor;
@@ -159,9 +160,9 @@
       throw new NotImplementedException();
    }
    
-   public void getReferences()
+   public List<ArrayReference> getArrayOwners()
    {
       ArrayRegistry registry = ArrayRegistry.getInstance();
-      registry.getArrayOwners(targetObject);
+      return registry.getArrayOwners(targetObject);
    }
 }

Modified: projects/aop/branches/arrays/aop/src/main/org/jboss/aop/array/ArrayReference.java
===================================================================
--- projects/aop/branches/arrays/aop/src/main/org/jboss/aop/array/ArrayReference.java	2006-12-30 19:37:19 UTC (rev 59249)
+++ projects/aop/branches/arrays/aop/src/main/org/jboss/aop/array/ArrayReference.java	2006-12-30 21:52:49 UTC (rev 59250)
@@ -24,13 +24,49 @@
 import java.util.List;
 
 /**
+ * Contains information about one reference to a particular array. 
  * 
  * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
  * @version $Revision: 1.1 $
  */
 public interface ArrayReference
 {
+   /**
+    * @return The object containing the field with the array reference. If the root field is non static this 
+    * will be the reference of the instance, if the field is static it will be the class
+    */
    Object getRootObject();
+
+   /**
+    * @return The field with the array reference 
+    */
    String getRootField();
+   
+   /**
+    * If the root field is a direct reference to the array this will be null. If the field is an array and the reference is from within 
+    * a nested array, this will be a list of the indexes from the top to get to the array.<BR/>
+    * 
+    * So if we have:
+    * <pre>
+    * class POJO{
+    *   int[] i;
+    * }
+    * POJO pojo = new POJO();
+    * int[] i arr = new int[]{1};
+    * pojo.i = arr;
+    * </pre>
+    *  getNestedArrayIndices will be null for arr.If we have:
+    * <pre>
+    * class POJO{
+    *   int[][][] i;
+    * }
+    * POJO pojo = new POJO();
+    * int[] arr = new int[]{1};
+    * pojo.i = new int[][][]{new int[][]{new int[]{1}}, new int[][]{new int[]{2}, new int[]{3}, arr}};
+    * </pre>
+    *  getNestedArrayIndices will {1,2} for arr.
+
+    * @ return the nested indices of the array.  
+    */
    List<Integer> getNestedArrayIndices();
 }

Modified: projects/aop/branches/arrays/aop/src/main/org/jboss/aop/array/ArrayRegistry.java
===================================================================
--- projects/aop/branches/arrays/aop/src/main/org/jboss/aop/array/ArrayRegistry.java	2006-12-30 19:37:19 UTC (rev 59249)
+++ projects/aop/branches/arrays/aop/src/main/org/jboss/aop/array/ArrayRegistry.java	2006-12-30 21:52:49 UTC (rev 59250)
@@ -194,7 +194,6 @@
 
    public List<ArrayReference> getArrayOwners(Object array)
    {
-      System.out.println("----> getArrayOwners " + array);
       Lock readLock = lock.readLock();
       readLock.lock();
       

Modified: projects/aop/branches/arrays/aop/src/test/org/jboss/test/aop/array/ArrayReferenceTestCase.java
===================================================================
--- projects/aop/branches/arrays/aop/src/test/org/jboss/test/aop/array/ArrayReferenceTestCase.java	2006-12-30 19:37:19 UTC (rev 59249)
+++ projects/aop/branches/arrays/aop/src/test/org/jboss/test/aop/array/ArrayReferenceTestCase.java	2006-12-30 21:52:49 UTC (rev 59250)
@@ -468,4 +468,23 @@
       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));
+   }
 }

Modified: projects/aop/branches/arrays/aop/src/test/org/jboss/test/aop/array/TestArrayElementInterceptor.java
===================================================================
--- projects/aop/branches/arrays/aop/src/test/org/jboss/test/aop/array/TestArrayElementInterceptor.java	2006-12-30 19:37:19 UTC (rev 59249)
+++ projects/aop/branches/arrays/aop/src/test/org/jboss/test/aop/array/TestArrayElementInterceptor.java	2006-12-30 21:52:49 UTC (rev 59250)
@@ -21,9 +21,13 @@
 */ 
 package org.jboss.test.aop.array;
 
+import java.util.List;
+
 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.joinpoint.Invocation;
 
 /**
@@ -35,11 +39,13 @@
 {
    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()
@@ -59,7 +65,7 @@
          index = ((ArrayElementWriteInvocation)invocation).getIndex();
          value = ((ArrayElementWriteInvocation)invocation).getValue();
       } 
-      
+      owners = ArrayRegistry.getInstance().getArrayOwners(invocation.getTargetObject());
       invocation.getMetaData().addMetaData("test", "invoked", "TestArrayElementInterceptor");
       return invocation.invokeNext();
    }




More information about the jboss-cvs-commits mailing list