1 Reply Latest reply on Aug 28, 2008 10:26 AM by Carlo de Wolf

    Annotation processing without top-level annotation

    Emanuel Muckenhuber Master

      It seems that we are missing one use case of annotation processing.

      e.g. if you specify a stateful bean in the ejb-jar.xml and have a bean without a top-level annotation like:

      public class RemoveBean
      {
       @Remove
       public void remove()
       {
       }
      }
      


      As it is now the Stateful annotation processor requires a top-level @Stateful annotation to be able to create the metadata.
      Therefore the annotation deployer only looks for those top-level annotations - which makes sense, as this annotation is required to create the correct metaData with ejbName and ejbClass.

      To work around this problem we would need to skip this top-level processing and create the metaData based on the xml metaData.

      So in more detail what needs to be added to the JBoss50Creator is something like:

       public JBoss50MetaData create(Collection<Class<?>> classes)
       {
       // Create meta data
       JBoss50MetaData metaData = create();
      
       for(EnterpriseBeanMetaData bean : ejbJarMetaData.getEnterpriseBeans())
       {
       Class<?> ejbClass = classLoader.loadClass(bean.getEjbClass());
       if(! classes.contains(ejbClass))
       {
       if(bean.isSession())
       {
       SessionBeanMetaData sb = (SessionBeanMetaData) bean;
       JBossSessionBeanMetaData sessionBean = new JBossSessionBeanMetaData();
       sessionBean.setEjbName(sb.getEjbName());
       sessionBean.setEjbClass(sb.getEjbClass());
       if(sb.isStateful())
       {
       StatefulProcessor processor = new StatefulProcessor(finder);
       sessionBean.setSessionType(SessionType.Stateful);
       processor.process(sessionBean, ejbClass);
       metaData.getEnterpriseBeans().add(sessionBean);
       }
       else
       {
       sessionBean.setSessionType(SessionType.Stateless);
       // ...
       }
       }
       else if(bean.isMessageDriven())
       {
       // ...
       }
       }
       }
      
       processMetaData(classes, metaData);
       return metaData;
       }
      


      This (not compiled prototype) basically processes every class defined in the xml if not already picked up by the annotationDeployer.
      I think this should be handled differently in future, but i would consider that as last minute workaround :)