Dynamically Access & Call An EJB From Another EJB?

S

Steve

Is there a way to dynamically access and call an EJB from another EJB?
For example, can a session bean read a file with information about
another session bean without hardcoding information about the second
bean in the first bean's .java bean class or its .xml descriptor files? Can
some form of reflection or introspection be used?

Thanks.

Steve
 
J

John C. Bollinger

Steve said:
Is there a way to dynamically access and call an EJB from another EJB?

What, exactly, do you want to do?
For example, can a session bean read a file with information about
another session bean without hardcoding information about the second
bean in the first bean's .java bean class or its .xml descriptor files? Can
some form of reflection or introspection be used?

It sounds like what you are trying to do might be at least partially
solved by implementing polymorphic EJBs. (Actually, you already have
them: every EJB home interface extends EJBHome, every remote interface
extends EJBObject, etc. You can always access bean implementations via
these interfaces, albeit perhaps not usefully.) You can always type a
reference to an EJB implementation object according to any interface it
implements, and invoke methods on it via that interface. You can also
dynamically construct JNDI names by which to look up home interfaces,
which can also be polymorphic. You can create a session bean that
obtains other bean implementations for you, based on whatever criteria
and algorithms you like.

What you cannot do is ever use a bean that you do not, somewhere,
declare a reference to in a deployment descriptor. You can hide the
lookup and deployment information in a single session bean, for
instance, but at least that one bean has to know about all the beans you
might want to access. This is inherent in the EJB model.


John Bollinger
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top