Esempio n. 1
0
 static Class<?> getDeclaringRawType(InjectionPoint injectionPoint) {
   if (injectionPoint.getBean() != null) {
     return getRawType(injectionPoint.getBean().getBeanClass());
   } else {
     return getRawType(injectionPoint.getMember().getDeclaringClass());
   }
 }
Esempio n. 2
0
 private static boolean isInjectionPointSatisfied(
     InjectionPoint ij, Set<?> resolvedBeans, BeanManagerImpl beanManager) {
   if (ij.getBean() instanceof Decorator<?>) {
     if (beanManager.getEnabled().getDecorator(ij.getBean().getBeanClass()) != null) {
       return resolvedBeans.size() > 0;
     } else {
       return true;
     }
   } else {
     return resolvedBeans.size() > 0;
   }
 }
Esempio n. 3
0
 public void validateInjectionPointPassivationCapable(
     InjectionPoint ij, Bean<?> resolvedBean, BeanManagerImpl beanManager) {
   if (!ij.isTransient() && !Beans.isPassivationCapableDependency(resolvedBean)) {
     if (resolvedBean.getScope().equals(Dependent.class)
         && resolvedBean instanceof AbstractProducerBean<?, ?, ?>) {
       throw new IllegalProductException(
           NON_SERIALIZABLE_BEAN_INJECTED_INTO_PASSIVATING_BEAN, ij.getBean(), resolvedBean);
     }
     throw new UnserializableDependencyException(
         INJECTION_POINT_HAS_NON_SERIALIZABLE_DEPENDENCY, ij.getBean(), resolvedBean);
   }
 }
Esempio n. 4
0
 private void validateInjectionPoints(Set<InjectionPoint> injectionPoints) {
   assertEquals(2, injectionPoints.size());
   for (InjectionPoint ip : injectionPoints) {
     AnnotatedParameter<Factory> parameter =
         this.<AnnotatedParameter<Factory>>cast(ip.getAnnotated());
     if (parameter.getPosition() == 0) {
       // BeanManager
       assertEquals(BeanManager.class, parameter.getBaseType());
     } else if (parameter.getPosition() == 1) {
       // SpaceSuit<Toy>
       Type baseType = parameter.getBaseType();
       if (baseType instanceof ParameterizedType
           && ((ParameterizedType) baseType).getRawType() instanceof Class<?>) {
         assertEquals(((ParameterizedType) baseType).getRawType(), SpaceSuit.class);
       } else {
         fail();
       }
     } else {
       fail("Unexpected injection point " + ip);
     }
     assertFalse(ip.isDelegate());
     assertFalse(ip.isTransient());
     assertNull(ip.getBean());
   }
 }
Esempio n. 5
0
  @Produces
  public Logger produceLogger(InjectionPoint injectionPoint) {
    Bean<?> bean = injectionPoint.getBean();
    Class<?> clazz;

    if (bean == null) {
      clazz = injectionPoint.getMember().getDeclaringClass();
    } else {
      clazz = bean.getBeanClass();
    }

    return produceLogger(clazz);
  }
  private void validatePassivating(Bean<?> bean) {
    Type baseType = _annotatedType.getBaseType();

    Class<?> cl = getBeanManager().createTargetBaseType(baseType).getRawClass();
    boolean isStateful = _annotatedType.isAnnotationPresent(Stateful.class);

    if (!Serializable.class.isAssignableFrom(cl) && !isStateful) {
      throw new ConfigException(
          L.l(
              "'{0}' is an invalid @{1} bean because it's not serializable for {2}.",
              cl.getSimpleName(), bean.getScope().getSimpleName(), bean));
    }

    for (InjectionPoint ip : bean.getInjectionPoints()) {
      if (ip.isTransient()) continue;

      Type type = ip.getType();

      if (ip.getBean() instanceof CdiStatefulBean) continue;

      if (type instanceof Class<?>) {
        Class<?> ipClass = (Class<?>) type;

        if (!ipClass.isInterface()
            && !Serializable.class.isAssignableFrom(ipClass)
            && !getBeanManager().isNormalScope(ip.getBean().getScope())) {
          throw new ConfigException(
              L.l(
                  "'{0}' is an invalid @{1} bean because '{2}' value {3} is not serializable for {4}.",
                  cl.getSimpleName(),
                  bean.getScope().getSimpleName(),
                  ip.getType(),
                  ip.getMember().getName(),
                  bean));
        }
      }
    }
  }
Esempio n. 7
0
 /**
  * Produces an instance of a slf4j logger for the given injection point.
  *
  * @param injectionPoint to use
  * @return a logger
  */
 @Produces
 public Logger getLogger(final InjectionPoint injectionPoint) {
   // The injection point is used to instantiate the correct logger for the
   // caller class.
   Bean<?> bean = injectionPoint.getBean();
   Logger l = null;
   if (bean != null) {
     Class<?> beanClass = bean.getBeanClass();
     l = LoggerFactory.getLogger(beanClass);
   } else {
     l = LoggerFactory.getLogger("Default logger");
   }
   return l;
 }
  @Produces
  public Configuration getConfiguration(final InjectionPoint injectionPoint) {

    Context context;
    String defaultName;

    // try CDI bean name
    defaultName = injectionPoint.getBean() != null ? injectionPoint.getBean().getName() : null;

    // try field / method name
    if (StringHelper.isEmpty(defaultName)) {
      defaultName = injectionPoint.getMember().getName();
    }

    // context needed annotation
    context = injectionPoint.getAnnotated().getAnnotation(Context.class);

    // if no @Context annotation is present, create a default one with no name
    if (context == null) {
      context = ContextHelper.createContext(defaultName);
    }

    return provides(context, defaultName, Configuration.class);
  }
 public void validateProducer(Producer<?> producer) {
   if (container.getState().equals(ContainerState.VALIDATED)
       || container.getState().equals(ContainerState.INITIALIZED)) {
     // We are past the bootstrap and therefore we can validate the producer immediately
     validator.validateProducer(producer, beanManager);
   } else {
     // Validate injection points for definition errors now
     for (InjectionPoint ip : producer.getInjectionPoints()) {
       validator.validateInjectionPointForDefinitionErrors(ip, ip.getBean(), beanManager);
       validator.validateEventMetadataInjectionPoint(ip);
     }
     // Schedule validation for deployment problems to be done later
     producersToValidate.add(producer);
   }
 }
Esempio n. 10
0
 /**
  * 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);
 }