4 Replies Latest reply on Feb 20, 2009 8:22 AM by bryan.kearney

    Accessing EJB's with custom annotations.

    bryan.kearney

      I dont know if this is an EJB or a Microcontainer question, but I will post it here. I am working with JBoss 5.0 GA. I would like to be able to annotate my session beans with a custom annotation (say @BK) and be able to interrogate the EJBs with this annotation at load time. Using interceptors is too late, since I do not get access to the object until contstruction. I looked at the @Install annotation from the beans metadata to capture beans when they are loaded but that is not viable. Is my best path to write a custom deployer? It seems like the doco hints at being able to add custom helpers/callbacks but the doco is not complete.

      My use case is to have a registry of beans which implement a command pattern. So, at runtime a single controller can access the registry to determine which command to call.

        • 1. Re: Accessing EJB's with custom annotations.
          alesj
          • 2. Re: Accessing EJB's with custom annotations.
            bryan.kearney

            I have seen it.. but does this work for EJB's as well? I ask becuase I have an EJB which looks like this:


            @Command(commandName = "PingBackend")
            @AuditType(AuditLogType.PING_BACKEND)
            @Stateless
            public class PingBackendCommand extends VdcCommandBase {
            ....


            I then created an Annotation Resolver:

            public class CommandAnnotationPlugin extends ClassAnnotationPlugin{

            private Log log = LogFactory.getLog(CommandAnnotationPlugin.class);

            public CommandAnnotationPlugin() {
            this(Command.class) ;
            log.debug("************************************************************");
            }

            protected CommandAnnotationPlugin(Class annotation) {
            super(annotation);
            // TODO Auto-generated constructor stub
            }


            protected List<? extends MetaDataVisitorNode> internalApplyAnnotation(ClassInfo info, Command annotation, BeanMetaData beanMetaData) throws Throwable
            {
            log.debug("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");
            log.debug("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");


            I see the Stars at creation, but never the Percents. I added another bean which implements the same code to register a custom builder

            BeanAnnotationAdapter beanAnnotationAdapter = BeanAnnotationAdapterFactory.getInstance().getBeanAnnotationAdapter();
            //String beanAnnotationAdapterBindName = MC_NAMESPACE_EJB3 + "BeanAnnotationAdapter";
            String beanAnnotationAdapterBindName = "CommandBeanAnnotationAdapter" ;
            BeanMetaDataBuilder bmdb = BeanMetaDataBuilder.createBuilder(beanAnnotationAdapterBindName, beanAnnotationAdapter.getClass().getName()) ;
            bmdb.addMethodInstallCallback("addAnnotationPlugin");
            bmdb.addMethodUninstallCallback("removeAnnotationPlugin");


            No matter if I put it in the ear, or in the deployer, I it seems like it never matches up the annotation. Is there somehting else I need to do?

            -- bk


            • 3. Re: Accessing EJB's with custom annotations.
              alrubinger

              Ah, you're tackling this from the other end.

              ejb3-mc integration as described in the blog post is how I enabled @EJB injection into MC Beans.

              Here you're trying for custom annotation support on EJBs. As EJB bean impl classes are not installed as MC beans, the annotation plugin is not getting called.

              To complete the equation we'd need to revisit the EJB injection framework to leverage MC a bit more to do both this example, and stuff like @Inject MC beans into EJBs.

              S,
              ALR

              • 4. Re: Accessing EJB's with custom annotations.
                bryan.kearney

                Well.. at least i dont feel too bad about not being able to follow the blog. So.. how does the jbossws stuff accomplish this? This seems like something in the deployers/jbossws.deployer is intercepting the EJB deployment and adding endpoints into a web application. It seems like all the bits to do it are "there".

                -- bk