Example #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);
              }
            }
          }
        }
      }
    }
  }
Example #2
0
 private void validateDecorators(BeanManagerImpl beanManager, AbstractClassBean<?> classBean) {
   if (classBean.getDecorators().size() > 0) {
     boolean passivationCapabilityCheckRequired =
         isPassivationCapabilityCheckRequired(beanManager, classBean);
     for (Decorator<?> decorator : classBean.getDecorators()) {
       if (passivationCapabilityCheckRequired) {
         boolean isSerializable =
             (decorator instanceof WeldDecorator<?>)
                 ? (((WeldDecorator<?>) decorator).getWeldAnnotated().isSerializable())
                 : (decorator instanceof PassivationCapable);
         if (!isSerializable) {
           throw new UnserializableDependencyException(
               PASSIVATING_BEAN_WITH_NONSERIALIZABLE_DECORATOR, classBean, decorator);
         }
       }
       for (InjectionPoint ij : decorator.getInjectionPoints()) {
         if (!ij.isDelegate()) {
           Bean<?> resolvedBean = beanManager.resolve(beanManager.getBeans(ij));
           validateInjectionPoint(ij, beanManager);
           if (passivationCapabilityCheckRequired) {
             validateInjectionPointPassivationCapable(ij, resolvedBean, beanManager);
           }
         }
       }
     }
   }
 }
Example #3
0
 /**
  * Variation of the validateInjectionPoint method which allows the bean to be defined explicitly
  * (used for disposer method validation)
  */
 public void validateInjectionPoint(InjectionPoint ij, Bean<?> bean, BeanManagerImpl beanManager) {
   if (ij.getAnnotated().getAnnotation(New.class) != null && ij.getQualifiers().size() > 1) {
     throw new DefinitionException(NEW_WITH_QUALIFIERS, ij);
   }
   if (ij.getType().equals(InjectionPoint.class) && bean == null) {
     throw new DefinitionException(INJECTION_INTO_NON_BEAN, ij);
   }
   if (ij.getType().equals(InjectionPoint.class) && !Dependent.class.equals(bean.getScope())) {
     throw new DefinitionException(INJECTION_INTO_NON_DEPENDENT_BEAN, ij);
   }
   if (ij.getType() instanceof TypeVariable<?>) {
     throw new DefinitionException(INJECTION_POINT_WITH_TYPE_VARIABLE, ij);
   }
   if (!(ij.getMember() instanceof Field)
       && ij.getAnnotated().isAnnotationPresent(Named.class)
       && ij.getAnnotated().getAnnotation(Named.class).value().equals("")) {
     throw new DefinitionException(NON_FIELD_INJECTION_POINT_CANNOT_USE_NAMED, ij);
   }
   boolean newBean = (bean instanceof NewManagedBean<?>) || (bean instanceof NewSessionBean<?>);
   if (!newBean) {
     checkScopeAnnotations(ij, beanManager.getServices().get(MetaAnnotationStore.class));
   }
   checkFacadeInjectionPoint(ij, Instance.class);
   checkFacadeInjectionPoint(ij, Event.class);
   Annotation[] bindings = ij.getQualifiers().toArray(new Annotation[0]);
   Set<?> resolvedBeans = beanManager.getBeanResolver().resolve(beanManager.getBeans(ij));
   if (!isInjectionPointSatisfied(ij, resolvedBeans, beanManager)) {
     throw new DeploymentException(
         INJECTION_POINT_HAS_UNSATISFIED_DEPENDENCIES,
         ij,
         Formats.formatAnnotations(bindings),
         Formats.formatType(ij.getType()));
   }
   if (resolvedBeans.size() > 1 && !ij.isDelegate()) {
     throw new DeploymentException(
         INJECTION_POINT_HAS_AMBIGUOUS_DEPENDENCIES,
         ij,
         Formats.formatAnnotations(bindings),
         Formats.formatType(ij.getType()),
         resolvedBeans);
   }
   // Account for the case this is disabled decorator
   if (!resolvedBeans.isEmpty()) {
     Bean<?> resolvedBean = (Bean<?>) resolvedBeans.iterator().next();
     if (beanManager
         .getServices()
         .get(MetaAnnotationStore.class)
         .getScopeModel(resolvedBean.getScope())
         .isNormal()) {
       UnproxyableResolutionException ue = Proxies.getUnproxyableTypeException(ij.getType());
       if (ue != null) {
         UnproxyableResolutionException exception =
             new UnproxyableResolutionException(
                 INJECTION_POINT_HAS_NON_PROXYABLE_DEPENDENCIES, ij);
         exception.initCause(ue);
         throw exception;
       }
     }
     if (Reflections.isPrimitive(ij.getType()) && resolvedBean.isNullable()) {
       throw new NullableDependencyException(INJECTION_POINT_HAS_NULLABLE_DEPENDENCIES, ij);
     }
     if (bean != null
         && Beans.isPassivatingScope(bean, beanManager)
         && (!ij.isTransient())
         && !Beans.isPassivationCapableBean(resolvedBean)) {
       validateInjectionPointPassivationCapable(ij, resolvedBean, beanManager);
     }
   }
 }