java ee - CDI as a factory? -


i have endpoint on jax-rs java ee application:

public class searchendpoint implements isearchendpoint  {      @inject protected searchservice searchservice;      @override     public response search()     {         return response.ok().entity(this.searchservice.search()).build();     }  } 

in searchservice's search method:

public class searchservice {      @inject private queryvisitor visitor;      public list<?> search() {         (expression<?> group : groups)             group.accept(this.visitor);     } } 

and in queryvisitor,

@override public esentitypathpointer<?> visit(expression<?> expr, esentitypathpointer<?> context) {     switch ((entitytype)expr.getmetadata().getelement())     {         case digitalinput:             if (context == null)                 context = new digitalinputesentitypathpointer();             break;         case followupactivity:             if (context == null)                 context = new followupactivityesentitypathpointer();             break;         case ...;     }     return context; } 

so, cdi injects searchservice on jax-rs endpoint implementation, cdi injects queryvisitor in injected searchservice.

so, you're able guess basicly queryvisitor.visit acts factory. according entitytype enum value creates esentitypathpointer<?> object or another.

i'd these objects created using cdi. i've read bit it, nevertheless i'm not quite able figure out how this.

any ideas?

try following:

somebean bean = cdi.current().select(somebean.class).get(); 

using qualifiers? try following:

somebean bean = cdi.current().select(somebean,                                       new annotationliteral<qualifier1>(){},                                       new annotationliteral<qualifier2>(){}).get(); 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -