2 Replies Latest reply on Dec 1, 2011 8:53 PM by ahhughes

    Programmatic Lookup with incomplete Qualifiers

    ahhughes

      Hi Again,


      I'm stuck and need help. If I have the following Qualified bean...


      @Named("ClarkKent")
      @SuperHeroType(SuperMan.class)
      public class SuperManBean implements SuperHeroAlterEgo<SuperMan> {}
      



      Question



      How can I programmatically lookup SuperManBean with either the String ClarkKent OR superHero.getClass(), which is of course SuperMan.


      My Broken Code...



      I have tried to lookup by NameLiternal only (I can't provide a SuperHeroTypeLiteral here)


      @Inject @Any Instance<SuperHeroAlterEgo<SuperHero>> source;
      source.select(new NamedLiteral("ClarkKent")); //and similar for 
      



      I have also tried by new SuperHeroTypeLiteral(superHero.getClass()) only - I dont have a NamedLiternal here


      @Inject @Any Instance<SuperHeroAlterEgo<SuperHero>> source;
      source.select(new SuperHeroTypeLiteral(superHero.getClass())); //and similar for 
      



      But both have unsatisfied dependencies. Seems that you need both qualifiers no @Any and nothing else :'(


      Help would be excellent :)

        • 1. Re: Programmatic Lookup with incomplete Qualifiers
          alesj

          What's wrong with


          @Inject @Named(ClarkKent) SuperHeroAlterEgo superman;

          • 2. Re: Programmatic Lookup with incomplete Qualifiers
            ahhughes

            Ales Justin wrote on Dec 01, 2011 04:30:


            What's wrong with

            @Inject @Named(ClarkKent) SuperHeroAlterEgo superman;



            Thanks Justin, but that doesn't correlate to my question. That's not programmatic lookup and at runtime I have either...


            String someonesName = ...;
            



            OR


            Class<? extends SuperHero> superHeroClass = ...;
            



            NEVER BOTH


            Which means I can't do programmatic lookup with ALL qualifiers, only ever one of them (Named or SuperHeroType).


            I'll keep hoping there is a solution for this.


            Cheers
            --AH