org.nakedobjects.headlessviewer.viewer.internal.JavaProxyFactory Maven / Gradle / Ivy
The newest version!
package org.nakedobjects.headlessviewer.viewer.internal;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;
import org.nakedobjects.headlessviewer.applib.ViewObject;
public class JavaProxyFactory implements IProxyFactory {
@SuppressWarnings("unchecked")
public T createProxy(final T toProxy, final InvocationHandler handler) {
final Class proxyClass = (Class) toProxy.getClass();
return (T) Proxy.newProxyInstance(proxyClass.getClassLoader(), new Class[] { proxyClass }, handler);
}
@SuppressWarnings("unchecked")
public T createProxy(final Class toProxy, final InvocationHandler handler) {
return (T) Proxy.newProxyInstance(toProxy.getClassLoader(), new Class[] { toProxy, ViewObject.class }, handler);
}
}