I have the following implementation of Visitor:
public class RecipientsGenerator implements RecipientTypeVisitor<List<Integer>>{
//Spring bean
private RecipientService<?> recipientService;
//Spring bean
private DynamicGroupService dynamicGroupService;
public List<Integer> visit(RecipientSetType t) {
//Impl
}
public List<Integer> visit(DynamicGroupType t) {
//Impl
}
public List<Integer> visit(StaticGroupType t) {
//Impl
}
}
and the visitor interface itself:
public interface RecipientTypeVisitor<ReturnType> {
public ReturnType visit(RecipientSetType t);
public ReturnType visit(DynamicGroupType t);
public ReturnType visit(StaticGroupType t);
}
I need to use this RecipientGenerator within a controller in order to show recipients identifiers.
private List<Integer> getRecipientIds() {
RecipientType t;
//obtaining the type
RecipientTypeVisitor<?> visitor = new RecipientsGenerator();
return (List<Integer>) t.accept(visitor);
}
My question is, what is the better way to obtain the instances of the services?
-
(We don't put the Visitor into a spring config)
ApplicationContext ctx = ContextLoader.getCurrentWebApplicationContext(); ctx.getBean("dynamicGroupService");
-
We put it into a spring config and inject the services. But in that case we couldn't just apply
new RecipientsGenerator();to create the intance of the visitor.
Aucun commentaire:
Enregistrer un commentaire