[jboss-dev-forums] [Design the new POJO MicroContainer] - BeanAnnotationAdapter/AnnotationPlugin

kabir.khan@jboss.com do-not-reply at jboss.com
Wed Aug 12 13:33:48 EDT 2009


1)
The BeanAnnotationAdapter currently does this for each bean class/constructor/property/parameter:


  | AnnotatedInfo info = class/constructor/property
  | MetaDataRetrieval retrieval = //MDR for class/constructor/property/parameter
  | List<BeanAnnotationPlugin> list = //get plugins for class/constructor/property/parameter
  | for (AnnotationPlugin plugin : list)
  |    plugin.applyAnnotations(info, retrieval)
  | 
Then the plugin does the following:

  | public abstract class AbstractAnnotationPlugin<T extends AnnotatedInfo, C extends Annotation> extends BaseMetaDataAnnotationPlugin<T, C> implements AnnotationPlugin<T, C>
  | {
  |    public final void applyAnnotation(T info, MetaData retrieval, MetaDataVisitor visitor) throws Throwable
  |    {
  |       Class<C> annotationClass = getAnnotation();
  |          C annotation = retrieval.getAnnotation(annotationClass);
  |          if (annotation == null)
  |          {
  |             return;
  |          }
  | 	 //create metadata from annotation
  |    }
  | }
  | 
So every class/constructor/property results in a call to MDR.getAnnotation() for each plugin regardless of if annotations exist or not. Would it not make more sense to do something like this instead, which would only hit the MDR.getAnnotation() when there actually are any annotations? 

  | AnnotatedInfo info = class/constructor/property
  | MetaDataRetrieval retrieval = //MDR for class/constructor/property
  | Map<Annotation, AnnotationPlugin> map = //get plugins for class/constructor/property
  | for (Annotation annotation : info.getAnnotations()){
  |    AnnotationPlugin plugin = map.get(annotation);
  |    if (plugin != null)
  |       plugin.applyAnnotations(info, retrieval);
  | }
  | 

2)
For the web beans work the annotation types of the binding types are not known in advance, and so the plugins can not easily be plugged in to the framework. I would like to extend it to accommodate this better as I am currently checking the annotations myself in a custom DescribeAction.

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

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



More information about the jboss-dev-forums mailing list