title: Dynamically fire CDI event with qualifier with members
body: <p>I'm trying to use CDI events in my backend services, on JBoss AS6 - ideally with maximum code reuse.</p>
  
  <p>I can see from the docs I can cut down on the qualifier annotation classes I have to create by using a qualifier with members e.g.</p>
  
  <pre><code>@Qualifier
  @Retention(RUNTIME)
  @Target({METHOD, FIELD, PARAMETER, TYPE})
  public @interface Type {
      TypeEnum value();
  }
  </code></pre>
  
  <p>I can observe this with</p>
  
  <pre><code>public void onTypeAEvent(@Observes @Type(TypeEnum.TYPEA) String eventMsg) {...}
  </code></pre>
  
  <p>So far, so good. However, to further cut down on the number of classes needed, I want to have one EventFirer class, where the qualifier of the event thrown is dynamic. Not a problem with qualifiers without members:</p>
  
  <pre><code>public class DynamicEventFirer {
  
      @Inject @Any private Event&lt;String&gt; event;
  
      public void fireEvent(AnnotationLiteral&lt;?&gt; eventQualifier){
          event.select(eventQualifier).fire("FIRED"); 
      }
  }
  </code></pre>
  
  <p>then called like</p>
  
  <pre><code>dynamicEventFirer.fireEvent(new AnnotationLiteral&lt;Type&gt;() {});
  </code></pre>
  
  <p>But what about when the qualifier should have members? Looking at the code for AnnotationLiteral, it's certainly setup for members, and the class element comment has the example:</p>
  
  <pre><code>new PayByQualifier() { public PaymentMethod value() { return CHEQUE; } }
  </code></pre>
  
  <p>This makes sense to me - you're overriding the value() method of the annotation interface. However, when I tried this myself:</p>
  
  <pre><code>dynamicEventFirer.fireEvent(new AnnotationLiteral&lt;Type&gt;() {
      public TypeEnum value() {
          return TypeEnum.TYPEA;
      }
  });
  </code></pre>
  
  <p>I receive the exception</p>
  
  <pre><code>java.lang.RuntimeException: class uk.co.jam.concept.events.MemberQualifierEventManager$1 does not implement the annotation type with members uk.co.jam.concept.events.Type
      at javax.enterprise.util.AnnotationLiteral.getMembers(AnnotationLiteral.java:69)
      at javax.enterprise.util.AnnotationLiteral.hashCode(AnnotationLiteral.java:281)
      at java.util.HashMap.getEntry(HashMap.java:344)
      at java.util.HashMap.containsKey(HashMap.java:335)
      at java.util.HashSet.contains(HashSet.java:184)
      at org.jboss.weld.util.Beans.mergeInQualifiers(Beans.java:939)
      at org.jboss.weld.bean.builtin.FacadeInjectionPoint.&lt;init&gt;(FacadeInjectionPoint.java:29)
      at org.jboss.weld.event.EventImpl.selectEvent(EventImpl.java:96)
      at org.jboss.weld.event.EventImpl.select(EventImpl.java:80)
      at uk.co.jam.concept.events.DynamicEventFirer.fireEvent(DynamicEventFirer.java:20)
  </code></pre>
  
  <p>Can anyone see what I'm doing wrong? MemberQualifierEventManager is an ApplicationScoped bean which calls on DynamicEventFirer to fire the event.</p>
  
  <p>Thanks,
  Ben</p>