You don't expect my hare-brained ideas to actually *work*, do you? :-)
If you want to try it out, the client would look something like this
(remember to insert proper exception handling code and blah blah blah):
public class CarClient
{
// ...
// Get CarProxy. See below...
CarProxy carProxy = new CarProxy();
Car car = carProxy.findByPrimaryKey(CarPK carPK);
// At this point, "car" could be a reference to
// a Car, or a SportsCar, or any other subclass...
// ...
}
...where we have something like this:
public class CarProxy
{
private EJBHome _myEJBHome;
private Method _myFinderMethod;
public CarProxy()
{
this( "CarHome" );
}
public CarProxy( String jndiHomeName )
{
// Get JNDI context (app-server specific code here)
Context context = new InitialContext();
// Get EJBHome object
Object o = context.lookup( "CarHome" );
// Perform CORBA narrowing voodoo
_myEJBHome = (EJBHome)PortableRemoteObject.narrow( o, EJBHome.class
);
// Get the metadata for this EJB (we need to do all this
// because EJBHome doesn't define findByPrimaryKey() )
EJBMetaData ejbMetaData = ejbHome.getEJBMetaData();
// Get the Home class for the EJB from the metadata
Class ejbHomeClass = ejbMetaData.getHomeInterfaceClass();
// Get the finder method
Class[] argTypes = { CarPK.class };
_myFinderMethod = ejbHomeClass.getMethod( "findByPrimaryKey",
argTypes );
}
public Car findByPrimaryKey( CarPK carPK )
{
Object[] args = { carPK };
return _myFinderMethod.invoke( _myEJBHome, args );
}
}
public class SportsCarProxy
{
public SportsCarProxy()
{
super( "SportsCarHome" );
}
}
Again, note that this all assumes that certain other inheritance
relationships are in place: SportsCarPK must extend CarPK, and SportsCarBean
should extend CarBean, and whatever else you may need.
KurtC
-----Original Message-----
From: Tom Lepski [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, August 08, 2000 1:16 AM
To: [EMAIL PROTECTED]
Subject: Re: A design question...
Hi Kurt,
Thanks for the pointer but I'm still clueless about the client side code.
Could you please tell me how would a client can get all the cars (including
SportsCars) by calling just one findByXXX() method.
thanks for your help,
Tom.
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".