use of javassist.util.proxy.MethodHandler in project jbosstools-hibernate by jbosstools.
the class ForeignKeyFacadeTest method setUp.
@Before
public void setUp() throws Exception {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setSuperclass(ForeignKey.class);
Class<?> proxyClass = proxyFactory.createClass();
foreignKey = (ForeignKey) proxyClass.newInstance();
((ProxyObject) foreignKey).setHandler(new MethodHandler() {
@Override
public Object invoke(Object self, Method m, Method proceed, Object[] args) throws Throwable {
if (methodName == null) {
methodName = m.getName();
}
if (arguments == null) {
arguments = args;
}
return proceed.invoke(self, args);
}
});
foreignKeyFacade = new AbstractForeignKeyFacade(FACADE_FACTORY, foreignKey) {
};
reset();
}
use of javassist.util.proxy.MethodHandler in project jbosstools-hibernate by jbosstools.
the class GenericExporterFacadeTest method setUp.
@Before
public void setUp() throws Exception {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setSuperclass(GenericExporter.class);
Class<?> proxyClass = proxyFactory.createClass();
genericExporter = (GenericExporter) proxyClass.newInstance();
((ProxyObject) genericExporter).setHandler(new MethodHandler() {
@Override
public Object invoke(Object self, Method m, Method proceed, Object[] args) throws Throwable {
if (methodName == null) {
methodName = m.getName();
}
if (arguments == null) {
arguments = args;
}
return proceed.invoke(self, args);
}
});
genericExporterFacade = new AbstractGenericExporterFacade(FACADE_FACTORY, genericExporter) {
};
reset();
}
use of javassist.util.proxy.MethodHandler in project jbosstools-hibernate by jbosstools.
the class Hbm2DDLExporterFacadeTest method setUp.
@Before
public void setUp() throws Exception {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setSuperclass(Hbm2DDLExporter.class);
Class<?> proxyClass = proxyFactory.createClass();
hbm2ddlExporter = (Hbm2DDLExporter) proxyClass.newInstance();
((ProxyObject) hbm2ddlExporter).setHandler(new MethodHandler() {
@Override
public Object invoke(Object self, Method m, Method proceed, Object[] args) throws Throwable {
if (methodName == null) {
methodName = m.getName();
}
if (arguments == null) {
arguments = args;
}
return proceed.invoke(self, args);
}
});
hbm2DDLExporterFacade = new AbstractHbm2DDLExporterFacade(FACADE_FACTORY, hbm2ddlExporter) {
};
reset();
}
use of javassist.util.proxy.MethodHandler in project fastjson by alibaba.
the class ProxyTest method create.
public static <T> T create(Class<T> classs) throws Exception {
ProxyFactory factory = new ProxyFactory();
factory.setSuperclass(classs);
Class clazz = factory.createClass();
MethodHandler handler = new MethodHandler() {
public Object invoke(Object self, Method overridden, Method forwarder, Object[] args) throws Throwable {
return forwarder.invoke(self, args);
}
};
Object instance = clazz.newInstance();
((ProxyObject) instance).setHandler(handler);
return (T) instance;
}
use of javassist.util.proxy.MethodHandler in project frames by tinkerpop.
the class JavaHandlerModule method createHandler.
<T> T createHandler(final Object framedElement, final FramedGraph<?> graph, final Element element, Class<?> frameClass, final Method method) {
try {
Class<T> implClass = (Class<T>) classCache.get(frameClass);
T handler = factory.create(implClass);
((Proxy) handler).setHandler(new MethodHandler() {
private JavaHandlerContextImpl<Element> defaultJavahandlerImpl = new JavaHandlerContextImpl<Element>(graph, method, element);
@Override
public Object invoke(Object o, Method m, Method proceed, Object[] args) throws Throwable {
if (!Modifier.isAbstract(m.getModifiers())) {
return proceed.invoke(o, args);
} else {
if (m.getAnnotation(JavaHandler.class) != null) {
throw new JavaHandlerException("Method " + m + " is marked with @JavaHandler but is not implemented");
}
if (m.getDeclaringClass() == JavaHandlerContext.class) {
return m.invoke(defaultJavahandlerImpl, args);
}
return m.invoke(framedElement, args);
}
}
});
return handler;
} catch (ExecutionException e) {
Throwable cause = e.getCause();
if (cause instanceof ClassNotFoundException) {
throw new JavaHandlerException("Problem locating handler class for " + frameClass, e);
} else {
throw new JavaHandlerException("Cannot create class for handling framed method", cause);
}
} catch (InstantiationException e) {
throw new JavaHandlerException("Problem instantiating handler class", e);
} catch (IllegalAccessException e) {
throw new JavaHandlerException("Problem instantiating handler class", e);
}
}
Aggregations