9 Replies Latest reply on Feb 17, 2009 8:53 AM by Carlo de Wolf

    How to add Annotation Plugin?

    Andrew Rubinger Master

      I'm currently adding my annotation plugin like:

      // Add our annotation plugin
       BeanAnnotationAdapter beanAnnotationAdapter = BeanAnnotationAdapterFactory.getInstance()
       .getBeanAnnotationAdapter();
       AbstractBeanAnnotationAdapter abstractAdapter = (AbstractBeanAnnotationAdapter) beanAnnotationAdapter; //FIXME Relies on implementation internals
       abstractAdapter.addAnnotationPlugin(EjbReferenceAnnotationPlugin.INSTANCE); //FIXME


      Requiring this cast to AbstractBeanAnnotationAdapter brings me out of interface-centric programming and into MC internals. Is there a better way where this approach may be avoided?

      S,
      ALR

        • 1. Re: How to add Annotation Plugin?
          Ales Justin Master

           

          "alr" wrote:
          Is there a better way where this approach may be avoided?

          Register BeanAnnotationAdapter singleton instance as MC bean.
          Then add its add/remove plugin methods as callbacks.
          And register your custom EJB plugin as MC bean as well.
          It will be then auto-magically :-) picked up by BAA.

          • 2. Re: How to add Annotation Plugin?
            Andrew Rubinger Master

            Yes, was hoping for this auto-registration much like is done when installing a KernelRegistryPlugin (ie. picks up the interface and takes appropriate action).

            So the following works:

            // Install the BeanAnnotationAdapter w/ callback to add annotation plugins on install
             BeanAnnotationAdapter beanAnnotationAdapter = BeanAnnotationAdapterFactory.getInstance()
             .getBeanAnnotationAdapter();
             String beanAnnotationAdapterBindName = "ejb3.BeanAnnotationAdapter";
             BeanMetaDataBuilder bmdb = BeanMetaDataBuilder.createBuilder(beanAnnotationAdapterBindName, beanAnnotationAdapter
             .getClass().getName());
             bmdb.addMethodInstallCallback("addAnnotationPlugin");
             controller.install(bmdb.getBeanMetaData(), beanAnnotationAdapter);


            ...course, I still gotta hardcode that "addAnnotationPlugin" method as a String... ;)

            S,
            ALR

            • 3. Re: How to add Annotation Plugin?
              Trustin Lee Apprentice

              Thanks ALR for sharing your code: http://tinyurl.com/7wjv78

              Are the callbacks called only when an installed AnnotationPlugin is described in the same deployment, or are they called regardless of whether the installed plugins are described in a different deployment (i.e. different JAR / different beans.xml)?

              • 4. Re: How to add Annotation Plugin?
                Trustin Lee Apprentice

                Just for the record, here's ALR's blog post which explains this topic more in detail: http://tinyurl.com/9wwgx7

                • 5. Re: How to add Annotation Plugin?
                  Andrew Rubinger Master

                   

                  "trustin" wrote:
                  Thanks ALR for sharing your code: http://tinyurl.com/7wjv78


                  I put it out there just hoping you'd find it. :)

                  "trustin" wrote:
                  Are the callbacks called only when an installed AnnotationPlugin is described in the same deployment, or are they called regardless of whether the installed plugins are described in a different deployment (i.e. different JAR / different beans.xml)?


                  The callbacks are added for any deployment under the same Controller.

                  S,
                  ALR

                  • 6. Re: How to add Annotation Plugin?
                    Andrew Rubinger Master

                     

                    "ALRubinger" wrote:
                    The callbacks are added for any deployment under the same Controller


                    So beware, you're actually altering MC's behaviour. I believe Ales made some mention of considering whether these callbacks should be made by default (so this bit wouldn't be needed)?

                    S,
                    ALR

                    • 7. Re: How to add Annotation Plugin?
                      Trustin Lee Apprentice

                       

                      "ALRubinger" wrote:
                      "ALRubinger" wrote:
                      The callbacks are added for any deployment under the same Controller

                      So beware, you're actually altering MC's behaviour. I believe Ales made some mention of considering whether these callbacks should be made by default (so this bit wouldn't be needed)?


                      If it modifies MC's global behavior, then I think it should be part of MC. Otherwise each 3rd party integration module will end up with trying to add the same annotation plugin. Or... I might be missing something. ;-)

                      • 8. Re: How to add Annotation Plugin?
                        Ales Justin Master

                         

                        "trustin" wrote:

                        If it modifies MC's global behavior, then I think it should be part of MC. Otherwise each 3rd party integration module will end up with trying to add the same annotation plugin. Or... I might be missing something. ;-)

                        I don't think this should be made directly into MC code.
                        Since you can easily do it via API or xml (as shown).

                        What I meant was to put this xml code in some high (early) deployment.
                        e.g. in JBossAS we should put it next to beans deployers

                        And I'll probably do this asap - in JBossAS and in MC demos.

                        • 9. Re: How to add Annotation Plugin?
                          Carlo de Wolf Master

                          This bit:

                          <bean name="AnnotationHandlerFactory">
                           <constructor factoryClass="org.jboss.kernel.plugins.annotations.BeanAnnotationAdapterFactory" factoryMethod="getInstance" />
                           </bean>
                           <bean name="AnnotationHandler">
                           <constructor factoryMethod="getBeanAnnotationAdapter">
                           <factory bean="AnnotationHandlerFactory"/>
                           </constructor>
                           <incallback method="addAnnotationPlugin" />
                           <uncallback method="removeAnnotationPlugin" />
                           </bean>

                          must go into the bootstrap. https://jira.jboss.org/jira/browse/JBAS-6514