コード例 #1
0
  protected <Z extends Annotation> Z getAnnotation(
      Class<Z> annotationType,
      AnnotatedMethod<?> apiMethod,
      AnnotatedType<?> apiClass,
      AnnotatedMethod<?> implementationMethod,
      AnnotatedType<?> implementationClass) {
    Z annotation = null;

    if (apiMethod != null) {
      annotation = apiMethod.getAnnotation(annotationType);
    }

    if (annotation == null && apiClass != null) {
      annotation = apiClass.getAnnotation(annotationType);
    }

    if ((annotation == null) && (implementationMethod != null)) {
      annotation = implementationMethod.getAnnotation(annotationType);
    }

    if ((annotation == null) && (implementationClass != null)) {
      annotation = implementationClass.getAnnotation(annotationType);
    }

    return annotation;
  }
コード例 #2
0
  @Override
  public ConfigProgram introspectType(AnnotatedType<?> type) {
    for (Class<?> parentClass = type.getJavaClass().getSuperclass();
        parentClass != null;
        parentClass = parentClass.getSuperclass()) {
      Resources resources = parentClass.getAnnotation(Resources.class);

      if (resources != null) {
        for (Resource resource : resources.value()) {
          introspectClass(getClass().getName(), resource);
        }
      }

      Resource resource = parentClass.getAnnotation(Resource.class);

      if (resource != null) introspectClass(getClass().getName(), resource);
    }

    Resources resources = type.getAnnotation(Resources.class);

    if (resources != null) {
      for (Resource resource : resources.value()) {
        introspectClass(getClass().getName(), resource);
      }
    }

    Resource resource = type.getAnnotation(Resource.class);

    if (resource != null) introspectClass(getClass().getName(), resource);

    return new NullProgram();
  }
コード例 #3
0
  protected <Z extends Annotation> Z getAnnotation(
      Class<Z> annotationType, AnnotatedType<?> apiClass, AnnotatedType<?> implClass) {
    Z annotation = null;

    if (apiClass != null) annotation = apiClass.getAnnotation(annotationType);

    if ((annotation == null) && (implClass != null)) {
      annotation = implClass.getAnnotation(annotationType);
    }

    return annotation;
  }
コード例 #4
0
 <T, X> void registerGenericBeanObserverMethod(@Observes ProcessObserverMethod<T, X> event) {
   AnnotatedType<X> declaringType = event.getAnnotatedMethod().getDeclaringType();
   if (declaringType.isAnnotationPresent(GenericConfiguration.class)) {
     AnnotatedMethod<X> method = event.getAnnotatedMethod();
     Class<? extends Annotation> genericConfigurationType =
         declaringType.getAnnotation(GenericConfiguration.class).value();
     genericBeanObserverMethods.put(
         genericConfigurationType,
         new ObserverMethodHolder<X, T>(method, event.getObserverMethod()));
   }
 }
 <X> void processType(@Observes ProcessAnnotatedType<X> event) {
   AnnotatedType<X> original = event.getAnnotatedType();
   if (original.isAnnotationPresent(ManagedBean.class)
       && !original.isAnnotationPresent(Named.class)) {
     AnnotatedType<X> modified =
         new AnnotatedTypeBuilder<X>()
             .readFromType(event.getAnnotatedType(), true)
             .addToClass(new NamedLiteral(original.getAnnotation(ManagedBean.class).value()))
             .create();
     event.setAnnotatedType(modified);
   }
 }
コード例 #6
0
 <X, T> void registerGenericBeanProducerMethod(@Observes ProcessProducerMethod<X, T> event) {
   AnnotatedType<X> declaringType = event.getAnnotatedProducerMethod().getDeclaringType();
   Annotation genericConfiguration = getGenericConfiguration(event.getAnnotated());
   if (declaringType.isAnnotationPresent(GenericConfiguration.class)) {
     genericBeanProducerMethods.put(
         declaringType.getAnnotation(GenericConfiguration.class).value(),
         getProducerMethodHolder(event));
   } else if (genericConfiguration != null) {
     if (validateGenericProducer(
         genericConfiguration, event.getBean(), event.getAnnotatedProducerMethod())) {
       genericProducerBeans.put(event.getAnnotatedProducerMethod(), event.getBean());
     }
   }
 }
コード例 #7
0
 <X> void registerGenericBean(@Observes ProcessManagedBean<X> event) {
   AnnotatedType<X> type = event.getAnnotatedBeanClass();
   if (type.isAnnotationPresent(GenericConfiguration.class)) {
     Class<? extends Annotation> genericType =
         type.getAnnotation(GenericConfiguration.class).value();
     genericBeans.put(
         genericType, new BeanHolder<X>(event.getAnnotatedBeanClass(), event.getBean()));
     for (AnnotatedMethod<? super X> m : event.getAnnotatedBeanClass().getMethods()) {
       if (m.isAnnotationPresent(Unwraps.class)) {
         unwrapsMethods.put(genericType, m);
       }
     }
   }
 }
コード例 #8
0
  <X, T> void registerGenericBeanProducerField(@Observes ProcessProducerField<X, T> event) {

    AnnotatedType<X> declaringType = event.getAnnotatedProducerField().getDeclaringType();
    Annotation genericConfiguration = getGenericConfiguration(event.getAnnotated());
    if (declaringType.isAnnotationPresent(GenericConfiguration.class)) {
      AnnotatedField<X> field = event.getAnnotatedProducerField();
      Class<? extends Annotation> genericConfigurationType =
          declaringType.getAnnotation(GenericConfiguration.class).value();
      genericBeanProducerFields.put(
          genericConfigurationType, new FieldHolder<X, T>(field, event.getBean()));
    } else if (genericConfiguration != null) {
      if (validateGenericProducer(
          genericConfiguration, event.getBean(), event.getAnnotatedProducerField())) {
        genericProducerBeans.put(event.getAnnotatedProducerField(), event.getBean());
      }
    }
  }
コード例 #9
0
  @Override
  public ConfigProgram introspectType(AnnotatedType<?> type) {
    PersistenceContext pContext = type.getAnnotation(PersistenceContext.class);

    String location = type.getJavaClass().getName() + ": ";

    String jndiName = null;

    if (!"".equals(pContext.name())) jndiName = pContext.name();

    Bean<?> bean = bindEntityManager(location, pContext);

    BeanValueGenerator gen = new BeanValueGenerator(location, bean);

    if (jndiName != null) bindJndi(jndiName, gen, null);

    return new NullProgram();
  }
コード例 #10
0
  <X> void replaceInjectOnGenericBeans(@Observes ProcessAnnotatedType<X> event) {
    AnnotatedType<X> type = event.getAnnotatedType();
    if (type.isAnnotationPresent(GenericConfiguration.class)) {
      final Class<? extends Annotation> genericConfigurationType =
          type.getAnnotation(GenericConfiguration.class).value();
      // validate that the configuration type is annotated correctly
      if (!genericConfigurationType.isAnnotationPresent(GenericType.class)) {
        errors.add(
            "Bean "
                + type.getJavaClass().getName()
                + " specifies generic annotation "
                + type.getAnnotation(GenericConfiguration.class)
                + " however "
                + genericConfigurationType
                + " is not annotated @GenericConfiguration.");
      } else {
        Class<?> configType = genericConfigurationType.getAnnotation(GenericType.class).value();
        if (configType.isAnnotationPresent(GenericConfiguration.class)) {
          errors.add(
              "Generic configuration type "
                  + genericConfigurationType
                  + " specifies a value() of "
                  + configType
                  + " however "
                  + configType
                  + " is a generic bean. Generic configuration types may not be generic beans");
        }
      }

      final AnnotatedTypeBuilder<X> builder = new AnnotatedTypeBuilder<X>().readFromType(type);
      builder.addToClass(genericBeanQualifier);
      builder.redefine(
          Inject.class,
          new AnnotationRedefiner<Inject>() {

            public void redefine(RedefinitionContext<Inject> ctx) {
              if (ctx.getAnnotatedElement() instanceof Field) {
                if (ctx.getAnnotatedElement().isAnnotationPresent(Generic.class)) {
                  // This is a Generic bean injection point
                  ctx.getAnnotationBuilder()
                      .remove(Inject.class)
                      .add(InjectGenericLiteral.INSTANCE);
                }
              }
            }
          });
      builder.redefine(
          Produces.class,
          new AnnotationRedefiner<Produces>() {

            public void redefine(RedefinitionContext<Produces> ctx) {
              // Add the marker qualifier
              ctx.getAnnotationBuilder()
                  .add(GenericMarkerLiteral.INSTANCE)
                  .add(genericBeanQualifier);
            }
          });
      builder.redefine(
          Disposes.class,
          new AnnotationRedefiner<Disposes>() {

            public void redefine(RedefinitionContext<Disposes> ctx) {
              // Add the marker qualifier
              ctx.getAnnotationBuilder()
                  .add(GenericMarkerLiteral.INSTANCE)
                  .add(genericBeanQualifier);
            }
          });

      builder.redefine(
          Generic.class,
          new AnnotationRedefiner<Generic>() {
            public void redefine(RedefinitionContext<Generic> ctx) {
              // if it is a parameter annotation
              if (!(ctx.getAnnotatedElement() instanceof AccessibleObject)) {
                // stick an InjectGeneric as a marker.
                ctx.getAnnotationBuilder().remove(Generic.class).add(InjectGenericLiteral.INSTANCE);
                if (ctx.getRawType().isAnnotationPresent(GenericConfiguration.class)) {
                  ctx.getAnnotationBuilder().add(genericBeanQualifier);
                }
              }
            }
          });
      event.setAnnotatedType(builder.create());
    }
  }