[jboss-dev-forums] [JBoss Microcontainer Development] - Re: Non-public field properties

kabir.khan@jboss.com do-not-reply at jboss.com
Tue Nov 17 05:53:34 EST 2009


Although my tests for @Inject work fine now, I am not 100% sure I am using the right annotation plugins. Here's what I am doing for @Inject annotated constructors:


  | public class Jsr330InjectConstructorAnnotationPlugin extends ConstructorAnnotationPlugin<Inject>
  | {
  |    public static final Jsr330InjectConstructorAnnotationPlugin INSTANCE = new Jsr330InjectConstructorAnnotationPlugin();
  |    
  |    protected Jsr330InjectConstructorAnnotationPlugin()
  |    {
  |       super(Inject.class);
  |    }
  | 
  |    protected List<? extends MetaDataVisitorNode> internalApplyAnnotation(ConstructorInfo info, Inject annotation, BeanMetaData beanMetaData) throws Throwable
  |    {
  |       if (info.getParameters().length == 0)
  |          return null;
  |       if (beanMetaData instanceof AbstractBeanMetaData == false)
  |          throw new IllegalArgumentException("beanMetaData is not a AbstractBeanMetaData");
  |       
  |       AbstractConstructorMetaData constructor = new AbstractConstructorMetaData();
  | 
  |       List<ParameterMetaData> values = new ArrayList<ParameterMetaData>(info.getParameters().length);
  |       for (ParameterInfo parameter : info.getParameters())
  |          values.add(new AbstractParameterMetaData(Jsr330InjectionResolver.createValueMetaData(parameter.getParameterType().getType(), parameter.getUnderlyingAnnotations())));
  | 
  |       constructor.setParameters(values);
  |       ((AbstractBeanMetaData)beanMetaData).setConstructor(constructor);
  |       
  |       return Collections.singletonList(constructor);
  |    }
  | 
  |    @Override
  |    protected void internalCleanAnnotation(ConstructorInfo info, MetaData retrieval, Inject annotation,
  |          KernelControllerContext context) throws Throwable
  |    {
  |       if (context.getBeanMetaData() instanceof AbstractBeanMetaData == false)
  |          throw new IllegalArgumentException("beanMetaData is not a AbstractBeanMetaData");
  |       ((AbstractBeanMetaData)context.getBeanMetaData()).setConstructor(null);
  |    }
  | }
  | 

I see elsewhere that the ConstructorParameterAnnotationPlugin is used, which takes a set of Annotation2ValueMetaDataAdapters used to parse the parameters. However, Annotation2ValueMetaDataAdapters need to know which annotation is being used, which in the case of Annotation2ValueMetaDataAdapters is unknown, since the trigger is  looking for @Qualifier on the parameter annotations. 
Also, parameters might not have any annotations which is probably currently handled some other way for normal injection.

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

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



More information about the jboss-dev-forums mailing list