Search in sources :

Example 1 with InterceptedProxyMethodHandler

use of org.jboss.weld.bean.proxy.InterceptedProxyMethodHandler 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;
}
Also used : ProxyObject(org.jboss.weld.bean.proxy.ProxyObject) InterceptedProxyMethodHandler(org.jboss.weld.bean.proxy.InterceptedProxyMethodHandler) InterceptionFactoryData(org.jboss.weld.bean.proxy.InterceptionFactoryDataCache.InterceptionFactoryData) InterceptionFactoryDataCache(org.jboss.weld.bean.proxy.InterceptionFactoryDataCache) UnproxyableResolutionException(org.jboss.weld.exceptions.UnproxyableResolutionException) InterceptorMethodHandler(org.jboss.weld.interceptor.proxy.InterceptorMethodHandler)

Aggregations

InterceptedProxyMethodHandler (org.jboss.weld.bean.proxy.InterceptedProxyMethodHandler)1 InterceptionFactoryDataCache (org.jboss.weld.bean.proxy.InterceptionFactoryDataCache)1 InterceptionFactoryData (org.jboss.weld.bean.proxy.InterceptionFactoryDataCache.InterceptionFactoryData)1 ProxyObject (org.jboss.weld.bean.proxy.ProxyObject)1 UnproxyableResolutionException (org.jboss.weld.exceptions.UnproxyableResolutionException)1 InterceptorMethodHandler (org.jboss.weld.interceptor.proxy.InterceptorMethodHandler)1