Can EJBs do polymorphism?
My exact question is: I have an abstract base class called BaseClass, and a
bunch of subclasses, let's call them SubClass1, SubClass2.... All classes
have a method execute().
I used to have Java code doing this:

BaseClass bc;
bc = (BaseClass)Class.forName(subClassName).newInstance();
bc.execute();

When the parameter "className" is the qualified path of any of the
subclasses, then by calling bc.execute(), that particular subclass's
execute() method is actually run. By doing this, I don't have to know
exactly which subclass it is but run its execute() method. Can EJB do the
same thing?
The way EJB obtains a home interface doesn't seem to allow me to Cast an
object of subclass into the base class's home interface like below. I got an
java.lang.ClassCastException.

Object objref = initialContext.lookup(subClassJNDIName);
(BaseClassHome)PortableRemoteObject.narrow(objref, BaseClassHome.class);


So Basically how can I use EJB to achieve the same thing as my old code? Any
help is appreciated.

Li

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to