Example #1
0
  public BeanBuilder<T> annotation(Annotation ann) {
    if (_annotated == null) _annotated = new AnnotatedElementImpl(_managedBean.getAnnotated());

    _annotated.addAnnotation(ann);

    return this;
  }
Example #2
0
  public BeanBuilder<T> annotation(Collection<Annotation> list) {
    if (_annotated == null) _annotated = new AnnotatedElementImpl(_managedBean.getAnnotated());

    for (Annotation ann : list) {
      _annotated.addAnnotation(ann);
    }

    return this;
  }
  private ProducesMethodBean(
      InjectManager manager,
      Bean<X> producerBean,
      AnnotatedMethod<? super X> producesMethod,
      Arg<?>[] producesArgs,
      AnnotatedMethod<? super X> disposesMethod,
      Arg<?>[] disposesArgs) {
    super(manager, producesMethod.getBaseType(), producesMethod);

    _producerBean = producerBean;
    _producesMethod = producesMethod;
    _producesArgs = producesArgs;

    if (producesMethod == null) throw new NullPointerException();

    if (producesArgs == null) throw new NullPointerException();

    producesMethod.getJavaMember().setAccessible(true);

    if (disposesMethod != null) {
      _disposesProducer =
          new DisposesProducer<T, X>(
              manager, producerBean,
              disposesMethod, disposesArgs);

      for (AnnotatedParameter<? super X> param : disposesMethod.getParameters()) {
        if (param.isAnnotationPresent(Disposes.class)) _disposedParam = param;
      }
    }

    introspectInjectionPoints();

    _methodProducer = new MethodProducer();
    _producer = _methodProducer;

    Method javaMethod = producesMethod.getJavaMember();
    int modifiers = javaMethod.getModifiers();

    if (producesMethod.isAnnotationPresent(Specializes.class)) {
      if (Modifier.isStatic(modifiers)) {
        throw new ConfigException(
            L.l(
                "{0}.{1} is an invalid @Specializes @Producer because the method is static.",
                javaMethod.getDeclaringClass().getName(), javaMethod.getName()));
      }

      Method parentMethod = getSpecializedMethod(javaMethod);

      if (parentMethod == null) {
        throw new ConfigException(
            L.l(
                "{0}.{1} is an invalid @Specializes @Producer because it does not directly specialize a parent method",
                javaMethod.getDeclaringClass().getName(), javaMethod.getName()));
      }

      if (producesMethod.getJavaMember().isAnnotationPresent(Named.class)
          && parentMethod.isAnnotationPresent(Named.class)) {
        throw new ConfigException(
            L.l(
                "{0}.{1} is an invalid @Specializes @Producer because both it and its parent defines @Named",
                javaMethod.getDeclaringClass().getName(), javaMethod.getName()));
      }

      for (Annotation ann : parentMethod.getAnnotations()) {
        if (ann.annotationType().isAnnotationPresent(Qualifier.class)) {
          // ioc/07a5
          if (producesMethod instanceof AnnotatedElementImpl) {
            ((AnnotatedElementImpl) producesMethod).addAnnotation(ann);
          }
        }
      }
    }
  }