Exemplo n.º 1
0
 @Produces
 Logger produceLog(InjectionPoint injectionPoint) {
   Annotated annotated = injectionPoint.getAnnotated();
   if (annotated.isAnnotationPresent(Category.class)) {
     if (annotated.isAnnotationPresent(Suffix.class)) {
       return getLogger(
           annotated.getAnnotation(Category.class).value(),
           annotated.getAnnotation(Suffix.class).value());
     } else {
       return getLogger(annotated.getAnnotation(Category.class).value());
     }
   } else if (annotated.isAnnotationPresent(TypedCategory.class)) {
     if (annotated.isAnnotationPresent(Suffix.class)) {
       return getLogger(
           annotated.getAnnotation(TypedCategory.class).value(),
           annotated.getAnnotation(Suffix.class).value());
     } else {
       return getLogger(annotated.getAnnotation(TypedCategory.class).value());
     }
   } else {
     if (annotated.isAnnotationPresent(Suffix.class)) {
       return getLogger(
           getDeclaringRawType(injectionPoint), annotated.getAnnotation(Suffix.class).value());
     } else {
       return getLogger(getDeclaringRawType(injectionPoint));
     }
   }
 }
Exemplo n.º 2
0
  private Arg<X> introspectArg(Annotated ann, AnnotatedParameter<X> param) {
    Annotation[] qualifiers = getQualifiers(param);

    InjectionPoint ip = new InjectionPointImpl<X>(getBeanManager(), this, param);

    if (ann.isAnnotationPresent(Inject.class)) {
      // ioc/022k
      _injectionPointSet.add(ip);
    }

    if (param.isAnnotationPresent(Disposes.class)) {
      throw new ConfigException(
          L.l(
              "{0} is an invalid managed bean because its constructor has a @Disposes parameter",
              getAnnotatedType().getJavaClass().getName()));
    }

    if (param.isAnnotationPresent(Observes.class)) {
      throw new ConfigException(
          L.l(
              "{0} is an invalid managed bean because its constructor has an @Observes parameter",
              getAnnotatedType().getJavaClass().getName()));
    }

    return new BeanArg<X>(getBeanManager(), param.getBaseType(), qualifiers, ip);
  }
Exemplo n.º 3
0
  /**
   * Finds an annotation in an Annotated, taking stereo types into account
   *
   * @param beanManager the current bean manager
   * @param annotated the Annotated in which to search
   * @param annotationType the type of the annotation to search for
   * @return An Optional that contains an instance of annotation type for which was searched if the
   *     annotated contained this.
   */
  public static <A extends Annotation> Optional<A> getAnnotation(
      BeanManager beanManager, Annotated annotated, Class<A> annotationType) {

    annotated.getAnnotation(annotationType);

    if (annotated.getAnnotations().isEmpty()) {
      return empty();
    }

    if (annotated.isAnnotationPresent(annotationType)) {
      return Optional.of(annotated.getAnnotation(annotationType));
    }

    Queue<Annotation> annotations = new LinkedList<>(annotated.getAnnotations());

    while (!annotations.isEmpty()) {
      Annotation annotation = annotations.remove();

      if (annotation.annotationType().equals(annotationType)) {
        return Optional.of(annotationType.cast(annotation));
      }

      if (beanManager.isStereotype(annotation.annotationType())) {
        annotations.addAll(beanManager.getStereotypeDefinition(annotation.annotationType()));
      }
    }

    return empty();
  }
  <T> void saveRemoteInjectionPoints(
      @Observes ProcessInjectionTarget<T> event, BeanManager beanManager) {
    final InjectionTarget<T> injectionTarget = event.getInjectionTarget();

    for (InjectionPoint injectionPoint : injectionTarget.getInjectionPoints()) {
      final Annotated annotated = injectionPoint.getAnnotated();
      final Type type = annotated.getBaseType();
      final Class<?> rawType = Reflections.getRawType(annotated.getBaseType());
      final Set<Annotation> qualifiers =
          Reflections.getQualifiers(beanManager, annotated.getAnnotations());

      if (rawType.equals(RemoteCache.class) && qualifiers.isEmpty()) {
        qualifiers.add(new AnnotationLiteral<Default>() {});
        addRemoteCacheInjectionPoint(type, qualifiers);

      } else if (!annotated.isAnnotationPresent(Remote.class)
          && Reflections.getMetaAnnotation(annotated, Remote.class) != null
          && rawType.isAssignableFrom(RemoteCache.class)) {

        addRemoteCacheInjectionPoint(type, qualifiers);
      }
    }
  }
 /** Adds the stereotypes from the bean's annotations */
 @Override
 protected void introspectSpecializes(Annotated annotated) {
   if (!annotated.isAnnotationPresent(Specializes.class)) return;
 }