private void addInterceptorInstance(Interceptor<Object> interceptor, BeanManagerImpl beanManager, Map<String, SerializableContextualInstance<Interceptor<Object>, Object>> instances, final CreationalContext<Object> creationalContext) { Object instance = beanManager.getReference(interceptor, interceptor.getBeanClass(), creationalContext, true); SerializableContextualInstance<Interceptor<Object>, Object> serializableContextualInstance = beanManager.getServices().get(ContextualStore.class).<Interceptor<Object>, Object>getSerializableContextualInstance(interceptor, instance, creationalContext); instances.put(interceptor.getBeanClass().getName(), serializableContextualInstance); }
private void validateInterceptors(BeanManagerImpl beanManager, AbstractClassBean<?> classBean) { InterceptionModel interceptionModel = beanManager.getInterceptorModelRegistry().get(classBean.getAnnotated()); if (interceptionModel != null) { Set<? extends InterceptorClassMetadata<?>> interceptors = interceptionModel.getAllInterceptors(); if (interceptors.size() > 0) { boolean passivationCapabilityCheckRequired = beanManager.isPassivatingScope(classBean.getScope()); for (InterceptorClassMetadata<?> interceptorMetadata : interceptors) { Interceptor<?> interceptor = cdiInterceptorFactory.getInterceptor(); boolean isSerializable = (interceptor instanceof InterceptorImpl) ? ((InterceptorImpl<?>) interceptor).isSerializable() : Beans.isPassivationCapableDependency(interceptor); if (!isSerializable) { throw ValidatorLogger.LOG.passivatingBeanWithNonserializableInterceptor(classBean, interceptor); beanManager = ((InterceptorImpl<?>) interceptor).getBeanManager(); for (InjectionPoint injectionPoint : interceptor.getInjectionPoints()) { Bean<?> resolvedBean = beanManager.resolve(beanManager.getBeans(injectionPoint)); validateInterceptorDecoratorInjectionPointPassivationCapable(injectionPoint, resolvedBean, beanManager, classBean); PlainInterceptorFactory<?> factory = (PlainInterceptorFactory<?>) interceptorMetadata.getInterceptorFactory(); Class<?> interceptorClass = interceptorMetadata.getJavaClass(); if (passivationCapabilityCheckRequired && !Reflections.isSerializable(interceptorClass)) { throw ValidatorLogger.LOG.passivatingBeanWithNonserializableInterceptor(this, interceptorClass.getName()); validateInjectionPoint(injectionPoint, beanManager); if (passivationCapabilityCheckRequired) { Bean<?> resolvedBean = beanManager.resolve(beanManager.getBeans(injectionPoint)); validateInterceptorDecoratorInjectionPointPassivationCapable(injectionPoint, resolvedBean, beanManager, classBean);
@Override protected boolean matches(InterceptorResolvable resolvable, Interceptor<?> bean) { return bean.intercepts(resolvable.getInterceptionType()) && bean.getInterceptorBindings().size() > 0 && Beans.containsAllInterceptionBindings(bean.getInterceptorBindings(), resolvable.getQualifiers(), getManager()) && manager.getEnabled().isInterceptorEnabled(bean.getBeanClass()); }
@Override public T create(CreationalContext<T> ctx, BeanManagerImpl manager) { return cast(manager.getReference(interceptor, interceptor.getBeanClass(), ctx, true)); }
protected void validateInterceptor(Interceptor<?> interceptor, BeanManagerImpl manager) { if (interceptor instanceof InterceptorImpl<?>) { EnhancedAnnotatedType<?> annotated = ((InterceptorImpl<?>) interceptor).getEnhancedAnnotated(); if (!BeanMethods.getObserverMethods(annotated).isEmpty()) { throw ValidatorLogger.LOG.interceptorsCannotHaveObserverMethods(interceptor); } if (!interceptor.getScope().equals(Dependent.class)) { throw ValidatorLogger.LOG.interceptorOrDecoratorMustBeDependent(interceptor); } while (annotated != null && annotated.getJavaClass() != Object.class) { if (!annotated.getDeclaredEnhancedMethods(Produces.class).isEmpty()) { throw ValidatorLogger.LOG.interceptorsCannotHaveProducerMethods(interceptor); } if (!annotated.getDeclaredEnhancedFields(Produces.class).isEmpty()) { throw ValidatorLogger.LOG.interceptorsCannotHaveProducerFields(interceptor); } if (!annotated.getDeclaredEnhancedMethodsWithAnnotatedParameters(Disposes.class).isEmpty()) { throw ValidatorLogger.LOG.interceptorsCannotHaveDisposerMethods(interceptor); } annotated = annotated.getEnhancedSuperclass(); } } for (InjectionPoint injectionPoint : interceptor.getInjectionPoints()) { validateInjectionPoint(injectionPoint, manager); } }
private void validateEnabledInterceptorClasses(BeanManagerImpl beanManager, BeanDeployment deployment) { BeansXml beansXml = deployment.getBeanDeploymentArchive().getBeansXml(); if (beansXml != null && !beansXml.getEnabledInterceptors().isEmpty()) { Set<String> interceptorBeanClasses = new HashSet<String>(); for (Interceptor<?> interceptor : beanManager.getDynamicAccessibleInterceptors()) { interceptorBeanClasses.add(interceptor.getBeanClass().getName()); } for (Metadata<String> interceptorClassName : beansXml.getEnabledInterceptors()) { if (!interceptorBeanClasses.contains(interceptorClassName.getValue())) { throw ValidatorLogger.LOG.interceptorClassDoesNotMatchInterceptorBean(interceptorClassName.getValue(), interceptorClassName.getLocation()); } } } }
private void initInterceptor(InterceptionType interceptionType, AnnotatedMethod<?> method, Set<Annotation> methodBindingAnnotations) { List<Interceptor<?>> methodBoundInterceptors = manager.resolveInterceptors(interceptionType, methodBindingAnnotations); if (methodBoundInterceptors != null && methodBoundInterceptors.size() > 0) { Method javaMethod = method.getJavaMember(); if (Reflections.isFinal(javaMethod)) { if (configuration.isFinalMethodIgnored(javaMethod.getDeclaringClass().getName())) { BeanLogger.LOG.finalMethodNotIntercepted(javaMethod, methodBoundInterceptors.get(0).getBeanClass().getName()); } else { throw BeanLogger.LOG.finalInterceptedBeanMethodNotAllowed(method, methodBoundInterceptors.get(0).getBeanClass().getName()); } } else { builder.interceptMethod(interceptionType, javaMethod, asInterceptorMetadata(methodBoundInterceptors), methodBindingAnnotations); } } }
@Override public Object proceed() throws Exception { currentInterceptorIdx++; return interceptor.intercept(interceptionType, instance, this); }
@SuppressWarnings("unchecked") public static <T> CustomInterceptorMetadata<T> of(Interceptor<T> interceptor) { return new CustomInterceptorMetadata<T>(new CdiInterceptorFactory<T>(interceptor), (Class<T>) interceptor.getBeanClass(), interceptor.getName() != null && !interceptor.getName().isEmpty() ? interceptor.getName() : null); }
@SuppressWarnings("unchecked") private void addInterceptorInstance(Interceptor<Object> interceptor, BeanManagerImpl beanManager, Map<String, SerializableContextualInstance<Interceptor<Object>, Object>> instances) { Object instance = beanManager.getContext(interceptor.getScope()).get(interceptor, creationalContext); SerializableContextualInstance<Interceptor<Object>, Object> serializableContextualInstance = beanManager.getServices().get(ContextualStore.class).<Interceptor<Object>, Object>getSerializableContextualInstance(interceptor, instance, creationalContext); instances.put(interceptor.getBeanClass().getName(), serializableContextualInstance); }
@SuppressWarnings("unchecked") private void addInterceptorInstance(Interceptor<Object> interceptor, InvocationContext invocationContext) { CreationalContext<Object> creationalContext = (CreationalContext<Object>) invocationContext.getContextData().get(SessionBeanInterceptor.CREATIONAL_CONTEXT); Object instance = beanManager.getContext(interceptor.getScope()).get(interceptor, creationalContext); SerializableContextualInstance<Interceptor<Object>,Object> serializableContextualInstance = beanManager.getServices().get(ContextualStore.class).<Interceptor<Object>,Object>getSerializableContextualInstance(interceptor, instance, creationalContext); interceptorInstances.put(interceptor.getBeanClass().getName(), serializableContextualInstance); }
.map(i -> bm.getReference(i, i.getBeanClass(), bm.createCreationalContext(null))) .collect(toList()); return new Interception(interceptors, instances); final Iterator<Object> instances = interception.instances.iterator(); final Interceptor next = it.next(); return next.intercept(AROUND_INVOKE, instances.next(), new DelegateInvocationContext(invocationContext, it, instances));
if(interceptor.getScope() != Dependent.class) logger.log(Level.WARNING, OWBLogConst.WARN_0005_1, interceptor.getBeanClass().getName()); if(interceptor.getName() != null) logger.log(Level.WARNING, OWBLogConst.WARN_0005_2, interceptor.getBeanClass().getName()); if(interceptor.isAlternative()) logger.log(Level.WARNING, OWBLogConst.WARN_0005_3, interceptor.getBeanClass().getName());
private void validateInterceptor(Interceptor<?> interceptor) { Set<Annotation> bindings = interceptor.getInterceptorBindings(); if (bindings == null) { throw InterceptorLogger.LOG.nullInterceptorBindings(interceptor); } for (Annotation annotation : bindings) { if (!getBeanManager().isInterceptorBinding(annotation.annotationType())) { throw MetadataLogger.LOG.notAnInterceptorBinding(annotation, interceptor); } } }
@Override public Set<Annotation> getInterceptorBindings() { return delegate().getInterceptorBindings(); }
if (!interceptor.intercepts(type)) return interceptor.intercept(type, instances.get(interceptor), this);
protected Object delegateInterception(InvocationContext invocationContext, InterceptionType interceptionType, List<Interceptor<?>> currentInterceptors, InterceptorInstances interceptorInstances) throws Exception { List<Object> currentInterceptorInstances = new ArrayList<Object>(); for (Interceptor<?> interceptor : currentInterceptors) { currentInterceptorInstances.add(interceptorInstances.getInstances().get(interceptor.getBeanClass().getName()).getInstance()); } if (currentInterceptorInstances.size() > 0) { return interceptorSupport.delegateInterception(invocationContext, interceptionType, currentInterceptors, currentInterceptorInstances); } else { return invocationContext.proceed(); } }
public List<Interceptor<?>> resolveInterceptors(InterceptionType type, Annotation... interceptorBindings) { List<Interceptor<?>> interceptorList = new ArrayList<>(); for (Interceptor<?> interceptor : cdiInterceptors) { if (interceptor.intercepts(type) && intercepts(interceptor, interceptorBindings) && isInterceptorClassEnabled(interceptor.getBeanClass())) { interceptorList.add(interceptor); } } Collections.sort(interceptorList, new InterceptorComparator(webBeansContext)); return interceptorList; }
@Override public boolean intercepts(InterceptionType type) { return delegate().intercepts(type); }