[jboss-dev-forums] [JBoss Microcontainer Development] - Re: Adding getAnnotationsAnnotatedWith() to MDR
kabir.khan@jboss.com
do-not-reply at jboss.com
Mon Dec 7 10:23:52 EST 2009
"alesj" wrote : Why would you need this?
| I don't see anything similar in CachingMDC for other retrieveX methods.
|
The problem is that I want to only iterate over everything once, which means I have to create the annotations item myself, e.g.:
| @SuppressWarnings("unchecked")
| Cache<Class, AnnotationsItem> cached = cachedMetaAnnotations;
| if (cached == null)
| {
| AnnotationsItem item = retrieveAnnotations();
| if (item.getAnnotations().length > 0)
| {
| Map<Class<? extends Annotation>, List<AnnotationItem<?>>> annotations = new HashMap<Class<? extends Annotation>, List<AnnotationItem<?>>>();
| for (AnnotationItem<?> annotation : item.getAnnotations())
| {
| for (Annotation current : annotation.getAnnotation().annotationType().getAnnotations())
| {
| List<AnnotationItem<?>> annotationsForMeta = annotations.get(current.annotationType());
| if (annotationsForMeta == null)
| {
| annotationsForMeta = new ArrayList<AnnotationItem<?>>();
| annotations.put(current.annotationType(), annotationsForMeta);
| }
| annotationsForMeta.add(annotation);
| }
| }
|
| cached = factory.createCache(Class.class, AnnotationsItem.class, getFqn());
| for (Map.Entry<Class<? extends Annotation>, List<AnnotationItem<?>>> entry : annotations.entrySet())
| {
|
| AnnotationsItem basic = new BasicAnnotationsItem(null, entry.getValue().toArray(new AnnotationItem<?>[entry.getValue().size()] ));
| cached.put(entry.getKey(), basic);
| }
| }
| cachedMetaAnnotations = cached;
| }
| return cached.get(meta);
|
So, I need to create the annotations item myself. If I don't pass in a loader, the BasicAnnotationsItem will fail on isCachable() since that calls the loader. This problem will also occur if when I move the pre-indexing logic into AbstractMetaDataContext.
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4269371#4269371
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4269371
More information about the jboss-dev-forums
mailing list