Object target = invocation.getTargetObject();
Object message = invocation.getMetaData().getMetaData(ConsumerContainer.CONSUMER_MESSAGE, ConsumerContainer.CONSUMER_MESSAGE);
if (fields != null)
{
for (Field field : fields)
{
field.set(target, message);
}
}
if (methods != null)
{
for (Method method : methods)
{
method.invoke(target, message);
}
}
try
{
return invocation.invokeNext();
}
finally
{
// clear so we don't leak.
if (fields != null)
{
for (Field field : fields)
{
field.set(target, null);
}
}
if (methods != null)
{
for (Method method : methods)
{
Object[] args = new Object[method.getParameterTypes().length];
for (int i = 0 ; i < args.length; ++i)
args[i] = null;
method.invoke(target, args);
}
}
}