use of org.jboss.weld.bean.proxy.InterceptionFactoryDataCache.InterceptionFactoryData in project core by weld.
the class InterceptionFactoryImpl method createInterceptedInstance.
@Override
public T createInterceptedInstance(T instance) {
if (used) {
throw InterceptorLogger.LOG.interceptionFactoryNotReusable();
}
if (instance instanceof ProxyObject) {
InterceptorLogger.LOG.interceptionFactoryInternalContainerConstruct(instance.getClass());
return instance;
}
UnproxyableResolutionException exception = Proxies.getUnproxyableTypeException(annotatedType.getBaseType(), null, beanManager.getServices(), ignoreFinalMethods);
if (exception != null) {
throw exception;
}
used = true;
if (annotatedType.getJavaClass().isInterface()) {
throw InterceptorLogger.LOG.interceptionFactoryNotOnInstance(annotatedType.getJavaClass().getCanonicalName());
}
Optional<InterceptionFactoryData<T>> cached = beanManager.getServices().get(InterceptionFactoryDataCache.class).getInterceptionFactoryData(configurator != null ? configurator.complete() : annotatedType);
if (!cached.isPresent()) {
InterceptorLogger.LOG.interceptionFactoryNotRequired(annotatedType.getJavaClass().getSimpleName());
return instance;
}
InterceptionFactoryData<T> data = cached.get();
InterceptedProxyMethodHandler methodHandler = new InterceptedProxyMethodHandler(instance);
methodHandler.setInterceptorMethodHandler(new InterceptorMethodHandler(InterceptionContext.forNonConstructorInterception(data.getInterceptionModel(), creationalContext, beanManager, data.getSlimAnnotatedType())));
T proxy = (System.getSecurityManager() == null) ? data.getInterceptedProxyFactory().run() : AccessController.doPrivileged(data.getInterceptedProxyFactory());
((ProxyObject) proxy).setHandler(methodHandler);
return proxy;
}
Aggregations