コード例 #1
0
  private void introspectInjectField(
      AnnotatedType<X> type, ArrayList<ConfigProgram> injectProgramList) {
    for (AnnotatedField<?> field : type.getFields()) {
      if (field.getAnnotations().size() == 0) continue;

      if (field.isAnnotationPresent(Inject.class)) {
        // boolean isOptional = isQualifierOptional(field);

        InjectionPoint ij = new InjectionPointImpl(getBeanManager(), this, field);

        _injectionPointSet.add(ij);

        if (field.isAnnotationPresent(Delegate.class)) {
          // ioc/0i60
          /*
          if (! type.isAnnotationPresent(javax.decorator.Decorator.class)) {
            throw new IllegalStateException(L.l("'{0}' may not inject with @Delegate because it is not a @Decorator",
                                                type.getJavaClass()));
          }
             */
        } else {
          injectProgramList.add(new FieldInjectProgram(field.getJavaMember(), ij));
        }
      } else {
        InjectionPointHandler handler = getBeanManager().getInjectionPointHandler(field);

        if (handler != null) {
          ConfigProgram program = new FieldHandlerProgram(field, handler);

          injectProgramList.add(program);
        }
      }
    }
  }
コード例 #2
0
ファイル: AnnotatedTypes.java プロジェクト: nmansard/core
  /** Compares two annotated types and returns true if they are the same */
  public static boolean compareAnnotatedTypes(AnnotatedType<?> t1, AnnotatedType<?> t2) {
    if (!t1.getJavaClass().equals(t2.getJavaClass())) {
      return false;
    }
    if (!compareAnnotated(t1, t2)) {
      return false;
    }

    if (t1.getFields().size() != t2.getFields().size()) {
      return false;
    }
    Map<Field, AnnotatedField<?>> fields = new HashMap<Field, AnnotatedField<?>>();
    for (AnnotatedField<?> f : t2.getFields()) {
      fields.put(f.getJavaMember(), f);
    }
    for (AnnotatedField<?> f : t1.getFields()) {
      if (fields.containsKey(f.getJavaMember())) {
        if (!compareAnnotatedField(f, fields.get(f.getJavaMember()))) {
          return false;
        }
      } else {
        return false;
      }
    }

    if (t1.getMethods().size() != t2.getMethods().size()) {
      return false;
    }
    Map<Method, AnnotatedMethod<?>> methods = new HashMap<Method, AnnotatedMethod<?>>();
    for (AnnotatedMethod<?> f : t2.getMethods()) {
      methods.put(f.getJavaMember(), f);
    }
    for (AnnotatedMethod<?> f : t1.getMethods()) {
      if (methods.containsKey(f.getJavaMember())) {
        if (!compareAnnotatedCallable(f, methods.get(f.getJavaMember()))) {
          return false;
        }
      } else {
        return false;
      }
    }
    if (t1.getConstructors().size() != t2.getConstructors().size()) {
      return false;
    }
    Map<Constructor<?>, AnnotatedConstructor<?>> constructors =
        new HashMap<Constructor<?>, AnnotatedConstructor<?>>();
    for (AnnotatedConstructor<?> f : t2.getConstructors()) {
      constructors.put(f.getJavaMember(), f);
    }
    for (AnnotatedConstructor<?> f : t1.getConstructors()) {
      if (constructors.containsKey(f.getJavaMember())) {
        if (!compareAnnotatedCallable(f, constructors.get(f.getJavaMember()))) {
          return false;
        }
      } else {
        return false;
      }
    }
    return true;
  }
コード例 #3
0
ファイル: Reflections.java プロジェクト: CODE4US/rewrite
 /**
  * Search the annotatedType for the field, returning the {@link AnnotatedField}
  *
  * @param annotatedType The annotatedType to search
  * @param field the field to search for
  * @return The {@link AnnotatedField} found, or null if no field is found
  */
 public static <X> AnnotatedField<? super X> getField(
     AnnotatedType<X> annotatedType, Field field) {
   for (AnnotatedField<? super X> annotatedField : annotatedType.getFields()) {
     if (annotatedField.getDeclaringType().getJavaClass().equals(field.getDeclaringClass())
         && annotatedField.getJavaMember().getName().equals(field.getName())) {
       return annotatedField;
     }
   }
   return null;
 }
コード例 #4
0
 public static <X, Y extends X> AnnotatedField<X> of(
     AnnotatedField<X> originalField,
     UnbackedAnnotatedType<Y> declaringType,
     SharedObjectCache cache) {
   UnbackedAnnotatedType<X> downcastDeclaringType = cast(declaringType);
   return new UnbackedAnnotatedField<X>(
       originalField.getBaseType(),
       originalField.getTypeClosure(),
       cache.getSharedSet(originalField.getAnnotations()),
       originalField.getJavaMember(),
       downcastDeclaringType);
 }
コード例 #5
0
 /**
  * Instantiate a new {@link InjectionPoint} based upon an {@link AnnotatedField}, reading the
  * qualifiers from the annotations declared on the field.
  *
  * @param field the field for which to create the injection point
  * @param declaringBean the declaringBean declaring the injection point
  * @param isTransient <code>true</code> if the injection point is transient
  * @param delegate <code>true</code> if the injection point is a delegate injection point on a
  *     decorator
  */
 public ImmutableInjectionPoint(
     AnnotatedField<?> field,
     BeanManager beanManager,
     Bean<?> declaringBean,
     boolean isTransient,
     boolean delegate) {
   annotated = field;
   member = field.getJavaMember();
   qualifiers = BeanUtils.getQualifiers(beanManager, field.getAnnotations());
   type = field.getJavaMember().getGenericType();
   this.isTransient = isTransient;
   this.delegate = delegate;
   this.declaringBean = declaringBean;
 }
コード例 #6
0
 /**
  * Instantiate a new {@link InjectionPoint} based upon an {@link AnnotatedField}.
  *
  * @param field the field for which to create the injection point
  * @param qualifiers the qualifiers on the injection point
  * @param declaringBean the declaringBean declaring the injection point
  * @param isTransient <code>true</code> if the injection point is transient
  * @param delegate <code>true</code> if the injection point is a delegate injection point on a
  *     decorator
  */
 public ImmutableInjectionPoint(
     AnnotatedField<?> field,
     Set<Annotation> qualifiers,
     Bean<?> declaringBean,
     boolean isTransient,
     boolean delegate) {
   annotated = field;
   member = field.getJavaMember();
   this.qualifiers = new HashSet<Annotation>(qualifiers);
   type = field.getJavaMember().getGenericType();
   this.isTransient = isTransient;
   this.delegate = delegate;
   this.declaringBean = declaringBean;
 }
コード例 #7
0
ファイル: AnnotatedTypes.java プロジェクト: nmansard/core
  /**
   * Generates a unique signature for a concrete class
   *
   * @param <X>
   * @param annotatedType
   * @return
   */
  public static <X> String createTypeId(
      Class<X> clazz,
      Collection<Annotation> annotations,
      Collection<AnnotatedMethod<? super X>> methods,
      Collection<AnnotatedField<? super X>> fields,
      Collection<AnnotatedConstructor<X>> constructors) {
    StringBuilder builder = new StringBuilder();

    builder.append(clazz.getName());
    builder.append(createAnnotationCollectionId(annotations));
    builder.append("{");

    // now deal with the fields
    List<AnnotatedField<? super X>> sortedFields = new ArrayList<AnnotatedField<? super X>>();
    sortedFields.addAll(fields);
    Collections.sort(sortedFields, AnnotatedFieldComparator.<X>instance());
    for (AnnotatedField<? super X> field : sortedFields) {
      if (!field.getAnnotations().isEmpty()) {
        builder.append(createFieldId(field));
        builder.append(SEPERATOR);
      }
    }

    // methods
    List<AnnotatedMethod<? super X>> sortedMethods = new ArrayList<AnnotatedMethod<? super X>>();
    sortedMethods.addAll(methods);
    Collections.sort(sortedMethods, AnnotatedMethodComparator.<X>instance());
    for (AnnotatedMethod<? super X> method : sortedMethods) {
      if (!method.getAnnotations().isEmpty() || hasMethodParameters(method)) {
        builder.append(createCallableId(method));
        builder.append(SEPERATOR);
      }
    }

    // constructors
    List<AnnotatedConstructor<? super X>> sortedConstructors =
        new ArrayList<AnnotatedConstructor<? super X>>();
    sortedConstructors.addAll(constructors);
    Collections.sort(sortedConstructors, AnnotatedConstructorComparator.<X>instance());
    for (AnnotatedConstructor<? super X> constructor : sortedConstructors) {
      if (!constructor.getAnnotations().isEmpty() || hasMethodParameters(constructor)) {
        builder.append(createCallableId(constructor));
        builder.append(SEPERATOR);
      }
    }
    builder.append("}");

    return builder.toString();
  }
コード例 #8
0
 @SuppressWarnings("unchecked")
 private <X, A extends AnnotatedMember<? super X>> A getAnnotatedMember(
     Class<X> javaClass, String memberName) {
   AnnotatedType<X> type = getCurrentManager().createAnnotatedType(javaClass);
   for (AnnotatedField<? super X> field : type.getFields()) {
     if (field.getJavaMember().getName().equals(memberName)) {
       return (A) field;
     }
   }
   for (AnnotatedMethod<? super X> method : type.getMethods()) {
     if (method.getJavaMember().getName().equals(memberName)) {
       return (A) method;
     }
   }
   throw new IllegalArgumentException("Member " + memberName + " not found on " + javaClass);
 }
コード例 #9
0
  @Override
  public ConfigProgram introspectField(AnnotatedField<?> field) {
    Resource resource = field.getAnnotation(Resource.class);

    Field javaField = field.getJavaMember();

    String loc = getLocation(javaField);

    String jndiName = javaField.getDeclaringClass().getName() + "/" + javaField.getName();
    Class<?> bindType = javaField.getType();

    ValueGenerator gen = generateContext(loc, bindType, jndiName, resource);

    bindJndi(javaField, gen);

    return new FieldGeneratorProgram(field.getJavaMember(), gen);
  }
コード例 #10
0
ファイル: AnnotatedTypes.java プロジェクト: nmansard/core
 public int compare(AnnotatedField<? super T> arg0, AnnotatedField<? super T> arg1) {
   if (arg0.getJavaMember().getName().equals(arg1.getJavaMember().getName())) {
     return arg0.getJavaMember()
         .getDeclaringClass()
         .getName()
         .compareTo(arg1.getJavaMember().getDeclaringClass().getName());
   }
   return arg0.getJavaMember().getName().compareTo(arg1.getJavaMember().getName());
 }
コード例 #11
0
  @Override
  public ConfigProgram introspectField(AnnotatedField<?> field) {
    PersistenceContext pContext = field.getAnnotation(PersistenceContext.class);

    PersistenceContextType type = pContext.type();

    Field javaField = field.getJavaMember();
    String location = getLocation(javaField);

    if (!javaField.getType().isAssignableFrom(EntityManager.class)) {
      throw new ConfigException(
          L.l(
              "{0}: @PersistenceContext field must be assignable from EntityManager.",
              getLocation(javaField)));
    }

    ValueGenerator gen;

    if (PersistenceContextType.EXTENDED.equals(type))
      gen = generateExtendedContext(location, pContext);
    else gen = generateTransactionContext(location, pContext);

    return new FieldGeneratorProgram(javaField, gen);
  }
コード例 #12
0
 private <X, T> Bean<T> createGenericProducerField(
     Bean<T> originalBean,
     GenericIdentifier identifier,
     AnnotatedField<X> field,
     BeanManager beanManager,
     Class<? extends Annotation> scopeOverride,
     boolean alternative,
     Class<?> javaClass) {
   Set<Annotation> declaringBeanQualifiers =
       getQualifiers(beanManager, identifier, originalBean.getQualifiers());
   Set<Annotation> qualifiers = getQualifiers(beanManager, identifier, field.getAnnotations());
   return new GenericProducerField<T, X>(
       originalBean,
       identifier,
       field,
       declaringBeanQualifiers,
       qualifiers,
       scopeOverride,
       alternative,
       javaClass,
       beanManager);
 }
コード例 #13
0
 public Field getJavaMember() {
   return delegate.getJavaMember();
 }
コード例 #14
0
ファイル: AnnotatedTypes.java プロジェクト: nmansard/core
 public static <X> String createFieldId(AnnotatedField<X> field) {
   return createFieldId(field.getJavaMember(), field.getAnnotations());
 }
コード例 #15
0
ファイル: AnnotatedTypes.java プロジェクト: nmansard/core
 public static boolean compareAnnotatedField(AnnotatedField<?> f1, AnnotatedField<?> f2) {
   if (!f1.getJavaMember().equals(f2.getJavaMember())) {
     return false;
   }
   return compareAnnotated(f1, f2);
 }
コード例 #16
0
 public boolean isStatic() {
   return delegate.isStatic();
 }
コード例 #17
0
 @Override
 public <T extends Annotation> Set<T> getAnnotations(Class<T> annotationType) {
   return delegate.getAnnotations(annotationType);
 }