Ejemplo n.º 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);
              }
            }
          }
        }
      }
    }
  }
Ejemplo n.º 2
0
 private void initTargetClassInterceptors() {
   if (!Beans.isInterceptor(getWeldAnnotated())) {
     InterceptorMetadata<T> interceptorClassMetadata =
         beanManager
             .getInterceptorMetadataReader()
             .getTargetClassInterceptorMetadata(
                 WeldInterceptorClassMetadata.of(getWeldAnnotated()));
     hasSerializationOrInvocationInterceptorMethods =
         !interceptorClassMetadata
                 .getInterceptorMethods(
                     org.jboss.interceptor.spi.model.InterceptionType.AROUND_INVOKE)
                 .isEmpty()
             || !interceptorClassMetadata
                 .getInterceptorMethods(
                     org.jboss.interceptor.spi.model.InterceptionType.AROUND_TIMEOUT)
                 .isEmpty()
             || !interceptorClassMetadata
                 .getInterceptorMethods(
                     org.jboss.interceptor.spi.model.InterceptionType.PRE_PASSIVATE)
                 .isEmpty()
             || !interceptorClassMetadata
                 .getInterceptorMethods(
                     org.jboss.interceptor.spi.model.InterceptionType.POST_ACTIVATE)
                 .isEmpty();
   } else {
     // an interceptor does not have lifecycle methods of its own, but it intercepts the methods of
     // the
     // target class
     hasSerializationOrInvocationInterceptorMethods = false;
   }
 }