Search in sources :

Example 1 with DefinitionException

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

the class Interceptors method addInterceptorBindings.

private static void addInterceptorBindings(EnhancedAnnotatedType<?> clazz, Collection<Annotation> interceptorBindings, Set<Annotation> flattenInterceptorBindings, MetaAnnotationStore metaAnnotationStore) {
    for (Annotation annotation : interceptorBindings) {
        Class<? extends Annotation> annotationType = annotation.annotationType();
        if (!annotation.annotationType().isAnnotationPresent(Repeatable.class)) {
            for (Annotation binding : flattenInterceptorBindings) {
                if (binding.annotationType().equals(annotationType) && !metaAnnotationStore.getInterceptorBindingModel(annotationType).isEqual(annotation, binding, false)) {
                    if (clazz != null) {
                        throw new DefinitionException(BeanLogger.LOG.conflictingInterceptorBindings(clazz));
                    } else {
                        throw BeanManagerLogger.LOG.duplicateInterceptorBinding(annotation);
                    }
                }
            }
        }
        flattenInterceptorBindings.add(annotation);
    }
}
Also used : Repeatable(java.lang.annotation.Repeatable) DefinitionException(org.jboss.weld.exceptions.DefinitionException) Annotation(java.lang.annotation.Annotation)

Example 2 with DefinitionException

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

the class ProxyFactory method run.

@Override
public T run() {
    try {
        Class<T> proxyClass = getProxyClass();
        boolean hasConstrutedField = SecurityActions.hasDeclaredField(proxyClass, CONSTRUCTED_FLAG_NAME);
        if (hasConstrutedField != useConstructedFlag()) {
            // The proxy class was created with a different type of ProxyInstantiator
            ProxyInstantiator newInstantiator = ProxyInstantiator.Factory.create(!hasConstrutedField);
            BeanLogger.LOG.creatingProxyInstanceUsingDifferentInstantiator(proxyClass, newInstantiator, proxyInstantiator);
            return newInstantiator.newInstance(proxyClass);
        }
        return proxyInstantiator.newInstance(proxyClass);
    } catch (InstantiationException e) {
        throw new DefinitionException(BeanLogger.LOG.proxyInstantiationFailed(this), e.getCause());
    } catch (IllegalAccessException e) {
        throw new DefinitionException(BeanLogger.LOG.proxyInstantiationBeanAccessFailed(this), e.getCause());
    }
}
Also used : DefinitionException(org.jboss.weld.exceptions.DefinitionException)

Example 3 with DefinitionException

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

Aggregations

DefinitionException (org.jboss.weld.exceptions.DefinitionException)3 Annotation (java.lang.annotation.Annotation)2 Repeatable (java.lang.annotation.Repeatable)1 HashSet (java.util.HashSet)1 DeploymentException (org.jboss.weld.exceptions.DeploymentException)1