[jboss-dev-forums] [Design of EJB 3.0] - Annotation processing without top-level annotation

emuckenhuber do-not-reply at jboss.com
Thu Aug 28 10:08:56 EDT 2008


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 :)

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4173076#4173076

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4173076



More information about the jboss-dev-forums mailing list