Search in sources :

Example 1 with UnproxyableResolutionException

use of org.jboss.weld.exceptions.UnproxyableResolutionException 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)

Example 2 with UnproxyableResolutionException

use of org.jboss.weld.exceptions.UnproxyableResolutionException in project core by weld.

the class Proxies method getUnproxyableClassException.

private static UnproxyableResolutionException getUnproxyableClassException(Class<?> clazz, Bean<?> declaringBean, ServiceRegistry services, boolean ignoreFinalMethods) {
    if (clazz.isInterface()) {
        return null;
    }
    Constructor<?> constructor = null;
    try {
        constructor = SecurityActions.getDeclaredConstructor(clazz);
    } catch (Exception ignored) {
    }
    if (clazz.isPrimitive()) {
        return ValidatorLogger.LOG.notProxyablePrimitive(clazz, getDeclaringBeanInfo(declaringBean));
    } else if (Reflections.isArrayType(clazz)) {
        return ValidatorLogger.LOG.notProxyableArrayType(clazz, getDeclaringBeanInfo(declaringBean));
    } else if (Reflections.isFinal(clazz)) {
        return ValidatorLogger.LOG.notProxyableFinalType(clazz, getDeclaringBeanInfo(declaringBean));
    } else {
        Method finalMethod = Reflections.getNonPrivateNonStaticFinalMethod(clazz);
        if (finalMethod != null) {
            if (ignoreFinalMethods || Beans.shouldIgnoreFinalMethods(declaringBean) || services.get(WeldConfiguration.class).isFinalMethodIgnored(clazz.getName())) {
                ValidatorLogger.LOG.notProxyableFinalMethodIgnored(finalMethod, getDeclaringBeanInfo(declaringBean));
            } else {
                return ValidatorLogger.LOG.notProxyableFinalMethod(clazz, finalMethod, getDeclaringBeanInfo(declaringBean));
            }
        }
    }
    UnproxyableResolutionException exception = services.get(ProxyInstantiator.class).validateNoargConstructor(constructor, clazz, declaringBean);
    if (exception != null) {
        return exception;
    }
    return null;
}
Also used : UnproxyableResolutionException(org.jboss.weld.exceptions.UnproxyableResolutionException) ProxyInstantiator(org.jboss.weld.bean.proxy.ProxyInstantiator) Method(java.lang.reflect.Method) UnproxyableResolutionException(org.jboss.weld.exceptions.UnproxyableResolutionException)

Aggregations

UnproxyableResolutionException (org.jboss.weld.exceptions.UnproxyableResolutionException)2 Method (java.lang.reflect.Method)1 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 ProxyInstantiator (org.jboss.weld.bean.proxy.ProxyInstantiator)1 ProxyObject (org.jboss.weld.bean.proxy.ProxyObject)1 InterceptorMethodHandler (org.jboss.weld.interceptor.proxy.InterceptorMethodHandler)1