Suppose that Act is a class which needs to maintain a reference to an
instance of type Trans. Suppose that Join and Split are subclasses of
Trans and the the Act reference can be either a Join instance or a Split
instance. I am having trouble implementing the beans for this
relationship.
The following are the classes I am interested in.
public interface ActHome extends EJBHome{ \\.... }
public interface Act extends EJBObject
{
public Trans getTrans() throws RemoteException;
public void setTrans(Trans t) throws RemoteException;
\\......
}
public interface Trans extends EJBObject{
\\...}
public interface Join extends Trans{\\...}
public interface Split extends Trans{\\...}
One way to do this would be as follows:
public ActBean implements EntityBean
{
private int myTransKey;
private int myTransType;
public Trans getTrans() throw RemoteException
{
if(myTransType == Trans.JOIN)
{
\\Get JoinHome and look up Join object using myTransKey
JoinHome home = (JoinHome) ctx.lookup("JoinHome");
Join ac = null;
try {
ac = (Join) home.findByPrimaryKey(myTransKey);
return ac;
}
catch {\\...}
}
else if(myTransType == Trans.SPLIT)
{
\\Get SplitHome and look up
SplitHome home = (SplitHome) ctx.lookup("SplitHome");
Join ac = null;
try {
ac = (Split) home.findByPrimaryKey(myTransKey);
return ac
}
catch{\\....}
}
}
The big problem with this approach is that it requires knowing all the
Trans subclasses at the time the code is written. Anytime I want to add
a new class I will need to add code to the ActBean. For example if I
add Trans.OR I will need to and another "else if" clause above.
Any recommendations on a better way to do this?
dan
===========================================================================
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".