[Design the new POJO MicroContainer] - BeanAnnotationAdapter/AnnotationPlugin
by kabir.khan@jboss.com
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
16 years, 7 months
[Design the new POJO MicroContainer] - Re: Does ScopeKey need to maintain a sorted (in ScopeLevel.l
by smarlow@redhat.com
"adrian(a)jboss.org" wrote :
| 2) The other is as I mention above. Use the ScopeKey as the builder class
| and retrieve a more optimizated key for internal use within the MDR.
|
| e.g. something like:
|
| | public class ScopeKey
| | {
| | ...
| |
| | Object getOptimzedKey() {} // Key for use at runtime
| | }
| |
|
| In fact (1) and (2) are just variations on the same theme, with (2) potentially
| being more optimal.
|
I'm trying to do (2) as follows.
| public class ScopeKey
| {
| ...
|
| /**
| * The returned ScopeKey is immutable and optimized for use at runtime.
| * @return Optimized immutable ScopeKey
| */
| public ScopeKey getOptimizedKey()
| {
| return new UnmodifiableScopeKey(this);
| }
|
| }
|
Where UnmodifiableScopeKey is similar to the code that I previously posted.
There is a dependency between UnmodifiableScopeKey + ScopeKey that needs to be manually maintained but maybe I could test for that in a UnmodifiableScopeKey unit test. UnmodifiableScopeKey extends ScopeKey and overides all of the public ScopeKey methods.
The (work in progress) UnmodifiableScopeKey source is here http://pastebin.com/m5d484e25
Does UnmodifiableScopeKey work for everyone? I assume this will work as the optimizedKey.
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4249231#4249231
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4249231
16 years, 7 months