String methodName = invocation.getMethod().getName();
// TODO Needs to handle Collection interceptor as well.
if (methodName.equals(MethodDeclarations.attachInterceptor.getName()))
{
Method method = MethodDeclarations.undoAttachInterceptor;
MethodCall mc = new MethodCall(method, invocation.getArguments(), invocation.getTargetObject());
handler.addToList(mc);
}
else if (methodName.equals(MethodDeclarations.detachInterceptor.getName()))
{
Method method = MethodDeclarations.undoDetachInterceptor;
MethodCall mc = new MethodCall(method, invocation.getArguments(), invocation.getTargetObject());
handler.addToList(mc);
}
else if (methodName.equals(MethodDeclarations.inMemorySubstitution.getName()))
{
Method method = MethodDeclarations.undoInMemorySubstitution;
Object obj = invocation.getArguments()[0];
Field field = (Field) invocation.getArguments()[1];
Object oldValue = field.get(obj);
Object[] args = new Object[]{obj, field, oldValue};
MethodCall mc = new MethodCall(method, args, invocation.getTargetObject());
handler.addToList(mc);
}
else if (methodName.equals(MethodDeclarations.incrementReferenceCount.getName()))
{
Method method = MethodDeclarations.undoIncrementReferenceCount;
Fqn fqn = (Fqn) invocation.getArguments()[0];
int count = (Integer) invocation.getArguments()[1];
List referenceList = (List) invocation.getArguments()[2];
Object[] args = new Object[]{fqn, count, referenceList};
MethodCall mc = new MethodCall(method, args, invocation.getTargetObject());
handler.addToList(mc);
}
else if (methodName.equals(MethodDeclarations.decrementReferenceCount.getName()))
{
Method method = MethodDeclarations.undoDecrementReferenceCount;
Fqn fqn = (Fqn) invocation.getArguments()[0];
int count = (Integer) invocation.getArguments()[1];
List referenceList = (List) invocation.getArguments()[2];
Object[] args = new Object[]{fqn, count, referenceList};
MethodCall mc = new MethodCall(method, args, invocation.getTargetObject());
handler.addToList(mc);
}
else
{
throw new PojoCacheException("PojoTxUndoInterceptor: invalid invocation name: " + methodName);