예제 #1
0
파일: Validator.java 프로젝트: edpzjh/core
  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);
              }
            }
          }
        }
      }
    }
  }
예제 #2
0
파일: Validator.java 프로젝트: edpzjh/core
 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);
           }
         }
       }
     }
   }
 }
예제 #3
0
파일: Validator.java 프로젝트: edpzjh/core
 /**
  * Validate an RIBean. This includes validating whether two beans specialize the same bean
  *
  * @param bean the bean to validate
  * @param beanManager the current manager
  * @param specializedBeans the existing specialized beans
  */
 private void validateRIBean(
     RIBean<?> bean, BeanManagerImpl beanManager, Collection<RIBean<?>> specializedBeans) {
   validateBean(bean, beanManager);
   if (!(bean instanceof NewManagedBean<?>) && !(bean instanceof NewSessionBean<?>)) {
     RIBean<?> abstractBean = bean;
     if (abstractBean.isSpecializing()) {
       if (specializedBeans.contains(abstractBean.getSpecializedBean())) {
         throw new InconsistentSpecializationException(BEAN_SPECIALIZED_TOO_MANY_TIMES, bean);
       }
       specializedBeans.add(abstractBean.getSpecializedBean());
     }
     if ((bean instanceof AbstractClassBean<?>)) {
       AbstractClassBean<?> classBean = (AbstractClassBean<?>) bean;
       if (classBean.hasDecorators()) {
         validateDecorators(beanManager, classBean);
       }
       // validate CDI-defined interceptors
       if (classBean.hasInterceptors()) {
         validateInterceptors(beanManager, classBean);
       }
     }
     // for each producer method validate its disposer method
     if (bean instanceof ProducerMethod<?, ?>
         && ((ProducerMethod<?, ?>) bean).getDisposalMethod() != null) {
       DisposalMethod<?, ?> disposalMethod = ((ProducerMethod<?, ?>) bean).getDisposalMethod();
       for (InjectionPoint ip : disposalMethod.getInjectionPoints()) {
         // pass the producer bean instead of the disposal method bean
         validateInjectionPoint(ip, bean, beanManager);
       }
     }
   }
 }
예제 #4
0
파일: Validator.java 프로젝트: edpzjh/core
 private void validateBean(Bean<?> bean, BeanManagerImpl beanManager) {
   for (InjectionPoint ij : bean.getInjectionPoints()) {
     validateInjectionPoint(ij, beanManager);
   }
   boolean normalScoped =
       beanManager
           .getServices()
           .get(MetaAnnotationStore.class)
           .getScopeModel(bean.getScope())
           .isNormal();
   if (normalScoped && !Beans.isBeanProxyable(bean)) {
     throw Proxies.getUnproxyableTypesException(bean);
   }
   if (!normalScoped) {
     validatePseudoScopedBean(bean, beanManager);
   }
 }
예제 #5
0
파일: Validator.java 프로젝트: edpzjh/core
 private void validateObserverMethods(
     Iterable<ObserverMethodImpl<?, ?>> observers, BeanManagerImpl beanManager) {
   for (ObserverMethodImpl<?, ?> omi : observers) {
     for (InjectionPoint ip : omi.getInjectionPoints()) validateInjectionPoint(ip, beanManager);
   }
 }
예제 #6
0
파일: Validator.java 프로젝트: edpzjh/core
 public void validateInjectionTarget(
     InjectionTarget<?> injectionTarget, BeanManagerImpl beanManager) {
   for (InjectionPoint injectionPoint : injectionTarget.getInjectionPoints()) {
     validateInjectionPoint(injectionPoint, beanManager);
   }
 }
예제 #7
0
파일: Validator.java 프로젝트: edpzjh/core
 /**
  * Validate an injection point
  *
  * @param ij the injection point to validate
  * @param beanManager the bean manager
  */
 public void validateInjectionPoint(InjectionPoint ij, BeanManagerImpl beanManager) {
   validateInjectionPoint(ij, ij.getBean(), beanManager);
 }