Search in sources :

Example 1 with DeploymentException

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

the class InterceptionModelInitializer method init.

public void init() {
    initTargetClassInterceptors();
    businessMethods = Beans.getInterceptableMethods(annotatedType);
    initEjbInterceptors();
    initCdiInterceptors();
    InterceptionModel interceptionModel = builder.build();
    if (interceptionModel.getAllInterceptors().size() > 0 || hasSerializationOrInvocationInterceptorMethods) {
        if (annotatedType.isFinal()) {
            throw BeanLogger.LOG.finalBeanClassWithInterceptorsNotAllowed(annotatedType.getJavaClass());
        }
        if (Reflections.isPrivate(constructor.getJavaMember())) {
            throw new DeploymentException(ValidatorLogger.LOG.notProxyablePrivateConstructor(annotatedType.getJavaClass().getName(), constructor, annotatedType.getJavaClass()));
        }
        manager.getInterceptorModelRegistry().put(annotatedType.slim(), interceptionModel);
    }
}
Also used : InterceptionModel(org.jboss.weld.interceptor.spi.model.InterceptionModel) DeploymentException(org.jboss.weld.exceptions.DeploymentException)

Example 2 with DeploymentException

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

the class InterceptionModelInitializer method initMethodDeclaredEjbInterceptors.

private void initMethodDeclaredEjbInterceptors(AnnotatedMethod<?> method) {
    Method javaMethod = method.getJavaMember();
    boolean excludeClassInterceptors = method.isAnnotationPresent(interceptorsApi.getExcludeClassInterceptorsAnnotationClass());
    if (excludeClassInterceptors) {
        builder.addMethodIgnoringGlobalInterceptors(javaMethod);
    }
    Class<?>[] methodDeclaredInterceptors = interceptorsApi.extractInterceptorClasses(method);
    if (methodDeclaredInterceptors != null && methodDeclaredInterceptors.length > 0) {
        if (Reflections.isFinal(method.getJavaMember())) {
            throw new DeploymentException(BeanLogger.LOG.finalInterceptedBeanMethodNotAllowed(method, methodDeclaredInterceptors[0].getName()));
        }
        InterceptionType interceptionType = isTimeoutAnnotationPresentOn(method) ? InterceptionType.AROUND_TIMEOUT : InterceptionType.AROUND_INVOKE;
        builder.interceptMethod(interceptionType, javaMethod, getMethodDeclaredInterceptorMetadatas(methodDeclaredInterceptors), null);
    }
}
Also used : DeploymentException(org.jboss.weld.exceptions.DeploymentException) EnhancedAnnotatedMethod(org.jboss.weld.annotated.enhanced.EnhancedAnnotatedMethod) Method(java.lang.reflect.Method) AnnotatedMethod(javax.enterprise.inject.spi.AnnotatedMethod) InterceptionType(javax.enterprise.inject.spi.InterceptionType)

Example 3 with DeploymentException

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

the class Interceptors method mergeBeanInterceptorBindings.

/**
 * Merge class-level interceptor bindings with interceptor bindings inherited from interceptor bindings and stereotypes.
 */
public static Multimap<Class<? extends Annotation>, Annotation> mergeBeanInterceptorBindings(BeanManagerImpl beanManager, EnhancedAnnotatedType<?> clazz, Collection<Class<? extends Annotation>> stereotypes) {
    Set<Annotation> rawBindings = clazz.getMetaAnnotations(InterceptorBinding.class);
    Set<Annotation> classBindingAnnotations = flattenInterceptorBindings(clazz, beanManager, filterInterceptorBindings(beanManager, rawBindings), true, false);
    Set<Annotation> inheritedBindingAnnotations = new HashSet<Annotation>();
    inheritedBindingAnnotations.addAll(flattenInterceptorBindings(clazz, beanManager, filterInterceptorBindings(beanManager, rawBindings), false, true));
    for (Class<? extends Annotation> annotation : stereotypes) {
        inheritedBindingAnnotations.addAll(flattenInterceptorBindings(clazz, beanManager, filterInterceptorBindings(beanManager, beanManager.getStereotypeDefinition(annotation)), true, true));
    }
    try {
        return mergeBeanInterceptorBindings(beanManager, clazz, classBindingAnnotations, inheritedBindingAnnotations);
    } catch (DeploymentException e) {
        throw new DefinitionException(BeanLogger.LOG.conflictingInterceptorBindings(clazz.getJavaClass()));
    }
}
Also used : DeploymentException(org.jboss.weld.exceptions.DeploymentException) DefinitionException(org.jboss.weld.exceptions.DefinitionException) Annotation(java.lang.annotation.Annotation) HashSet(java.util.HashSet)

Example 4 with DeploymentException

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

the class Interceptors method mergeBeanInterceptorBindings.

/**
 * Merge class-level interceptor bindings with interceptor bindings inherited from interceptor bindings and stereotypes.
 */
public static Multimap<Class<? extends Annotation>, Annotation> mergeBeanInterceptorBindings(BeanManagerImpl beanManager, AnnotatedType<?> clazz, Collection<Annotation> classBindingAnnotations, Collection<Annotation> inheritedBindingAnnotations) {
    SetMultimap<Class<? extends Annotation>, Annotation> mergedBeanBindings = SetMultimap.newSetMultimap();
    SetMultimap<Class<? extends Annotation>, Annotation> acceptedInheritedBindings = SetMultimap.newSetMultimap();
    MetaAnnotationStore metaAnnotationStore = beanManager.getServices().get(MetaAnnotationStore.class);
    // add all class-level interceptor bindings (these have precedence)
    for (Annotation binding : classBindingAnnotations) {
        Class<? extends Annotation> annotationType = binding.annotationType();
        if (!annotationType.isAnnotationPresent(Repeatable.class)) {
            // Detec conflicts for non repeating bindings
            for (Annotation mergedBinding : mergedBeanBindings.get(annotationType)) {
                if (!metaAnnotationStore.getInterceptorBindingModel(annotationType).isEqual(binding, mergedBinding, false)) {
                    throw new DeploymentException(BeanLogger.LOG.conflictingInterceptorBindings(clazz.getJavaClass()));
                }
            }
        }
        mergedBeanBindings.put(binding.annotationType(), binding);
    }
    // add inherited interceptor bindings
    for (Annotation binding : inheritedBindingAnnotations) {
        Class<? extends Annotation> annotationType = binding.annotationType();
        if (!mergedBeanBindings.containsKey(annotationType) || annotationType.isAnnotationPresent(Repeatable.class)) {
            mergedBeanBindings.put(annotationType, binding);
            acceptedInheritedBindings.put(annotationType, binding);
        } else {
            Set<Annotation> inheritedBindings = acceptedInheritedBindings.get(annotationType);
            for (Annotation inheritedBinding : inheritedBindings) {
                if (!metaAnnotationStore.getInterceptorBindingModel(annotationType).isEqual(binding, inheritedBinding, false)) {
                    throw new DeploymentException(BeanLogger.LOG.conflictingInterceptorBindings(clazz.getJavaClass()));
                }
            }
        }
    }
    return mergedBeanBindings;
}
Also used : Repeatable(java.lang.annotation.Repeatable) MetaAnnotationStore(org.jboss.weld.metadata.cache.MetaAnnotationStore) DeploymentException(org.jboss.weld.exceptions.DeploymentException) Annotation(java.lang.annotation.Annotation)

Example 5 with DeploymentException

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

the class InterceptorApplyingInstantiator method applyInterceptors.

protected T applyInterceptors(T instance, InterceptionContext interceptionContext) {
    try {
        InterceptorMethodHandler methodHandler = new InterceptorMethodHandler(interceptionContext);
        CombinedInterceptorAndDecoratorStackMethodHandler wrapperMethodHandler = (CombinedInterceptorAndDecoratorStackMethodHandler) ((ProxyObject) instance).getHandler();
        wrapperMethodHandler.setInterceptorMethodHandler(methodHandler);
    } catch (Exception e) {
        throw new DeploymentException(e);
    }
    return instance;
}
Also used : CombinedInterceptorAndDecoratorStackMethodHandler(org.jboss.weld.bean.proxy.CombinedInterceptorAndDecoratorStackMethodHandler) InterceptorMethodHandler(org.jboss.weld.interceptor.proxy.InterceptorMethodHandler) DeploymentException(org.jboss.weld.exceptions.DeploymentException) DeploymentException(org.jboss.weld.exceptions.DeploymentException)

Aggregations

DeploymentException (org.jboss.weld.exceptions.DeploymentException)5 Annotation (java.lang.annotation.Annotation)2 Repeatable (java.lang.annotation.Repeatable)1 Method (java.lang.reflect.Method)1 HashSet (java.util.HashSet)1 AnnotatedMethod (javax.enterprise.inject.spi.AnnotatedMethod)1 InterceptionType (javax.enterprise.inject.spi.InterceptionType)1 EnhancedAnnotatedMethod (org.jboss.weld.annotated.enhanced.EnhancedAnnotatedMethod)1 CombinedInterceptorAndDecoratorStackMethodHandler (org.jboss.weld.bean.proxy.CombinedInterceptorAndDecoratorStackMethodHandler)1 DefinitionException (org.jboss.weld.exceptions.DefinitionException)1 InterceptorMethodHandler (org.jboss.weld.interceptor.proxy.InterceptorMethodHandler)1 InterceptionModel (org.jboss.weld.interceptor.spi.model.InterceptionModel)1 MetaAnnotationStore (org.jboss.weld.metadata.cache.MetaAnnotationStore)1