Hi.

N.B.: This is a generic EJB question, not a JBoss-specific
      question. Ignore it if you wish.

I'm curious if it is possible to have EJBs implement interfaces. In my
case, I'd like to create a bunch of different session beans that have
the same method names. In other words, I would like to replace

SpecificBeanHome lHome 
      = (SpecificBeanHome) lContext.lookup( "SpecificBean's JNDI name" );

with

GenericBeanHome lHome 
      = (GenericBeanHome) lContext.lookup( beanNameInAString );

...where beanNameInAString is set to the JNDI name of some session
bean implementing the GenericBean interface. I would define methods
foo(), bar(), etc. in the GenericBean interface, implement them in the
bean, and would be able to call foo() or bar() on the bean from the
GenericBean interface. This would mean that I could avoid hard-coding
the specific type of the bean in the code.

I tried the naive method: defining an interface and adding it to 
a bean's "extends" list. That didn't work. (I've omitted the details
because I assumed that that was far too naive to work).

I've checked a few books; the only one that seems to bridge the issue
is the O'Reilly EJB book. The "Implementing a Common Interface"
chapter discusses "[using] a common interface to ensure consistency
between the bean class and the remote interface" --- but that isn't
quite what I want.

Is there some way of addressing multiple beans through a user-defined
interface?

Thanks in advance,

--Joe

Attachment: pgp00000.pgp
Description: PGP signature

Reply via email to