4 Replies Latest reply: Jun 26, 2012 4:34 PM by Michael Anstis RSS

Look up beans with qualifier with value members

Jervis Liu Apprentice

Hi, I have a use case in which I need to look up beans on the client side using qualifier. The qualifier has value members. I defined qualifier annotation like below:

 

@Qualifier

@Retention(RetentionPolicy.RUNTIME)

@Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.TYPE})

public @interface NameToken {

    String value();

}

 

Then I have NameToken on several Activity classes, for example:

 

@Dependent

@NameToken("MyAdminArea")

public class MyAdminAreaActivity implements Activity {

 

}

 

When I use following code to look up Activity, I got a "

Caused by: org.jboss.errai.ioc.client.container.IOCResolutionException: multiple matching bean instances for: org.drools.guvnor.client.mvp.Activity" exception.

 

 

        NameToken qual = new NameToken() {

            public Class annotationType() {

              return NameToken.class;

            }

 

            @Override

            public String value() {

                // TODO Auto-generated method stub

                return placeRequest.getNameToken();

            }

          };

       

        IOCBeanDef();

 

    for (Annotation a :qualifiers) {

      matchFrom.add(a.annotationType().getName());

    }

 

    for (Annotation a : annotations) {

      matchTo.add(a.annotationType().getName());

    }

 

    return matchFrom.containsAll(matchTo);

  }

 

The matches method only checks if the IOCBean has same annotation name as the qualifier, but does not check the member value of the qualifier.

I wonder if I am missing anything here or if there is alternative way to get this working? Thanks.

 

Cheers,

Jervis