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);
}
}
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);
}
}
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()));
}
}
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;
}
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;
}
Aggregations