users@glassfish.java.net

Re: injecting the collection of EJBs, not the specific one, is that possible?

From: Mahesh Kannan <Mahesh.Kannan_at_Sun.COM>
Date: Mon, 09 Jul 2007 07:27:07 -0700

On Jul 9, 2007, at 4:30 AM, Witold Szczerba wrote:

> Hi there,
> I know this question is not Glassfish specific, but Java EE 5 in
> general, but I do not know where to ask this: is this possible to use
> something like @EJB to inject session bean, but I would like to inject
> all the session beans implementing given interface? (not the only
> one).
No, this is not possible. The closest that I can think of is to do
explicit jndi lookup(s) to get references of all such session beans
and add to the collection.
Note that you can use @Resource and use a custom ObjectFactory, but
the ObjectFactory will have to do multiple lookup(s) itself to
populate the collection.,

Thanks,
--Mahesh


> I would like to create session beans implementing something like:
>
> public void process(Operation operation);
>
> I could implement each operation type in separate session bean, then
> inject all of them and use like this:
> Collection<OperationLocal> operationBeans;
> ...
> Operation someOperation = ....;
> for (OperationLocal operationBean : operationBeans) {
> operationBean.process(someOperation);
> }
>
> Each implementation could internally check if it is interested in that
> operation and ignore it if that is so.
>
> So, is this possible to inject collection of session beans
> implementing given interface instead of only one per @EJB annotation?
>
> Thanks,
> Witek
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>