JBoss.org Community Documentation
Writing aspects for array element interception is more or less the same as for any other joinpoint.
However, array element interception comes with its own hierarchy of Invocation
clases.
Which one of these is used depends on what is being itercepted. The hierarchy is shown below (all the
classes live in the org.jboss.aop.array
package):
ArrayElementInvocation -ArrayElementReadInvocation --BooleanArrayElementReadInvocation -Element read from a boolean[] --ByteArrayElementReadInvocation -Element read from a byte[] --CharArrayElementReadInvocation -Element read from a char[] --DoubleArrayElementReadInvocation -Element read from a double[] --FloatArrayElementReadInvocation -Element read from a float[] --IntArrayElementReadInvocation -Element read from a int[] --LongArrayElementReadInvocation -Element read from a long[] --ObjectArrayElementReadInvocation -Element read from a Object[], String[] etc. --ShortArrayElementReadInvocation -Element read from a shore[] -ArrayElementWriteInvocation --BooleanArrayElementWriteInvocation -Element written to a boolean[] --ByteArrayElementWriteInvocation -Element written to a byte[] --CharArrayElementWriteInvocation -Element written to a char[] --DoubleArrayElementWriteInvocation -Element written to a double[] --FloatArrayElementWriteInvocation -Element written to a float[] --IntArrayElementWriteInvocation -Element written to a int[] --LongArrayElementWriteInvocation -Element written to a long[] --ObjectArrayElementWriteInvocation -Element written to a Object[], String[] etc. --ShortArrayElementWriteInvocation -Element written to a short[]
The write invocation classes allow you access to the value the element is being set to.
ArrayElementReadInvocation
defines a method to get hold of the value being
set:
public abstract Object getValue();
The sub-classes override this value, and also define a more fine-grained value to avoid using the
wrapper classes where appropriate, as shown in the following methods from
DoubleArrayElementWriteInvocation
:
public Object getValue() { return new Double(value); } public double getDoubleValue() { return value; }
When reading an array element the invocation's return value contains the value read. For all
array invocations you can get the index of the element being accessed by calling
ArrayElementInvocation.getIndex()
.