users@glassfish.java.net

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

From: Witold Szczerba <pljosh.mail_at_gmail.com>
Date: Mon, 9 Jul 2007 20:00:13 +0200

So many years of EJB and Java Enterprise and nobody though about
referencing collection of objects implementing same interface :(
What you said about ObjectFactory seems interesting, I didn't know
about custom resources, This is too bad one have to accomplish special
steps (registering custom resource) before application can use this.
That means one more step before new application server is ready for
.ear to deploy.

2007/7/9, Mahesh Kannan <Mahesh.Kannan_at_sun.com>:
>
> 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