Oops! I just realized that I didn't actually answer your question. What
you're looking for is actually sort of tricky. "findXXX" is (sort of)
analogous to "get(Object o)" in the Collection interface. Now, if I had:
public class MyCollection implements Collection
{
// ...
}
and
public class MySuperCoolCollection extends MyCollection
{
// ...
}
...you wouldn't expect a get() on a MyCollection to return everything in
MySuperCoolCollection as well. But this is what you're asking for when you
ask for a generic findXXX() method in the base class. Luckily, since EJBHome
objects are basically singleton objects, we can probably accomplish
something along the lines of what you're looking for....
public class CarProxy
{
private EJBHome _myEJBHome;
private Method _myFinderMethod;
private static Hashtable _myChildFindByNames = new Hashtable(89);
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 findByName method
Class[] argTypes = { String.class };
_myFinderMethod = ejbHomeClass.getMethod( "findByName", argTypes );
// Save the finder method in our collection of finder methods
_myChildFindByNames.put( _myEJBHome, _myFinderMethod );
}
public Car findByPrimaryKey( CarPK carPK )
{
Object[] args = { carPK };
return _myFinderMethod.invoke( _myEJBHome, args );
}
public Collection findByName( String name )
{
ArrayList resultSet = new ArrayList();
Enumeration keys = _myChildFindByNames.keys();
while( keys.hasMoreElements() )
{
EJBHome ejbHome = (EJBHome)keys.nextElement();
Method finderMethod = (Method)_myChildFindByNames.get( ejbHome
);
Collection results = (Collection)finderMethod.invoke( ejbHome,
name );
resultSet.addAll( results );
}
return resultSet;
}
}
public class SportsCarProxy
{
public SportsCarProxy()
{
super( "SportsCarHome" );
}
}
This probably isn't exactly right, but I think it's a good avenue for what
you're trying to accomplish. If anyone out there has any bright ideas of
what to do here, join in the fun...
KurtC
===========================================================================
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".