public void destroyContext(Context context) {
context = ForwardingContext.unwrap(context);
if (context instanceof ManagedContext) {
ManagedContext managedContext = (ManagedContext) context;
managedContext.invalidate();
managedContext.deactivate();
managedContext.activate();
} else if (context instanceof ApplicationContext) {
((ApplicationContext) context).invalidate();
} else {
throw new UnsupportedOperationException();