@Override
public Object createContextualProxy(Object instance, Map<String, String> executionProperties, Class<?>... interfaces) {
if (instance == null) {
throw new IllegalArgumentException(NULL_INSTANCE);
}
if (interfaces == null || interfaces.length == 0) {
throw new IllegalArgumentException(NO_INTERFACES);
}
Class instanceClass = instance.getClass();
for (Class thisInterface: interfaces) {
if (! thisInterface.isAssignableFrom(instanceClass)) {
throw new IllegalArgumentException(CLASS_DOES_NOT_IMPLEMENT_INTERFACES);
}
}
ContextProxyInvocationHandler handler = new ContextProxyInvocationHandler(this, instance, executionProperties);
Object proxy = Proxy.newProxyInstance(instance.getClass().getClassLoader(), interfaces, handler);
return proxy;
}