public Object createInterceptorFor(Object instanceToIntercept) { if (getInterceptorClassToBeUsed() != null) { try { // Class[] parameterTypes = {Object.class}; // Object[] parameters = {instanceToIntercept}; // Constructor constructor = getInterceptorClassToBeUsed().getConstructor(parameterTypes); // InvocationHandler handler = (InvocationHandler) constructor.newInstance(parameters); // use helper class to instantiate InvocationHandler handler = (InvocationHandler) ClassHelper.newInstance( getInterceptorClassToBeUsed(), Object.class, instanceToIntercept); Class[] interfaces = computeInterfaceArrayFor(instanceToIntercept.getClass()); Object result = Proxy.newProxyInstance( ClassHelper.getClassLoader(), interfaces, handler); return result; } catch (Throwable t) { LoggerFactory.getDefaultLogger().error("can't use Interceptor " + getInterceptorClassToBeUsed().getName() + "for " + instanceToIntercept.getClass().getName(), t); return instanceToIntercept; } } else { return instanceToIntercept; } }
@Override public boolean allows(final Class<?> type) { return type != null && type != Object.class && !type.isInterface() && (Proxy.isProxyClass(type) || type.getName().startsWith(Proxy.class.getPackage().getName() + ".")); }
public boolean allows(Class paramClass) { return (paramClass != null) && (paramClass != Object.class) && (!paramClass.isInterface()) && ((Proxy.isProxyClass(paramClass)) || (paramClass.getName().startsWith(Proxy.class.getPackage().getName() + "."))); }
/** * Creates a new dynamic accessor instance. * * @param accessor specification for the accessor instance to create * @param finderInterceptor the finder interceptor to use * @return a Warp Persist-generated instance of the given accessor */ public static Object newDynamicAccessor(Class<?> accessor, MethodInterceptor finderInterceptor) { return Proxy.newProxyInstance(accessor.getClassLoader(), new Class<?>[] { accessor }, new AopAllianceJdkProxyAdapter( finderInterceptor)); }