Exemple #1
0
  private void validateInterceptors(BeanManagerImpl beanManager, AbstractClassBean<?> classBean) {
    InterceptionModel<ClassMetadata<?>, ?> interceptionModel =
        beanManager.getInterceptorModelRegistry().get(classBean.getType());
    if (interceptionModel != null) {
      Set<? extends InterceptorMetadata<?>> interceptors = interceptionModel.getAllInterceptors();
      if (interceptors.size() > 0) {
        boolean passivationCapabilityCheckRequired =
            isPassivationCapabilityCheckRequired(beanManager, classBean);
        for (InterceptorMetadata<?> interceptorMetadata : interceptors) {
          if (interceptorMetadata.getInterceptorReference().getInterceptor()
              instanceof SerializableContextual) {
            SerializableContextual<Interceptor<?>, ?> serializableContextual =
                cast(interceptorMetadata.getInterceptorReference().getInterceptor());

            if (passivationCapabilityCheckRequired) {
              Interceptor<?> interceptor = serializableContextual.get();
              boolean isSerializable =
                  (interceptor instanceof InterceptorImpl)
                      ? ((InterceptorImpl<?>) interceptor).isSerializable()
                      : (interceptor instanceof PassivationCapable);
              if (isSerializable == false)
                throw new DeploymentException(
                    PASSIVATING_BEAN_WITH_NONSERIALIZABLE_INTERCEPTOR, classBean, interceptor);
            }
            for (InjectionPoint injectionPoint :
                serializableContextual.get().getInjectionPoints()) {
              Bean<?> resolvedBean = beanManager.resolve(beanManager.getBeans(injectionPoint));
              validateInjectionPoint(injectionPoint, beanManager);
              if (passivationCapabilityCheckRequired) {
                validateInjectionPointPassivationCapable(injectionPoint, resolvedBean, beanManager);
              }
            }
          }
          if (interceptorMetadata.getInterceptorReference().getInterceptor()
              instanceof ClassMetadata<?>) {
            ClassMetadata<?> classMetadata =
                (ClassMetadata<?>) interceptorMetadata.getInterceptorReference().getInterceptor();
            if (passivationCapabilityCheckRequired
                && !Reflections.isSerializable(classMetadata.getJavaClass())) {
              throw new DeploymentException(
                  PASSIVATING_BEAN_WITH_NONSERIALIZABLE_INTERCEPTOR,
                  this,
                  classMetadata.getJavaClass().getName());
            }
            InjectionTarget<Object> injectionTarget =
                cast(
                    beanManager.createInjectionTarget(
                        beanManager.createAnnotatedType(classMetadata.getJavaClass())));
            for (InjectionPoint injectionPoint : injectionTarget.getInjectionPoints()) {
              Bean<?> resolvedBean = beanManager.resolve(beanManager.getBeans(injectionPoint));
              validateInjectionPoint(injectionPoint, beanManager);
              if (passivationCapabilityCheckRequired) {
                validateInjectionPointPassivationCapable(injectionPoint, resolvedBean, beanManager);
              }
            }
          }
        }
      }
    }
  }
 private Object readResolve() throws ObjectStreamException {
   InterceptionModel<ClassMetadata<?>> interceptionModel =
       manager.getInterceptorModelRegistry().get(targetClass);
   MetadataCachingReader reader = manager.getInterceptorMetadataReader();
   TargetClassInterceptorMetadata<?> targetClassInterceptorMetadata =
       reader.getTargetClassInterceptorMetadata(reader.getClassMetadata(targetClass));
   return new InterceptionContext(
       interceptorInstances, manager, targetClassInterceptorMetadata, interceptionModel);
 }