Why do not introduce AnnotationInstanceProvider from Solder or Deltaspike?
by fluids liu
With pure cdi api,in every module we have to create the same annotation
literal classes. For example:
In module A,we have an observes method:
public void hundleCommand(@Observes @Named("shell") MyCommand command){...}
In module B and C,we should send event to module A:
@Inject
Event<MyCommand> event;
@Override
public void execute() throws Exception {
event.select(new NamedLiteral("shell")).fire(new MyCommand());
}
In order to send event,we must define a literal type:
public class NamedLiteral extends AnnotationLiteral<Named> implements
Named
{
private static final long serialVersionUID = -1457223276475846060L;
private final String value;
public NamedLiteral(String value)
{
this.value = value;
}
public NamedLiteral()
{
value = "";
}
@Override public String value()
{
return value;
}
}
Why cdi do not define a util class to simplify those as following:
@Inject
Event<MyCommand> event;
@Override
public void execute() throws Exception {
Map<String, String> values=new HashMap<String, String>();
values.put("value", "shell");
Named commandQualifier = AnnotationInstanceProvider.of(Named.class,
values);
event.select(commandQualifier).fire(new MyCommand());
}
12 years