public static <T> InterceptorImpl<T> of(BeanAttributes<T> attributes, EnhancedAnnotatedType<T> type, BeanManagerImpl beanManager) { return new InterceptorImpl<T>(attributes, type, beanManager); }
@Override public void initializeAfterBeanDiscovery() { super.initializeAfterBeanDiscovery(); checkInterceptorBindings(); }
@SuppressWarnings("unchecked") private InterceptorClassMetadata<T> initInterceptorMetadata() { CdiInterceptorFactory<T> reference = new CdiInterceptorFactory<T>(this); return new InterceptorMetadataImpl<T>((Class<T>) getBeanClass(), reference, InterceptorMetadataUtils.buildMethodMap(getEnhancedAnnotated(), false, getBeanManager())); }
@Override public String toString() { return "Interceptor [" + getBeanClass() + " intercepts " + Formats.formatAnnotations(getInterceptorBindings()) + "]"; } }
public void endInitialization() { tracker.start(Tracker.OP_END_INIT); final BeanIdentifierIndex index = deploymentManager.getServices().get(BeanIdentifierIndex.class); if (index != null) { deploymentManager.getServices().cleanupAfterBoot(); deploymentManager.cleanupAfterBoot(); for (BeanDeployment beanDeployment : getBeanDeployments()) { BeanManagerImpl beanManager = beanDeployment.getBeanManager(); for (Decorator<?> decorator : beanManager.getDecorators()) { if (decorator instanceof DecoratorImpl<?>) { Reflections.<DecoratorImpl<?>>cast(decorator).cleanupAfterBoot(); for (Interceptor<?> interceptor : beanManager.getInterceptors()) { if (interceptor instanceof InterceptorImpl<?>) { Reflections.<InterceptorImpl<?>>cast(interceptor).cleanupAfterBoot(); if (modules != null) { modules.processBeanDeployments(getBeanDeployments()); BootstrapLogger.LOG.debugv("EE modules: {0}", modules);
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);
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); } }
protected InterceptorImpl(BeanAttributes<T> attributes, EnhancedAnnotatedType<T> type, BeanManagerImpl beanManager) { super(attributes, type, new StringBeanIdentifier(forInterceptor(type)), beanManager); this.interceptorMetadata = initInterceptorMetadata(); this.serializable = type.isSerializable(); this.interceptorBindingTypes = Interceptors.mergeBeanInterceptorBindings(beanManager, getEnhancedAnnotated(), getStereotypes()).uniqueValues(); }
protected InterceptorImpl(BeanAttributes<T> attributes, EnhancedAnnotatedType<T> type, BeanManagerImpl beanManager) { super(attributes, type, new StringBeanIdentifier(forInterceptor(type)), beanManager); this.interceptorMetadata = initInterceptorMetadata(); this.serializable = type.isSerializable(); this.interceptorBindingTypes = Collections.unmodifiableSet(new HashSet<Annotation>(Interceptors.mergeBeanInterceptorBindings(beanManager, getEnhancedAnnotated(), getStereotypes()).values())); if (Beans.findInterceptorBindingConflicts(beanManager, interceptorBindingTypes)) { throw new DeploymentException(BeanLogger.LOG.conflictingInterceptorBindings(getType())); } }
public <T> InterceptorClassMetadata<T> getCdiInterceptorMetadata(Interceptor<T> interceptor) { if (interceptor instanceof InterceptorImpl) { InterceptorImpl<T> interceptorImpl = (InterceptorImpl<T>) interceptor; return interceptorImpl.getInterceptorMetadata(); } return cdiInterceptorMetadataCache.getCastValue(interceptor); }
private void checkInterceptorBindings() { if (interceptorMetadata.isEligible(org.jboss.weld.interceptor.spi.model.InterceptionType.POST_CONSTRUCT) || interceptorMetadata.isEligible(org.jboss.weld.interceptor.spi.model.InterceptionType.PRE_DESTROY) || interceptorMetadata.isEligible(org.jboss.weld.interceptor.spi.model.InterceptionType.POST_ACTIVATE) || interceptorMetadata.isEligible(org.jboss.weld.interceptor.spi.model.InterceptionType.PRE_PASSIVATE)) { for (Annotation interceptorBindingType : interceptorBindingTypes) { Target target = interceptorBindingType.annotationType().getAnnotation(Target.class); if (target == null || hasInvalidTargetType(target.value())) { ReflectionLogger.LOG.lifecycleCallbackInterceptorWithInvalidBindingTarget(this, interceptorBindingType.annotationType().getName(), target != null ? Arrays.toString(target.value()) : "Target meta-annotation is not present"); } } } }
public void endInitialization() { tracker.start(Tracker.OP_END_INIT); final BeanIdentifierIndex index = deploymentManager.getServices().get(BeanIdentifierIndex.class); if (index != null) { deploymentManager.getServices().cleanupAfterBoot(); deploymentManager.cleanupAfterBoot(); for (BeanDeployment beanDeployment : getBeanDeployments()) { BeanManagerImpl beanManager = beanDeployment.getBeanManager(); for (Decorator<?> decorator : beanManager.getDecorators()) { if (decorator instanceof DecoratorImpl<?>) { Reflections.<DecoratorImpl<?>>cast(decorator).cleanupAfterBoot(); for (Interceptor<?> interceptor : beanManager.getInterceptors()) { if (interceptor instanceof InterceptorImpl<?>) { Reflections.<InterceptorImpl<?>>cast(interceptor).cleanupAfterBoot(); if (modules != null) { modules.processBeanDeployments(getBeanDeployments()); BootstrapLogger.LOG.debugv("EE modules: {0}", modules); beanDeployment.getBeanManager().getBeanResolver().clear(); deploymentManager.getServices().get(Validator.class).clearResolved(); deploymentManager.getServices().get(ClassTransformer.class).cleanupAfterBoot();
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);
protected void validateInterceptor(Interceptor<?> interceptor, BeanManagerImpl manager) { if (interceptor instanceof InterceptorImpl<?>) { EnhancedAnnotatedType<?> annotated = ((InterceptorImpl<?>) interceptor).getEnhancedAnnotated(); if (!BeanMethods.getObserverMethods(annotated).isEmpty() || !BeanMethods.getAsyncObserverMethods(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); } }
protected InterceptorImpl(BeanAttributes<T> attributes, EnhancedAnnotatedType<T> type, BeanManagerImpl beanManager) { super(attributes, type, new StringBeanIdentifier(forInterceptor(type)), beanManager); this.interceptorMetadata = initInterceptorMetadata(); this.serializable = type.isSerializable(); this.interceptorBindingTypes = Interceptors.mergeBeanInterceptorBindings(beanManager, getEnhancedAnnotated(), getStereotypes()).uniqueValues(); }
@Override public String toString() { return "Interceptor [" + getBeanClass() + " intercepts " + Formats.formatAnnotations(getInterceptorBindings()) + "]"; } }
public <T> InterceptorClassMetadata<T> getCdiInterceptorMetadata(Interceptor<T> interceptor) { if (interceptor instanceof InterceptorImpl) { InterceptorImpl<T> interceptorImpl = (InterceptorImpl<T>) interceptor; return interceptorImpl.getInterceptorMetadata(); } return cdiInterceptorMetadataCache.getCastValue(interceptor); }
private void checkInterceptorBindings() { if (interceptorMetadata.isEligible(org.jboss.weld.interceptor.spi.model.InterceptionType.POST_CONSTRUCT) || interceptorMetadata.isEligible(org.jboss.weld.interceptor.spi.model.InterceptionType.PRE_DESTROY) || interceptorMetadata.isEligible(org.jboss.weld.interceptor.spi.model.InterceptionType.POST_ACTIVATE) || interceptorMetadata.isEligible(org.jboss.weld.interceptor.spi.model.InterceptionType.PRE_PASSIVATE)) { for (Annotation interceptorBindingType : interceptorBindingTypes) { Target target = interceptorBindingType.annotationType().getAnnotation(Target.class); if (target == null || hasInvalidTargetType(target.value())) { ReflectionLogger.LOG.lifecycleCallbackInterceptorWithInvalidBindingTarget(this, interceptorBindingType.annotationType().getName(), target != null ? Arrays.toString(target.value()) : "Target meta-annotation is not present"); } } } }
public void endInitialization() { tracker.start(Tracker.OP_END_INIT); final BeanIdentifierIndex index = deploymentManager.getServices().get(BeanIdentifierIndex.class); if (index != null) { deploymentManager.getServices().cleanupAfterBoot(); deploymentManager.cleanupAfterBoot(); for (BeanDeployment beanDeployment : getBeanDeployments()) { BeanManagerImpl beanManager = beanDeployment.getBeanManager(); for (Decorator<?> decorator : beanManager.getDecorators()) { if (decorator instanceof DecoratorImpl<?>) { Reflections.<DecoratorImpl<?>>cast(decorator).cleanupAfterBoot(); for (Interceptor<?> interceptor : beanManager.getInterceptors()) { if (interceptor instanceof InterceptorImpl<?>) { Reflections.<InterceptorImpl<?>>cast(interceptor).cleanupAfterBoot(); if (modules != null) { modules.processBeanDeployments(getBeanDeployments()); BootstrapLogger.LOG.debugv("EE modules: {0}", modules); beanDeployment.getBeanManager().getBeanResolver().clear(); deploymentManager.getServices().get(Validator.class).clearResolved(); deploymentManager.getServices().get(ClassTransformer.class).cleanupAfterBoot();
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);