3 Replies Latest reply on Dec 11, 2008 1:10 PM by alesj

    How to pick up field-level annotations in annotation plugin?

    alrubinger

      I've got an annotation plugin:

      public class EjbReferenceAnnotationPlugin extends FieldAnnotationPlugin<EJB>
      {...}


      ..which does not run through "protected ValueMetaData createValueMetaData(FieldInfo fieldInfo, EJB annotation)" upon encountering @EJB on a field-level property.

      If I change this to extend from PropertyAnnotationPlugin, accessor methods annotated w/ @EJB are picked up.

      Assuming I've given enough information to describe the disconnect, what am I missing to get field-level annotations read?

      S,
      ALR


        • 1. Re: How to pick up field-level annotations in annotation plu
          alesj

           

          "alr" wrote:
          what am I missing to get field-level annotations read?

          You need to set the correct BeanAccessMode for your bean.
          By default we don't look into fields.
          Either set bean's BeanAccessMode to FIELDS or ALL.

          • 2. Re: How to pick up field-level annotations in annotation plu
            alrubinger

             

            "alesj" wrote:
            Either set bean's BeanAccessMode to FIELDS or ALL.


            Great, thanks. ;)

            A follow-up question:

            public class Pojo
            {
             @EJB
             private Object injectedEjb;
            
             public Object getInjectedMember()
             {
             return injectedEjb;
             }
            
            }


            I must use "getInjectedMember"; using "getInjectedEjb" means the field annotation is ignored. This is expected according to docs in BeanAccessMode:

            STANDARD(BeanInfoCreator.STANDARD), // Getters and Setters
             FIELDS(BeanInfoCreator.FIELDS), // Getters/Setters and fields without getters and setters
             ALL(BeanInfoCreator.ALL); // As above but with non public fields included


            No way to get private fields with a corresponding accessor/mutator read in? Why this design (against JavaBean conventions)?

            S,
            ALR

            • 3. Re: How to pick up field-level annotations in annotation plu
              alesj

               

              "ALRubinger" wrote:

              No way to get private fields with a corresponding accessor/mutator read in?

              Perhaps we should join the metadata on field and its accessor/mutator if the BAM is FIELDS or ALL.
              Or we can easily add new BAM - it just needs BeanInfoCreator.