[jboss-cvs] JBossAS SVN: r66076 - in projects/aop/trunk/aop/src/main/org/jboss/aop: array and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Oct 12 04:04:04 EDT 2007
Author: stalep
Date: 2007-10-12 04:04:04 -0400 (Fri, 12 Oct 2007)
New Revision: 66076
Added:
projects/aop/trunk/aop/src/main/org/jboss/aop/array/
projects/aop/trunk/aop/src/main/org/jboss/aop/array/ArrayAdvisor.java
projects/aop/trunk/aop/src/main/org/jboss/aop/array/ArrayBinding.java
projects/aop/trunk/aop/src/main/org/jboss/aop/array/ArrayElementInvocation.java
projects/aop/trunk/aop/src/main/org/jboss/aop/array/ArrayElementReadInvocation.java
projects/aop/trunk/aop/src/main/org/jboss/aop/array/ArrayElementWriteInvocation.java
projects/aop/trunk/aop/src/main/org/jboss/aop/array/ArrayReference.java
projects/aop/trunk/aop/src/main/org/jboss/aop/array/ArrayReferenceImpl.java
projects/aop/trunk/aop/src/main/org/jboss/aop/array/ArrayRegistry.java
projects/aop/trunk/aop/src/main/org/jboss/aop/array/ArrayRegistryEntry.java
projects/aop/trunk/aop/src/main/org/jboss/aop/array/ArrayReplacement.java
projects/aop/trunk/aop/src/main/org/jboss/aop/array/BooleanArrayElementReadInvocation.java
projects/aop/trunk/aop/src/main/org/jboss/aop/array/BooleanArrayElementWriteInvocation.java
projects/aop/trunk/aop/src/main/org/jboss/aop/array/ByteArrayElementReadInvocation.java
projects/aop/trunk/aop/src/main/org/jboss/aop/array/ByteArrayElementWriteInvocation.java
projects/aop/trunk/aop/src/main/org/jboss/aop/array/ByteBooleanConverter.java
projects/aop/trunk/aop/src/main/org/jboss/aop/array/CharArrayElementReadInvocation.java
projects/aop/trunk/aop/src/main/org/jboss/aop/array/CharArrayElementWriteInvocation.java
projects/aop/trunk/aop/src/main/org/jboss/aop/array/DoubleArrayElementReadInvocation.java
projects/aop/trunk/aop/src/main/org/jboss/aop/array/DoubleArrayElementWriteInvocation.java
projects/aop/trunk/aop/src/main/org/jboss/aop/array/ElementArrayRegistryEntry.java
projects/aop/trunk/aop/src/main/org/jboss/aop/array/FieldArrayRegistryEntry.java
projects/aop/trunk/aop/src/main/org/jboss/aop/array/FloatArrayElementReadInvocation.java
projects/aop/trunk/aop/src/main/org/jboss/aop/array/FloatArrayElementWriteInvocation.java
projects/aop/trunk/aop/src/main/org/jboss/aop/array/IntArrayElementReadInvocation.java
projects/aop/trunk/aop/src/main/org/jboss/aop/array/IntArrayElementWriteInvocation.java
projects/aop/trunk/aop/src/main/org/jboss/aop/array/LongArrayElementReadInvocation.java
projects/aop/trunk/aop/src/main/org/jboss/aop/array/LongArrayElementWriteInvocation.java
projects/aop/trunk/aop/src/main/org/jboss/aop/array/ObjectArrayElementReadInvocation.java
projects/aop/trunk/aop/src/main/org/jboss/aop/array/ObjectArrayElementWriteInvocation.java
projects/aop/trunk/aop/src/main/org/jboss/aop/array/ShortArrayElementReadInvocation.java
projects/aop/trunk/aop/src/main/org/jboss/aop/array/ShortArrayElementWriteInvocation.java
projects/aop/trunk/aop/src/main/org/jboss/aop/array/Type.java
projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/ArrayAccessTransformer.java
Modified:
projects/aop/trunk/aop/src/main/org/jboss/aop/AspectManager.java
projects/aop/trunk/aop/src/main/org/jboss/aop/AspectXmlLoader.java
projects/aop/trunk/aop/src/main/org/jboss/aop/Domain.java
projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/FieldAccessTransformer.java
projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorFieldAccessTransformer.java
projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/Instrumentor.java
projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/MethodExecutionTransformer.java
projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/NonOptimizedFieldAccessTransformer.java
projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/OptimizedFieldAccessTransformer.java
Log:
[JBAOP-265] merging from array branch
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/AspectManager.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/AspectManager.java 2007-10-12 07:26:54 UTC (rev 66075)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/AspectManager.java 2007-10-12 08:04:04 UTC (rev 66076)
@@ -55,6 +55,9 @@
import org.jboss.aop.advice.PrecedenceDefEntry;
import org.jboss.aop.advice.PrecedenceSorter;
import org.jboss.aop.advice.Scope;
+import org.jboss.aop.array.ArrayAdvisor;
+import org.jboss.aop.array.ArrayBinding;
+import org.jboss.aop.array.ArrayReplacement;
import org.jboss.aop.classpool.AOPClassLoaderScopingPolicy;
import org.jboss.aop.classpool.AOPClassPoolRepository;
import org.jboss.aop.instrument.GeneratedAdvisorInstrumentor;
@@ -124,6 +127,8 @@
protected int subscribedDomainQueueRef;
protected LinkedHashMap interfaceIntroductions = UnmodifiableEmptyCollections.EMPTY_LINKED_HASHMAP;
+ protected LinkedHashMap arrayReplacements = UnmodifiableEmptyCollections.EMPTY_LINKED_HASHMAP;
+ protected LinkedHashMap arrayBindings = UnmodifiableEmptyCollections.EMPTY_LINKED_HASHMAP;
protected LinkedHashMap annotationIntroductions =UnmodifiableEmptyCollections. EMPTY_LINKED_HASHMAP;
protected LinkedHashMap annotationOverrides = UnmodifiableEmptyCollections.EMPTY_LINKED_HASHMAP;
protected LinkedHashMap bindings = UnmodifiableEmptyCollections.EMPTY_LINKED_HASHMAP;
@@ -1577,8 +1582,83 @@
pointcut.clearAdvisors();
}
}
+
+ /**
+ * Retrieve an introduction pointcut of a certain name
+ */
+ public InterfaceIntroduction getArrayReplacement(String name)
+ {
+ synchronized (arrayReplacements)
+ {
+ return (InterfaceIntroduction) arrayReplacements.get(name);
+ }
+ }
/**
+ * Register an introduction pointcut
+ */
+ public synchronized void addArrayReplacement(ArrayReplacement pointcut)
+ {
+ removeArrayReplacement(pointcut.getName());
+ initArrayReplacementMap();
+ synchronized (arrayReplacements)
+ {
+ arrayReplacements.put(pointcut.getName(), pointcut);
+ }
+ }
+
+ /**
+ * remove an introduction pointcut of a certain name
+ */
+ public void removeArrayReplacement(String name)
+ {
+ synchronized (arrayReplacements)
+ {
+ ArrayReplacement pointcut = (ArrayReplacement) arrayReplacements.remove(name);
+ if (pointcut == null) return;
+ }
+ }
+
+ /**
+ * Retrieve an introduction pointcut of a certain name
+ */
+ public InterfaceIntroduction getArrayBinding(String name)
+ {
+ synchronized (arrayBindings)
+ {
+ return (InterfaceIntroduction) arrayBindings.get(name);
+ }
+ }
+
+ /**
+ * Register an introduction pointcut
+ */
+ public synchronized void addArrayBinding(ArrayBinding binding)
+ {
+ removeArrayBinding(binding.getName());
+ initArrayBindingMap();
+ synchronized (arrayBindings)
+ {
+ arrayBindings.put(binding.getName(), binding);
+ ArrayAdvisor.addBinding(binding);
+ }
+ }
+
+ /**
+ * remove an introduction pointcut of a certain name
+ */
+ public void removeArrayBinding(String name)
+ {
+ synchronized (arrayBindings)
+ {
+ ArrayBinding pointcut = (ArrayBinding) arrayBindings.remove(name);
+ if (pointcut == null) return;
+ ArrayAdvisor.removeBinding(pointcut);
+ }
+ }
+
+
+ /**
* Register an annotation introduction
*/
public synchronized void addAnnotationIntroduction(AnnotationIntroduction pointcut)
@@ -1853,6 +1933,11 @@
{
return interfaceIntroductions;
}
+
+ public Map getArrayReplacements()
+ {
+ return arrayReplacements;
+ }
public Map getTypedefs()
{
@@ -2178,6 +2263,45 @@
}
}
+ protected void initArrayReplacementMap()
+ {
+ if (arrayReplacements == UnmodifiableEmptyCollections.EMPTY_LINKED_HASHMAP)
+ {
+ lockWrite();
+ try
+ {
+ if (arrayReplacements == UnmodifiableEmptyCollections.EMPTY_LINKED_HASHMAP)
+ {
+ arrayReplacements = new LinkedHashMap();
+ }
+ }
+ finally
+ {
+ unlockWrite();
+ }
+ }
+ }
+
+ protected void initArrayBindingMap()
+ {
+ if (arrayBindings == UnmodifiableEmptyCollections.EMPTY_LINKED_HASHMAP)
+ {
+ lockWrite();
+ try
+ {
+ if (arrayBindings == UnmodifiableEmptyCollections.EMPTY_LINKED_HASHMAP)
+ {
+ arrayBindings = new LinkedHashMap();
+ }
+ }
+ finally
+ {
+ unlockWrite();
+ }
+ }
+ }
+
+
protected void initAnnotationIntroductionsMap()
{
if (annotationIntroductions == UnmodifiableEmptyCollections.EMPTY_LINKED_HASHMAP)
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/AspectXmlLoader.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/AspectXmlLoader.java 2007-10-12 07:26:54 UTC (rev 66075)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/AspectXmlLoader.java 2007-10-12 08:04:04 UTC (rev 66076)
@@ -49,6 +49,9 @@
import org.jboss.aop.advice.Scope;
import org.jboss.aop.advice.ScopeUtil;
import org.jboss.aop.advice.ScopedInterceptorFactory;
+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;
@@ -296,7 +299,38 @@
String pointcut = getName("pointcut");
manager.removePointcut(pointcut);
}
+
+ 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++)
+ {
+ if (!inters[i].getAspect().getScope().equals(Scope.PER_VM))
+ {
+ throw new RuntimeException("Only PER_VM scoped aspects/interceptors can be used in arraybindings");
+ }
+ }
+ ArrayBinding binding = new ArrayBinding(name, inters, theType);
+ manager.addArrayBinding(binding);
+ }
+ public void undeployArrayBinding(Element element) throws Exception
+ {
+ String binding = getName(element, "arraybinding");
+ if (binding == null) throw new RuntimeException("undeploying Arraybinding that is null!");
+ manager.removeArrayBinding(binding);//done in bulkUndeploy() step
+ }
+
private void deployPrecedence(Element element) throws Exception
{
String name = getName(element, "precedence");
@@ -692,7 +726,52 @@
}
manager.addPointcut(p);
}
+
+ public void undeployArrayReplacement(Element pointcut) throws Exception
+ {
+ String name = getName(pointcut, "arrayReplacement");
+ manager.removeArrayReplacement(name);
+ }
+
+ public void deployArrayReplacement(Element pointcut) throws Exception
+ {
+ String name = getName(pointcut, "arrayReplacement");
+ String classExpr = pointcut.getAttribute("class");
+ if (classExpr != null && classExpr.trim().equals(""))
+ {
+ classExpr = null;
+ }
+ String ast = pointcut.getAttribute("expr");
+ if (ast != null && ast.trim().equals(""))
+ {
+ ast = null;
+ }
+
+ if (classExpr == null && ast == null)
+ {
+ throw new RuntimeException("A class nor a expr attribute is defined for this <arrayreplacement>");
+ }
+
+ if (classExpr != null && ast != null)
+ {
+ throw new RuntimeException("You cannot define both a class and expr attribute in the same <arrayreplacement>");
+ }
+
+ ArrayReplacement pcut = null;
+ if (classExpr != null)
+ {
+ pcut = new ArrayReplacement(name, classExpr);
+ }
+ else
+ {
+ ASTStart start = new TypeExpressionParser(new StringReader(ast)).Start();
+ pcut = new ArrayReplacement(name, start);
+ }
+ manager.addArrayReplacement(pcut);
+ }
+
+
public void deployAnnotationIntroduction(Element pointcut) throws Exception
{
manager.addAnnotationIntroduction(loadAnnotationIntroduction(pointcut));
@@ -1099,6 +1178,14 @@
{
//Handled by AspctDeployer in JBoss
}
+ else if (tag.equals("arrayreplacement"))
+ {
+ deployArrayReplacement(element);
+ }
+ else if (tag.equals("arraybind"))
+ {
+ deployArrayBinding(element);
+ }
else
{
throw new IllegalArgumentException("Unknown AOP tag: " + tag);
@@ -1213,6 +1300,14 @@
{
undeployDeclare(element);
}
+ else if (tag.equals("arrayreplacement"))
+ {
+ undeployArrayReplacement(element);
+ }
+ else if (tag.equals("arraybind"))
+ {
+ undeployArrayBinding(element);
+ }
}
}
}
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/Domain.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/Domain.java 2007-10-12 07:26:54 UTC (rev 66075)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/Domain.java 2007-10-12 08:04:04 UTC (rev 66076)
@@ -288,7 +288,36 @@
return super.getAnnotationIntroductions();
}
+
+ public Map getArrayReplacements()
+ {
+ if (inheritsBindings)
+ {
+ HashMap map = new HashMap();
+ if (!parentFirst)
+ {
+ // when child first, parent bindings go in first so that they can be overridden by child.
+ map.putAll(parent.getArrayReplacements());
+ synchronized (arrayReplacements)
+ {
+ map.putAll(arrayReplacements);
+ }
+ return map;
+ }
+ else
+ {
+ synchronized (arrayReplacements)
+ {
+ map.putAll(arrayReplacements);
+ }
+ map.putAll(parent.getArrayReplacements());
+ return map;
+ }
+ }
+ return super.getArrayReplacements();
+ }
+
public boolean hasOwnAnnotationIntroductions()
{
return hasOwnAnnotationIntroductions;
Added: projects/aop/trunk/aop/src/main/org/jboss/aop/array/ArrayAdvisor.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/array/ArrayAdvisor.java (rev 0)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/array/ArrayAdvisor.java 2007-10-12 08:04:04 UTC (rev 66076)
@@ -0,0 +1,497 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.aop.array;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+import org.jboss.aop.AspectManager;
+import org.jboss.aop.advice.AdviceFactory;
+import org.jboss.aop.advice.GeneratedAdvisorInterceptor;
+import org.jboss.aop.advice.Interceptor;
+import org.jboss.aop.advice.InterceptorFactory;
+import org.jboss.aop.advice.PerVmAdvice;
+import org.jboss.aop.advice.PrecedenceSorter;
+import org.jboss.aop.advice.ScopedInterceptorFactory;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ArrayAdvisor
+{
+ static HashSet<ArrayBinding> bindings = new LinkedHashSet<ArrayBinding>();
+ static boolean updated;
+
+ public static void addBinding(ArrayBinding arrayBinding)
+ {
+ ChainCreator.addBinding(arrayBinding);
+ }
+
+ public static void removeBinding(ArrayBinding arrayBinding)
+ {
+ ChainCreator.removeBinding(arrayBinding);
+ }
+
+ public static Interceptor[] getReadInterceptors()
+ {
+ 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();
+ registry.removeFieldReference(target, fieldName, oldValue);
+ registry.addFieldReference(target, fieldName, newValue);
+ }
+
+ public static void arrayWriteObject(Object array, int index, Object value) throws Throwable
+ {
+ Interceptor[] interceptors = getWriteInterceptors();
+ ArrayRegistry registry = ArrayRegistry.getInstance();
+ if (registry.isRegistered(array))
+ {
+ //The old value might be an array, remove references to that
+ Object oldValue = ((Object[])array)[index];
+ boolean ignoreUpdate = (oldValue == value);
+ if (!ignoreUpdate)
+ {
+ registry.removeElementReference(array, index, oldValue);
+
+ //The new value might be an array
+ if (value != null && value.getClass().isArray())
+ {
+ registry.addElementReference(array, index, value);
+ }
+ if (interceptors != null)
+ {
+ ObjectArrayElementWriteInvocation invocation = new ObjectArrayElementWriteInvocation(interceptors, (Object[])array, index, value);
+ invocation.invokeNext();
+ return;
+ }
+ }
+ }
+ ((Object[])array)[index] = value;
+ }
+
+ public static void arrayWriteInt(Object array, int index, int value) throws Throwable
+ {
+ Interceptor[] interceptors = getWriteInterceptors();
+ if (interceptors != null && ArrayRegistry.getInstance().isRegistered(array) && ((int[])array)[index] != value)
+ {
+ IntArrayElementWriteInvocation invocation = new IntArrayElementWriteInvocation(interceptors, ((int[])array), index, value);
+ invocation.invokeNext();
+ }
+ else
+ {
+ ((int[])array)[index] = value;
+ }
+ }
+
+ public static void arrayWriteByteOrBoolean(Object array, int index, byte value) throws Throwable
+ {
+ Interceptor[] interceptors = getWriteInterceptors();
+ if (interceptors != null && ArrayRegistry.getInstance().isRegistered(array))
+ {
+ if (array instanceof boolean[])
+ {
+ if (((boolean[])array)[index] != ByteBooleanConverter.toBoolean(value))
+
+ {
+ BooleanArrayElementWriteInvocation invocation = new BooleanArrayElementWriteInvocation(interceptors, ((boolean[])array), index, ByteBooleanConverter.toBoolean(value));
+ invocation.invokeNext();
+ return;
+ }
+ ((boolean[])array)[index] = ByteBooleanConverter.toBoolean(value);
+ }
+ else
+ {
+ if (((byte[])array)[index] != value)
+ {
+ ByteArrayElementWriteInvocation invocation = new ByteArrayElementWriteInvocation(interceptors, ((byte[])array), index, value);
+ invocation.invokeNext();
+ return;
+ }
+ ((byte[])array)[index] = value;
+ }
+ }
+ }
+
+ public static void arrayWriteChar(Object array, int index, char value) throws Throwable
+ {
+ Interceptor[] interceptors = getWriteInterceptors();
+ if (interceptors != null && ArrayRegistry.getInstance().isRegistered(array) && ((char[])array)[index] != value)
+ {
+ CharArrayElementWriteInvocation invocation = new CharArrayElementWriteInvocation(interceptors, ((char[])array), index, value);
+ invocation.invokeNext();
+ }
+ else
+ {
+ ((char[])array)[index] = value;
+ }
+ }
+
+ public static void arrayWriteDouble(Object array, int index, double value) throws Throwable
+ {
+ Interceptor[] interceptors = getWriteInterceptors();
+ if (interceptors != null && ArrayRegistry.getInstance().isRegistered(array) && ((double[])array)[index] != value)
+ {
+ DoubleArrayElementWriteInvocation invocation = new DoubleArrayElementWriteInvocation(interceptors, ((double[])array), index, value);
+ invocation.invokeNext();
+ }
+ else
+ {
+ ((double[])array)[index] = value;
+ }
+ }
+
+ public static void arrayWriteShort(Object array, int index, short value) throws Throwable
+ {
+ Interceptor[] interceptors = getWriteInterceptors();
+ if (interceptors != null && ArrayRegistry.getInstance().isRegistered(array) && ((short[])array)[index] != value)
+ {
+ ShortArrayElementWriteInvocation invocation = new ShortArrayElementWriteInvocation(interceptors, ((short[])array), index, value);
+ invocation.invokeNext();
+ }
+ else
+ {
+ ((short[])array)[index] = value;
+ }
+ }
+
+ public static void arrayWriteFloat(Object array, int index, float value) throws Throwable
+ {
+ Interceptor[] interceptors = getWriteInterceptors();
+ if (interceptors != null && ArrayRegistry.getInstance().isRegistered(array) && ((float[])array)[index] != value)
+ {
+ FloatArrayElementWriteInvocation invocation = new FloatArrayElementWriteInvocation(interceptors, ((float[])array), index, value);
+ invocation.invokeNext();
+ }
+ else
+ {
+ ((float[])array)[index] = value;
+ }
+ }
+
+ public static void arrayWriteLong(Object array, int index, long value) throws Throwable
+ {
+ Interceptor[] interceptors = getWriteInterceptors();
+ if (interceptors != null && ArrayRegistry.getInstance().isRegistered(array) && ((long[])array)[index] != value)
+ {
+ LongArrayElementWriteInvocation invocation = new LongArrayElementWriteInvocation(interceptors, ((long[])array), index, value);
+ invocation.invokeNext();
+ }
+ else
+ {
+ ((long[])array)[index] = value;
+ }
+ }
+
+ public static Object arrayReadObject(Object array, int index) throws Throwable
+ {
+ Interceptor[] interceptors = getReadInterceptors();
+ if (interceptors != null && ArrayRegistry.getInstance().isRegistered(array))
+ {
+ ObjectArrayElementReadInvocation invocation = new ObjectArrayElementReadInvocation(interceptors, (Object[])array, index);
+ return invocation.invokeNext();
+ }
+ else
+ {
+ return ((Object[])array)[index];
+ }
+ }
+
+ public static int arrayReadInt(Object array, int index) throws Throwable
+ {
+ Interceptor[] interceptors = getReadInterceptors();
+ if (interceptors != null && ArrayRegistry.getInstance().isRegistered(array))
+ {
+ IntArrayElementReadInvocation invocation = new IntArrayElementReadInvocation(interceptors, (int[])array, index);
+ return ((Integer)invocation.invokeNext()).intValue();
+ }
+ else
+ {
+ return ((int[])array)[index];
+ }
+ }
+
+ public static byte arrayReadByteOrBoolean(Object array, int index) throws Throwable
+ {
+ Interceptor[] interceptors = getReadInterceptors();
+ if (interceptors != null && ArrayRegistry.getInstance().isRegistered(array))
+ {
+ if (array instanceof boolean[])
+ {
+ BooleanArrayElementReadInvocation invocation = new BooleanArrayElementReadInvocation(interceptors, (boolean[])array, index);
+ boolean b = ((Boolean)invocation.invokeNext()).booleanValue();
+ return ByteBooleanConverter.toByte(b);
+ }
+ else
+ {
+ ByteArrayElementReadInvocation invocation = new ByteArrayElementReadInvocation(interceptors, (byte[])array, index);
+ return ((Byte)invocation.invokeNext()).byteValue();
+ }
+ }
+ else
+ {
+ if (array instanceof boolean[])
+ {
+ return ByteBooleanConverter.toByte(((boolean[])array)[index]);
+ }
+ else
+ {
+ return ((byte[])array)[index];
+ }
+ }
+ }
+
+ public static char arrayReadChar(Object array, int index) throws Throwable
+ {
+ Interceptor[] interceptors = getReadInterceptors();
+ if (interceptors != null && ArrayRegistry.getInstance().isRegistered(array))
+ {
+ CharArrayElementReadInvocation invocation = new CharArrayElementReadInvocation(interceptors, (char[])array, index);
+ return ((Character)invocation.invokeNext()).charValue();
+ }
+ else
+ {
+ return ((char[])array)[index];
+ }
+ }
+
+ public static double arrayReadDouble(Object array, int index) throws Throwable
+ {
+ Interceptor[] interceptors = getReadInterceptors();
+ if (interceptors != null && ArrayRegistry.getInstance().isRegistered(array))
+ {
+ DoubleArrayElementReadInvocation invocation = new DoubleArrayElementReadInvocation(interceptors, (double[])array, index);
+ return ((Double)invocation.invokeNext()).doubleValue();
+ }
+ else
+ {
+ return ((double[])array)[index];
+ }
+ }
+
+ public static float arrayReadFloat(Object array, int index) throws Throwable
+ {
+ Interceptor[] interceptors = getReadInterceptors();
+ if (interceptors != null && ArrayRegistry.getInstance().isRegistered(array))
+ {
+ FloatArrayElementReadInvocation invocation = new FloatArrayElementReadInvocation(interceptors, (float[])array, index);
+ return ((Float)invocation.invokeNext()).floatValue();
+ }
+ else
+ {
+ return ((float[])array)[index];
+ }
+ }
+
+ public static long arrayReadLong(Object array, int index) throws Throwable
+ {
+ Interceptor[] interceptors = getReadInterceptors();
+ if (interceptors != null && ArrayRegistry.getInstance().isRegistered(array))
+ {
+ LongArrayElementReadInvocation invocation = new LongArrayElementReadInvocation(interceptors, (long[])array, index);
+ return ((Long)invocation.invokeNext()).longValue();
+ }
+ else
+ {
+ return ((long[])array)[index];
+ }
+ }
+
+ public static short arrayReadShort(Object array, int index) throws Throwable
+ {
+ Interceptor[] interceptors = getReadInterceptors();
+ if (interceptors != null && ArrayRegistry.getInstance().isRegistered(array))
+ {
+ ShortArrayElementReadInvocation invocation = new ShortArrayElementReadInvocation(interceptors, (short[])array, index);
+ return ((Short)invocation.invokeNext()).shortValue();
+ }
+ else
+ {
+ return ((short[])array)[index];
+ }
+ }
+
+ private static class ChainCreator
+ {
+ private static ReadWriteLock lock = new ReentrantReadWriteLock();
+ static Interceptor[] readInterceptors;
+ static Interceptor[] writeInterceptors;
+ public static void addBinding(ArrayBinding arrayBinding)
+ {
+ Lock writeLock = lock.writeLock();
+ writeLock.lock();
+ try
+ {
+ bindings.add(arrayBinding);
+ updated = true;
+ }
+ finally
+ {
+ writeLock.unlock();
+ }
+ }
+
+ public static void removeBinding(ArrayBinding arrayBinding)
+ {
+ Lock writeLock = lock.writeLock();
+ writeLock.lock();
+ try
+ {
+ bindings.remove(arrayBinding);
+ updated = true;
+ }
+ finally
+ {
+ writeLock.unlock();
+ }
+ }
+
+ public static Interceptor[] getReadInterceptors()
+ {
+ return getInterceptors(true);
+ }
+
+ public static Interceptor[] getWriteInterceptors()
+ {
+ return getInterceptors(false);
+ }
+
+ private static Interceptor[] getInterceptors(boolean read)
+ {
+ Lock readLock = lock.readLock();
+ readLock.lock();
+ boolean lockedRead = true;
+ try
+ {
+ if (updated)
+ {
+ readLock.unlock();
+ lockedRead = false;
+ Lock writeLock = lock.writeLock();
+ writeLock.lock();
+ try
+ {
+ if (updated)
+ {
+ //Create the interceptor chains
+ ArrayList<Interceptor> newReadInterceptors = new ArrayList<Interceptor>();
+ ArrayList<Interceptor> newWriteInterceptors = new ArrayList<Interceptor>();
+ for (ArrayBinding binding : bindings)
+ {
+ InterceptorFactory[] factories = binding.getInterceptorFactories();
+ for (int i = 0; i < factories.length; i++)
+ {
+ Interceptor icptr = createInterceptor(factories[i]);
+ if (icptr != null)
+ {
+ if (binding.isWrite())
+ {
+ newWriteInterceptors.add(icptr);
+ }
+ if (binding.isRead())
+ {
+ newReadInterceptors.add(icptr);
+ }
+ }
+ }
+ }
+ readInterceptors = finalizeChain(newReadInterceptors);
+ writeInterceptors = finalizeChain(newWriteInterceptors);
+ updated = false;
+ return (read) ? readInterceptors : writeInterceptors;
+ }
+ }
+ finally
+ {
+ writeLock.unlock();
+ }
+ }
+ return (read) ? readInterceptors : writeInterceptors;
+ }
+ finally
+ {
+ if (lockedRead)
+ {
+ readLock.unlock();
+ }
+ }
+ }
+
+ 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)
+ {
+ //TODO: must be fixed!
+// if (factory instanceof GeneratedOnly)
+// {
+// throw new RuntimeException("Before/After/Throwing is only supported for Generated Advisors");
+// }
+
+ try
+ {
+ if (factory.isDeployed())
+ {
+ if (factory instanceof AdviceFactory)
+ {
+ return PerVmAdvice.generateOptimized(null, AspectManager.instance(), factory.getAdvice(), factory.getAspect());
+ }
+ else if (factory instanceof ScopedInterceptorFactory)
+ {
+ return (Interceptor) AspectManager.instance().getPerVMAspect(factory.getAspect());
+ }
+ }
+
+ return null;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+}
Added: projects/aop/trunk/aop/src/main/org/jboss/aop/array/ArrayBinding.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/array/ArrayBinding.java (rev 0)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/array/ArrayBinding.java 2007-10-12 08:04:04 UTC (rev 66076)
@@ -0,0 +1,91 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.aop.array;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.jboss.aop.advice.InterceptorFactory;
+import org.jboss.aop.pointcut.Pointcut;
+import org.jboss.aop.pointcut.ast.ParseException;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ArrayBinding
+{
+ protected String name;
+ protected Type type;
+
+ protected InterceptorFactory[] interceptorFactories = new InterceptorFactory[0];
+
+ public ArrayBinding(String name, InterceptorFactory[] factories, Type type) throws ParseException
+ {
+ this.name = name;
+ interceptorFactories = factories;
+ this.type = type;
+ }
+
+ public void addInterceptorFactory(InterceptorFactory factory)
+ {
+ List list = Arrays.asList(interceptorFactories);
+ list = new ArrayList(list);
+ list.add(factory);
+ interceptorFactories = (InterceptorFactory[]) list.toArray(new InterceptorFactory[list.size()]);
+ }
+
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public InterceptorFactory[] getInterceptorFactories()
+ {
+ return interceptorFactories;
+ }
+
+ public boolean equals(Object obj)
+ {
+ if (obj == this) return true;
+ if (!(obj instanceof ArrayBinding)) return false;
+ return ((ArrayBinding) obj).getName().equals(name);
+ }
+
+ public int hashCode()
+ {
+ return name.hashCode();
+ }
+
+ 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/trunk/aop/src/main/org/jboss/aop/array/ArrayElementInvocation.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/array/ArrayElementInvocation.java (rev 0)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/array/ArrayElementInvocation.java 2007-10-12 08:04:04 UTC (rev 66076)
@@ -0,0 +1,168 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.aop.array;
+
+import java.util.List;
+import java.util.Map;
+
+import org.jboss.aop.Advisor;
+import org.jboss.aop.advice.Interceptor;
+import org.jboss.aop.joinpoint.Invocation;
+import org.jboss.aop.joinpoint.InvocationBase;
+import org.jboss.aop.metadata.MetaDataResolver;
+import org.jboss.util.NotImplementedException;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class ArrayElementInvocation extends InvocationBase
+{
+ int index;
+
+ public ArrayElementInvocation(Interceptor[] interceptors, Object array, int index)
+ {
+ // FIXME ArrayElementInvocation constructor
+ super(interceptors);
+ super.setTargetObject(array);
+ this.index = index;
+ }
+
+ public int getIndex()
+ {
+ return index;
+ }
+ /**
+ * Invoke on the next interceptor in the chain. If this is already
+ * the end of the chain, reflection will call the constructor, field, or
+ * method you are invoking on.
+ */
+ public Object invokeNext() throws Throwable
+ {
+ if (interceptors != null && currentInterceptor < interceptors.length)
+ {
+ try
+ {
+ return interceptors[currentInterceptor++].invoke(this);
+ }
+ finally
+ {
+ // so that interceptors like clustering can reinvoke down the chain
+ currentInterceptor--;
+ }
+ }
+
+ return invokeTarget();
+ }
+
+ public abstract Object invokeTarget();
+
+
+ @Override
+ public void addResponseAttachment(Object key, Object val)
+ {
+ throw new NotImplementedException();
+ }
+
+ @Override
+ public Advisor getAdvisor()
+ {
+ throw new NotImplementedException();
+ }
+
+ @Override
+ public int getCurrentInterceptor()
+ {
+ throw new NotImplementedException();
+ }
+
+ @Override
+ public Object getResponseAttachment(Object key)
+ {
+ throw new NotImplementedException();
+ }
+
+ @Override
+ public Map getResponseContextInfo()
+ {
+ throw new NotImplementedException();
+ }
+
+ @Override
+ public Object resolveAnnotation(Class annotation)
+ {
+ throw new NotImplementedException();
+ }
+
+ @Override
+ public Object resolveAnnotation(Class[] annotations)
+ {
+ throw new NotImplementedException();
+ }
+
+ @Override
+ public Object resolveClassAnnotation(Class annotation)
+ {
+ throw new NotImplementedException();
+ }
+
+ @Override
+ public Object resolveClassMetaData(Object key, Object attr)
+ {
+ throw new NotImplementedException();
+ }
+
+ @Override
+ public void setAdvisor(Advisor advisor)
+ {
+ throw new NotImplementedException();
+ }
+
+ @Override
+ public void setInstanceResolver(MetaDataResolver instanceResolver)
+ {
+ throw new NotImplementedException();
+ }
+
+ @Override
+ public void setResponseContextInfo(Map responseContextInfo)
+ {
+ throw new NotImplementedException();
+ }
+
+ public Invocation copy()
+ {
+ throw new NotImplementedException();
+ }
+
+ public Invocation getWrapper(Interceptor[] newchain)
+ {
+ throw new NotImplementedException();
+ }
+
+ public List<ArrayReference> getArrayOwners()
+ {
+ ArrayRegistry registry = ArrayRegistry.getInstance();
+ return registry.getArrayOwners(targetObject);
+ }
+}
Added: projects/aop/trunk/aop/src/main/org/jboss/aop/array/ArrayElementReadInvocation.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/array/ArrayElementReadInvocation.java (rev 0)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/array/ArrayElementReadInvocation.java 2007-10-12 08:04:04 UTC (rev 66076)
@@ -0,0 +1,38 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.aop.array;
+
+import org.jboss.aop.advice.Interceptor;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class ArrayElementReadInvocation extends ArrayElementInvocation
+{
+ public ArrayElementReadInvocation(Interceptor[] interceptors, Object array, int index)
+ {
+ // FIXME ArrayElementReadInvocation constructor
+ super(interceptors, array, index);
+ }
+}
Added: projects/aop/trunk/aop/src/main/org/jboss/aop/array/ArrayElementWriteInvocation.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/array/ArrayElementWriteInvocation.java (rev 0)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/array/ArrayElementWriteInvocation.java 2007-10-12 08:04:04 UTC (rev 66076)
@@ -0,0 +1,39 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.aop.array;
+
+import org.jboss.aop.advice.Interceptor;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class ArrayElementWriteInvocation extends ArrayElementInvocation
+{
+ public ArrayElementWriteInvocation(Interceptor[] interceptors, Object array, int index)
+ {
+ super(interceptors, array, index);
+ }
+
+ public abstract Object getValue();
+}
Added: projects/aop/trunk/aop/src/main/org/jboss/aop/array/ArrayReference.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/array/ArrayReference.java (rev 0)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/array/ArrayReference.java 2007-10-12 08:04:04 UTC (rev 66076)
@@ -0,0 +1,72 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.aop.array;
+
+import java.util.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();
+}
Added: projects/aop/trunk/aop/src/main/org/jboss/aop/array/ArrayReferenceImpl.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/array/ArrayReferenceImpl.java (rev 0)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/array/ArrayReferenceImpl.java 2007-10-12 08:04:04 UTC (rev 66076)
@@ -0,0 +1,83 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.aop.array;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ArrayReferenceImpl implements ArrayReference
+{
+ Object root;
+ String rootField;
+ ArrayList<Integer> nestedArrayIndices;
+
+ public ArrayReferenceImpl(Object root, String rootField)
+ {
+ this.root = root;
+ this.rootField = rootField;
+ }
+
+ public Object getRootObject()
+ {
+ return root;
+ }
+
+ public String getRootField()
+ {
+ return rootField;
+ }
+
+ public void addNestedArrayIndex(Integer index)
+ {
+ if (nestedArrayIndices == null)
+ {
+ nestedArrayIndices = new ArrayList<Integer>();
+ }
+ nestedArrayIndices.add(index);
+ }
+
+ public List<Integer> getNestedArrayIndices()
+ {
+ return nestedArrayIndices;
+ }
+
+ public String toString()
+ {
+ StringBuffer sb = new StringBuffer();
+ sb.append(root + "." + rootField);
+
+ if (nestedArrayIndices != null && nestedArrayIndices.size() > 0)
+ {
+ for (Integer index : nestedArrayIndices)
+ {
+ sb.append("[" + index + "]");
+ }
+ }
+
+ return sb.toString();
+ }
+}
Added: projects/aop/trunk/aop/src/main/org/jboss/aop/array/ArrayRegistry.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/array/ArrayRegistry.java (rev 0)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/array/ArrayRegistry.java 2007-10-12 08:04:04 UTC (rev 66076)
@@ -0,0 +1,386 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.aop.array;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.WeakHashMap;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ArrayRegistry
+{
+ private final static ArrayRegistryEntryFactory ELEMENT_ARRAY_REGISTRY_ENTRY_FACTORY = new ElementArrayRegistryEntryFactory();
+ private final static ArrayRegistryEntryFactory FIELD_ARRAY_REGISTRY_ENTRY_FACTORY = new FieldArrayRegistryEntryFactory();
+ private ArrayReferenceBuilder referenceBuilder = new ArrayReferenceBuilder();
+ private static ArrayRegistry singleton = new ArrayRegistry();
+ private ReadWriteLock lock = new ReentrantReadWriteLock();
+ private WeakHashMap<Object, WeakHashMap<Object, HashMap<Object, ArrayRegistryEntry>>> cache = new WeakHashMap<Object, WeakHashMap<Object, HashMap<Object, ArrayRegistryEntry>>>();
+
+ public static ArrayRegistry getInstance()
+ {
+ return singleton;
+ }
+
+ private ArrayRegistry()
+ {
+
+ }
+
+ public void addFieldReference(Object owner, String fieldName, Object array)
+ {
+ if (array == null)
+ {
+ return;
+ }
+ addReference(owner, fieldName, array, FIELD_ARRAY_REGISTRY_ENTRY_FACTORY);
+ }
+
+ public void addElementReference(Object owner, int index, Object array)
+ {
+ if (array == null)
+ {
+ return;
+ }
+ addReference(owner, new Integer(index), array, ELEMENT_ARRAY_REGISTRY_ENTRY_FACTORY);
+ }
+
+ public void addReference(Object owner, Object qualifier, Object array, ArrayRegistryEntryFactory factory)
+ {
+ if (array == null)
+ {
+ return;
+ }
+ Lock writeLock = lock.writeLock();
+ writeLock.lock();
+ try
+ {
+ WeakHashMap<Object, HashMap<Object, ArrayRegistryEntry>> arrayReferences = cache.get(array);
+ if (arrayReferences == null)
+ {
+ arrayReferences = new WeakHashMap<Object, HashMap<Object, ArrayRegistryEntry>>();
+ cache.put(array, arrayReferences);
+ }
+
+ HashMap<Object, ArrayRegistryEntry> ownerReferences = arrayReferences.get(owner);
+ if (ownerReferences == null)
+ {
+ ownerReferences = new HashMap<Object, ArrayRegistryEntry>();
+ arrayReferences.put(owner, ownerReferences);
+ }
+
+ ArrayRegistryEntry regEntry = ownerReferences.get(qualifier);
+ if (regEntry == null || regEntry.getArray() != array)
+ {
+ ArrayRegistryEntry entry = factory.createArrayRegistryEntry(owner, qualifier, factory);
+ ownerReferences.put(qualifier, entry);
+ }
+ addNestedArrays(array);
+ }
+ finally
+ {
+ writeLock.unlock();
+ }
+ }
+
+ public void removeFieldReference(Object owner, String fieldName, Object array)
+ {
+ if (array == null)
+ {
+ return;
+ }
+
+ removeReference(owner, fieldName, array);
+ }
+
+ public void removeElementReference(Object owner, int index, Object array)
+ {
+ if (array == null)
+ {
+ return;
+ }
+
+ removeReference(owner, new Integer(index), array);
+ }
+
+ public void removeReference(Object owner, Object qualifier, Object array)
+ {
+ if (array == null)
+ {
+ return;
+ }
+
+ Lock writeLock = lock.writeLock();
+ writeLock.lock();
+ try
+ {
+ WeakHashMap<Object, HashMap<Object,ArrayRegistryEntry>> arrayReferences = cache.get(array);
+ if (arrayReferences != null)
+ {
+ HashMap<Object,ArrayRegistryEntry> ownerReferences = arrayReferences.get(owner);
+ if (ownerReferences != null)
+ {
+ ArrayRegistryEntry regEntry = ownerReferences.remove(qualifier);
+ if (regEntry != null)
+ {
+ if (ownerReferences.size() == 0)
+ {
+ arrayReferences.remove(owner);
+
+ if (arrayReferences.size() == 0)
+ {
+ cache.remove(array);
+ }
+ }
+ ///Should this be here or below?
+ removeNestedArrays(array);
+ }
+
+ }
+ }
+// removeNestedArrays(owner, array);
+ }
+ finally
+ {
+ writeLock.unlock();
+ }
+ }
+
+ public boolean isRegistered(Object array)
+ {
+ Lock readLock = lock.readLock();
+ readLock.lock();
+
+ try
+ {
+ WeakHashMap<Object, HashMap<Object, ArrayRegistryEntry>> arrayReferences = cache.get(array);
+ if (arrayReferences == null)
+ {
+ return false;
+ }
+ return true;
+ }
+ finally
+ {
+ readLock.unlock();
+ }
+ }
+
+ public List<ArrayReference> getArrayOwners(Object array)
+ {
+ Lock readLock = lock.readLock();
+ readLock.lock();
+
+ try
+ {
+ return referenceBuilder.getArrayReferences(array);
+ }
+ finally
+ {
+ readLock.unlock();
+ }
+ }
+
+ private void addNestedArrays(Object array)
+ {
+ if (array == null)
+ {
+ return;
+ }
+ ArrayType type = isArray(array);
+ if (type == ArrayType.MULTIDIM_ARRAY)
+ {
+ for (int i = 0 ; i < ((Object[])array).length ; i++)
+ {
+ addElementReference(array, i, ((Object[])array)[i]);
+ addNestedArrays(((Object[])array)[i]);
+ }
+ }
+ else if (type == ArrayType.OBJECT_ARRAY)
+ {
+ for (int i = 0 ; i < ((Object[])array).length ; i++)
+ {
+ Object val = ((Object[])array)[i];
+ if (val != null && val.getClass().isArray())
+ {
+ addElementReference(array, i, ((Object[])array)[i]);
+ addNestedArrays(((Object[])array)[i]);
+ }
+ }
+ }
+ }
+
+ private void removeNestedArrays(Object array)
+ {
+ if (array == null)
+ {
+ return;
+ }
+ ArrayType type = isArray(array);
+ if (type == ArrayType.MULTIDIM_ARRAY)
+ {
+ for (int i = 0 ; i < ((Object[])array).length ; i++)
+ {
+ removeElementReference(array, i, ((Object[])array)[i]);
+ removeNestedArrays(((Object[])array)[i]);
+ }
+ }
+ else if (type == ArrayType.OBJECT_ARRAY)
+ {
+ for (int i = 0 ; i < ((Object[])array).length ; i++)
+ {
+ Object val = ((Object[])array)[i];
+ if (val != null && val.getClass().isArray())
+ {
+ removeElementReference(array, i, ((Object[])array)[i]);
+ removeNestedArrays(((Object[])array)[i]);
+ }
+ }
+ }
+ }
+
+ private ArrayType isArray(Object arrayCandidate)
+ {
+ Class candidateClass = arrayCandidate.getClass();
+ if (candidateClass.isArray())
+ {
+ Class componentType = candidateClass.getComponentType();
+ if (componentType.isArray())
+ {
+ return ArrayType.MULTIDIM_ARRAY;
+ }
+ if (componentType == Object.class)
+ {
+ return ArrayType.OBJECT_ARRAY;
+ }
+ }
+ return ArrayType.NOT_ARRAY;
+ }
+
+ private interface ArrayRegistryEntryFactory
+ {
+ ArrayRegistryEntry createArrayRegistryEntry(Object owner, Object qualifier, Object array);
+ }
+
+ private static class FieldArrayRegistryEntryFactory implements ArrayRegistryEntryFactory
+ {
+ public ArrayRegistryEntry createArrayRegistryEntry(Object owner, Object qualifier, Object array)
+ {
+ return new FieldArrayRegistryEntry(owner, (String)qualifier, array);
+ }
+ }
+
+ private static class ElementArrayRegistryEntryFactory implements ArrayRegistryEntryFactory
+ {
+ public ArrayRegistryEntry createArrayRegistryEntry(Object owner, Object qualifier, Object array)
+ {
+ return new ElementArrayRegistryEntry(owner, (Integer)qualifier, array);
+ }
+ }
+
+ private class ArrayReferenceBuilder
+ {
+ private List<ArrayReference> getArrayReferences(Object array)
+ {
+ List<ArrayReference> references = null;
+ WeakHashMap<Object, HashMap<Object, ArrayRegistryEntry>> arrayReferences = cache.get(array);
+ if (arrayReferences != null && arrayReferences.size() > 0)
+ {
+ for (Object owner : arrayReferences.keySet())
+ {
+ HashMap<Object, ArrayRegistryEntry> ownerReferences = arrayReferences.get(owner);
+ for (Object qualifier : ownerReferences.keySet())
+ {
+ ArrayRegistryEntry regEntry = ownerReferences.get(qualifier);
+
+ if (regEntry.isOwnerRoot())
+ {
+ ArrayReference reference = getRootReference((FieldArrayRegistryEntry)regEntry);
+ if (reference != null)
+ {
+ if (references == null)
+ {
+ references = new ArrayList<ArrayReference>();
+ }
+ references.add(reference);
+ }
+ }
+ else
+ {
+ List<ArrayReference> parentReferences = getElementReferences((ElementArrayRegistryEntry)regEntry);
+ if (parentReferences != null)
+ {
+ if (references == null)
+ {
+ references = new ArrayList<ArrayReference>();
+ }
+ references.addAll(parentReferences);
+ }
+ }
+ }
+ }
+ }
+ return references;
+ }
+
+ private ArrayReference getRootReference(FieldArrayRegistryEntry regEntry)
+ {
+ Object root = regEntry.getOwner();
+ if (root != null)
+ {
+ String fieldName = regEntry.getFieldName();
+ return new ArrayReferenceImpl(root, fieldName);
+ }
+ return null;
+ }
+
+ private List<ArrayReference> getElementReferences(ElementArrayRegistryEntry regEntry)
+ {
+ Object ownerArray = regEntry.getOwner();
+ if (ownerArray != null)
+ {
+ List<ArrayReference> references = getArrayReferences(ownerArray);
+ if (references != null && references.size() > 0)
+ {
+ for (ArrayReference reference : references)
+ {
+ ((ArrayReferenceImpl)reference).addNestedArrayIndex(regEntry.getIndex());
+ }
+ }
+ return references;
+ }
+ return null;
+ }
+ }
+
+ private enum ArrayType
+ {
+ NOT_ARRAY,MULTIDIM_ARRAY,OBJECT_ARRAY;
+ }
+}
Added: projects/aop/trunk/aop/src/main/org/jboss/aop/array/ArrayRegistryEntry.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/array/ArrayRegistryEntry.java (rev 0)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/array/ArrayRegistryEntry.java 2007-10-12 08:04:04 UTC (rev 66076)
@@ -0,0 +1,77 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.aop.array;
+
+import java.lang.ref.WeakReference;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class ArrayRegistryEntry
+{
+ /** WeakReference to the object or array containing the reference */
+ WeakReference owner;
+
+ /** WeakReference to the referenced array */
+ WeakReference array;
+
+ /** True if the object referencing the array is a "normal" object, false if it ia an array */
+ boolean ownerIsRoot;
+
+ ArrayRegistryEntry(Object owner, boolean ownerIsRoot, Object array)
+ {
+ this.owner = new WeakReference(owner);
+ this.array = new WeakReference(array);
+ this.ownerIsRoot = ownerIsRoot;
+ if (ownerIsRoot && owner.getClass().isArray()) {
+ throw new RuntimeException("Owner is root and an array was passed in");
+ }
+ if (!ownerIsRoot && !owner.getClass().isArray()) {
+ throw new RuntimeException("Owner is not root and no array was passed in");
+ }
+ }
+
+ public Object getArray()
+ {
+ if (array != null)
+ {
+ return array.get();
+ }
+ return null;
+ }
+
+ public Object getOwner()
+ {
+ if (owner != null)
+ {
+ return owner.get();
+ }
+ return null;
+ }
+
+ public boolean isOwnerRoot()
+ {
+ return ownerIsRoot;
+ }
+}
Added: projects/aop/trunk/aop/src/main/org/jboss/aop/array/ArrayReplacement.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/array/ArrayReplacement.java (rev 0)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/array/ArrayReplacement.java 2007-10-12 08:04:04 UTC (rev 66076)
@@ -0,0 +1,104 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.aop.array;
+
+import javassist.CtClass;
+
+import org.jboss.aop.Advisor;
+import org.jboss.aop.pointcut.TypeMatcher;
+import org.jboss.aop.pointcut.Util;
+import org.jboss.aop.pointcut.ast.ASTStart;
+import org.jboss.aop.pointcut.ast.ClassExpression;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ArrayReplacement
+{
+ private String name;
+ protected ClassExpression classExpr;
+ protected ASTStart ast;
+
+ public ArrayReplacement(String name, String exp)
+ {
+ this.name = name;
+ this.classExpr = new ClassExpression(exp);
+ }
+
+ public ArrayReplacement(String name, ASTStart ast)
+ {
+ this.name = name;
+ this.ast = ast;
+ }
+
+ public boolean equals(Object obj)
+ {
+ if (obj == this) return true;
+ if (!(obj instanceof ArrayReplacement)) return false;
+ return ((ArrayReplacement) obj).getName().equals(name);
+ }
+
+ public int hashCode()
+ {
+ return name.hashCode();
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public String getClassExpr()
+ {
+ if (classExpr == null) return null;
+ return classExpr.getOriginal();
+ }
+
+ public ASTStart getAst()
+ {
+ return ast;
+ }
+
+ public boolean matches(Advisor advisor, CtClass clazz) throws Exception
+ {
+ if (classExpr != null)
+ return Util.matchesClassExpr(classExpr, clazz, advisor);
+ else
+ {
+ TypeMatcher matcher = new TypeMatcher(advisor, clazz);
+ return ((Boolean) ast.jjtAccept(matcher, null)).booleanValue();
+ }
+ }
+
+ public boolean matches(Advisor advisor, Class clazz)
+ {
+ if (classExpr != null)
+ return Util.matchesClassExpr(classExpr, clazz, advisor);
+ else
+ {
+ TypeMatcher matcher = new TypeMatcher(advisor, clazz);
+ return ((Boolean) ast.jjtAccept(matcher, null)).booleanValue();
+ }
+ }
+}
Added: projects/aop/trunk/aop/src/main/org/jboss/aop/array/BooleanArrayElementReadInvocation.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/array/BooleanArrayElementReadInvocation.java (rev 0)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/array/BooleanArrayElementReadInvocation.java 2007-10-12 08:04:04 UTC (rev 66076)
@@ -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.aop.array;
+
+import org.jboss.aop.advice.Interceptor;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class BooleanArrayElementReadInvocation extends ArrayElementReadInvocation
+{
+ private static final long serialVersionUID = 4894358007089083877L;
+ boolean[] array;
+
+ public BooleanArrayElementReadInvocation(Interceptor[] interceptors, boolean[] target, int index)
+ {
+ super(interceptors, target, index);
+ array = target;
+ }
+
+ public Object invokeTarget()
+ {
+ return new Boolean(array[index]);
+ }
+}
Added: projects/aop/trunk/aop/src/main/org/jboss/aop/array/BooleanArrayElementWriteInvocation.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/array/BooleanArrayElementWriteInvocation.java (rev 0)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/array/BooleanArrayElementWriteInvocation.java 2007-10-12 08:04:04 UTC (rev 66076)
@@ -0,0 +1,61 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.aop.array;
+
+import org.jboss.aop.advice.Interceptor;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class BooleanArrayElementWriteInvocation extends ArrayElementWriteInvocation
+{
+ private static final long serialVersionUID = -8806734067322751711L;
+ boolean[] array;
+ boolean value;
+
+ public BooleanArrayElementWriteInvocation(Interceptor[] interceptors, boolean[] target, int index, boolean value)
+ {
+ super(interceptors, target, index);
+ this.value = value;
+ this.array = target;
+ }
+
+ @Override
+ public Object invokeTarget()
+ {
+ array[index] = value;
+ return null;
+ }
+
+ @Override
+ public Object getValue()
+ {
+ return new Boolean(value);
+ }
+
+ public boolean getBooleanValue()
+ {
+ return value;
+ }
+}
Added: projects/aop/trunk/aop/src/main/org/jboss/aop/array/ByteArrayElementReadInvocation.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/array/ByteArrayElementReadInvocation.java (rev 0)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/array/ByteArrayElementReadInvocation.java 2007-10-12 08:04:04 UTC (rev 66076)
@@ -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.aop.array;
+
+import org.jboss.aop.advice.Interceptor;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ByteArrayElementReadInvocation extends ArrayElementReadInvocation
+{
+ private static final long serialVersionUID = 407921822383443705L;
+ byte[] array;
+
+ public ByteArrayElementReadInvocation(Interceptor[] interceptors, byte[] target, int index)
+ {
+ super(interceptors, target, index);
+ array = target;
+ }
+
+ public Object invokeTarget()
+ {
+ return new Byte(array[index]);
+ }
+}
Added: projects/aop/trunk/aop/src/main/org/jboss/aop/array/ByteArrayElementWriteInvocation.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/array/ByteArrayElementWriteInvocation.java (rev 0)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/array/ByteArrayElementWriteInvocation.java 2007-10-12 08:04:04 UTC (rev 66076)
@@ -0,0 +1,61 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.aop.array;
+
+import org.jboss.aop.advice.Interceptor;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ByteArrayElementWriteInvocation extends ArrayElementWriteInvocation
+{
+ private static final long serialVersionUID = -3311231820298166088L;
+ byte[] array;
+ byte value;
+
+ public ByteArrayElementWriteInvocation(Interceptor[] interceptors, byte[] target, int index, byte value)
+ {
+ super(interceptors, target, index);
+ this.value = value;
+ this.array = target;
+ }
+
+ @Override
+ public Object invokeTarget()
+ {
+ array[index] = value;
+ return null;
+ }
+
+ @Override
+ public Object getValue()
+ {
+ return new Byte(value);
+ }
+
+ public byte getByteValue()
+ {
+ return value;
+ }
+}
Added: projects/aop/trunk/aop/src/main/org/jboss/aop/array/ByteBooleanConverter.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/array/ByteBooleanConverter.java (rev 0)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/array/ByteBooleanConverter.java 2007-10-12 08:04:04 UTC (rev 66076)
@@ -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.aop.array;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ByteBooleanConverter
+{
+ private static final byte BOOLEAN_FALSE = 0;
+ private static final byte BOOLEAN_TRUE = 1;
+
+ public static byte toByte(boolean b)
+ {
+ return (b) ? BOOLEAN_TRUE : BOOLEAN_FALSE;
+ }
+
+ public static boolean toBoolean(byte b)
+ {
+ if (b == BOOLEAN_FALSE) return false;
+ else if (b == BOOLEAN_TRUE) return true;
+
+ throw new RuntimeException("Invalid byte " + b + " cannot be converted to a boolean");
+ }
+}
Added: projects/aop/trunk/aop/src/main/org/jboss/aop/array/CharArrayElementReadInvocation.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/array/CharArrayElementReadInvocation.java (rev 0)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/array/CharArrayElementReadInvocation.java 2007-10-12 08:04:04 UTC (rev 66076)
@@ -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.aop.array;
+
+import org.jboss.aop.advice.Interceptor;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class CharArrayElementReadInvocation extends ArrayElementReadInvocation
+{
+ private static final long serialVersionUID = -8421466785835226302L;
+ char[] array;
+
+ public CharArrayElementReadInvocation(Interceptor[] interceptors, char[] target, int index)
+ {
+ super(interceptors, target, index);
+ array = target;
+ }
+
+ public Object invokeTarget()
+ {
+ return new Character(array[index]);
+ }
+}
Added: projects/aop/trunk/aop/src/main/org/jboss/aop/array/CharArrayElementWriteInvocation.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/array/CharArrayElementWriteInvocation.java (rev 0)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/array/CharArrayElementWriteInvocation.java 2007-10-12 08:04:04 UTC (rev 66076)
@@ -0,0 +1,61 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.aop.array;
+
+import org.jboss.aop.advice.Interceptor;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class CharArrayElementWriteInvocation extends ArrayElementWriteInvocation
+{
+ private static final long serialVersionUID = -7731135396849504354L;
+ char[] array;
+ char value;
+
+ public CharArrayElementWriteInvocation(Interceptor[] interceptors, char[] target, int index, char value)
+ {
+ super(interceptors, target, index);
+ this.value = value;
+ this.array = target;
+ }
+
+ @Override
+ public Object invokeTarget()
+ {
+ array[index] = value;
+ return null;
+ }
+
+ @Override
+ public Object getValue()
+ {
+ return new Character(value);
+ }
+
+ public char getCharValue()
+ {
+ return value;
+ }
+}
Added: projects/aop/trunk/aop/src/main/org/jboss/aop/array/DoubleArrayElementReadInvocation.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/array/DoubleArrayElementReadInvocation.java (rev 0)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/array/DoubleArrayElementReadInvocation.java 2007-10-12 08:04:04 UTC (rev 66076)
@@ -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.aop.array;
+
+import org.jboss.aop.advice.Interceptor;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class DoubleArrayElementReadInvocation extends ArrayElementReadInvocation
+{
+ private static final long serialVersionUID = 4414714543578046462L;
+ double[] array;
+
+ public DoubleArrayElementReadInvocation(Interceptor[] interceptors, double[] target, int index)
+ {
+ super(interceptors, target, index);
+ array = target;
+ }
+
+ public Object invokeTarget()
+ {
+ return new Double(array[index]);
+ }
+}
Added: projects/aop/trunk/aop/src/main/org/jboss/aop/array/DoubleArrayElementWriteInvocation.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/array/DoubleArrayElementWriteInvocation.java (rev 0)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/array/DoubleArrayElementWriteInvocation.java 2007-10-12 08:04:04 UTC (rev 66076)
@@ -0,0 +1,61 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.aop.array;
+
+import org.jboss.aop.advice.Interceptor;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class DoubleArrayElementWriteInvocation extends ArrayElementWriteInvocation
+{
+ private static final long serialVersionUID = 4952638087031381514L;
+ double[] array;
+ double value;
+
+ public DoubleArrayElementWriteInvocation(Interceptor[] interceptors, double[] target, int index, double value)
+ {
+ super(interceptors, target, index);
+ this.value = value;
+ this.array = target;
+ }
+
+ @Override
+ public Object invokeTarget()
+ {
+ array[index] = value;
+ return null;
+ }
+
+ @Override
+ public Object getValue()
+ {
+ return new Double(value);
+ }
+
+ public double getDoubleValue()
+ {
+ return value;
+ }
+}
Added: projects/aop/trunk/aop/src/main/org/jboss/aop/array/ElementArrayRegistryEntry.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/array/ElementArrayRegistryEntry.java (rev 0)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/array/ElementArrayRegistryEntry.java 2007-10-12 08:04:04 UTC (rev 66076)
@@ -0,0 +1,45 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.aop.array;
+
+import java.util.HashSet;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ElementArrayRegistryEntry extends ArrayRegistryEntry
+{
+ Integer index;;
+
+ ElementArrayRegistryEntry(Object owner, Integer index, Object array)
+ {
+ super(owner, false, array);
+ this.index = index;
+ }
+
+ public Integer getIndex()
+ {
+ return index;
+ }
+}
Added: projects/aop/trunk/aop/src/main/org/jboss/aop/array/FieldArrayRegistryEntry.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/array/FieldArrayRegistryEntry.java (rev 0)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/array/FieldArrayRegistryEntry.java 2007-10-12 08:04:04 UTC (rev 66076)
@@ -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.aop.array;
+
+import java.util.HashSet;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class FieldArrayRegistryEntry extends ArrayRegistryEntry
+{
+ String fieldName;
+
+ FieldArrayRegistryEntry(Object owner, String fieldName, Object array)
+ {
+ // FIXME FieldArrayRegistryEntry constructor
+ super(owner, true, array);
+ this.fieldName = fieldName;
+ }
+
+ public String getFieldName()
+ {
+ return fieldName;
+ }
+}
\ No newline at end of file
Added: projects/aop/trunk/aop/src/main/org/jboss/aop/array/FloatArrayElementReadInvocation.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/array/FloatArrayElementReadInvocation.java (rev 0)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/array/FloatArrayElementReadInvocation.java 2007-10-12 08:04:04 UTC (rev 66076)
@@ -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.aop.array;
+
+import org.jboss.aop.advice.Interceptor;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class FloatArrayElementReadInvocation extends ArrayElementReadInvocation
+{
+ private static final long serialVersionUID = 1588317122571729022L;
+ float[] array;
+
+ public FloatArrayElementReadInvocation(Interceptor[] interceptors, float[] target, int index)
+ {
+ super(interceptors, target, index);
+ array = target;
+ }
+
+ public Object invokeTarget()
+ {
+ return new Float(array[index]);
+ }
+}
Added: projects/aop/trunk/aop/src/main/org/jboss/aop/array/FloatArrayElementWriteInvocation.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/array/FloatArrayElementWriteInvocation.java (rev 0)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/array/FloatArrayElementWriteInvocation.java 2007-10-12 08:04:04 UTC (rev 66076)
@@ -0,0 +1,61 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.aop.array;
+
+import org.jboss.aop.advice.Interceptor;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class FloatArrayElementWriteInvocation extends ArrayElementWriteInvocation
+{
+ private static final long serialVersionUID = 2124265298388536292L;
+ float[] array;
+ float value;
+
+ public FloatArrayElementWriteInvocation(Interceptor[] interceptors, float[] target, int index, float value)
+ {
+ super(interceptors, target, index);
+ this.value = value;
+ this.array = target;
+ }
+
+ @Override
+ public Object invokeTarget()
+ {
+ array[index] = value;
+ return null;
+ }
+
+ @Override
+ public Object getValue()
+ {
+ return new Float(value);
+ }
+
+ public float getFloatValue()
+ {
+ return value;
+ }
+}
Added: projects/aop/trunk/aop/src/main/org/jboss/aop/array/IntArrayElementReadInvocation.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/array/IntArrayElementReadInvocation.java (rev 0)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/array/IntArrayElementReadInvocation.java 2007-10-12 08:04:04 UTC (rev 66076)
@@ -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.aop.array;
+
+import org.jboss.aop.advice.Interceptor;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class IntArrayElementReadInvocation extends ArrayElementReadInvocation
+{
+ private static final long serialVersionUID = 407921822383443705L;
+ int[] array;
+
+ public IntArrayElementReadInvocation(Interceptor[] interceptors, int[] target, int index)
+ {
+ super(interceptors, target, index);
+ array = target;
+ }
+
+ public Object invokeTarget()
+ {
+ return new Integer(array[index]);
+ }
+}
Added: projects/aop/trunk/aop/src/main/org/jboss/aop/array/IntArrayElementWriteInvocation.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/array/IntArrayElementWriteInvocation.java (rev 0)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/array/IntArrayElementWriteInvocation.java 2007-10-12 08:04:04 UTC (rev 66076)
@@ -0,0 +1,61 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.aop.array;
+
+import org.jboss.aop.advice.Interceptor;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class IntArrayElementWriteInvocation extends ArrayElementWriteInvocation
+{
+ private static final long serialVersionUID = -3311231820298166088L;
+ int[] array;
+ int value;
+
+ public IntArrayElementWriteInvocation(Interceptor[] interceptors, int[] target, int index, int value)
+ {
+ super(interceptors, target, index);
+ this.value = value;
+ this.array = target;
+ }
+
+ @Override
+ public Object invokeTarget()
+ {
+ array[index] = value;
+ return null;
+ }
+
+ @Override
+ public Object getValue()
+ {
+ return new Integer(value);
+ }
+
+ public int getIntValue()
+ {
+ return value;
+ }
+}
Added: projects/aop/trunk/aop/src/main/org/jboss/aop/array/LongArrayElementReadInvocation.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/array/LongArrayElementReadInvocation.java (rev 0)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/array/LongArrayElementReadInvocation.java 2007-10-12 08:04:04 UTC (rev 66076)
@@ -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.aop.array;
+
+import org.jboss.aop.advice.Interceptor;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class LongArrayElementReadInvocation extends ArrayElementReadInvocation
+{
+ private static final long serialVersionUID = -6196706501416214971L;
+ long[] array;
+
+ public LongArrayElementReadInvocation(Interceptor[] interceptors, long[] target, int index)
+ {
+ super(interceptors, target, index);
+ array = target;
+ }
+
+ public Object invokeTarget()
+ {
+ return new Long(array[index]);
+ }
+}
Added: projects/aop/trunk/aop/src/main/org/jboss/aop/array/LongArrayElementWriteInvocation.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/array/LongArrayElementWriteInvocation.java (rev 0)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/array/LongArrayElementWriteInvocation.java 2007-10-12 08:04:04 UTC (rev 66076)
@@ -0,0 +1,61 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.aop.array;
+
+import org.jboss.aop.advice.Interceptor;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class LongArrayElementWriteInvocation extends ArrayElementWriteInvocation
+{
+ private static final long serialVersionUID = -609480261599580470L;
+ long[] array;
+ long value;
+
+ public LongArrayElementWriteInvocation(Interceptor[] interceptors, long[] target, int index, long value)
+ {
+ super(interceptors, target, index);
+ this.value = value;
+ this.array = target;
+ }
+
+ @Override
+ public Object invokeTarget()
+ {
+ array[index] = value;
+ return null;
+ }
+
+ @Override
+ public Object getValue()
+ {
+ return new Long(value);
+ }
+
+ public long getLongValue()
+ {
+ return value;
+ }
+}
Added: projects/aop/trunk/aop/src/main/org/jboss/aop/array/ObjectArrayElementReadInvocation.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/array/ObjectArrayElementReadInvocation.java (rev 0)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/array/ObjectArrayElementReadInvocation.java 2007-10-12 08:04:04 UTC (rev 66076)
@@ -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.aop.array;
+
+import org.jboss.aop.advice.Interceptor;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ObjectArrayElementReadInvocation extends ArrayElementReadInvocation
+{
+ private static final long serialVersionUID = 2579696791090966825L;
+ Object[] array;
+
+ public ObjectArrayElementReadInvocation(Interceptor[] interceptors, Object[] target, int index)
+ {
+ super(interceptors, target, index);
+ array = target;
+ }
+
+ public Object invokeTarget()
+ {
+ return array[index];
+ }
+}
Added: projects/aop/trunk/aop/src/main/org/jboss/aop/array/ObjectArrayElementWriteInvocation.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/array/ObjectArrayElementWriteInvocation.java (rev 0)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/array/ObjectArrayElementWriteInvocation.java 2007-10-12 08:04:04 UTC (rev 66076)
@@ -0,0 +1,56 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.aop.array;
+
+import org.jboss.aop.advice.Interceptor;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ObjectArrayElementWriteInvocation extends ArrayElementWriteInvocation
+{
+ private static final long serialVersionUID = 4256767659280908515L;
+ Object[] array;
+ Object value;
+
+ public ObjectArrayElementWriteInvocation(Interceptor[] interceptors, Object[] target, int index, Object value)
+ {
+ super(interceptors, target, index);
+ this.value = value;
+ this.array = target;
+ }
+
+ @Override
+ public Object invokeTarget()
+ {
+ array[index] = value;
+ return null;
+ }
+
+ @Override
+ public Object getValue()
+ {
+ return value;
+ }
+}
Added: projects/aop/trunk/aop/src/main/org/jboss/aop/array/ShortArrayElementReadInvocation.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/array/ShortArrayElementReadInvocation.java (rev 0)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/array/ShortArrayElementReadInvocation.java 2007-10-12 08:04:04 UTC (rev 66076)
@@ -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.aop.array;
+
+import org.jboss.aop.advice.Interceptor;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ShortArrayElementReadInvocation extends ArrayElementReadInvocation
+{
+ private static final long serialVersionUID = -6743791579057380824L;
+ short[] array;
+
+ public ShortArrayElementReadInvocation(Interceptor[] interceptors, short[] target, int index)
+ {
+ super(interceptors, target, index);
+ array = target;
+ }
+
+ public Object invokeTarget()
+ {
+ return new Short(array[index]);
+ }
+}
Added: projects/aop/trunk/aop/src/main/org/jboss/aop/array/ShortArrayElementWriteInvocation.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/array/ShortArrayElementWriteInvocation.java (rev 0)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/array/ShortArrayElementWriteInvocation.java 2007-10-12 08:04:04 UTC (rev 66076)
@@ -0,0 +1,61 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.aop.array;
+
+import org.jboss.aop.advice.Interceptor;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ShortArrayElementWriteInvocation extends ArrayElementWriteInvocation
+{
+ private static final long serialVersionUID = -8003520567342434348L;
+ short[] array;
+ short value;
+
+ public ShortArrayElementWriteInvocation(Interceptor[] interceptors, short[] target, int index, short value)
+ {
+ super(interceptors, target, index);
+ this.value = value;
+ this.array = target;
+ }
+
+ @Override
+ public Object invokeTarget()
+ {
+ array[index] = value;
+ return null;
+ }
+
+ @Override
+ public Object getValue()
+ {
+ return new Short(value);
+ }
+
+ public short getShortValue()
+ {
+ return value;
+ }
+}
Added: projects/aop/trunk/aop/src/main/org/jboss/aop/array/Type.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/array/Type.java (rev 0)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/array/Type.java 2007-10-12 08:04:04 UTC (rev 66076)
@@ -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
+}
Added: projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/ArrayAccessTransformer.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/ArrayAccessTransformer.java (rev 0)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/ArrayAccessTransformer.java 2007-10-12 08:04:04 UTC (rev 66076)
@@ -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.instrument;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ArrayAccessTransformer
+{
+
+}
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/FieldAccessTransformer.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/FieldAccessTransformer.java 2007-10-12 07:26:54 UTC (rev 66075)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/FieldAccessTransformer.java 2007-10-12 08:04:04 UTC (rev 66076)
@@ -77,7 +77,7 @@
// Public --------------------------------------------------------
- protected void buildFieldWrappers(CtClass clazz, ClassAdvisor advisor) throws NotFoundException, CannotCompileException
+ protected void buildFieldWrappers(CtClass clazz, ClassAdvisor advisor, boolean shouldReplaceArrayAccess) throws NotFoundException, CannotCompileException
{
List fields = Instrumentor.getAdvisableFields(clazz);
@@ -101,7 +101,7 @@
skipFieldInterception = false;
}
- doBuildFieldWrappers(clazz, field, fieldIndex, classificationGet, classificationSet);
+ doBuildFieldWrappers(clazz, field, fieldIndex, shouldReplaceArrayAccess, classificationGet, classificationSet);
}
}
@@ -182,7 +182,17 @@
return classification != JoinpointClassification.NOT_INSTRUMENTED;
}
- protected abstract void doBuildFieldWrappers(CtClass clazz, CtField field, int index, JoinpointClassification classificationGet, JoinpointClassification classificationSet) throws NotFoundException, CannotCompileException;
+ protected abstract void doBuildFieldWrappers(CtClass clazz, CtField field, int index, boolean shouldReplaceArrayAccess, JoinpointClassification classificationGet, JoinpointClassification classificationSet) throws NotFoundException, CannotCompileException;
+
+ protected String getArrayWriteRegistration(boolean shouldReplaceArrayAccess, String target, CtField field, String oldValue, String newValue) throws NotFoundException
+ {
+ if (shouldReplaceArrayAccess && (field.getType().isArray() || field.getType().getName().equals("java.lang.Object")))
+ {
+ return "org.jboss.aop.array.ArrayAdvisor.updateArrayField(" + target + ", \"" + field.getName() + "\", " + oldValue + ", " + newValue + ");";
+ }
+ return "";
+ }
+
/**
* replace field access for possible public/protected fields that are intercepted
* don't need to replace access for private fields.
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorFieldAccessTransformer.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorFieldAccessTransformer.java 2007-10-12 07:26:54 UTC (rev 66075)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorFieldAccessTransformer.java 2007-10-12 08:04:04 UTC (rev 66076)
@@ -47,7 +47,7 @@
super(instrumentor);
}
- protected void doBuildFieldWrappers(CtClass clazz, CtField field, int index, JoinpointClassification classificationGet, JoinpointClassification classificationSet) throws NotFoundException, CannotCompileException
+ protected void doBuildFieldWrappers(CtClass clazz, CtField field, int index, boolean shouldReplaceArrayAccess, JoinpointClassification classificationGet, JoinpointClassification classificationSet) throws NotFoundException, CannotCompileException
{
instrumentor.setupBasics(clazz);
boolean wrappedGet = classificationGet.equals(JoinpointClassification.WRAPPED);
@@ -106,7 +106,7 @@
// executeWrapping
replaceFieldAccessInternally(clazz, field, wrappedGet, wrappedSet, index);
- buildWrappers(clazz, field, wrappedGet, wrappedSet, index);
+ buildWrappers(clazz, field, shouldReplaceArrayAccess, wrappedGet, wrappedSet, index);
}
protected String addFieldReadInfoFieldToGeneratedAdvisor(CtField field, int index)throws NotFoundException, CannotCompileException
@@ -298,7 +298,7 @@
return code;
}
- private String getAdvisorWriteWrapperBody(CtClass clazz, CtField field, int index)
+ private String getAdvisorWriteWrapperBody(CtClass clazz, CtField field, int index, boolean shouldReplaceArrayAccess)
throws NotFoundException, CannotCompileException
{
boolean isStatic = Modifier.isStatic(field.getModifiers());
@@ -307,15 +307,18 @@
String infoName = getFieldWriteInfoFieldName(field.getName());
if (isStatic)
{
+ String targetString = "java.lang.Class.forName(\"" + clazz.getName() + "\")";
+ String fieldString = clazz.getName() + "." + field.getName();
code =
"{" +
+ " " + getArrayWriteRegistration(shouldReplaceArrayAccess, targetString, field, fieldString, "$2") +
" if (" + joinpointName + " == null && " + infoName + " != null && " + infoName + ".hasAdvices())" +
" {" +
" super." + JoinPointGenerator.GENERATE_JOINPOINT_CLASS + "(" + infoName + ");" +
" }" +
" if (" + joinpointName + " == null)" +
" { " +
- " " + clazz.getName() + "." + field.getName() + " = $2;" +
+ " " + fieldString + " = $2;" +
" }" +
" else" +
" {" +
@@ -325,15 +328,18 @@
}
else
{
+ String targetString = "((" + clazz.getName() + ")$1)";
+ String fieldString = targetString + "." + field.getName();
code =
"{" +
+ " " + getArrayWriteRegistration(shouldReplaceArrayAccess, targetString, field, fieldString, "$2") +
" if (" + joinpointName + " == null && " + infoName + " != null && " + infoName + ".hasAdvices())" +
" {" +
" super." + JoinPointGenerator.GENERATE_JOINPOINT_CLASS + "(" + infoName + ");" +
" }" +
" if (" + joinpointName + " == null)" +
" { " +
- " ((" + clazz.getName() + ")$1)." + field.getName() + " = $2;" +
+ " " + fieldString + " = $2;" +
" }" +
" else" +
" {" +
@@ -375,7 +381,7 @@
- private void buildWrappers(CtClass clazz, CtField field, boolean doGet, boolean doSet, int index) throws NotFoundException, CannotCompileException
+ private void buildWrappers(CtClass clazz, CtField field, boolean shouldReplaceArrayAccess, boolean doGet, boolean doSet, int index) throws NotFoundException, CannotCompileException
{
if (doGet)
{
@@ -400,7 +406,7 @@
if (doSet)
{
//Set wrapper code in advisor
- String code = getAdvisorWriteWrapperBody(clazz, field, index);
+ String code = getAdvisorWriteWrapperBody(clazz, field, index, shouldReplaceArrayAccess);
CtMethod method = getGenadvisor().getDeclaredMethod(advisorFieldWrite(getGenadvisor(), field.getName()));
try
{
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/Instrumentor.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/Instrumentor.java 2007-10-12 07:26:54 UTC (rev 66075)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/Instrumentor.java 2007-10-12 08:04:04 UTC (rev 66076)
@@ -34,6 +34,8 @@
import org.jboss.aop.AspectManager;
import org.jboss.aop.ClassAdvisor;
import org.jboss.aop.annotation.compiler.AnnotationInfoCreator;
+import org.jboss.aop.array.ArrayAdvisor;
+import org.jboss.aop.array.ArrayReplacement;
import org.jboss.aop.classpool.AOPClassPool;
import org.jboss.aop.classpool.AOPClassPoolRepository;
import org.jboss.aop.introduction.AnnotationIntroduction;
@@ -715,6 +717,10 @@
instrumentIntroductions(clazz, advisor);
converted = convertReferences(clazz) || converted;
+
+ boolean shouldReplaceArrayAccess = replaceArrayAccess(clazz, advisor);
+ converted = converted || shouldReplaceArrayAccess;
+
// need to instrument no matter what so that
// previously declared field and constructor interceptions
// get instrumented within this class.
@@ -725,7 +731,7 @@
// create static wrapper methods after
// clazz.instrument because the wrappers may call cons or fields
- fieldAccessTransformer.buildFieldWrappers(clazz, advisor);
+ fieldAccessTransformer.buildFieldWrappers(clazz, advisor, shouldReplaceArrayAccess);
if (constructorAccessConverted)
{
constructorExecutionTransformer.codeConverted();
@@ -998,6 +1004,28 @@
}
}
+ private boolean replaceArrayAccess(CtClass clazz, Advisor advisor) throws Exception
+ {
+ boolean shouldReplaceArrayAccess = false;
+ Map arrayReplacements = manager.getArrayReplacements();
+ for (Iterator it = arrayReplacements.values().iterator() ; it.hasNext() ; )
+ {
+ ArrayReplacement arrayReplacement = (ArrayReplacement)it.next();
+ if (arrayReplacement.matches(advisor, clazz))
+ {
+ shouldReplaceArrayAccess = true;
+ break;
+ }
+ }
+
+ if (shouldReplaceArrayAccess)
+ {
+ if (AspectManager.verbose) System.out.println("[debug] Replacing array access in " + clazz.getName());
+ converter.replaceArrayAccess(classPool.get(ArrayAdvisor.class.getName()), new CodeConverter.DefaultArrayAccessReplacementMethodNames());
+ }
+ return shouldReplaceArrayAccess;
+ }
+
/**
* Converts all processed classes to make wrapping of the appropriate joinpoints.
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/MethodExecutionTransformer.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/MethodExecutionTransformer.java 2007-10-12 07:26:54 UTC (rev 66075)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/MethodExecutionTransformer.java 2007-10-12 08:04:04 UTC (rev 66076)
@@ -407,12 +407,5 @@
return instrumentor;
}
- /**
- * @param wmethod2
- */
- public void setMethod(CtMethod method)
- {
- this.method = method;
- }
}
}
\ No newline at end of file
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/NonOptimizedFieldAccessTransformer.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/NonOptimizedFieldAccessTransformer.java 2007-10-12 07:26:54 UTC (rev 66075)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/NonOptimizedFieldAccessTransformer.java 2007-10-12 08:04:04 UTC (rev 66076)
@@ -43,7 +43,7 @@
super(instrumentor);
}
- protected void doBuildFieldWrappers(CtClass clazz, CtField field, int fieldIndex, JoinpointClassification classificationGet, JoinpointClassification classificationSet)
+ protected void doBuildFieldWrappers(CtClass clazz, CtField field, int fieldIndex, boolean shouldReplaceArrayAccess, JoinpointClassification classificationGet, JoinpointClassification classificationSet)
throws NotFoundException, CannotCompileException
{
instrumentor.setupBasics(clazz);
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/OptimizedFieldAccessTransformer.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/OptimizedFieldAccessTransformer.java 2007-10-12 07:26:54 UTC (rev 66075)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/OptimizedFieldAccessTransformer.java 2007-10-12 08:04:04 UTC (rev 66076)
@@ -43,7 +43,7 @@
super(instrumentor);
}
- protected void doBuildFieldWrappers(CtClass clazz, CtField field, int fieldIndex, JoinpointClassification classificationGet, JoinpointClassification classificationSet) throws NotFoundException, CannotCompileException
+ protected void doBuildFieldWrappers(CtClass clazz, CtField field, int fieldIndex, boolean shouldReplaceArrayAccess, JoinpointClassification classificationGet, JoinpointClassification classificationSet) throws NotFoundException, CannotCompileException
{
instrumentor.setupBasics(clazz);
boolean wrappedGet = classificationGet.equals(JoinpointClassification.WRAPPED);
More information about the jboss-cvs-commits
mailing list