The old code is:
DbAccessFactory.java:
public class DbAccessFactory {
public DbAccessHome getHome(Hashtable p, boolean proxy) throws
NamingException {
DbAccessHome dbAccessHome = null;
try {
InitialContext ctx = new InitialContext(p);
if (proxy) {
dbAccessHome =
(DbAccessHome)PortableRemoteObject.narrow(ctx.lookup("ejb/DbAccessProxy"),DbAccessHome.class);
}
else {
dbAccessHome = (DbAccessHome)
PortableRemoteObject.narrow(ctx.lookup("ejb/DbAccess"), DbAccessHome.class);
}
}
finally {...}
return dbAccessHome;
}
}
DbAccessBean.java:
public class DbAccessBean implements SessionBean, DbAccess {...}
DbAccessProxyBean.java:
public class DbAccessProxyBean implements SessionBean, DbAccess {
private DbAccessHome siteAHome;
private DbAccessHome siteBHome;
public void ejbCreate()throws javax.ejb.CreateException {
try {
InitialContext ctx = new InitialContext();
siteAHome = (DbAccessHome)
PortableRemoteObject.narrow(ctx.lookup("ejb/SiteA"), DbAccessHome.class);
siteBHome = (DbAccessHome)
PortableRemoteObject.narrow(ctx.lookup("ejb/SiteB"), DbAccessHome.class);
}
catch (NamingException e) {...}
finally {...}
}
public long access() throws RemoteException {
DbAccess dbAccess = null;
if(isSiteA) {
dbAccess = siteAHome.create();
}
else {
dbAccess = siteBHome.create();
}
dbAccess.getData();
}
...
}
I tried to convert the code to:
public DbAccess getHome(Hashtable p, boolean proxy) throws NamingException {
DbAccess dbAccess = null;
InitialContext ctx = new InitialContext(p);
try {
if (proxy) {
dbAccess = (dbAccess) ctx.lookup(DbAccess.class.getName());
}
else {
dbAccess =(dbAccess) ctx.lookup(DbAccess.class.getName());
}
finally {...}
return dbAccess;
}
But how to differentiate the proxy beans if the lookup class is the same?
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3928564#3928564
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3928564
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
JBoss-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-user