public static <T> T proxy(final TypedObjectFactory<T> objectFactory, final Class<T> genericType) { try { return new ProxyFactory<T>(objectFactory, genericType).create(); } catch (final RuntimeException e) { LOG.error("exception", e); throw e; } }
/** * @return a proxy of {@link ReadOnlyContext} object. This solution is preferred to {@link InjectorObjectFactory} * because the injected field ensure thread-safe behavior. */ private Object createReadOnlyContextProxy() { return ProxyFactory.proxy(new TypedObjectFactory<ReadOnlyContext>() { public ReadOnlyContext create() { return Context.get(); } public Class<? extends ReadOnlyContext> getObjectClass() { return Context.class; } }, ReadOnlyContext.class); }
@SuppressWarnings("unchecked") private T create() { final InvocationHandler handler = new InvocationHandler() { public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable { try { return method.invoke(objectFactory.create(), args); } catch (final InvocationTargetException ex) { // Preserve original exception throw ex.getCause(); } } }; LOG.debug("genericType: {}", genericType); return (T) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), getInterfacesSet().toArray( new Class[] {}), handler); }
@SuppressWarnings("unchecked") private T create() { final InvocationHandler handler = new InvocationHandler() { public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable { try { return method.invoke(objectFactory.create(), args); } catch (final InvocationTargetException ex) { // Preserve original exception throw ex.getCause(); } } }; LOG.debug("genericType: {}", genericType); return (T) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), getInterfacesSet().toArray( new Class[] {}), handler); }
public static <T> T proxy(final TypedObjectFactory<T> objectFactory, final Class<T> genericType) { try { return new ProxyFactory<T>(objectFactory, genericType).create(); } catch (final RuntimeException e) { LOG.error("exception", e); throw e; } }
/** * @return a proxy of {@link ReadOnlyContext} object. This solution is preferred to {@link InjectorObjectFactory} * because the injected field ensure thread-safe behavior. */ private Object createReadOnlyContextProxy() { return ProxyFactory.proxy(new TypedObjectFactory<ReadOnlyContext>() { public ReadOnlyContext create() { return Context.get(); } public Class<? extends ReadOnlyContext> getObjectClass() { return Context.class; } }, ReadOnlyContext.class); }